From f0229b7c6801f6429dec75e208192b61053b8c7d Mon Sep 17 00:00:00 2001 From: yiming <m13691596795@163.com> Date: 星期三, 03 四月 2024 09:46:02 +0800 Subject: [PATCH] 书目 --- pages/cart/index.js | 95 ++++++++++++++++++++++++++++++++--------------- 1 files changed, 64 insertions(+), 31 deletions(-) diff --git a/pages/cart/index.js b/pages/cart/index.js index 546e1c1..175bdd6 100644 --- a/pages/cart/index.js +++ b/pages/cart/index.js @@ -1,9 +1,14 @@ const app = getApp(); // import { getPublicImage } from '@/assets/js/middleGround/tool.js' -import { getPublicImage } from '../../assets/js/middleGround/tool'; +import { + loginInfo +} from '../../assets/js/login'; +import { + getPublicImage +} from '../../assets/js/middleGround/tool'; import Toast from 'tdesign-miniprogram/toast/index'; -import { loginInfo } from '../../assets/js/login'; + Page({ data: { onDisabled: false, @@ -35,9 +40,11 @@ }) } this.shoppingCartGet(); - this.setData({ totalPrice: 0.00, selectedCount: 0, checkAll: false, }) - - + this.setData({ + totalPrice: 0.00, + selectedCount: 0, + checkAll: false, + }) }, onDelete(e) { const item = e.currentTarget.dataset.item; @@ -45,7 +52,15 @@ ids: [item.id] }).then(res => { this.shoppingCartGet(); - wx.showToast({ title: '鍒犻櫎鍥句功鎴愬姛', icon: 'none' }); + wx.showToast({ + title: '鍒犻櫎鍥句功鎴愬姛', + icon: 'none' + }); + this.setData({ + totalPrice: 0.00, + selectedCount: 0, + checkAll: false, + }) }); }, @@ -57,28 +72,28 @@ searchList: [] }; app.MG.store.getShoppingCartProductList(query).then(res => { - + console.log(res, 'res'); this.setData({ totalSize: res.totalSize }) res.datas.forEach(item => { - // console.log(item, 'item456'); item.imgUrl = getPublicImage(item.productMonWithLinkDto.product.icon, '', '160'); - - this.setData({ - type: item.saleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product' - }) - + // this.setData({ + // type: item.saleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product' + // }) + const type = item.saleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product'; + item.type = type; // 灏唗ype璁剧疆涓篿tem瀵硅薄鐨勫睘鎬э紝鑰屼笉鏄娇鐢╯etData + console.log(item.linkCmsItems[0].name); + item.name = item.linkCmsItems[0].name ? item.productMonWithLinkDto.product.name + ':' + item.linkCmsItems[0].name : item.productMonWithLinkDto.product.name }); this.setData({ shoppingCartData: res.datas }); - + console.log(this.data.shoppingCartData, 'shoppingCartData'); if (this.data.shoppingCartData.length === 0) { - console.log(11111); this.setData({ onDisabled: true }) @@ -108,7 +123,9 @@ }, HandelItemChange(e) { - const { item } = e.target.dataset; + const { + item + } = e.target.dataset; const items = this.data.shoppingCartData items.map(eitem => { if (eitem.id == item.id) { @@ -147,7 +164,6 @@ goPaymentPage() { - // 棣栭〉娴嬭瘯鐧诲綍鍔熻兘锛屽悗缁敞閲� // 妫�鏌ョ櫥褰曠姸鎬� const token = wx.getStorageSync(app.config.tokenKey) @@ -155,8 +171,6 @@ loginInfo(app, (data) => { // 濡傛灉涓嶆槸绗竴娆$櫥褰曪紝浼氭墽琛屽洖璋� if (data) { - - const selectedItems = this.data.shoppingCartData.filter(item => item.checked); // console.log(selectedItems, 789); const selectedIds = selectedItems.map(item => item.id); @@ -166,9 +180,6 @@ linkIds: selectedIds } app.MG.store.shoppingCartCreateOrder(data).then(res => { - // console.log(res, 456); - - const url = '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber wx.navigateTo({ url @@ -188,11 +199,30 @@ } }) } else { - // 濡傛灉鏄涓�娆$櫥褰曪紝浼氳烦杞嚦缁戝畾鐢ㄦ埛淇℃伅椤甸潰锛屽~鍐欏畬鐢ㄦ埛淇℃伅鍚庤繘琛岀櫥褰曞苟鍌ㄥ瓨token鍜岀敤鎴蜂俊鎭紝缁撴潫鍚庤烦杞洖褰撳墠椤甸潰锛堟惡甯﹂〉闈㈠弬鏁帮級 + const selectedItems = this.data.shoppingCartData.filter(item => item.checked); + // console.log(selectedItems, 789); + const selectedIds = selectedItems.map(item => item.id); + console.log('閫変腑鐨勫晢鍝� id:', selectedIds); + if (selectedIds.length) { + let data = { + linkIds: selectedIds + } + app.MG.store.shoppingCartCreateOrder(data).then(res => { + const url = '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber + wx.navigateTo({ + url + }); + }) + } else { + Toast({ + context: this, + selector: '#t-toast', + message: '璇烽�夋嫨鍟嗗搧', + theme: 'warning', + direction: 'column', + }); + } } - - - @@ -202,8 +232,9 @@ url: '/pages/testLogin/index' }); }, - //瑙﹀簳鍑芥暟 - onReachBottom() { + + + onScrollToLower() { if (this.data.shoppingCartData.length < this.data.totalSize) { this.setData({ isMore: true, @@ -220,17 +251,19 @@ }) console.log('300'); }, 300) - } }, // 涓嬫媺鍑芥暟 onPullDownRefresh() { this.setData({ - start: 1 + start: 1, + checkAll: false, + selectedCount: 0, + totalPrice: 0.00, }) console.log(978); this.shoppingCartGet() }, -}); +}); \ No newline at end of file -- Gitblit v1.9.1