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 | 150 +++++++++++++++++++++++++++++++++++-------------- 1 files changed, 107 insertions(+), 43 deletions(-) diff --git a/pages/cart/index.js b/pages/cart/index.js index df1d933..175bdd6 100644 --- a/pages/cart/index.js +++ b/pages/cart/index.js @@ -1,7 +1,13 @@ 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'; + Page({ data: { @@ -34,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; @@ -44,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, + }) }); }, @@ -56,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 }) @@ -107,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) { @@ -139,41 +157,84 @@ totalPrice: totalPrice.toFixed(2) }); }, + + + + + goPaymentPage() { - 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 => { - // console.log(res, 456); - - const url = '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber - wx.navigateTo({ - url - }); + // 棣栭〉娴嬭瘯鐧诲綍鍔熻兘锛屽悗缁敞閲� + // 妫�鏌ョ櫥褰曠姸鎬� + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + 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); + 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', + }); + } + } else { + // 鍑虹幇閿欒锛岃繑鍥瀎alse + } }) } else { - Toast({ - context: this, - selector: '#t-toast', - message: '璇烽�夋嫨鍟嗗搧', - theme: 'warning', - direction: 'column', - }); + 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', + }); + } } + + + }, onLogin() { wx.navigateTo({ url: '/pages/testLogin/index' }); }, - //瑙﹀簳鍑芥暟 - onReachBottom() { + + + onScrollToLower() { if (this.data.shoppingCartData.length < this.data.totalSize) { this.setData({ isMore: true, @@ -188,18 +249,21 @@ this.setData({ isMore: false }) - }, 100) - + 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