exchange.vue
12.8 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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
<template>
<address-list v-if="showChoseAddress" :address="address"></address-list>
<div v-else class="return return-exchange">
<product-list :list="goodsArr" :data="exchangeData" type="exchange">
</product-list>
<div class="title">换货明细</div>
<!--换货信息-->
<div class="list exchange-info">
<!--address-->
<div class="list-item exchange-address" @click="changeAddress">
<div class="consignee">
<span class="mr50 name">{{address.consignee}}</span>
<span class="right">{{address.mobile}}</span>
</div>
<p class="address address-detail">{{address.area}} {{address.address}}</p>
</div>
<!--mode-->
<div class="list-item exchange-mode">
<span>换货方式</span>
<i class="icon iconfont right"></i>
<select class="right select-mode" v-model="deliveryTpye">
<option v-for="(mode, index) in delivery" :key="index" :value="mode.id">{{mode.name}}</option>
</select>
</div>
</div>
</div>
</template>
<script>
const $ = require('yoho-jquery');
const qs = require('yoho-qs');
const Modal = require('plugin/modal2');
const returnUtil = require('plugin/util');
const bus = require('plugin/vue-bus');
const loading = require('plugin/loading');
const chosePanel = require('common/chose-panel-new');
const productList = require('home/return/list.vue');
const reasonConfig = require('home/return/reason');
const addressList = require('home/address/list.vue');
const specialRid = [0, 4, 6, 8];
module.exports = {
data() {
return {
title: '请选择换货商品',
page: 'exchange',
orderCode: qs.orderCode,
showFeatureSelector: false,
entity: {},
exchangeData: {},
goodsArr: [],
address: {},
delivery: [],
deliveryTpye: null,
indexMap: {}, // goods[index].id 与 index 的映射
processing: false,
showChoseAddress: false
};
},
events: {
'feature.close': function() {
this.showFeatureSelector = false;
}
},
created() {
this.$submitBtn = $('.yoho-header').find('.nav-btn');
// 提交表单
bus.$on('subExchangeForm', () => {
this.submit();
});
bus.$on('open.featureSelector', msg => {
this.queryProductFeature(msg.pid, msg.sku, msg.rid);
});
bus.$on('modify.exchangeAddress', addr => {
if (addr) {
this.address = addr;
}
this.showChoseAddress = false;
});
// 获取 换货商品
$.ajax({
url: '/home/return/exchange/order',
data: {
orderCode: this.orderCode
}
}).then(res => {
const self = this;
if (res.data && res.data.goods_list) {
res.data.goods_list.forEach((product, index) => {
product.checked = false;
product.change = {};
product.reason = {
id: 0
};
product.imageList = [];
self.indexMap[product.product_id] = index; // 生成映射
});
this.goodsArr = res.data.goods_list;
this.exchangeData = res.data;
this.address = res.data.address;
reasonConfig.specialReasons = [];
res.data.special_exchange_reason.forEach(obj => reasonConfig.specialReasons.push(obj.id));
reasonConfig.reasons = [{
id: 0,
name: '请选择'
}].concat(res.data.exchange_reason);
reasonConfig.specialNotice = res.data.special_notice;
}
});
},
computed: {
selectedGoods() {
return this.goodsArr.filter(goods => goods.checked);
}
},
methods: {
changeAddress() {
this.showChoseAddress = true;
},
// 商品 feature改变
whenFeatureChange(selection) {
const index = this.indexMap[selection.productId];
const goods = this.goodsArr[index];
goods.change = {
color: selection.sku.prop.color.valName,
size: selection.sku.prop.size.valName,
goodsId: selection.sku.prop.color.goodsId,
sku: selection.sku.skuId
};
},
// 处理商品尺码数据
handelProductData(data, sku) {
if (data && data.cartInfo) {
data.cartInfo.skus.map(value => {
if (sku && +value.skuId === sku) {
value.limitBuyTip = '无理由换货不可选择相同颜色尺码';
value.storage = 0;
} else {
value.limitBuyTip && delete value.limitBuyTip;
value.storage = value.realStorage;
}
return value;
});
}
return data;
},
// 查询 商品 feature
queryProductFeature(pid, sku, rid) {
let that = this;
let _sku = specialRid.indexOf(rid) === -1 ? +sku : false;
if (this.entity[pid]) {
this.showChosePanel(this.entity[pid], _sku);
return;
}
$.get('/product/detail/newinfo', {
id: pid
}, function(data) {
if (data && data.cartInfo) {
data.cartInfo.skus.map(value => {
value.realStorage = value.storage;
return value;
});
}
that.showChosePanel(data, _sku);
that.entity[pid] = data;
});
},
// 商品选择板
showChosePanel(data, sku) {
var that = this;
this.handelProductData(data, sku);
chosePanel.show({
data,
disableNum: 1,
buttonText: {
text: '确定'
}
}).then(result => {
that.whenFeatureChange(result);
}).catch(error => {
console.log(error);
});
},
reflushDeliveryTpye(code) {
$.get('/home/return/exchange/delivery', {
areaCode: code
}).then(result => {
this.delivery = result.data;
$.each(result.data, (index, obj) => {
if (obj.is_default === 'Y') {
this.deliveryTpye = obj.id;
return false;
}
});
});
},
// 生成提交数据
submitData() {
const data = {
order_code: this.orderCode,
address_id: this.address.addressId,
address: this.address.address,
consignee_name: this.address.consignee,
area_code: this.address.areaCode,
zip_code: this.address.zipCode,
mobile: this.address.mobile,
delivery_tpye: this.deliveryTpye,
goods: []
};
this.selectedGoods.forEach(good => {
data.goods.push({
product_skn: good.product_skn,
product_skc: good.product_skc,
product_sku: good.product_sku,
goods_type: good.goods_type_id,
last_price: good.last_price,
exchange_reason: good.reason.id,
remark: good.remark || '',
evidence_images: good.imageList || '',
new_goods_id: good.change.goodsId,
new_product_sku: good.change.sku
});
});
return data;
},
validator: function(data) {
let msg = '';
if (!data.order_code) {
msg = '订单号有问题';
}
if (!data.goods.length) {
msg = '至少选中一个换货商品';
}
data.goods.some(goods => {
let isSpecialReason = reasonConfig.specialReasons.indexOf(goods.exchange_reason) !== -1;
if (goods.exchange_reason === 0) {
msg = '请选择选货原因';
return true;
}
if (isSpecialReason && !(goods.remark && goods.evidence_images && goods.evidence_images.length)) {
msg = '换货原因请填写完整';
return true;
}
return false;
});
return msg;
},
// 提交 换货
submit() {
const self = this;
const data = this.submitData();
const msg = this.validator(data);
if (msg === '' && !this.processing) {
this.processing = true;
data.goods = JSON.stringify(data.goods);
$.ajax({
method: 'POST',
url: '/home/return/exchange/submit',
data
}).then(result => {
if (result.code === 200) {
returnUtil.applySuccuss(self.page, result.data.apply_id);
} else {
Modal.alert(result.message);
}
}).always(()=>{
self.processing = false;
});
} else {
Modal.alert('', msg);
}
}
},
watch: {
showChoseAddress(val) {
if (val) {
this.$submitBtn.hide();
} else {
this.$submitBtn.show();
}
},
'address.areaCode': function(newVal) { // area code 改变,重新获取 换货方式
this.reflushDeliveryTpye(newVal);
},
processing(val) {
if (val) {
loading.showLoading();
} else {
loading.hideLoading();
}
}
},
components: {
productList,
addressList
}
};
</script>
<style>
@import "home/refund/_return.css";
@import "cart/chose-panel.css";
body {
background-color: #f6f6f6;
}
.right {
float: right;
}
.return-exchange .title {
padding: 0 30px;
color: #b0b0b0;
font-size: 28px;
line-height: 60px;
}
.exchange-info {
padding: 0 30px;
margin-bottom: 20px;
background-color: #fff;
}
.exchange-address {
padding: 20px 0;
font-size: 28px;
.name {
font-size: 34px;
}
.address {
color: #b0b0b0;
padding-top: 10px;
line-height: 1.5;
}
&:after {
position: absolute;
z-index: 1;
content: "";
height: 0;
display: block;
right: 0;
left: 30px;
border-bottom: 1px solid #eee;
margin-top: 20px;
}
}
.exchange-mode {
font-size: 34px;
line-height: 34px;
padding: 20px 0;
.icon,
select {
font-size: 28px;
line-height: 34px;
color: #b0b0b0;
}
.select-mode {
margin-right: 6px;
}
}
.return-exchange-page {
.chose-items > .num {
display: none;
}
}
</style>