exchange.vue
10.9 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
<template>
<div class="return">
<product-list :list="goodsArr" :data="exchangeData" type="exchange">
</product-list>
<!--换货信息-->
<div class="list exchange-info">
<!--address-->
<div class="list-item exchange-address" @click="changeAddress">
<div class="consignee">
<span class="mr50">{{address.consignee}}</span>
<span>{{address.mobile}}</span>
</div>
<p class="address address-region">{{address.area}}</p>
<p class="address address-detail">{{address.address}}</p>
</div>
<!--mode-->
<div class="list-item exchange-mode">
<span>换货方式</span>
<i class="icon icon-right right"></i>
<select class="right" v-model="deliveryTpye">
<option v-for="mode in delivery" :value="mode.id">{{mode.name}}</option>
</select>
</div>
</div>
<feature-selector
:is-visible="showFeatureSelector"
:entity="entity"
:on-add-to-cart="whenFeatureChange"
button-text="确定">
</feature-selector>
</div>
</template>
<script>
const $ = require('jquery');
const qs = require('yoho-qs');
const tip = require('common/tip');
const bus = require('common/vue-bus');
const modal = require('common/modal');
const yoho = require('yoho');
const productList = require('me/return/list.vue');
const featureSelector = require('component/product/feature-selector.vue');
const reasonConfig = require('me/return/reason');
module.exports = {
el: '#exchange',
data() {
return {
title: '请选择换货商品',
page: 'exchange',
orderCode: qs.orderCode,
showFeatureSelector: false,
entity: {},
exchangeData: {},
goodsArr: [],
address: {},
delivery: [],
deliveryTpye: null,
indexMap: {}, // goods[index].id 与 index 的映射
processing: false
};
},
events: {
'feature.close': function() {
this.showFeatureSelector = false;
}
},
created() {
// 打开 更换 颜色尺码
bus.$on('open.featureSelector', msg => {
this.queryProductFeature(msg.pid);
});
yoho.addNativeMethod('submitForm', this.submit.bind(this));
// 获取 换货商品
$.ajax({
url: '/me/return/exchange/order',
data: {
orderCode: this.orderCode
}
}).then(res => {
const self = this;
if (res.data && res.data.goodsList) {
res.data.goodsList.forEach((product, index) => {
product.checked = false;
product.change = null;
product.reason = {
id: 0
};
product.imageList = [];
self.indexMap[product.productId] = index; // 生成映射
});
this.$set('goodsArr', res.data.goodsList);
this.$set('exchangeData', res.data);
this.$set('address', res.data.address);
reasonConfig.specialReasons = [];
res.data.specialExchangeReason.forEach(obj => reasonConfig.specialReasons.push(obj.id));
reasonConfig.reasons = [{
id: 0,
name: '请选择'
}].concat(res.data.exchangeReason);
reasonConfig.specialNotice = res.data.specialNoticeBo;
}
});
},
computed: {
selectedGoods() {
return this.goodsArr.filter(goods => goods.checked);
}
},
methods: {
changeAddress() {
const self = this;
yoho.goAddress({
type: '1'
}, (address) => {
if (address) {
self.$set('address', {
addressId: address.address_id,
area: address.area,
zipCode: address.zip_code,
mobile: address.mobile,
address: address.address,
consigneeName: address.consignee_name
});
}
}, () => {
tip('更换地址失败~');
});
},
// 商品 feature改变
whenFeatureChange(selection) {
const index = this.indexMap[selection.goodsId];
const goods = this.goodsArr[index];
goods.change = {
color: selection.color.text,
size: selection.size.text,
goodsId: selection.size.goodsId,
sku: selection.size.value
};
console.log(goods.goodsId);
this.showFeatureSelector = false;
},
// 查询 商品 feature
queryProductFeature(pid) {
$.get(`/product/product_${pid}.json`).then(result => {
this.entity = result;
this.showFeatureSelector = true;
return result;
});
},
// 生成提交数据
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,
app_type: 1,
goods: []
};
this.selectedGoods.forEach(good => {
data.goods.push({
product_skn: good.productSkn,
product_skc: good.productSkc,
product_sku: good.productSku,
goods_type: good.goodsTypeId,
last_price: good.lastPrice,
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.mark && goods.evidence_images)) {
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: '/me/return/exchange/submit',
data
}).then(result => {
if (result.code === 200) {
yoho.goNewPage({
url: `/me/return/exchange/detail/${result.data.applyId}`,
header: {
headerid: 1,
left: {
action: [location.protocol, '//', location.host , '/me/return'].join('')
}
}
});
} else {
modal.alert(result.message);
}
}).always(()=>{
self.processing = false;
});
} else {
modal.alert(msg);
}
}
},
watch: {
// area code 改变,重新获取 换货方式
'address.areaCode': function(newVal, oldVal) {
const self = this;
$.get('/me/return/exchange/delivery', {
areaCode: newVal
})
.then(result => {
$.each(result.data, (index, obj) => {
if (obj.isDefault === 'Y') {
self.$set('deliveryTpye', obj.id);
return false;
}
});
self.$set('delivery', result.data);
});
},
processing(val) {
if (val) {
// when processing
} else {
// when not in processing
}
}
},
components: {
featureSelector,
productList
}
};
</script>
<style>
body {
background-color: #f6f6f6;
}
.exchange-info {
margin: 30px 0;
background-color: #fff;
}
.exchange-address {
.consignee {
font-size: 32px;
font-weight: bold;
margin-bottom: 10px;
}
.address {
font-size: 28px;
color: #b0b0b0;
}
}
.exchange-mode {
font-size: 34px;
.icon,
select {
color: #b0b0b0;
}
.icon:before {
vertical-align: -5px;
}
}
</style>