From e3f600eb79583a4e118b16cc200ee1e552fa5259 Mon Sep 17 00:00:00 2001 From: whitechiina <1293616053@qq.com> Date: Mon, 20 Jul 2026 14:13:12 +0800 Subject: [PATCH] updata --- .../components/shop-cart/shop-cart.vue | 328 +++++++++--------- unpackage/dist/build/web/index.html | 2 +- .../{index.edf786db.js => index.842605a0.js} | 2 +- ...urant-home-shop_home-shop_home.69677837.js | 1 - ...urant-home-shop_home-shop_home.967c4a3a.js | 1 + 5 files changed, 165 insertions(+), 169 deletions(-) rename unpackage/dist/build/web/static/js/{index.edf786db.js => index.842605a0.js} (99%) delete mode 100644 unpackage/dist/build/web/static/js/pages-restaurant-home-shop_home-shop_home.69677837.js create mode 100644 unpackage/dist/build/web/static/js/pages-restaurant-home-shop_home-shop_home.967c4a3a.js diff --git a/pages/restaurant/home/shop_home/components/shop-cart/shop-cart.vue b/pages/restaurant/home/shop_home/components/shop-cart/shop-cart.vue index 3ee9885..1ddf705 100644 --- a/pages/restaurant/home/shop_home/components/shop-cart/shop-cart.vue +++ b/pages/restaurant/home/shop_home/components/shop-cart/shop-cart.vue @@ -549,174 +549,170 @@ }).exec(); }, methods: { - /** - * @本地数据与当前餐厅数格式化 - * */ - initCategoryNum() { - this['totalPrice'] = 0; - console.log(this.GetCartList, '进入initCategoryNum'); - console.log('新'); - console.log(this['tabbar'], '获取tabbar'); - // 因为该方法是每次商品数据变更都会重新加载,所以不用考虑是否会重复添加问题 - if (this['tabbar']['length'] <= 0) return; - // console.time() - // 先将菜单数据整合成一个数组 - let shoparr = []; - let newArr = []; - let Price = 0; - let lastPrice = 0; - let cardbtPrice = 0; - this['tabbar'].map(item => { - shoparr.push(...item['foods']) - }); - // 将所有商品的id取出 - let commodityids = shoparr.map(item => item['product_id']); - // 循环购物车 - let list = Object.keys(this['GetCartList']); + /** + * @本地数据与当前餐厅数格式化 + * */ + initCategoryNum() { + this['totalPrice'] = 0; + console.log(this.GetCartList, '进入initCategoryNum'); + console.log('新'); + console.log(this['tabbar'], '获取tabbar'); + // 因为该方法是每次商品数据变更都会重新加载,所以不用考虑是否会重复添加问题 + if (this['tabbar']['length'] <= 0) return; + // console.time() + // 先将菜单数据整合成一个数组 + let shoparr = []; + let newArr = []; + let Price = 0; + this['tabbar'].map(item => { + shoparr.push(...item['foods']) + }); + // 将所有商品的id取出 + let commodityids = shoparr.map(item => item['product_id']); + // 循环购物车 + let list = Object.keys(this['GetCartList']); for (let i = 0; i < list['length']; i++) { - let id = +Object.keys(this['GetCartList'])[i]; - console.log(this['GetCartList'][id], "当前商品") - let index = commodityids.indexOf(id); - let item = {}; - if (index != -1) { - item = { - ...shoparr[index], - num: this['GetCartList'][id]['num'], - sku: this['GetCartList'][id]['sku'], - sku_code: this['GetCartList'][id]['sku_code'], - restaurant_id: this['GetShopInfor']['restaurant_id'], - adj_pay: 0, - add_price: this['GetCartList'][id]?.add_price ? (+this['GetCartList'][id]['add_price']) : 0 - }; - console.log(item['sku'], '当前sku'); - item['adj_pay'] = (+item['product_price']) + (+item['add_price']); - Price += item['bt_price'] * item['num']; - lastPrice += item['adj_pay'] * item['num']; - - // 修正:父级商品使用自己的补贴价格 - cardbtPrice += item['subsidy_card_price'] * item['num']; - newArr.push(item); - console.log(this['GetCartList'][id], '是否规格商品'); - - if (this['GetCartList'][id]['Differentskulist'] && this['GetCartList'][id]['Differentskulist']['length'] > 0) { - console.log('多规格'); - for (let j = 0; j < this['GetCartList'][id]['Differentskulist']['length']; j++) { - let _item = this['GetCartList'][id]['Differentskulist'][j]; - console.log(_item, '当前规格商品'); - _item = { - ...shoparr[index], - num: _item['num'], - sku: _item['sku'], - sku_code: _item['sku_code'], - adj_pay: 0, - add_price: _item?.add_price ? _item['add_price'] : 0 - }; - _item['adj_pay'] = (+_item['product_price']) + (+_item['add_price']); - Price += _item['bt_price'] * _item['num']; - lastPrice += _item['adj_pay'] * _item['num']; - - // 修正:使用规格自己的补贴价格,而不是父级商品的 - cardbtPrice += _item['subsidy_card_price'] * _item['num']; - - this['GetCartList'][id]['Differentskulist'][j] = _item; - }; - newArr.push(...this['GetCartList'][id]['Differentskulist']); - } - } else { - // 后期处理存在购物车但是店铺已下架商品 - } - }; - console.log(Price,'Price'); - console.log(newArr, 'newArrnewArrnewArrnewArr'); - this['MealList'] = newArr; + // 将item转为数字 + let id = +Object.keys(this['GetCartList'])[i]; + console.log(this['GetCartList'][id], "当前商品") + // // 在commodityids中查找item + let index = commodityids.indexOf(id); + let item = {}; + if (index != -1) { + + item = { + ...shoparr[index], + num: this['GetCartList'][id]['num'], + sku: this['GetCartList'][id]['sku'], + sku_code: this['GetCartList'][id]['sku_code'], + restaurant_id: this['GetShopInfor']['restaurant_id'], + // 原价 + 加价 + adj_pay: 0, + // 商品加料价格 + add_price:this['GetCartList'][id]?.add_price?(+this['GetCartList'][id]['add_price']):0 + }; + console.log(item['sku'],'当前sku'); + // 原价 + 加料价格 + item['adj_pay'] = (+item['product_price']) + (+item['add_price']); + Price += item['adj_pay'] * item['num']; + newArr.push(item); + console.log(this['GetCartList'][id],'是否规格商品'); + // 此处逻辑是将同商品下的不同规格数据取出来 + if (this['GetCartList'][id]['Differentskulist'] && this['GetCartList'][id]['Differentskulist']['length'] > 0) { + console.log('多规格'); + for (let i = 0; i < this['GetCartList'][id]['Differentskulist']['length']; i++) { + let _item = this['GetCartList'][id]['Differentskulist'][i]; + console.log(_item,'当前规格商品'); + _item = { + ...shoparr[index], + num: _item['num'], + sku: _item['sku'], + sku_code: _item['sku_code'], + // 商品原价 + adj_pay: 0, + // 商品加料价格 + add_price: _item?.add_price?_item['add_price']:0 + }; + _item['adj_pay'] = (+_item['product_price']) + (+_item['add_price']); + Price += _item['adj_pay'] * _item['num']; + this['GetCartList'][id]['Differentskulist'][i] = _item; + }; + newArr.push(...this['GetCartList'][id]['Differentskulist']); + } + + } else { + // 后期处理存在购物车但是店铺已下架商品 + } + }; + console.log(Price,'Price'); + console.log(newArr, 'newArrnewArrnewArrnewArr'); + this['MealList'] = newArr; this['totalPrice'] = Price; - this['lastPrice'] = lastPrice; - this['cardbtPrice'] = cardbtPrice; - // console.timeEnd() - console.log('结束initCategoryNum'); - // if(this['BrandInfor']['brand_id'] == 1 || this['BrandInfor']['brand_id'] == 2 || this['BrandInfor']['brand_id'] == 5 || this['BrandInfor']['brand_id'] == 10 || this['BrandInfor']['brand_id'] == 13){ - - // return - // }; - // console.log(this['tabbar'], '-----------'); - // // 因为该方法是每次商品数据变更都会重新加载,所以不用考虑是否会重复添加问题 - // if (this['tabbar']['length'] <= 0) return; - // console.log(this.GetCartList, '进入initCategoryNum'); - // // console.time() - // // 先将菜单数据整合成一个数组 - // let shoparr = []; - // let newArr = []; - // let Price = 0; - // this['tabbar'].map(item => { - // shoparr.push(...item['foods']) - // }); - // // 将所有商品的id取出 - // let commodityids = shoparr.map(item => item['product_id']); - // // 循环购物车 - // console.log(Object.keys(this['GetCartList']), '*********'); - // let list = Object.keys(this['GetCartList']); - // console.log(list, '进入initCategoryNum'); - // for (let i = 0; i < list['length']; i++) { - // console.log('*********'); - // // 将item转为数字 - // let id = +Object.keys(this['GetCartList'])[i]; - // // // 在commodityids中查找item - // let index = commodityids.indexOf(id); - // let item = {}; - // if (index != -1) { - // item = { - // // ...this['GetCartList'][id], - // ...shoparr[index], - // num: this['GetCartList'][id]['num'], - // sku: this['GetCartList'][id]['sku'], - // sku_code: this['GetCartList'][id]['sku_code'], - // restaurant_id: this['GetShopInfor']['restaurant_id'], - // // 加入购物车时会根据商品原价与算选规格价格计算得到规格价格加上原价的实际价格 - // pay: this['GetCartList'][id]['pay'] || 0 - // }; - - // newArr.push(item); - // if (this['BrandInfor']['brand_id'] == 10) { - // Price += ((+item['pay']) * item['num']); - // } else { - // Price += ((+item['pay_price']) * item['num']); - // }; - // // 此处逻辑是将同商品下的不同规格数据取出来 - // if (this['GetCartList'][id]['Differentskulist'] && this['GetCartList'][id]['Differentskulist'][ - // 'length' - // ] > 0) { - // for (let i = 0; i < this['GetCartList'][id]['Differentskulist']['length']; i++) { - // let _item = this['GetCartList'][id]['Differentskulist'][i]; - // console.log(_item); - // _item = { - // ...shoparr[index], - // num: _item['num'], - // sku: _item['sku'], - // sku_code: _item['sku_code'], - // // 加入购物车时会根据商品原价与算选规格价格计算得到规格价格加上原价的实际价格 - // pay: _item['pay'] - // }; - // this['GetCartList'][id]['Differentskulist'][i] = _item; - // }; - // newArr.push(...this['GetCartList'][id]['Differentskulist']); - // if (this['BrandInfor']['brand_id'] == 10) { - // Price += this['GetCartList'][id]['Differentskulist'].map(e => e['pay'] * e['num']) - // .reduce((a, b) => a + b); - // } else { - // Price += this['GetCartList'][id]['Differentskulist'].map(e => e['pay_price'] * e['num']) - // .reduce((a, b) => a + b); - // } - // } - - // } else { - // // 后期处理存在购物车但是店铺已下架商品 - // } - // }; - // console.log(newArr, 'newArrnewArrnewArrnewArr'); - // this['MealList'] = newArr; - // this['totalPrice'] = Price; - // // console.timeEnd() - // console.log('结束initCategoryNum'); + // console.timeEnd() + console.log('结束initCategoryNum'); + // if(this['BrandInfor']['brand_id'] == 1 || this['BrandInfor']['brand_id'] == 2 || this['BrandInfor']['brand_id'] == 5 || this['BrandInfor']['brand_id'] == 10 || this['BrandInfor']['brand_id'] == 13){ + + // return + // }; + // console.log(this['tabbar'], '-----------'); + // // 因为该方法是每次商品数据变更都会重新加载,所以不用考虑是否会重复添加问题 + // if (this['tabbar']['length'] <= 0) return; + // console.log(this.GetCartList, '进入initCategoryNum'); + // // console.time() + // // 先将菜单数据整合成一个数组 + // let shoparr = []; + // let newArr = []; + // let Price = 0; + // this['tabbar'].map(item => { + // shoparr.push(...item['foods']) + // }); + // // 将所有商品的id取出 + // let commodityids = shoparr.map(item => item['product_id']); + // // 循环购物车 + // console.log(Object.keys(this['GetCartList']), '*********'); + // let list = Object.keys(this['GetCartList']); + // console.log(list, '进入initCategoryNum'); + // for (let i = 0; i < list['length']; i++) { + // console.log('*********'); + // // 将item转为数字 + // let id = +Object.keys(this['GetCartList'])[i]; + // // // 在commodityids中查找item + // let index = commodityids.indexOf(id); + // let item = {}; + // if (index != -1) { + // item = { + // // ...this['GetCartList'][id], + // ...shoparr[index], + // num: this['GetCartList'][id]['num'], + // sku: this['GetCartList'][id]['sku'], + // sku_code: this['GetCartList'][id]['sku_code'], + // restaurant_id: this['GetShopInfor']['restaurant_id'], + // // 加入购物车时会根据商品原价与算选规格价格计算得到规格价格加上原价的实际价格 + // pay: this['GetCartList'][id]['pay'] || 0 + // }; + + // newArr.push(item); + // if (this['BrandInfor']['brand_id'] == 10) { + // Price += ((+item['pay']) * item['num']); + // } else { + // Price += ((+item['pay_price']) * item['num']); + // }; + // // 此处逻辑是将同商品下的不同规格数据取出来 + // if (this['GetCartList'][id]['Differentskulist'] && this['GetCartList'][id]['Differentskulist'][ + // 'length' + // ] > 0) { + // for (let i = 0; i < this['GetCartList'][id]['Differentskulist']['length']; i++) { + // let _item = this['GetCartList'][id]['Differentskulist'][i]; + // console.log(_item); + // _item = { + // ...shoparr[index], + // num: _item['num'], + // sku: _item['sku'], + // sku_code: _item['sku_code'], + // // 加入购物车时会根据商品原价与算选规格价格计算得到规格价格加上原价的实际价格 + // pay: _item['pay'] + // }; + // this['GetCartList'][id]['Differentskulist'][i] = _item; + // }; + // newArr.push(...this['GetCartList'][id]['Differentskulist']); + // if (this['BrandInfor']['brand_id'] == 10) { + // Price += this['GetCartList'][id]['Differentskulist'].map(e => e['pay'] * e['num']) + // .reduce((a, b) => a + b); + // } else { + // Price += this['GetCartList'][id]['Differentskulist'].map(e => e['pay_price'] * e['num']) + // .reduce((a, b) => a + b); + // } + // } + + // } else { + // // 后期处理存在购物车但是店铺已下架商品 + // } + // }; + // console.log(newArr, 'newArrnewArrnewArrnewArr'); + // this['MealList'] = newArr; + // this['totalPrice'] = Price; + // // console.timeEnd() + // console.log('结束initCategoryNum'); }, diff --git a/unpackage/dist/build/web/index.html b/unpackage/dist/build/web/index.html index f607bb6..2451762 100644 --- a/unpackage/dist/build/web/index.html +++ b/unpackage/dist/build/web/index.html @@ -1,2 +1,2 @@