|
|
|
@ -18,21 +18,21 @@
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<block v-if="goods._skus.length > 0">
|
|
|
|
|
<view v-for="(item, index) in goods._skus"
|
|
|
|
|
:key="index"
|
|
|
|
|
<view v-for="(item, index) in goods._skus"
|
|
|
|
|
:key="index"
|
|
|
|
|
class="sku_list">
|
|
|
|
|
<view class="sku_name">
|
|
|
|
|
{{item.skuname}}
|
|
|
|
|
</view>
|
|
|
|
|
<view class="sku_tag">
|
|
|
|
|
<view v-for="(row, sIndex) in item.child"
|
|
|
|
|
:key="row.id"
|
|
|
|
|
class="tag_s"
|
|
|
|
|
<view v-for="(row, sIndex) in item.child"
|
|
|
|
|
:key="row.id"
|
|
|
|
|
class="tag_s"
|
|
|
|
|
:class="[currentArr['' + index] == row.id ? ' active' : '']"
|
|
|
|
|
@tap="setTag(item, index, sIndex, row)"
|
|
|
|
|
@tap="setTag(item, index, sIndex, row)"
|
|
|
|
|
>
|
|
|
|
|
{{row.tagname}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
@ -41,8 +41,8 @@
|
|
|
|
|
<view class="n_left">购买数量</view>
|
|
|
|
|
<view class="n_right">
|
|
|
|
|
<text class="jian" @tap="onChangeNum('reduce')">-</text>
|
|
|
|
|
<input v-model="number"
|
|
|
|
|
type="number" max="99999"
|
|
|
|
|
<input v-model="number"
|
|
|
|
|
type="number" max="99999"
|
|
|
|
|
@input="handlerChangeNum"
|
|
|
|
|
min="1"
|
|
|
|
|
class="inputs"></input>
|
|
|
|
@ -72,7 +72,7 @@ export default {
|
|
|
|
|
issku: false ,//判断当前商品是否存在规格
|
|
|
|
|
update: true,
|
|
|
|
|
nowList:{},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stock: 99999
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
@ -104,50 +104,48 @@ export default {
|
|
|
|
|
this.$set(this.currentArr, index, v.child[0].id)
|
|
|
|
|
})
|
|
|
|
|
this.number = 1 //初始数量
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
handlerChangeNum() {
|
|
|
|
|
debounce(() => {
|
|
|
|
|
const num = Number(this.number)
|
|
|
|
|
if (num < 1 || !num) {
|
|
|
|
|
this.number = 1
|
|
|
|
|
}
|
|
|
|
|
if (num > this.stock) {
|
|
|
|
|
this.number = this.stock
|
|
|
|
|
}
|
|
|
|
|
}, 500)
|
|
|
|
|
|
|
|
|
|
// debounce(() => {
|
|
|
|
|
|
|
|
|
|
// }, 5000)
|
|
|
|
|
const num = Number(this.number)
|
|
|
|
|
if (num > this.stock) {
|
|
|
|
|
this.number = this.stock
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
moveHandle(){
|
|
|
|
|
return
|
|
|
|
|
return
|
|
|
|
|
},
|
|
|
|
|
setTag(items, current, indexs,row) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(items, current, indexs,row)
|
|
|
|
|
//选择规格
|
|
|
|
|
let that = this
|
|
|
|
|
let item = items
|
|
|
|
|
let pid = items.sku_id
|
|
|
|
|
let isChecked = true; // 选中 or 取消选中
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const findIndex = this.currentArr.findIndex(v => v === row.id)
|
|
|
|
|
// if (findIndex > -1) {
|
|
|
|
|
// this.currentArr.splice(findIndex, 1, '');
|
|
|
|
|
// isChecked = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
// this.$set(this.currentArr, current, row.id)
|
|
|
|
|
// }
|
|
|
|
|
// this.currentArr[current + ''] = row.id
|
|
|
|
|
this.$set(this.currentArr, current, row.id)
|
|
|
|
|
|
|
|
|
|
const chooseSkuId = Object.values(this.currentArr).filter(v => !!v);
|
|
|
|
|
|
|
|
|
|
const chooseSkuId = Object.values(this.currentArr).filter(v => !!v);
|
|
|
|
|
|
|
|
|
|
let newSku = this.getAllSku() //获取符合条件的规格数据
|
|
|
|
|
|
|
|
|
|
that.skulength = chooseSkuId.length
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(chooseSkuId.length == that.nowList.sku.length && newSku.length){
|
|
|
|
|
//如果所有的规格类都被选中了 设置当前选中项商品的信息
|
|
|
|
|
that.currentSku = newSku[0]
|
|
|
|
@ -160,7 +158,7 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
changeDisabled(isChecked=false,skuId=0, pid=0){ //改变禁用状态
|
|
|
|
|
let newSku = []
|
|
|
|
|
if (isChecked) {
|
|
|
|
|
if (isChecked) {
|
|
|
|
|
for(let key of this.skuArr){ //遍历可用规格数组
|
|
|
|
|
if(key.stock <= 0){ //如果规格现有的库存小于等于0
|
|
|
|
|
continue
|
|
|
|
@ -197,7 +195,7 @@ export default {
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 当前已选择的规格大类
|
|
|
|
|
let chooseSkuKey = [];
|
|
|
|
|
if (!isChecked) {
|
|
|
|
@ -241,7 +239,8 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onChangeNum(type = 'reduce') {
|
|
|
|
|
let num = Number(this.number)
|
|
|
|
|
const total = Math.floor(Number(this.number))
|
|
|
|
|
let num = total < 1 ? 1 : total > this.stock ? this.stock : total
|
|
|
|
|
if (type === 'add') {
|
|
|
|
|
if (num >= this.stock) {
|
|
|
|
|
return
|
|
|
|
@ -255,7 +254,7 @@ export default {
|
|
|
|
|
num -= 1
|
|
|
|
|
}
|
|
|
|
|
this.number = num
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
onsubmit(value) {
|
|
|
|
|
// 此处应该判断是否登录 如果没登录 跳转到登录页
|
|
|
|
@ -284,6 +283,8 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
const data = this.goods
|
|
|
|
|
const selectedSku = []
|
|
|
|
|
const total = Math.floor(Number(this.number))
|
|
|
|
|
this.number = total < 1 ? 1 : total > this.stock ? this.stock : total
|
|
|
|
|
Object.keys(this.currentArr).forEach(key => {
|
|
|
|
|
const item = this.currentArr[key]
|
|
|
|
|
if (item) {
|
|
|
|
@ -317,7 +318,7 @@ export default {
|
|
|
|
|
colCart = [data]
|
|
|
|
|
}
|
|
|
|
|
resetCart(colCart)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 存储商品数据
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '加入购物车成功 !',
|
|
|
|
@ -327,7 +328,7 @@ export default {
|
|
|
|
|
* 模拟获取购物车的数量 getCart
|
|
|
|
|
*/
|
|
|
|
|
let cartNum = getCartNumber()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTabBarBadge(cartNum)
|
|
|
|
|
}else{ //如果是购买商品
|
|
|
|
|
let goods = []
|
|
|
|
@ -537,4 +538,4 @@ export default {
|
|
|
|
|
background-color: #F9F9F9;
|
|
|
|
|
opacity: 0.5;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
</style>
|
|
|
|
|