Commit fb44b462 by wangzhihui

fixed

1 parent 00356dec
...@@ -63,8 +63,52 @@ Page({ ...@@ -63,8 +63,52 @@ Page({
inputValue: '', inputValue: '',
keyWord: '', // 搜索关键词 keyWord: '', // 搜索关键词
searchTimer: null, // 防抖定时器 searchTimer: null, // 防抖定时器
isDialogShowing: false // Dialog显示状态 isDialogShowing: false, // Dialog显示状态
}, // 地址选择相关
regionData: [], // 原始的省市数据
regionPickerRange: [[], []], // pick-view 的列数据
regionPickerValue: [0, 0] // picker-view 的选中索引
},
onLoad() {
this.initRegionData()
},
// 获取高德省市数据
initRegionData() {
wx.request({
url: 'https://restapi.amap.com/v3/config/district?key=d22348363c34c266f772ae9b635eef2a&subdistrict=2',
method: 'GET',
success: (res) => {
if (res.data && res.data.status === '1' && res.data.districts.length > 0) {
const countryData = res.data.districts[0].districts || [];
// 格式化省份数据
const provinces = countryData.map(p => ({
name: p.name,
adcode: p.adcode,
cities: p.districts ? p.districts.map(c => ({
name: c.name,
adcode: c.adcode
})) : []
}));
// 初始化 picker-view 的第一列(省份)和第二列(第一个省份对应的城市)
const provinceNames = provinces.map(p => p.name);
const cityNames = provinces.length > 0 ? provinces[0].cities.map(c => c.name) : [];
this.setData({
regionData: provinces,
regionPickerRange: [provinceNames, cityNames],
regionPickerValue: [0, 0]
});
}
},
fail: (err) => {
console.error('获取省市数据失败', err);
}
});
},
// 勾选/取消勾选“未创建系统门店” // 勾选/取消勾选“未创建系统门店”
toggleUncreatedStore() { toggleUncreatedStore() {
const bySystemMerchant = !this.data.bySystemMerchant const bySystemMerchant = !this.data.bySystemMerchant
...@@ -126,21 +170,51 @@ Page({ ...@@ -126,21 +170,51 @@ Page({
this.setData({ formList }) this.setData({ formList })
}, },
// 门店地址选择 // 门店地址选择 (高德地图省市二级联动)
onRegionChange(e) { onRegionChange(e) {
console.log(e) const value = e.detail.value;
const code = e.detail.code const { regionData, formList } = this.data;
const value = e.detail.value
// value 是个数组:[省, 市, 区] const provinceIndex = value[0] || 0;
const province = value[0] || '' const cityIndex = value[1] || 0;
const city = value[1] || ''
const formList = this.data.formList if (!regionData || regionData.length === 0) return;
const addressStr = `${province}${city}`
const addreddCode = code.join('/') const province = regionData[provinceIndex];
formList[FORM_FIELDS.ADDRESS].value = addreddCode const city = province.cities[cityIndex];
formList[FORM_FIELDS.ADDRESS].displayValue = addressStr
formList[FORM_FIELDS.ADDRESS].otherValue = province const provinceName = province ? province.name : '';
this.setData({ formList }) const cityName = city ? city.name : '';
const provinceCode = province ? province.adcode : '';
const cityCode = city ? city.adcode : '';
const addressStr = provinceName === cityName ? provinceName : `${provinceName}${cityName}`;
const addressCode = `${provinceCode}/${cityCode}`;
formList[FORM_FIELDS.ADDRESS].value = addressCode;
formList[FORM_FIELDS.ADDRESS].displayValue = addressStr;
formList[FORM_FIELDS.ADDRESS].otherValue = provinceName;
this.setData({
formList,
regionPickerValue: value
});
},
onRegionColumnChange(e) {
const { column, value } = e.detail;
if (column === 0) {
const { regionData, regionPickerRange } = this.data;
const provinceIndex = value;
const province = regionData[provinceIndex];
const cityNames = province && province.cities ? province.cities.map(c => c.name) : [];
this.setData({
'regionPickerRange[1]': cityNames,
'regionPickerValue[0]': value,
'regionPickerValue[1]': 0
});
}
}, },
onFormItemTap(e) { onFormItemTap(e) {
const index = e.currentTarget.dataset.index const index = e.currentTarget.dataset.index
......
...@@ -31,14 +31,15 @@ ...@@ -31,14 +31,15 @@
<input class="number-input" type="number" placeholder="{{ item.placeholder }}" placeholder-style="color: #BBBBBB;font-size:var(--fontSize28)" value="{{ item.displayValue }}" bindinput="onSalesInput" /> <input class="number-input" type="number" placeholder="{{ item.placeholder }}" placeholder-style="color: #BBBBBB;font-size:var(--fontSize28)" value="{{ item.displayValue }}" bindinput="onSalesInput" />
</view> </view>
<view class="value" wx:elif="{{ item.label === '门店地址' }}"> <view class="value" wx:elif="{{ item.label === '门店地址' }}">
<picker mode="region" bindchange="onRegionChange" level='city' value="{{ item.value ? item.value.split(' ') : [] }}"> <picker mode="multiSelector" range="{{ regionPickerRange }}" value="{{ regionPickerValue }}" bindchange="onRegionChange" bindcolumnchange="onRegionColumnChange">
<view class="picker-inner"> <view class="picker-inner">
<text class="display_value" wx:if="{{ item.displayValue }}">{{item.displayValue}}</text> <text class="display_value" wx:if="{{ item.displayValue }}">{{item.displayValue}}</text>
<text class="placeholder" wx:else>{{item.placeholder}}</text> <text class="placeholder" wx:else>{{item.placeholder}}</text>
<image class="arrow_right" src="/packageWorkspace/pages/image/arrow-right.png" mode="aspectFill" /> <image class="arrow_right" src="/packageWorkspace/pages/image/arrow-right.png" mode="aspectFill" />
</view> </view>
</picker> </picker>
</view> </view>
<view class="value" wx:elif="{{ item.label === '是否急招' }}"> <view class="value" wx:elif="{{ item.label === '是否急招' }}">
<switch checked="{{ switch1Checked }}" bindchange="switch1Change" /> <switch checked="{{ switch1Checked }}" bindchange="switch1Change" />
</view> </view>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!