Browse Source

修复编辑货源中的地区没有记忆功能问题

pull/1/head
徐飞洋 3 months ago
parent
commit
fd5867fa7c
  1. 65
      pages/seller/index.js
  2. 33
      pages/seller/index.wxml

65
pages/seller/index.js

@ -4863,6 +4863,49 @@ Page({
}); });
}, },
// 根据地区字符串查找对应的省市区索引
findRegionIndex(region) {
if (!region) return { provinceIndex: 0, cityIndex: 0, districtIndex: 0 };
const regionArray = region.split(' ').filter(item => item.trim() !== '');
if (regionArray.length < 3) return { provinceIndex: 0, cityIndex: 0, districtIndex: 0 };
const provinceName = regionArray[0];
const cityName = regionArray[1];
const districtName = regionArray[2];
// 查找省份索引
let provinceIndex = 0;
for (let i = 0; i < this.data.regionOptions.length; i++) {
if (this.data.regionOptions[i].name === provinceName) {
provinceIndex = i;
break;
}
}
// 查找城市索引
const province = this.data.regionOptions[provinceIndex];
let cityIndex = 0;
for (let i = 0; i < province.cities.length; i++) {
if (province.cities[i].name === cityName) {
cityIndex = i;
break;
}
}
// 查找区县索引
const city = province.cities[cityIndex];
let districtIndex = 0;
for (let i = 0; i < city.districts.length; i++) {
if (city.districts[i] === districtName) {
districtIndex = i;
break;
}
}
return { provinceIndex, cityIndex, districtIndex };
},
// 打开编辑货源的地区选择弹窗 // 打开编辑货源的地区选择弹窗
openEditRegionModal() { openEditRegionModal() {
// 通过全局数据控制自定义tab-bar的显示状态 // 通过全局数据控制自定义tab-bar的显示状态
@ -4871,18 +4914,28 @@ Page({
app.globalData.showTabBar = false; app.globalData.showTabBar = false;
} }
// 重置三级联动选择和搜索 // 获取当前编辑货源的地区
const currentRegion = this.data.editSupply.region;
// 查找地区对应的省市区索引
const { provinceIndex, cityIndex, districtIndex } = this.findRegionIndex(currentRegion);
// 获取对应的省市区数据
const province = this.data.regionOptions[provinceIndex];
const city = province.cities[cityIndex];
// 设置地区选择器状态
this.setData({ this.setData({
currentRegionMode: 'edit', currentRegionMode: 'edit',
regionSearchKeyword: '', regionSearchKeyword: '',
editRegionSearchKeyword: '', editRegionSearchKeyword: '',
filteredRegionOptions: [], filteredRegionOptions: [],
showSearchResults: false, showSearchResults: false,
selectedProvinceIndex: 0, selectedProvinceIndex: provinceIndex,
selectedCityIndex: 0, selectedCityIndex: cityIndex,
selectedDistrictIndex: 0, selectedDistrictIndex: districtIndex,
currentCities: this.data.regionOptions[0].cities, currentCities: province.cities,
currentDistricts: this.data.regionOptions[0].cities[0].districts, currentDistricts: city.districts,
showRegionSelectModal: true, showRegionSelectModal: true,
showTabBar: false // 隐藏底部tab-bar showTabBar: false // 隐藏底部tab-bar
}); });

33
pages/seller/index.wxml

@ -508,6 +508,14 @@
</view> </view>
</view> </view>
<!-- 搜索功能已移至弹窗内 --> <!-- 搜索功能已移至弹窗内 -->
<view style="font-size: 28rpx; font-weight: 500; color: #333; margin-bottom: 12rpx; margin-left: 10rpx;">地区</view>
<view bindtap="openCreateRegionModal" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block; background: white; position: relative; z-index: 1;">
<view style="display: flex; justify-content: space-between; align-items: center;">
<text>{{newSupply.region || '请选择省市区'}}</text>
<text style="color: #999;">▼</text>
</view>
</view>
<view style="font-size: 28rpx; font-weight: 500; color: #333; margin-bottom: 12rpx; margin-left: 10rpx;">价格</view> <view style="font-size: 28rpx; font-weight: 500; color: #333; margin-bottom: 12rpx; margin-left: 10rpx;">价格</view>
<input class="input" type="text" placeholder="请输入价格" bindinput="onInput" data-field="price" value="{{newSupply.price}}" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;" placeholder-style="font-size: 24rpx; color: #999; text-align: left;" catchtouchmove="true" bindtouchstart="onInputTouchStart" bindtouchmove="onInputTouchMove"></input> <input class="input" type="text" placeholder="请输入价格" bindinput="onInput" data-field="price" value="{{newSupply.price}}" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;" placeholder-style="font-size: 24rpx; color: #999; text-align: left;" catchtouchmove="true" bindtouchstart="onInputTouchStart" bindtouchmove="onInputTouchMove"></input>
@ -518,13 +526,6 @@
<input class="input" type="text" placeholder="请输入斤重" bindinput="onInput" data-field="grossWeight" value="{{newSupply.grossWeight || ''}}" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;" placeholder-style="font-size: 24rpx; color: #999; text-align: left;" catchtouchmove="true" bindtouchstart="onInputTouchStart" bindtouchmove="onInputTouchMove"></input> <input class="input" type="text" placeholder="请输入斤重" bindinput="onInput" data-field="grossWeight" value="{{newSupply.grossWeight || ''}}" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;" placeholder-style="font-size: 24rpx; color: #999; text-align: left;" catchtouchmove="true" bindtouchstart="onInputTouchStart" bindtouchmove="onInputTouchMove"></input>
<view style="font-size: 28rpx; font-weight: 500; color: #333; margin-bottom: 12rpx; margin-left: 10rpx;">地区</view>
<view bindtap="openCreateRegionModal" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block; background: white; position: relative; z-index: 1;">
<view style="display: flex; justify-content: space-between; align-items: center;">
<text>{{newSupply.region || '请选择省市区'}}</text>
<text style="color: #999;">▼</text>
</view>
</view>
<view style="display: flex; justify-content: space-between; margin-top: 20rpx; margin-bottom: 20rpx; gap: 20rpx;"> <view style="display: flex; justify-content: space-between; margin-top: 20rpx; margin-bottom: 20rpx; gap: 20rpx;">
<button bindtap="hideModal" style="flex: 1; height: 90rpx; line-height: 90rpx; background-color: #f5f5f5; color: #666; font-size: 30rpx; border-radius: 12rpx; margin: 0; display: flex; align-items: center; justify-content: center;">取消</button> <button bindtap="hideModal" style="flex: 1; height: 90rpx; line-height: 90rpx; background-color: #f5f5f5; color: #666; font-size: 30rpx; border-radius: 12rpx; margin: 0; display: flex; align-items: center; justify-content: center;">取消</button>
@ -591,7 +592,14 @@
</view> </view>
</view> </view>
<!-- 搜索功能已移至弹窗内 --> <!-- 搜索功能已移至弹窗内 -->
<view style="font-size: 28rpx; font-weight: 500; color: #333; margin-bottom: 12rpx; margin-left: 10rpx;">地区</view>
<view
class="region-picker input"
bindtap="openEditRegionModal"
style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;"
>
<text style="text-align: left;">{{editSupply.region || '请选择省市区'}}</text>
</view>
<view style="font-size: 28rpx; font-weight: 500; color: #333; margin-bottom: 12rpx; margin-left: 10rpx;">价格</view> <view style="font-size: 28rpx; font-weight: 500; color: #333; margin-bottom: 12rpx; margin-left: 10rpx;">价格</view>
<input class="input" type="text" placeholder="请输入价格" bindinput="onEditInput" data-field="price" value="{{editSupply.price}}" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;" placeholder-style="font-size: 24rpx; color: #999; text-align: left;"></input> <input class="input" type="text" placeholder="请输入价格" bindinput="onEditInput" data-field="price" value="{{editSupply.price}}" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;" placeholder-style="font-size: 24rpx; color: #999; text-align: left;"></input>
@ -603,14 +611,7 @@
<input class="input" type="text" placeholder="请输入斤重" bindinput="onEditInput" data-field="grossWeight" value="{{editSupply.grossWeight || ''}}" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;" placeholder-style="font-size: 24rpx; color: #999; text-align: left;"></input> <input class="input" type="text" placeholder="请输入斤重" bindinput="onEditInput" data-field="grossWeight" value="{{editSupply.grossWeight || ''}}" style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;" placeholder-style="font-size: 24rpx; color: #999; text-align: left;"></input>
<view style="font-size: 28rpx; font-weight: 500; color: #333; margin-bottom: 12rpx; margin-left: 10rpx;">地区</view>
<view
class="region-picker input"
bindtap="openEditRegionModal"
style="width: 100%; height: 90rpx; line-height: 90rpx; padding: 0 24rpx; font-size: 30rpx; border: 2rpx solid #eee; border-radius: 12rpx; box-sizing: border-box; margin: 0 auto 30rpx; display: block;"
>
<text style="text-align: left;">{{editSupply.region || '请选择省市区'}}</text>
</view>
<!-- 添加底部空白区域 --> <!-- 添加底部空白区域 -->
<view style="height: 20vh; background: transparent;"></view> <view style="height: 20vh; background: transparent;"></view>

Loading…
Cancel
Save