规格逻辑修改

This commit is contained in:
GaoHao
2024-08-06 14:08:34 +08:00
parent a6c73df5e7
commit 085abd62e5

View File

@@ -109,10 +109,10 @@
</view>
<view class="goods" @click="clickspecifications(item1,index,index1)"
v-for="(item1,index1) in item.products" :key="index1">
<!-- <image class="goodsImg" v-if="item1.coverImg!=null" :lazy-load="true"
:src="`${item1.coverImg}?x-oss-process=image/resize,m_lfit,w_150,h_150`" mode="aspectFill"></image> -->
<image class="goodsImg" v-if="item1.coverImg!=null" :lazy-load="true"
:src="`${item1.coverImg}`" mode="aspectFill"></image>
<image class="goodsImg" v-if="item1.coverImg!=null" :lazy-load="true"
:src="`${item1.coverImg}?x-oss-process=image/resize,m_lfit,w_150,h_150`" mode="aspectFill"></image>
<!-- <image class="goodsImg" v-if="item1.coverImg!=null" :lazy-load="true"
:src="`${item1.coverImg}`" mode="aspectFill"></image> -->
<image class="goodsImg" src="@/static/1.gif" mode="" v-else :lazy-load="true"></image>
<view v-if="item.name=='热销'" class="topSort" :class="'c'+(index1+1)">TOP{{index1+1}}
</view>
@@ -169,7 +169,7 @@
<text class="i"></text>
<text class="num">{{cartLists.amount||'0.00'}}</text>
</view>
<view class="btn" @tap="$u.debounce(orderdetail, 500)">
<view class="btn" @tap="orderdetail">
<text class="t">去结算</text>
</view>
</view>
@@ -276,15 +276,15 @@
{{item.name}}
</view>
<view class="flex-start">
<view class="shop_sku_box_item" v-for="(item1,index1) in item.children" :key="index1"
<view class="shop_sku_box_item" v-for="(item1,index1) in item.children" :key="index1"
@click="morloe(item1,index,index1,item)"
:class=" item.start === index1 ?'shop_sku_box_item_selected':'' ">
{{item1}}
:style="{color:!item1.isGrounding?'#999':''}"
:class=" item.start == index1 ?'shop_sku_box_item_selected':''">
{{item1.info}}
</view>
</view>
</view>
<view class="shop_bottom ">
<view class="flex-between">
<view class="price">
@@ -310,7 +310,7 @@
</view>
<view class="addShopping" :class="(amountcartNumber>0&&isSpec)?'active':''"
@click="addShopping(specifications,specifications.indexa,specifications.indexb,'+',specifications.tagSnap == null ? '单规格':'')">
添加到购物车</view>
{{skuBtnText}}</view>
</view>
</view>
</u-popup>
@@ -345,7 +345,6 @@
shopInfo: {}, //店铺信息
shopProductList: {}, //商品信息
specifications: {
}, // 规格信息
socketTicket: null,
amountcartNumber: 0,
@@ -357,7 +356,8 @@
cartListsdatashow: false, //是否显示购物车
showCart: false,
lastbottom: '', //元素最低端的距离
scrollxleft: false
scrollxleft: false,
orderdetailFlag: true,
}
},
onPageScroll(e) {
@@ -399,8 +399,10 @@
},
onUnload() {
this.socketTicket.Close()
uni.$off('message')
if ( this.socketTicket ) {
this.socketTicket.Close()
uni.$off('message')
}
},
onHide() {
this.socketTicket.Close()
@@ -408,6 +410,7 @@
this.fixedtrue = true
},
onShow() {
this.orderdetailFlag = true;
uni.pageScrollTo({
scrollTop: 0,
duration: 0
@@ -659,7 +662,7 @@
* @param {Object} index
* @param {Object} index1
*/
clickspecifications(item1, index, index1, type) {
async clickspecifications(item1, index, index1, type) {
this.skuidname = []
this.specifications = item1
this.specifications.indexa = index
@@ -671,18 +674,36 @@
this.hodgepodge(this.specifications, 2) //获取skuid /2查找价格和数量
} else {
// 多规格数据处理
this.specifications.tagSnap = JSON.parse(item1.productSkuResult.tagSnap).map((item) => {
let res = {
id: item1.id, //商品id
name: item.name,
start: 0,
children: item.value.split(",")
}
return res
})
this.specifications.tagSnap.forEach((val, index, arr) => { //初始化skuidname的数据 选择第一个
this.skuidname.push(val.children[0])
this.isSpec = true;
let res = await this.api.productquerySpec({
productId: item1.id, //商品id
querySpecList:[],
})
if( res.code == 0 ){
this.specifications.tagSnap = res.data.map((item) => {
console.log(item)
let data = {
id: item1.id, //商品id
name: item.name,
start: -1,
children: item.value
}
// for (let i = 0; i < item.value.length; i++) {
// if ( item.value[i].isGrounding ) {
// data.start = i;
// break; // 终止循环
// }
// }
return data
})
}
this.skuBtnText = `您还没选择${this.specifications.tagSnap[0].name}`
// this.specifications.tagSnap.forEach((val, index, arr) => { //初始化skuidname的数据 选择第一个
// console.log(val)
// this.skuidname.push(val.children[0].info)
// })
console.log(this.specifications.tagSnap)
this.hodgepodge(this.specifications.tagSnap[0], 2) //获取skuid /2查找价格和数量
}
@@ -699,25 +720,51 @@
* @param {Object} item
*/
async morloe(e, index, index1, item) {
this.specifications.tagSnap[index]['start'] = index1;
this.skuidname.splice(index, 1, e); //替换skuidname的数据
this.isSpec = true;
let _this = this;
if ( !e.isGrounding ) {
return;
}
let querySpecList = [];
this.specifications.tagSnap.forEach((v,e) => {
querySpecList.push({
name: v.name,
value : v.children[v.start],
})
this.skuBtnText = "添加到购物车";
this.isSpec = true;
if ( this.specifications.tagSnap[index].start != index1) {
this.$set(this.specifications.tagSnap[index], 'start', index1)
} else {
this.$set(this.specifications.tagSnap[index], 'start', -1)
}
_this.skuidname.splice(index, 1, e.info); //替换skuidname的数据
_this.specifications.tagSnap.forEach((v,i)=>{
if ( v.start >= 0 && v.start <= v.children.length) {
querySpecList.push({
name: v.name,
value: v.children[v.start].info
})
}
})
let res = await this.api.productquerySpec({
for (let i = 0; i < this.specifications.tagSnap.length; i++) {
if ( this.specifications.tagSnap[i].start < 0) {
this.isSpec = false;
this.skuBtnText = `您还没选择${this.specifications.tagSnap[i].name}`
break; // 终止循环
}
}
let res = await _this.api.productquerySpec({
productId: item.id, //商品id
querySpecList: querySpecList,
})
if( res.code == 0 ){
// this.isSpec = false;
// this.skuBtnText = "";
res.data.forEach((v,e)=>{
_this.$set(this.specifications.tagSnap[e], 'children', v.value)
// _this.specifications.tagSnap[e].children = v.value
})
}
this.hodgepodge(item, 2)
console.log(_this.specifications.tagSnap)
this.$forceUpdate();
_this.hodgepodge(item, 2)
},
/**
@@ -729,12 +776,12 @@
*/
async hodgepodge(item, a, c, num) { //此接口去获取商品id !!!赋值库存 数量 价格等
try {
console.log(this.skuidname.join(","))
let res = await this.api.productqueryProductSku({
code: uni.cache.get('tableCode'),
shopId: uni.cache.get('shopUser'),
productId: item.id, //商品id
spec_tag: this.skuidname.join(","),
querySpecList: [],
})
this.salePrice = res.data.salePrice // 价格
let data = null;
@@ -764,8 +811,10 @@
* 结算直接生成订单
*/
orderdetail() {
console.log(this.cartLists)
console.log(this.shopInfo)
if ( !this.orderdetailFlag ) {
return;
}
this.orderdetailFlag = false;
if (this.cartLists.data.length == 0) {
uni.showToast({
title: '请先添加商品',
@@ -1292,11 +1341,12 @@
.flex-start {
.shop_sku_box_item {
margin-top: 16rpx;
padding: 8rpx 24rpx;
padding: 12rpx 28rpx;
border-radius: 8rpx;
font-size: 24upx;
margin-left: 56rpx;
background: #F5F5F5;
border: 2rpx solid #F5F5F5;
}
.shop_sku_box_item:nth-child(1) {