多规格下架处理

This commit is contained in:
GaoHao
2024-08-07 13:28:02 +08:00
parent 83aeb25652
commit 3b3a08d460

View File

@@ -281,7 +281,7 @@
<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)" :style="{color:!item1.isGrounding?'#999':''}" @click="morloe(item1,index,index1,item)" :style="{color:!item1.isGrounding?'#999':''}"
:class=" item.start == index1 ?'shop_sku_box_item_selected':''"> :class=" item.start == index1 ?'shop_sku_box_item_selected':''">
{{item1.info}} {{item1.name}}
</view> </view>
</view> </view>
</view> </view>
@@ -347,6 +347,7 @@
shopInfo: {}, //店铺信息 shopInfo: {}, //店铺信息
shopProductList: {}, //商品信息 shopProductList: {}, //商品信息
specifications: {}, // 规格信息 specifications: {}, // 规格信息
querySpecList: [],
socketTicket: null, socketTicket: null,
amountcartNumber: 0, amountcartNumber: 0,
isSpec: false, isSpec: false,
@@ -417,6 +418,7 @@
this.fixedtrue = true this.fixedtrue = true
}, },
onShow() { onShow() {
let _this = this;
this.orderdetailFlag = true; this.orderdetailFlag = true;
uni.pageScrollTo({ uni.pageScrollTo({
scrollTop: 0, scrollTop: 0,
@@ -442,6 +444,48 @@
uni.cache.set('userInfo', res.data.userInfo); uni.cache.set('userInfo', res.data.userInfo);
uni.$on('message', this.getMessage) uni.$on('message', this.getMessage)
_this.getLocation()
}
},
fail: (err) => {}
});
} catch (e) {}
}
});
} else {
uni.$on('message', this.getMessage)
_this.getLocation()
}
},
methods: {
navigateBacknav() {
uni.pro.switchTab('index/index')
},
getQueryString(url, name) { //解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
if (r != null) {
return r[2]
}
return null;
},
/**
* socket初始化
*/
handlemessage() {
this.socketTicket ? this.socketTicket.Close() : null //调用前先判断是否有socket正在进行 先关闭后链接
this.socketTicket = new webSocketUtils(`${uni.conf.baseUrlwws}`, 5000, {
tableId: uni.cache.get('tableCode'),
shopId: uni.cache.get('shopUser'),
userId: uni.cache.get('userInfo').id,
"type": "connect",
})
},
/**
* 获取定位
*/
getLocation () {
uni.getLocation({ uni.getLocation({
type: 'wgs84', type: 'wgs84',
success: async (res) => { success: async (res) => {
@@ -484,41 +528,6 @@
} }
} }
}); });
}
},
fail: (err) => {}
});
} catch (e) {}
}
});
} else {
uni.$on('message', this.getMessage)
this.productqueryShop();
}
},
methods: {
navigateBacknav() {
uni.pro.switchTab('index/index')
},
getQueryString(url, name) { //解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
if (r != null) {
return r[2]
}
return null;
},
/**
* socket初始化
*/
handlemessage() {
this.socketTicket ? this.socketTicket.Close() : null //调用前先判断是否有socket正在进行 先关闭后链接
this.socketTicket = new webSocketUtils(`${uni.conf.baseUrlwws}`, 5000, {
tableId: uni.cache.get('tableCode'),
shopId: uni.cache.get('shopUser'),
userId: uni.cache.get('userInfo').id,
"type": "connect",
})
}, },
/** /**
@@ -736,28 +745,46 @@
} else { } else {
// 多规格数据处理 // 多规格数据处理
this.isSpec = false; this.isSpec = false;
let res = await this.api.productquerySpec({ let obj = await this.api.productquerySpec({
productId: item1.id, //商品id productId: item1.id, //商品id
querySpecList: [],
}) })
if (res.code == 0) { this.querySpecList = obj.data;
this.specifications.tagSnap = res.data.map((item) => { this.specifications.tagSnap = JSON.parse(item1.productSkuResult.tagSnap).map((item) => {
console.log(item) let res = {
let data = {
id: item1.id, //商品id id: item1.id, //商品id
name: item.name, name: item.name,
start: -1, start: -1,
children: item.value children: []
} }
// for (let i = 0; i < item.value.length; i++) { item.value.split(",").forEach((v,e)=>{
// if ( item.value[i].isGrounding ) { res.children.push({
// data.start = i; name: v,
// break; // 终止循环 isGrounding: false
// }
// }
return data
}) })
})
return res
})
//初始化第一列规格可编辑
let filteredJson;
let isSkuidname = [];
for (let o = 0; o < this.specifications.tagSnap[0].children.length; o++) {
isSkuidname = JSON.parse(JSON.stringify(this.skuidname));
isSkuidname.push(this.specifications.tagSnap[0].children[o].name)
//筛选符合条件的规格列表
console.log(isSkuidname);
filteredJson = this.querySpecList.filter(obj => obj.specSnap.indexOf(isSkuidname) == 0);
console.log(filteredJson);
for (let i = 0; i < filteredJson.length; i++) {
console.log(filteredJson[i].isGrounding)
if ( filteredJson[i].isGrounding ) {
this.specifications.tagSnap[0].children[o].isGrounding = true
break; // 终止循环
} }
}
}
this.skuBtnText = `您还没选择${this.specifications.tagSnap[0].name}` this.skuBtnText = `您还没选择${this.specifications.tagSnap[0].name}`
// this.specifications.tagSnap.forEach((val, index, arr) => { //初始化skuidname的数据 选择第一个 // this.specifications.tagSnap.forEach((val, index, arr) => { //初始化skuidname的数据 选择第一个
@@ -793,16 +820,20 @@
} else { } else {
this.$set(this.specifications.tagSnap[index], 'start', -1) this.$set(this.specifications.tagSnap[index], 'start', -1)
} }
// this.skuidname.splice(index, 1, e.info); //替换skuidname的数据 this.skuidname = [];
this.specifications.tagSnap.forEach((v,i)=>{ this.specifications.tagSnap.forEach((val, i, arr) => { //初始化skuidname的数据 选择第一个
if ( v.start >= 0 && v.start <= v.children.length) { if ( i > index ) {
querySpecList.push({ val.children.forEach(( v1,e1)=>{
name: v.name, v1.isGrounding = false;
value: v.children[v.start].info
}) })
val.start = -1;
}
if ( val.start >= 0 ) {
this.skuidname.push(val.children[val.start].name)
} }
}) })
// this.skuidname.splice(index, 1, e.info); //替换skuidname的数据
for (let i = 0; i < this.specifications.tagSnap.length; i++) { for (let i = 0; i < this.specifications.tagSnap.length; i++) {
if (this.specifications.tagSnap[i].start < 0) { if (this.specifications.tagSnap[i].start < 0) {
this.isSpec = false; this.isSpec = false;
@@ -811,23 +842,35 @@
} }
} }
let res = await this.api.productquerySpec({
productId: item.id, //商品id let filteredJson;
querySpecList: querySpecList, let isSkuidname = [];
}) //提前下一列规格循环,查看是否有下架规格
if( res.code == 0 ){ if ( this.specifications.tagSnap[index+1] ) {
res.data.forEach((v,e)=>{ for (let o = 0; o < this.specifications.tagSnap[index+1].children.length; o++) {
this.$set(this.specifications.tagSnap[e], 'children', v.value) isSkuidname = JSON.parse(JSON.stringify(this.skuidname));
}) isSkuidname.push(this.specifications.tagSnap[index+1].children[o].name)
//筛选符合条件的规格列表
console.log(isSkuidname);
filteredJson = this.querySpecList.filter(obj => obj.specSnap.indexOf(isSkuidname) == 0);
console.log(filteredJson);
for (let i = 0; i < filteredJson.length; i++) {
console.log(filteredJson[i].isGrounding)
if ( filteredJson[i].isGrounding ) {
this.specifications.tagSnap[index+1].children[o].isGrounding = true
break; // 终止循环
} }
}
}
}
// res.data.forEach((v,e)=>{
// // this.$set(this.specifications.tagSnap[e], 'children', v.value)
// })
console.log(this.specifications.tagSnap) console.log(this.specifications.tagSnap)
this.skuidname = [];
this.specifications.tagSnap.forEach((val, index, arr) => { //初始化skuidname的数据 选择第一个
console.log(val)
if ( val.start >= 0 ) {
this.skuidname.push(val.children[val.start].info)
}
})
this.$forceUpdate(); this.$forceUpdate();
this.hodgepodge(item, 2) this.hodgepodge(item, 2)
}, },