|
@@ -11,14 +11,22 @@ Page({
|
|
|
phone:'',
|
|
|
region: ['上海市', '上海市', '黄浦区'],
|
|
|
detailAddress:'',
|
|
|
+ id:null,
|
|
|
switchChecked:false, //是否默认
|
|
|
+ type:'add',
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
-
|
|
|
+ console.log(options,"options")
|
|
|
+ if (options.type ==='edit'){ // 表示编辑
|
|
|
+ this.setData({
|
|
|
+ type:'edit'
|
|
|
+ })
|
|
|
+ this.getEditAddress(this)
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -32,7 +40,7 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -119,26 +127,37 @@ Page({
|
|
|
});
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ let data ={
|
|
|
+ consignee: that.data.name, //收货人
|
|
|
+ province: that.data.region[0],
|
|
|
+ city: that.data.region[1],
|
|
|
+ area: that.data.region[2],
|
|
|
+ adress: that.data.detailAddress,
|
|
|
+ phone: that.data.phone,
|
|
|
+ adress_flag: that.data.switchChecked ? 0 : 1 // 是否默认 0是 1 否
|
|
|
+ },
|
|
|
+ url = host + '/adressapi/insertadd',
|
|
|
+ title = "地址添加成功";
|
|
|
+ if(that.data.type == 'edit'){
|
|
|
+ data['action_account'] = null;
|
|
|
+ data['id'] = that.data.id;
|
|
|
+ url = host + '/adressapi/update';
|
|
|
+ title = "地址编辑成功";
|
|
|
+ } else {
|
|
|
+ data['user_id'] =app.globalData.user_id;
|
|
|
+ url = host + '/adressapi/insertadd';
|
|
|
+ title = "地址添加成功";
|
|
|
+ }
|
|
|
wx.request({
|
|
|
- url: host +'/adressapi/insertadd',
|
|
|
+ url: url,
|
|
|
header: {
|
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
|
},
|
|
|
- data:{
|
|
|
- user_id: app.globalData.user_id, //'oovpNwjlsY6xx8ceCebFa1dOLd9E', //app.globalData.user_id,
|
|
|
- consignee: that.data.name, //收货人
|
|
|
- province:that.data.region[0],
|
|
|
- city: that.data.region[1],
|
|
|
- area: that.data.region[2],
|
|
|
- adress:that.data.detailAddress,
|
|
|
- phone:that.data.phone,
|
|
|
- adress_flag: that.data.switchChecked ? 0 : 1 // 是否默认 0是 1 否
|
|
|
- },
|
|
|
+ data: data,
|
|
|
success(res){
|
|
|
console.log(res,"地址保存")
|
|
|
wx.showToast({
|
|
|
- title: '地址添加成功',
|
|
|
+ title: title,
|
|
|
icon:'none',
|
|
|
success(){
|
|
|
setTimeout(()=>{
|
|
@@ -153,21 +172,23 @@ Page({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- getEditAddress(){ // 获取编辑的地址
|
|
|
-
|
|
|
+ getEditAddress(that){ // 获取编辑的地址
|
|
|
+
|
|
|
let address = wx.getStorageSync('address'),
|
|
|
name = address.consignee,
|
|
|
phone =address.phone,
|
|
|
region = [address.province,address.city,address.area],
|
|
|
detailAddress =address.adress,
|
|
|
- switchChecked = address.switchChecked;
|
|
|
+ switchChecked = address.adress_flag == '0'? true : false ,
|
|
|
+ id = address.id;
|
|
|
console.log(address)
|
|
|
- this.setData({
|
|
|
+ that.setData({
|
|
|
name:name,
|
|
|
phone:phone,
|
|
|
region: region,
|
|
|
detailAddress: detailAddress,
|
|
|
- switchChecked: switchChecked
|
|
|
+ switchChecked: switchChecked,
|
|
|
+ id: id
|
|
|
})
|
|
|
}
|
|
|
})
|