afterSale.js
10 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
// pages/orders/afterSale/afterSale.js
import { GET } from '../../../../libs/request';
import { API_HOST } from '../../../../libs/config';
import { getImageUrlWithWH } from '../../../../utils/util.js';
const REFUND_COMPUTE = 'app.refund.compute';
const REFUND_GOODSLIST = 'app.refund.goodsList';
const REFUND_SUBMIT = 'app.refund.submit';
Page({
/**
* 页面的初始数据
*/
data: {
refundProudectListTitle: '请选择退货商品',
selectedImage: '/pages/addressManager/images/default-select@3x.png',
unSelectedImage: '/pages/addressManager/images/default-normal@3x.png',
arrows: '/pages/bindPhoneNumber/images/arrow-down@2x.png',
tips: '/images/que_ic@3x.png',
order_code: 0,
refundData: {},
goodsList: [],
return_amount_mode: [],
defaultWay: '',
selectWay: {},
return_reason: [],
return_amount: '0.00',
return_asset_desc: '最多0.00,以实际退款为准',
isShowPrice: false,
showInputAndUploadImageArrays: [
4,
6,
8
],
paymentInfo: {
province: '',
city: '',
remark: '',
},
refundShipFeeDescription: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options);
let { order_code } = options;
console.log(order_code);
this.setData({
order_code
});
this.getRefundList(order_code);
},
getRefundList(order_code) {
GET(API_HOST, {
order_code,
method: REFUND_GOODSLIST
}).then(json => {
if (json && json.code === 200 && json.data) {
const list = this.handleList(json.data.goods_list);
let paymentInfo = this.data.paymentInfo;
let return_bank_mode = json.data.return_bank_mode;
paymentInfo.return_amount_mode = json.data.return_amount_mode[0].id;
paymentInfo.bank_id = return_bank_mode[0].id;
paymentInfo.head_bank_name = return_bank_mode[0].title;
paymentInfo.needSubBranch = return_bank_mode[0].needSubBranch;
this.setData({
refundData: json.data,
goodsList: list,
defaultWay: json.data.return_amount_mode[0].name,
return_amount_mode: json.data.return_amount_mode,
selectWay: json.data.return_amount_mode[0],
return_amount_desc: json.data.return_amount_desc,
return_reason: json.data.return_reason,
paymentInfo,
refundShipFeeDescription: json.data.refundShipFeeDescription
})
}
}).catch(error => {
console.log(error);
});
},
onChangeSelected(e) {
const index = e.detail;
const goodsList = this.data.goodsList;
const good = goodsList[index];
good.selected = !good.selected;
if (!good.selected) {
good.evidence_images = []
}
this.setData({
goodsList
})
this.getRefundPrice(goodsList);
},
handleSelectedGoods(goodsList) {
let newGoods = []
goodsList.forEach((item) => {
if (item.selected) {
let { product_sku, product_skn, product_skc, last_price, goods_type_id } = item;
let obj = {
product_sku,
product_skn,
product_skc,
last_price,
goods_type: goods_type_id
};
newGoods.push(obj);
}
});
return newGoods;
},
handleSubmitData(goodsList) {
let remark, returned_reason, evidence_images;
let newGoods = [];
let inputAndUploadImage = this.data.showInputAndUploadImageArrays;
return new Promise((resolve, reject) => {
goodsList.forEach((item) => {
if (item.selected) {
let { product_sku, product_skn, product_skc, last_price, goods_type_id } = item;
if (item.returned_reason) {
returned_reason = item.returned_reason;
// 质量瑕疵、发错货、图片与实物不符这三个时,下方展开"退货原因说明"和上传"照片凭证"
if (inputAndUploadImage.indexOf(returned_reason) !== -1) {
if (item.remark && item.remark.length > 0) {
remark = item.remark;
} else {
reject(new Error('请输入退款原因'));
}
if (item.evidence_images && item.evidence_images.length > 0) {
evidence_images = item.evidence_images
} else {
reject(new Error('请输入上传图片'));
}
}
} else {
reject(new Error('请选择退款原因'));
}
let obj = {
product_sku,
product_skn,
product_skc,
last_price,
goods_type: goods_type_id,
returned_reason
};
if (remark) {
obj.remark = remark;
}
if (evidence_images) {
obj.evidence_images = evidence_images;
}
newGoods.push(obj);
}
});
if (newGoods.length > 0) {
resolve(newGoods);
} else {
reject(new Error('请选择要退货的商品'));
}
})
},
getRefundPrice(goodsList) {
let isShowPrice = this.isShowPrice(goodsList);
let order_code = this.data.order_code;
if (isShowPrice) {
let goods = this.handleSelectedGoods(goodsList);
GET(API_HOST, {
order_code,
goods: JSON.stringify(goods),
method: REFUND_COMPUTE
}).then(json => {
if (json && json.code === 200 && json.data) {
this.setData({
isShowPrice,
return_amount: json.data.return_amount,
return_asset_desc: json.data.return_asset_desc
})
}
});
} else {
this.setData({
isShowPrice
})
}
},
isShowPrice(goodsList) {
let isShow = false;
goodsList.forEach((item) => {
let selected = item.selected;
isShow = isShow || selected;
});
return isShow;
},
handleList(goodsList) {
const list = goodsList.map((item) => {
item.goods_image = getImageUrlWithWH(item.goods_image, 180, 180 * 1.25);
item.selected = false;
item.reasonIndex = ''
item.returned_reason = '';
item.evidence_images = [];
if (item.goods_type === 'gift') {
item.returned_reason = '3'
}
return item;
})
return list;
},
showTips() {
wx.showModal({
title: '退款金额说明',
content: this.data.return_amount_desc,
showCancel: false,
confirmColor: '#D0021B',
confirmText: '我知道了'
})
},
bindPickerChange(e) {
const { return_amount_mode } = this.data;
this.setData({
defaultWay: return_amount_mode[e.detail.value].name,
selectWay: return_amount_mode[e.detail.value]
})
},
updateGoodsImage(e) {
console.log('afterSale: ', e.detail);
let { currentIndex, finalImageArray } = e.detail;
const goodsList = this.data.goodsList;
const good = goodsList[currentIndex];
good.evidence_images = finalImageArray;
this.setData({
goodsList
})
},
pickerSelectReason(e) {
const reasonIndex = e.detail.reasonIndex;
const index = e.detail.index;
const goodsList = this.data.goodsList;
const good = goodsList[index];
good.reasonIndex = reasonIndex;
good.returned_reason = e.detail.id;
this.setData({
goodsList
});
},
confirmReasonInfo(e) {
let { currentIndex, reason } = e.detail;
const goodsList = this.data.goodsList;
const good = goodsList[currentIndex];
good.remark = reason;
this.setData({
goodsList
})
},
submitRefundData(goods) {
let order_code = this.data.order_code;
let payment = this.data.paymentInfo;
GET(API_HOST, {
method: REFUND_SUBMIT,
order_code,
goods: JSON.stringify(goods),
payment: JSON.stringify(payment),
}).then(data => {
if (data && data.code === 200 && data.data) {
let apply_id = data.data.apply_id;
wx.showModal({
content: '退货申请已提交,\r\n请等待审核',
cancelText: '返回订单',
cancelColor: '#4A4A4A',
confirmText: '查看进度',
confirmColor: '#4A4A4A',
success(res) {
if (res.cancel) {
wx.navigateBack({
delta: 1
})
} else {
wx.navigateTo({
url: `../refundOrderProgress/refundOrderProgress?apply_id=${apply_id}`,
})
}
}
});
} else {
wx.showToast({
title: data.message,
icon: 'none'
});
}
}).catch(error => {
console.log(error);
})
},
refundSubmit(goods) {
let refundShipFeeDescription = this.data.refundShipFeeDescription;
let that = this;
wx.showModal({
title: '关于赠品退货说明',
content: refundShipFeeDescription,
cancelColor: '#D0021B',
cancelText: '我知道了',
confirmColor: '#4A4A4A',
confirmText: '赠品退货',
success(res) {
if (res.cancel) {
that.submitRefundData(goods);
}
}
});
},
submitRefund(e) {
let that = this;
const goodsList = this.data.goodsList;
this.handleSubmitData(goodsList).then(goods => {
if (goods.length > 0) {
that.refundSubmit(goods);
} else {
wx.showToast({
title: '请选择要退货的商品',
icon: 'none'
})
}
}).catch(error => {
wx.showToast({
title: error.message,
icon: 'none'
});
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})