175 lines
5.4 KiB
JavaScript
175 lines
5.4 KiB
JavaScript
var t = getApp(), i = require("../../utils/login.js");
|
|
|
|
Page({
|
|
data: {
|
|
showLoding: !0,
|
|
loading: !1,
|
|
isrefusedAuthLocation: 0,
|
|
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: "",
|
|
id: ""
|
|
},
|
|
onLoad: function(t) {
|
|
console.log(t), wx.showLoading({
|
|
title: ""
|
|
}), this.setData({
|
|
id: t.id || "",
|
|
show: t.id ? "edit" : "plus"
|
|
}), this.getContent(), wx.setNavigationBarTitle({
|
|
title: t.id ? "编辑地址" : "新增地址"
|
|
});
|
|
},
|
|
getContent: function() {
|
|
var e = this;
|
|
i.request(t.globalData.config.address.plus, {
|
|
id: this.data.id
|
|
}).then(function(t) {
|
|
if (wx.hideLoading(), 200 != t.code) return wx.showToast({
|
|
title: t.message
|
|
}), !1;
|
|
e.setData({
|
|
showLoding: !1,
|
|
info: t.data,
|
|
isdefault: t.isdefault || 0,
|
|
token: t.token
|
|
});
|
|
}).catch(function(t) {
|
|
wx.hideLoading();
|
|
});
|
|
},
|
|
checkboxChange: function(t) {
|
|
this.setData({
|
|
isdefault: t.detail.value[0] || 0
|
|
});
|
|
},
|
|
bindRegionChange: function(t) {
|
|
this.data.info.provincename = t.detail.value[0], this.data.info.cityname = t.detail.value[1],
|
|
this.data.info.countryname = t.detail.value[2], this.setData({
|
|
info: this.data.info
|
|
});
|
|
},
|
|
input: function(t) {
|
|
var i = t.currentTarget.dataset.input;
|
|
this.data.info[i] = t.detail.value, this.setData({
|
|
info: this.data.info
|
|
});
|
|
},
|
|
submit: function() {
|
|
if (this.data.issubmit) return !1;
|
|
this.setData({
|
|
issubmit: !0
|
|
});
|
|
var e = this;
|
|
i.request(t.globalData.config.address.submit, {
|
|
session: wx.getStorageSync("session"),
|
|
info: this.data.info,
|
|
isdefault: this.data.isdefault,
|
|
token: this.data.token,
|
|
uniqid: this.data.uniqid
|
|
}).then(function(t) {
|
|
wx.hideLoading(), e.setData({
|
|
issubmit: !1
|
|
}), 200 == t.code ? wx.navigateBack() : wx.showToast({
|
|
title: t.message,
|
|
icon: "none"
|
|
});
|
|
}).catch(function(t) {
|
|
wx.hideLoading(), e.setData({
|
|
issubmit: !1
|
|
});
|
|
});
|
|
},
|
|
delAddress: function() {
|
|
if (this.data.issubmit) return !1;
|
|
var e = this;
|
|
wx.showModal({
|
|
title: "是否删除该地址?",
|
|
content: "",
|
|
confirmColor: "#EF8176",
|
|
cancelColor: "#999999",
|
|
success: function(a) {
|
|
a.confirm && (e.setData({
|
|
issubmit: !0
|
|
}), i.request(t.globalData.config.address.delete, {
|
|
id: e.data.id
|
|
}).then(function(t) {
|
|
200 == t.code ? (wx.showToast({
|
|
title: "删除成功"
|
|
}), wx.navigateBack()) : wx.showModal({
|
|
title: "提示",
|
|
content: t.message,
|
|
confirmColor: "#EF8176",
|
|
cancelColor: "#999999"
|
|
});
|
|
}).catch(function(t) {
|
|
e.setData({
|
|
issubmit: !1
|
|
});
|
|
}));
|
|
},
|
|
fail: function(t) {
|
|
console.log("fail");
|
|
}
|
|
});
|
|
},
|
|
getSystemAddress: function() {
|
|
var t = this;
|
|
wx.chooseAddress({
|
|
success: function(i) {
|
|
console.log(i), t.data.info = {
|
|
cityname: i.cityName,
|
|
countryname: i.countyName,
|
|
detailinfo: i.detailInfo,
|
|
provincename: i.provinceName,
|
|
telnumber: i.telNumber,
|
|
username: i.userName
|
|
}, t.setData({
|
|
info: t.data.info
|
|
});
|
|
},
|
|
fail: function(i) {
|
|
console.log(i), t.setData({
|
|
isrefusedAuthLocation: 1
|
|
}), wx.showToast({
|
|
title: "获取地址失败",
|
|
icon: "none"
|
|
});
|
|
}
|
|
});
|
|
},
|
|
bindopensetting: function(t) {
|
|
res.detail.authSetting["scope.address"] ? (wx.showToast({
|
|
title: "授权成功,请再次点击导入微信地址"
|
|
}), this.setData({
|
|
isrefusedAuthLocation: 0
|
|
})) : wx.showToast({
|
|
title: "授权失败",
|
|
icon: "none"
|
|
});
|
|
},
|
|
select: function(i) {
|
|
var e = i.currentTarget.dataset.index;
|
|
"user" != this.data.selectAddressUniqid && (this.setData({
|
|
selectAddressUniqid: i.currentTarget.dataset.uniqid
|
|
}), t.globalData.selectAddress = this.data.data[e], setTimeout(function(i) {
|
|
t.globalData.selectAddress = {};
|
|
}, 2e3), wx.navigateBack({}));
|
|
}
|
|
}); |