var s = function(s) { return s && s.__esModule ? s : { default: s }; }(require("../../../utils/regions/Regions.js")), e = getApp(), a = e.globalData.setting,os=a,t = e.request; var ut = require("../../../utils/util.js"), oo = e.globalData; Page({ data: { url: a.url, resourceUrl: a.resourceUrl, iurl: a.imghost, address: null, isnew:0, }, onLoad: function(s) { var a = this,th=a; var is_e = ut.isEmptyObject(s); this.setData({ address: s, isnew:is_e, }), e.getUserInfo(function(s) { a.setData({ user: s }); th.initRegions(); }) }, initRegions: function() { var e = this; new s.default(this, "regions", { endAreaLevelCall: function(s, a, t) { console.log("initRegions"); console.log(t); Object.assign(e.data.address, t), e.setData({ "address.province_name": e.data.address.province_name, "address.city_name": e.data.address.city_name, "address.district_name": e.data.address.district_name, "address.twon_name": e.data.address.twon_name, "address.more_address": e.data.address.province_name + "-" + e.data.address.city_name + "-" + e.data.address.district_name +"-"+e.data.address.twon_name, }); console.log(e.data.address); } }); }, //-----------添加或者编辑----------- submitAddress: function(s) { var a= this.data.address, b=a,th=this; Object.assign(a, s.detail.value), a.is_default = Number(a.is_default); a.store_id = os.stoid; var ob = ut.check_mobile(a.mobile); if(ob.code!=1){ return getApp().my_warnning(ob.title,0,th); } if (a.more_address == null || a.more_address == undefined || a.more_address=="" ){ getApp().my_warnning("请选择地区",0,th); return false; } //判断是不是空对象 //--------如果是修改地址---------- if (!th.data.isnew){ if (a.is_default==1){ t.put("/api/weshop/useraddress/update", { data: { user_id: oo.user_id, is_default:0}, success: function (s) { t.put("/api/weshop/useraddress/updateById", { data: a, success: function (s) { e.showSuccess(s.data.msg, function () { wx.navigateBack(); }); } }); } }); }else{ t.put("/api/weshop/useraddress/updateById", { data: a, success: function (s) { e.showSuccess(s.data.msg, function () { wx.navigateBack(); }); } }); } }else{ a['user_id'] = oo.user_id; a['store_id'] = os.stoid; if (a.is_default == 1) { t.put("/api/weshop/useraddress/update", { data: { user_id: oo.user_id, is_default: 0 }, success: function (s) { //-----新增地址------- t.post("/api/weshop/useraddress/save", { data: a, success: function (s) { e.showSuccess(s.data.msg, function () { wx.navigateBack(); }); } }); } }) }else{ //-----新增地址------- t.post("/api/weshop/useraddress/save", { data: a, success: function (s) { e.showSuccess(s.data.msg, function () { wx.navigateBack(); }); } }); } } }, //---------删除收货地址------------ deleteAddress: function() { var s = this.data.address.address_id; s && wx.showModal({ title: "确定删除?", success: function(a) { a.confirm && t.delete("/api/weshop/useraddress/del/" + oo.user_id+"/"+s, { success: function(s) { e.showSuccess("删除成功", function() { wx.navigateBack(); }, 500); } }); } }); } });