规格逻辑修改

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