address-management.js
2.28 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
import {
getBindtapData,
getObjByListKeyValue
} from '../../utils/util';
let app = getApp();
Page({
data: {
authorizeVisible: false,
receiverList: [], // 收货地址
defaultReceiver: null, // 默认收货地址
},
onShareAppMessage() {},
showAuth() {
this.setData({
authorizeVisible: true
})
},
onLoad(options) {},
onShow() {
this.initData();
},
initData() {
app.queryIndex().then((result) => {
this.queryReceiver();
})
},
queryReceiver() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.receiver,
data: {}
}).then((result2) => {
let defaultReceiver = getObjByListKeyValue(1, "defaultAddress", result2);
this.setData({
indexInfo: app.globalData.indexInfo,
receiverList: result2,
defaultReceiver: defaultReceiver
})
resolve();
})
});
},
// 编辑收货地址
onAddressEditHandler(evt) {
console.log("edit");
let curData = getBindtapData(evt);
app.globalData.addressEditInfo = curData;
app.router.push({
path: "addressEdit"
})
},
// 添加收货地址
onAddressAddHandler(evt) {
app.globalData.addressEditInfo = null;
app.router.push({
path: "addressEdit"
})
},
/**
* 设置为默认地址
*/
onSetDefaultHandler(evt) {
let _this = this;
let curData = getBindtapData(evt);
wx.showModal({
title: '提示',
content: '设置为默认地址?',
success(res) {
if (res.confirm) {
curData.defaultAddress = 1;
app.post({
url: app.api.receiverSave,
data: curData
}).then((result) => {
_this.queryReceiver().then((result) => {
wx.showModal({
content: '操作成功',
showCancel: false,
success(res) {}
})
})
})
}
}
})
},
// 隐藏蒙层
hideMask() {
this.setData({
authorizeVisible: false,
})
},
// 子组件事件
evtcomp(evt) {
let {
name,
data
} = evt.detail;
switch (name) {
// 隐藏弹窗
case "_evt_hide_mask":
this.hideMask();
break;
default:
break;
}
},
})