diff --git a/pages/order_food/order_food.vue b/pages/order_food/order_food.vue index 2f2c26d..00e0ded 100644 --- a/pages/order_food/order_food.vue +++ b/pages/order_food/order_food.vue @@ -109,10 +109,10 @@ - - + + TOP{{index1+1}} @@ -169,7 +169,7 @@ {{cartLists.amount||'0.00'}} - + 去结算 @@ -276,15 +276,15 @@ {{item.name}} - - {{item1}} + :style="{color:!item1.isGrounding?'#999':''}" + :class=" item.start == index1 ?'shop_sku_box_item_selected':''"> + {{item1.info}} - @@ -310,7 +310,7 @@ - 添加到购物车 + {{skuBtnText}} @@ -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) {