132 lines
4.0 KiB
JavaScript
132 lines
4.0 KiB
JavaScript
var t = getApp(), a = require("../../utils/login.js");
|
|
|
|
Page({
|
|
data: {
|
|
showLoding: !0,
|
|
loading: !1,
|
|
data: [],
|
|
show: "index",
|
|
isdefault: 0,
|
|
region: [],
|
|
info: {
|
|
cityname: null,
|
|
countryname: null,
|
|
detailinfo: null,
|
|
provincename: null,
|
|
telnumber: null,
|
|
username: null
|
|
},
|
|
issubmit: !1,
|
|
show_comfirm: {
|
|
show: !1,
|
|
tips: ""
|
|
},
|
|
uniqid: "",
|
|
selectAddressUniqid: ""
|
|
},
|
|
onLoad: function(i) {
|
|
var e = this;
|
|
wx.showLoading({
|
|
title: ""
|
|
}), this.setData({
|
|
selectAddressUniqid: i.selectAddressUniqid || ""
|
|
}), a.pageStart(t).then(function(t) {
|
|
e.getData();
|
|
});
|
|
},
|
|
onShow: function() {
|
|
this.istoEdit && (this.istoEdit = !1, this.getData());
|
|
},
|
|
onShareAppMessage: function() {},
|
|
istoEdit: !1,
|
|
getData: function() {
|
|
var i = this;
|
|
if (this.data.loading) return !1;
|
|
this.setData({
|
|
loading: !0
|
|
}), a.request(t.globalData.config.address.init, {}).then(function(t) {
|
|
wx.hideLoading(), i.setData({
|
|
data: t.data,
|
|
loading: !1,
|
|
showLoding: !1
|
|
});
|
|
}).catch(function(t) {
|
|
wx.hideLoading(), i.setData({
|
|
loading: !1
|
|
});
|
|
});
|
|
},
|
|
openEdit: function(t) {
|
|
var a = t.currentTarget.dataset.uniqid || "";
|
|
return t.currentTarget.dataset.index || 0, this.data.show = a ? "edit" : "add",
|
|
wx.navigateTo({
|
|
url: "/pages/addAddress/addAddress?id=" + a
|
|
}), this.istoEdit = !0, !1;
|
|
},
|
|
select: function(t) {
|
|
return console.log("select"), !1;
|
|
},
|
|
delAddress: function(i) {
|
|
if (this.data.issubmit) return !1;
|
|
var e = i.currentTarget.dataset, n = e.id, s = e.index, o = this;
|
|
wx.showModal({
|
|
title: "是否删除该地址?",
|
|
content: "",
|
|
confirmColor: "#EF8176",
|
|
cancelColor: "#999999",
|
|
success: function(i) {
|
|
i.confirm && a.request(t.globalData.config.address.delete, {
|
|
id: n
|
|
}).then(function(t) {
|
|
o.setData({
|
|
issubmit: !1
|
|
}), 200 == t.code ? (wx.showToast({
|
|
title: "删除成功"
|
|
}), o.data.data.splice(s, 1), o.setData({
|
|
data: o.data.data
|
|
})) : wx.showModal({
|
|
title: "提示",
|
|
content: t.message,
|
|
confirmColor: "#EF8176",
|
|
cancelColor: "#999999"
|
|
});
|
|
}).catch(function(t) {
|
|
o.setData({
|
|
issubmit: !1
|
|
});
|
|
});
|
|
},
|
|
fail: function(t) {
|
|
console.log("fail"), o.setData({
|
|
issubmit: !0
|
|
});
|
|
}
|
|
});
|
|
},
|
|
setDefault: function(i) {
|
|
var e = i.currentTarget.dataset, n = e.id, s = e.index;
|
|
if (e.isdefault) return !1;
|
|
wx.showLoading({
|
|
title: ""
|
|
});
|
|
var o = this;
|
|
a.request(t.globalData.config.address.default, {
|
|
id: n
|
|
}).then(function(t) {
|
|
200 == t.code ? (wx.hideLoading(), o.data.data.map(function(t) {
|
|
t.isdefault = 0;
|
|
}), o.data.data[s].isdefault = 1, o.setData({
|
|
data: o.data.data
|
|
}), wx.showToast({
|
|
title: t.message
|
|
})) : wx.showModal({
|
|
title: "提示",
|
|
content: t.message,
|
|
confirmColor: "#EF8176",
|
|
cancelColor: "#999999"
|
|
});
|
|
}).catch(function(t) {
|
|
wx.hideLoading();
|
|
});
|
|
}
|
|
}); |