gift-detail.js
4.81 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import {
getBindtapData,
getObjByListKeyValue,
Fen2Yuan
} from '../../utils/util';
let app = getApp();
Page({
data: {
authorizeVisible: false,
commonTipsCompVisible: false,
orderSubmitSuccessCompVisible: false,
cid: "1", // 1奖金不足 2.账号未审核
innerTitle: "",
innerText: "",
innerButton: "",
indexInfo: {},
item: {},
remark: "",
receiverList: [], // 收货地址
defaultReceiver: null, // 默认收货地址
},
onShareAppMessage() {},
showAuth() {
this.setData({
authorizeVisible: true
})
},
onLoad(options) {
},
onShow() {
this.initData();
},
initData() {
return new Promise((resolve, reject) => {
app.queryIndex().then((result) => {
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,
item: app.globalData.giftInfo,
})
resolve();
})
})
});
},
showTips(tips) {
wx.showToast({
title: tips,
icon: "none"
})
},
/**
* 检查提交
*/
checkSubmit() {
return new Promise((resolve, reject) => {
let {
item,
defaultReceiver,
indexInfo
} = this.data;
if (indexInfo.memberPoints < item.commodityPrice) {
// 奖金不足
this.setData({
commonTipsCompVisible: true,
cid: "1",
innerTitle: "奖金不足",
innerText: "使用推广、签到功能\n可获取更多奖金!",
innerButton: "我知道了",
});
reject();
return;
} else if (indexInfo.auditStatus != "authorization") {
// 未验证
this.setData({
commonTipsCompVisible: true,
cid: "2",
innerTitle: "账号未审核",
innerText: "通过认证的用户才能兑换礼品哦,快去提交资料",
innerButton: "马上去验证",
});
reject();
return;
} else if (!defaultReceiver && item.commodityType == "object") {
// 实物奖品必须添加地址
this.showTips("请先添加地址")
reject();
return;
} else {
resolve();
}
});
},
/**
* 确认兑换 / 提交订单
*/
onSubmitHandler(evt) {
let _this = this;
this.checkSubmit().then((result) => {
let {
item,
defaultReceiver
} = this.data;
console.log("item:", item);
console.log("defaultReceiver:", defaultReceiver);
wx.showModal({
title: '兑换确认',
content: `将花费${Fen2Yuan(item.commodityPrice)}元兑换${item.commodityTitle}一份`,
success(res) {
if (res.confirm) {
app.post({
url: app.api.commodityExchange,
data: {
commodityCode: item.commodityCode,
receiverCode: defaultReceiver && defaultReceiver.receiverCode || "",
remark: _this.data.remark
}
}).then((result) => {
_this.initData().then((result) => {
_this.setData({
orderSubmitSuccessCompVisible: true
})
})
})
}
}
})
})
},
/**
* 收获地址管理
*/
onAddressManagementHandler() {
app.router.push({
path: "addressManagement"
})
},
/**
* 添加收货地址
* 同地址管理
*/
onAddressAddHandler() {
app.router.push({
path: "addressManagement"
})
},
bindRemarkInput(e) {
this.setData({
remark: e.detail.value
})
},
// 隐藏蒙层
hideMask() {
this.setData({
authorizeVisible: false,
commonTipsCompVisible: false,
orderSubmitSuccessCompVisible: false,
})
},
// 子组件事件
evtcomp(evt) {
let {
name,
data
} = evt.detail;
switch (name) {
case "_evt_hide_mask":
this.hideMask();
break;
// 隐藏弹窗
case "_evt_common_comp_button":
this.hideMask();
console.log("data.cid:", data.cid);
switch (data.cid) {
// 奖金不足
case "1":
this.hideMask();
break;
// 未验证
case "2":
app.router.push({
path: "vipLogin"
})
break;
default:
break;
}
break;
// 兑换成功
case "_evt_order_submit_success":
app.router.push({
path: "giftShop",
openType: "switchTab"
})
break;
default:
break;
}
},
})