add_address.js
5.72 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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,
is_op_co:false,//switch开关
disabled: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();
})
},
onReachBottom: function () {
if (this.data.total <= 6) return;
if (this.data.ismore) return;
this.requestAddressList();
},
requestAddressList: function () {
var e = this;
t.get(e.data.url + "/api/weshop/useraddress/page", {
data: { store_id: os.stoid, user_id: oo.user_id, page: e.data.curpage, pageSize: 6 },
success: function (t) {
e.data.curpage++;
var arr1 = e.data.addresses;
var arr2 = t.data.data.pageData;
var arr3 = [...arr1, ...arr2];
var ismore = 0;
if (arr3.length == t.data.data.total) ismore = 1
e.setData({
addresses: arr3, total: t.data.data.total, ismore: ismore
}), wx.stopPullDownRefresh();
}
});
},
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({
"disabled": 0,
"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 cs = th.check(a.consignee);
if (cs != 1) {
return getApp().my_warnning("收货姓名不能为空", 0, th);
}
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;
}
//判断地址是否为空
var add = th.check(a.address);
if (add != 1) {
return getApp().my_warnning("详细地址不能为空", 0, th);
}
//判断是不是空对象
//--------如果是修改地址----------
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);
}
});
}
});
},
//是否是默认地址
bind_is_op_co:function(e){
var i = e.detail;
this.setData({
is_op_co:i
})
console.log(i)
},
check:function(as){
var code = 1;
if(as===''){
code = -1;
}
return code;
}
});