returns.js
8.21 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
/**
* 退换货
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/7/19
*/
'use strict';
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
const mcHandler = require('./menu-crumb-handler');
const returnsAPI = require('./returns-api');
const helpers = global.yoho.helpers;
const pageSize = 10;
// const _reduceArrByProductSku = data => {
// const d = [];
//
// d.push(data[0]);
//
// data.reduce((p, c) => { //eslint-disable-line
// if (p && c && p.productSku !== c.productSku) {
// d.push[c];
// }
// });
//
// return d;
// };
const getUserReturn = (uid, page) => {
return api.get('', {
method: 'app.refund.getList',
uid: uid,
page: page || 1,
limit: 10
}).then(result => {
const basicData = {
title: '我的退/换货'
};
const refundStr = {
1: '退货',
2: '换货'
};
const data = camelCase(result.data);
const paginationOpts = data.total > pageSize ? {
paginationOpts: {
total: data.total,
page: data.page,
limit: pageSize
}
} : false;
data.list.forEach(item => {
item.orderGoods = item.goods;
item.createTime = item.orderCreateTime;
item.hidePrice = true;
item.showStatus = true;
item.refundStr = refundStr[item.refundType];
item.orderGoods.forEach(it => {
it.hidePrice = true;
});
});
return {
returnsList: Object.assign(data, paginationOpts, basicData)
};
});
};
const _setSideMenu = (type) => {
return {
nav: mcHandler.getMeCrumb(type),
navigation: mcHandler.getSideMenu(type)
};
};
const _calcStatusRate = (num, total) => {
let rate = 0;
if (total) {
rate = `${_.toInteger(num / total * 100)}%`;
}
return rate;
};
const _setDefaultStatus = (type) => {
const list = ['提交申请', '审核通过', '商品寄回', '商品入库', `${type}完成`];
let statusList = [];
let resData = {};
_.forEach(list, (value, key) => {
statusList.push({
step: _.toInteger(key) + 1,
name: value
});
});
statusList[0].act = true;
resData.returnStstus = {
rate: _calcStatusRate(1, statusList.length),
statusList: statusList
};
return resData;
};
const _setReturnStatus = (list, half) => {
let resData = {};
if (list && list.length) {
let statusList = [],
step = 0;
let rate;
// 遍历进度列表
_.forEach(list, (value, key) => {
let state = {
act: value.act === 'Y',
step: _.toInteger(key) + 1,
name: value.name
};
if (state.act) {
step++;
}
statusList.push(state);
});
// 多半格进度特殊处理
if (half) {
rate = _calcStatusRate(step * 2 + 1, statusList.length * 2);
} else {
rate = _calcStatusRate(step, statusList.length);
}
resData.returnStstus = {
rate: rate,
statusList: statusList
};
}
return resData;
};
const _setRefundGoodList = (data) => {
let resData = {};
if (data.goods_list) {
let goods = [];
_.forEach(data.goods_list, value => {
let cnAlphabet = value.cn_alphabet ? value.cn_alphabet : '';
goods.push({
href: helpers.urlFormat(`/product/pro_${value.product_id}_${value.goods_id}/${cnAlphabet}.html`),
img: value.goods_image,
name: value.product_name,
size: value.size_name,
color: value.color_name,
num: 1, // 接口目前不支持
price: value.last_price,
skn: value.product_skn,
skc: value.product_skc,
sku: value.product_sku,
type: value.goods_type,
typeId: value.goods_type_id,
reasonList: data.return_reason
});
if (value.hasShoes) {
resData.hasShoes = true;
}
});
resData.goods = goods;
}
resData.speclialReason = data.special_return_reason;
return resData;
};
const _setRefundDetailData = (data) => {
let resData = {};
switch (data.status) {
case 10:
resData.orderReview = {pass: true};
resData.refundExpress = true;
resData.refundAddress = true;
break;
case 20:
resData.refundExpress = true;
break;
case 30:
resData.backStorage = true;
break;
case 40:
resData.refundSure = true;
break;
default:
resData.orderReview = true;
break;
}
return resData;
};
const getRefundGoodsData = (orderCode, uid) => {
return returnsAPI.getRefundGoodsAsync(orderCode, uid).then(result => {
let resData = {};
Object.assign(resData, _setSideMenu('我的退/换货'));
resData.returns = {
title: '退货申请',
refund: _setDefaultStatus('退货') || {}
};
if (result.data) {
Object.assign(resData.returns.refund, _setRefundGoodList(result.data), {
orderCode: orderCode
});
}
return resData;
});
};
const getRefundDetailData = (applyId, uid) => {
return returnsAPI.getRefundDetailAsync(applyId, uid).then(result => {
let resData = {};
Object.assign(resData, _setSideMenu('我的退/换货'));
resData = {
title: '退货申请',
refundDetail: {}
};
if (result.data) {
// console.log(_setRefundDetailData(result.data));
Object.assign(resData.refundDetail, _setReturnStatus(result.data.statusList));
Object.assign(resData.refundDetail, _setRefundDetailData(result.data));
}
return {returns: resData};
});
};
const saveRefund = (orderCode, uid, goods, payment) => {
return returnsAPI.getOrderInfoAsync(orderCode, uid, '').then(result => {
if (!_.isEmpty(result)) {
return returnsAPI.refundSubmitAsync(orderCode, uid, goods, payment).then(subRes => {
if (subRes && subRes.data) {
return {
code: 200,
data: {
refer: helpers.urlFormat(`/return/refund/detail/${subRes.data.apply_id}`)
}
};
}
return {code: 400, message: '申请失败'};
});
} else {
return {code: 403, message: '没有找到该订单'};
}
});
};
const getProductInfo = (productId, productSkn) => {
return returnsAPI.getProductInfoAsync(productId, productSkn).then(result => {
if (result.code === 200) {
camelCase(result);
result.data.goodsList.forEach(good => {
good.colorImage = helpers.image(good.colorImage, 20, 20);
});
}
return result;
});
};
const getChangeGoodsList = (orderCode, uid) => {
return returnsAPI.getChangeGoodsListAsync(orderCode, uid).then(result => {
const basicData = {
title: '申请换货'
};
let data;
if (result && result.data) {
data = camelCase(result.data);
// data.goodsList = _reduceArrByProductSku(data.goodsList);
data.hidePrice = true;
data.goodsList.forEach(good => {
good.showCheckbox = true;
good.hidePrice = true;
// good.buyNumber = good.num;
good.buyNumber = 1;
data.goodsList[2].colorId = 1;
});
}
return {
returnsChange: Object.assign(basicData, data)
};
});
};
module.exports = {
getUserReturn,
getRefundGoodsData,
getChangeGoodsList,
getProductInfo,
getRefundDetailData,
saveRefund
};