3f535f30
杨鑫
'初始'
|
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
|
</view>
</view>
</view>
</view>
</view>
<!-- 商品详情-->
<u-popup v-model="goosDetailshowFlag" mode="bottom" border-radius="14">
<view class="goosDetailshow-box">
<view class="detailImg-box flex-row-plus">
<image class="detailImg default-img" :src="skuImg"></image>
<view class="flex-column-plus mar-left-40">
<view class="font-color-C5AA7B">
<label class="fs24">¥</label>
<label class="fs36 mar-left-10"
v-text="detailList.activityType == 1 ? skuOriginalPrice : skuPrice"></label>
</view>
<label class="fs24 font-color-999 mar-top-20">库存 {{stockNumber}} 件</label>
<label class="fs24 mar-top-20">已选</label>
</view>
</view>
<view class="color-box flex-column-plus">
<view v-for="(attritem,index) in skuProdList.names" :key="index">
<label class="fs24 font-color-999">{{attritem.skuName}}</label>
<view class="colorName-box">
<view class="pad-bot-30" v-for="(attrRes, resIndex) in attritem.values" :key="resIndex">
<view class="colorName" :class="{'colorName-on' :subIndex[index] == resIndex}"
@click="colorActiveClick(attrRes,index,resIndex)">{{attrRes.skuValue}}</view>
</view>
</view>
</view>
</view>
<view class="goodsNum-box flex-row-plus flex-sp-between">
<label class="font-color-999 fs24">数量</label>
<view class="goodsNum">
<text class="subtract" @click="numSub()">-</text>
<text class="goodsNumber" v-model="buyNum">{{buyNum}}</text>
<text class="add" @click.stop="numAdd()">+</text>
</view>
</view>
<view class="flex-items flex-sp-around btnBox">
<view class="goosDetailbut-box flex-row-plus" @click="goosDetailshowFlag = false">
<view class="buyNowBut cancelBtn">取消</view>
</view>
<view class="goosDetailbut-box flex-items-plus" @click="goosDetailshowFlag = false">
<view class="buyNowBut" @click="addCart">确定</view>
</view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
// selectCompose
const NET = require('../../utils/request')
const API = require('../../config/api')
export default {
name: "combination",
data() {
return {
page: 1,
pageSize: 10,
list:[],
pricing: {},
productList: [],
ruleList: [],
autoplay: true,
duration: 2000,
vertical: true,
circular: true,
buyNum: 1,
goosDetailshowFlag: false, // 规格选择
shopId: 0,
skuId: 0,
terminal: 1,
skuPrice: '',
skuOriginalPrice: '',
attrItemIdArr: [],
detailList: [],
subIndex: [],
selectArr: [], // 存放被选中的值
skuProdList: [],
stockNumber: 0,
skuImg: '',
currentIndex: null,
priceId: null
}
},
onLoad(option) {
console.log(option.priceId, 'priceId')
this.priceId = option.priceId
this.getSelectByPriceId() // 获取定价
this.getSelectProductListByPriceId()
},
methods: {
getSelectByPriceId() {
// uni.showLoading({
// mask: true,
// title: '加载中...',
// })
NET.request(API.selectByPriceId,{
priceId: this.priceId
},'GET').then(res => {
uni.hideLoading()
this.ruleList = res.data
}).catch(res => {
})
},
showRuleBox(item, index) {
this.shopId = item.shopId
this.productId = item.productId
this.skuId = item.skuId
this.currentIndex = index
this.goosDetailshowFlag = true
this.getProductSku()
this.queryProductDetail()
},
getSelectProductListByPriceId() {
NET.request(API.selectProductListByPriceId,{
priceId: this.priceId,
page: this.page,
pageSize: this.pageSize
},'GET').then(res => {
uni.hideLoading()
// this.productList = res.data.list
var proList = res.data.list
proList.forEach((item) => {
item['selected'] = 0
this.productList.push(item)
})
}).catch(res => {
})
},
//商品详情
goodsDateils(shopId,productId,skuId){
uni.navigateTo({
url: 'goodsDetails?shopId='+shopId + '&productId='+productId +'&skuId='+skuId
})
},
//获取商品详情
queryProductDetail() {
NET.request(API.QueryProductDetail, {
shopId: this.shopId,
productId: this.productId,
skuId: this.skuId,
terminal: 1
},
"GET").then(res => {
this.detailList = res.data
this.skuPrice = res.data.price
this.skuOriginalPrice = res.data.originalPrice
for (let i = 0; i < res.data.attrList.length; i++) {
this.subIndex[i] = 0
}
this.attrItemIdArr[0] = res.data.attrList[0].attrValueList[0].id
this.$forceUpdate()
}).catch(res => {
})
},
getProductSku() {
NET.request(API.QueryProductSku, {
skuId: this.skuId,
productId: this.productId
}, 'GET').then(res => {
this.skuProdList = res.data
this.attrList = res.data.names
this.attrValueList = res.data.names[0].values
console.log(this.attrValueList[0], 'arr')
//渲染商详之后,默认先选中第一个规格
this.colorActiveClick(this.attrValueList[0], 0, 0)
this.skuProdId = this.skuId
// this.skuImg = res.data.image
this.skuPrice = res.data.price
this.skuOriginalPrice = res.data.originalPrice
// console.log(this.skuOriginalPrice,333)
this.stockNumber = res.data.stockNumber
this.detailList.ifHuabei = res.data.ifHuabei
//this.renderHuabei(this.skuPrice)
this.$forceUpdate()
}).catch(res => {
})
},
//颜色选中事件
colorActiveClick(res, index, resIndex) {
let t = this;
console.log(res,index,resIndex)
console.log(this.selectArr)
console.log(this.subIndex)
console.log(this.attrItemIdArr)
t.selectArr[index] = res;
t.subIndex[index] = resIndex;
t.attrItemIdArr[index] = res.valueCode
t.checkItem();
t.checkItemDataClick(t.attrItemIdArr)
},
checkItemDataClick(attrItemIdArr) {
let attrkey = ''
for (let i = 0; i < attrItemIdArr.length; i++) {
attrkey += attrItemIdArr[i] + ','
}
attrkey = attrkey.substring(0, attrkey.length - 1)
let mapinfo = this.skuProdList.map
for (var key in mapinfo) {
if (attrkey == key) {
this.skuProdId = mapinfo[key].skuId
this.skuImg = mapinfo[key].skuImg
this.skuPrice = mapinfo[key].price
this.skuOriginalPrice = mapinfo[key].originalPrice
this.stockNumber = mapinfo[key].stockNumber
}
}
//console.log(attrItemIdArr.length, 'num')
var currentCode = ''
for (var i = 0; i < attrItemIdArr.length; i++) {
if (i === 1 && attrItemIdArr.length > 1) {
currentCode += ',' + attrItemIdArr[i]
} else {
currentCode += attrItemIdArr[i]
}
}
for (let key in this.skuProdList.map) {
if (key == currentCode) {
this.skuImg = this.skuProdList.map[key].image
this.detailList.originalPrice = this.skuProdList.map[key].originalPrice
if (this.skuProdList.map[key].activityType == 1) {
this.ifGroupPro = true
return false
} else {
this.ifGroupPro = false
}
}
}
//console.log(this.skuProdList, 'list')
},
checkItem() {
var self = this;
var option = self.attrList;
var result = []; // 定义数组存储被选中的值
for (let i in option) {
result[i] = self.selectArr[i] ? self.selectArr[i] : "";
if (!self.subIndex[i]) {
self.subIndex[i] = 0
}
if (!self.attrItemIdArr[i]) {
self.attrItemIdArr[i] = option[i].values[0].valueCode
}
}
for (let i in option) {
var last = result[i]; // 把选中的值存放到字符串last去
for (let k in option[i].item) {
result[i] = option[i].item[k].name; // 赋值,存在直接覆盖,不存在往里面添加name值
}
result[i] = last; // 还原,目的是记录点下去那个值,避免下一次执行循环时避免被覆盖
}
self.$forceUpdate(); // 重绘
},
// 数量减
numSub() {
console.log('this.buyNum', this.buyNum)
if (this.buyNum > 1) {
this.buyNum = this.buyNum - 1
} else {
uni.showToast({
title: '亲!至少一件哦!',
icon: "none"
})
}
},
// 数量加
numAdd() {
if (this.buyNum < this.stockNumber) {
this.buyNum = this.buyNum + 1
} else {
uni.showToast({
title: '库存不足!',
icon: "none"
})
}
},
//加入购物车
addCart() {
//判断是否登录
if (this.stockNumber < 1) {
uni.showToast({
title: '库存不足',
icon: "none"
})
} else {
// uni.showLoading({
// mask: true,
// title: '添加中...',
// })
NET.request(API.ShoppingaddCart, {
skuId: this.skuProdId,
number: this.buyNum,
}, 'POST').then(res => {
uni.hideLoading()
uni.showToast({
title: '添加成功',
icon: 'none'
})
setTimeout(() => {
this.productList[this.currentIndex].selected = 1
this.goosDetailshowFlag = false
uni.showModal({
title: '温馨提示',
content: '商品已成功加入购物车?',
confirmText: "去结算",
cancelText: '继续添加',
success: res => {
if (res.confirm) {
uni.switchTab({
url: '../../pages/tabbar/cart/index'
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}, 1000);
this.buyNum = 1
}).catch(res => {
uni.hideLoading()
if (res.data.code == 40005) {
uni.navigateTo({
url: '../../pages_category_page2/userModule/login'
})
}
})
}
}
}
}
</script>
<style lang="scss" scoped>
page {
background: #333333;
}
.combinationBox {
.topInfo {
margin: 40rpx 0;
.topBg {
margin: 30rpx auto;
width: 670rpx;
height: 86rpx;
line-height: 86rpx;
text-align: center;
|