Blame view

src/store/modules/details.js 5.65 KB
1b4b4938a   Adam   auto commit the c...
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
  import urlAlias from '../url'
  import request from '../request'
  
  const {
  	read,
  	cartList,
  	makePost,
  } = urlAlias
  
  const state = {
  	// 为配合参数选择框
  	goodInfo: {},
  	// 轮播图
  	carousel: [
  		'/static/img/detail/d9.png',
  	],
  	// 商品基本信息
  	goodsInfo: {
  		name: '暂无名称',
  		price: '暂无价格',
  		discountPrice: undefined,
  		tradeNumber: undefined,
  	},
  	// 商品介绍
  	// tag: {
  	// 	prod_tag_style: [{
  	// 		label: '青春学子风',
  	// 		value: '54',
  	// 	}],
  	// },
  	// 规格参数
  	specification: [{
  			key: 'frame_width',
  			img: '/static/img/detail/d2.png',
  			standard: '框架宽',
  			slength: '139mm'
  		},
  		{
  			key: 'glass_width',
  			img: '/static/img/detail/d3.png',
  			standard: '镜片宽',
  			slength: '51mm'
  		},
  		{
  			key: 'glass_height',
  			img: '/static/img/detail/d4.png',
  			standard: '镜片高',
  			slength: '45mm'
  		},
  		{
  			key: 'nose_width',
  			img: '/static/img/detail/d5.png',
  			standard: '鼻架宽',
  			slength: '19mm'
  		},
  		{
  			key: 'leg_long',
  			img: '/static/img/detail/d6.png',
  			standard: '框架耳长',
  			slength: '138mm'
  		},
  		{
  			key: 'weight',
  			img: '/static/img/detail/d7.png',
  			standard: '框架重',
  			slength: '19克(grams)'
  		},
  	],
  	Tag: {
  		Age: [],
  		Colour: [],
  		Eyeglasses: [],
  		Gender: [],
  		Hinge: [],
  		Material: [],
  		Rim: [],
  		Shape: [],
  		Style: [],
  	},
  	// 评价
  	evaluate: {
  		rate: '100%',
  		star: 5,
  		tag: [{
  			name: '价格实惠'
  		}],
  	},
  	// 商品详情
  	more: '',
  	// 购物车数目
  	cartNumber: 0,
  	// skuList
  	skuList: [],
  	postUrl: 'https://api.glass.xiuyetang.com/adv_pic/428_0_7.png',
  }
  
  const mutations = {
  	INIT: (state, {
  		goodInfo,
  		carousel,
  		goodsInfo,
  		Tag,
  		specification,
  		evaluate,
  		more,
  		skuList
  	}) => {
  		state.goodInfo = goodInfo
  		state.carousel = carousel
  		state.goodsInfo = goodsInfo
  		state.Tag = Tag
  		state.specification = specification
  		state.evaluate = evaluate
  		state.more = more
  		state.skuList = skuList
  		// state.current = 1
  	},
  	CART: (state, number) => {
  		state.cartNumber = number
  	},
  	POST: (state, url) => {
  		state.postUrl = url
  	},
  }
  
  const actions = {
  	// 获取详情
  	details({
  		commit,
  		rootState
  	}, param) {
  		// console.log('paramparamparamparamparam', param);
  		return new Promise((resolve, reject) => request({
  			url: read,
  			data: param,
  			success: ({
  				data: {
  					data
  				}
  			}) => {
  				// console.log('======>>>>>>>>>>>>>>>>datadatadatadatadatadatadata<<<<<<<<<<<<<<<<<<<<<======', data)
  				// console.log('rootStaterootStaterootStaterootState', rootState.details)
  				const specification = rootState.details.specification == undefined ? [] : rootState
  					.details.specification;
  				specification[0].key = "frame_width";
  				specification[0].slength = data.frame_width;
  				specification[1].key = "lens_width";
  				specification[1].slength = data.lens_width;
  				specification[2].key = "glass_height";
  				specification[2].slength = data.glass_height;
  				specification[3].key = "nose_width";
  				specification[3].slength = data.nose_bridge;
  				specification[4].key = "leg_long";
  				specification[4].slength = data.leg_temple;
  				specification[5].key = "weight";
  				specification[5].slength = data.frame_weight;
  
  				const parameter = {
  					frame_weight: data.frame_weight,
  					frame_width: data.frame_width,
  					glass_height: data.glass_height,
  					nose_width: data.nose_bridge,
  					lens_width: data.lens_width,
  					leg_long: data.leg_temple,
  					weight: data.frame_weight,
  				}
  				for (let index = 0; index < specification.length; index++) {
  					if (specification[index].key !== 'weight') {
  						specification[index].slength = `${parameter[specification[index].key]}mm`
  					} else {
  						if (parameter[specification[index].key] == 0) {
  							specification[index].slength = '未知重量'
  						} else {
  							specification[index].slength = `${parameter[specification[index].key]}克`
  						}
  
  					}
  				}
  
  				const Tag = data.tag_defined
  				if (Tag.Age == undefined || Tag.Age == null) {
  					Tag.Age = []
  				}
  				console.log('TagTagTagTagTagTagTag=======', Tag);
  				commit('INIT', {
  					goodInfo: data,
  					skuList: data.sku,
  					carousel: data.sku[0].sku_pic_arr_http,
  					goodsInfo: {
  						name: data.shop_wood_name,
  						price: data.sales_price,
  						discountPrice: data.sales_price - Number(0),
  						tradeNumber: data.sales_num,
  					},
  					Tag:Tag,
  					specification,
  					evaluate: {
  						rate: 5,
  						tag: data.judge.list,
  						// star: parseInt(5 * Number(data.judgeInfo.good.slice(0, -1)) / 100),
  						star: 5,
  					},
  					// eslint-disable-next-line
  					// more: data.prodIntro1.replace(/\<img/gi, '<img style="max-width:100%;height:auto"'),
  					more: data.shop_wood_desc_rich_text,
  					// current:1
  				})
  				resolve(data)
  			},
  			fail: (res) => {
  				console.log('fail status ===>', res)
  			},
  		}))
  	},
  	// 获取购物车列表
  	getCartNumber({
  		commit
  	}, param) {
  		return new Promise((resolve) => request({
  			url: cartList,
  			data: param,
  			success: ({
  				data: {
  					data
  				}
  			}) => {
  				let number = 0
  				for (let index = 0; index < data.length; index++) {
  					number += Number(data[index].num)
  				}
  				commit('CART', number)
  			},
  		}))
  	},
  	// 生成分享海报
  	post({
  		commit
  	}, param) {
  		return new Promise((resolve) => request({
  			url: makePost,
  			data: param,
  			success: ({
  				data
  			}) => {
  				commit('POST', data.data)
  				resolve()
  			},
  		}))
  	},
  }
  
  export default {
  	namespaced: true,
  	state,
  	mutations,
  	actions,
3cda19af7   范牧   详情页-售后保障
257
  }