add_address.js
4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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;
//-----新增地址-------
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);
}
});
}
});
}
});