exchange.vue
8.84 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
<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="co
<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="deliveryType">
<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('yoho-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('home/return/list.vue');
const featureSelector = require('component/product/feature-selector.vue');
module.exports = {
el: '#exchange',
data() {
return {
title: '请选择换货商品',
page: 'exchange',
orderCode: qs.orderId,
showFeatureSelector: false,
entity: {},
exchangeData: {},
goodsArr: [],
address: {},
delivery: [],
deliveryType: null,
indexMap: {} // goods[index].id 与 index 的映射
};
},
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: '/home/exchange/order',
data: {
orderId: 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);
// 全局只读变量 放入 全局对象
const arr = [];
res.data.specialExchangeReason.forEach(obj => arr.push(obj.id));
global.store.reasons = [{
id: 0,
name: '请选择'
}].concat(res.data.exchangeReason);
global.store.specialReasons = arr;
global.store.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;
// this.goodsArr.$set(index, Object.assign({}, goods, change));
},
// 查询 商品 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,
consigee_name: this.address.consignee,
area_code: this.address.areaCode,
zip_code: this.address.zipCode,
mobile: this.address.mobile,
delivery_typ: this.deliveryType,
app_type: 1,
goods: []
};
this.selectedGoods.forEach(good => {
data.goods.push({
product_skn: good.productSkn,
product_skc: 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;
},
// 提交 换货
submit() {
$.ajax({
method: 'POST',
url: '/home/exchange/submit',
data: this.submitData()
}).then(result => {
if (result.code === 200) {
console.log(result);
} else {
modal.alert(result.message);
}
});
}
},
watch: {
// area code 改变,重新获取 换货方式
'address.areaCode': function(newVal, oldVal) {
const self = this;
$.get('/home/exchange/delivery', {
areaCode: newVal
})
.then(result => {
$.each(result.data, (index, obj) => {
if (obj.isDefault === 'Y') {
self.$set('deliveryType', obj.id);
return false;
}
});
self.$set('delivery', result.data);
});
}
},
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>