182 lines
3.7 KiB
JavaScript
182 lines
3.7 KiB
JavaScript
import { areaList } from '../data/index';
|
|
import { headerStorage, postUrl } from '../../../utils/util';
|
|
import { apiArr } from '../../../api/user';
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
areaList,
|
|
pageState: null,
|
|
editAreaInfo: {
|
|
real_name: '',
|
|
mobile: '',
|
|
addr: '',
|
|
}, // 地址信息
|
|
show:false, //弹出层
|
|
areaInfoList: [ // 区域选项卡
|
|
{
|
|
desc: '区域',
|
|
},
|
|
{
|
|
desc: '地址',
|
|
},
|
|
{
|
|
desc: '区/县',
|
|
},
|
|
],
|
|
radio: null,
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
const _this = this;
|
|
console.log('aaaasadas', options);
|
|
wx.setNavigationBarTitle({
|
|
title: options.name === 'edit' ? '编辑地址' : '新增地址'
|
|
})
|
|
this.setData({ pageState: options.name})
|
|
if (options.name === 'edit') {
|
|
headerStorage(_this, 'itemData', 'editAreaInfo');
|
|
}
|
|
},
|
|
headerAreaListClick(event) {
|
|
console.log('1111', event);
|
|
const { name } = event.currentTarget.dataset;
|
|
const { value } = event.detail;
|
|
// 根据指定的name 参数 动态修改editAreaInfo 对象的信息
|
|
this.setData({
|
|
['editAreaInfo.' + name]: value
|
|
});
|
|
|
|
},
|
|
changeArea(){
|
|
let that = this
|
|
that.setData({
|
|
show:true
|
|
})
|
|
},
|
|
|
|
onClose(e){
|
|
let that = this
|
|
that.setData({
|
|
show:false
|
|
})
|
|
},
|
|
|
|
AreaConfirm(option) {
|
|
const { areaInfoList } = this.data;
|
|
// 按照索引对照映射关系
|
|
const newAreaInfoList = areaInfoList.map((item, index) => ({...item, ...option.detail.values[index]}))
|
|
console.log('newAreaInfonewAreaInfonewAreaInfo', newAreaInfoList);
|
|
|
|
this.setData({
|
|
areaInfoList: newAreaInfoList,
|
|
show:false
|
|
})
|
|
},
|
|
|
|
radioChange(event) {
|
|
const { value } = event.detail;
|
|
console.log('aaa', event);
|
|
this.setData({
|
|
radio: value
|
|
});
|
|
},
|
|
|
|
headerDetailAreaClick(event) {
|
|
console.log('1232313123', event);
|
|
const { value } = event.detail;
|
|
this.setData({
|
|
['editAreaInfo.' + 'addr']: value
|
|
})
|
|
},
|
|
|
|
headerSubmitClick() {
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
mask: true,
|
|
});
|
|
const {editAreaInfo, areaInfoList} = this.data;
|
|
console.log('editAreaInfoeditAreaInfo', editAreaInfo);
|
|
console.log('areaInfoList', areaInfoList);
|
|
|
|
postUrl(apiArr.setAddr,{
|
|
addr: editAreaInfo.addr,
|
|
mobile: editAreaInfo.mobile,
|
|
real_name: editAreaInfo.real_name,
|
|
city_id: Number(areaInfoList[0].code), // 省
|
|
area_id: Number(areaInfoList[1].code), // 市
|
|
business_id: Number(areaInfoList[2].code) // 区
|
|
}, res => {
|
|
console.log('编辑地址成功', res);
|
|
if (res) {
|
|
wx.hideLoading();
|
|
wx.showToast({
|
|
title: '地址更新成功',
|
|
mask: true,
|
|
success() {
|
|
setTimeout(() => {
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
}, 2000)
|
|
|
|
}
|
|
})
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |