From 0375a599e25b7f27c57d8c00f801761d9cce8aa2 Mon Sep 17 00:00:00 2001 From: yiming <m13691596795@163.com> Date: 星期二, 05 三月 2024 18:12:17 +0800 Subject: [PATCH] revert: 阿斯顿 --- pages/cart/index.js | 140 ++++++++++++++++++++++++++++++++-------------- 1 files changed, 97 insertions(+), 43 deletions(-) diff --git a/pages/cart/index.js b/pages/cart/index.js index 7622fcd..db4d31b 100644 --- a/pages/cart/index.js +++ b/pages/cart/index.js @@ -1,66 +1,120 @@ -// pages/cart/index.js +const app = getApp(); +// import { getPublicImage } from '@/assets/js/middleGround/tool.js' +import { getPublicImage } from '../../assets/js/middleGround/tool'; + Page({ - - /** - * 椤甸潰鐨勫垵濮嬫暟鎹� - */ data: { - + imgUrl: [], + shoppingCartData: [], + checkAll: false, + checkedList: [], + selectedCount: 0, + totalPrice: 0.00 }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 - */ onLoad(options) { - + wx.setNavigationBarTitle({ + title: '璐墿杞�' + }); + this.shoppingCartGet(); }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 - */ - onReady() { - + onDelete(e) { + const item = e.currentTarget.dataset.item; + app.MG.store.delShoppingCart({ + ids: [item.id] + }).then(res => { + this.shoppingCartGet(); + wx.showToast({ title: '浣犵偣鍑讳簡鍒犻櫎', icon: 'none' }); + }); }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず - */ - onShow() { + shoppingCartGet() { + let query = { + start: 0, + size: 999, + filterList: [], + searchList: [] + }; + app.MG.store.getShoppingCartProductList(query).then(res => { + res.datas.forEach(item => { + item.imgUrl = getPublicImage(item.productMonWithLinkDto.product.icon, '', '160'); + }); + this.setData({ + shoppingCartData: res.datas + }); + }); }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 - */ - onHide() { - + bottomChange(e) { + const checked = e.detail.value.length > 0; + const items = this.data.shoppingCartData.map(item => { + item.checked = checked; + return item; + }); + this.setData({ + shoppingCartData: items, + checkAll: checked + }); + this.calculateSelectedCount(); + this.calculateTotalPrice(); }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 - */ - onUnload() { + HandelItemChange(e) { + const { item } = e.target.dataset; + const items = this.data.shoppingCartData + items.map(eitem => { + if (eitem.id == item.id) { + eitem.checked = e.detail.checked + } + + }) + const data = items.filter(item => item.checked) + const checkAll = data.length == this.data.shoppingCartData.length + + this.setData({ + shoppingCartData: items, + checkAll + }); + this.calculateSelectedCount(); + this.calculateTotalPrice(); }, - /** - * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 - */ - onPullDownRefresh() { - + calculateSelectedCount() { + const selectedItems = this.data.shoppingCartData.filter(item => item.checked); + const selectedCount = selectedItems.length; + this.setData({ + selectedCount + }); }, - /** - * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� - */ - onReachBottom() { - + calculateTotalPrice() { + const selectedItems = this.data.shoppingCartData.filter(item => item.checked); + const totalPrice = selectedItems.reduce((total, item) => total + parseFloat(item.saleMethod.price), 0); + this.setData({ + totalPrice: totalPrice.toFixed(2) + }); }, + goPaymentPage() { - /** - * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� - */ - onShareAppMessage() { + + const selectedItems = this.data.shoppingCartData.filter(item => item.checked); + console.log(selectedItems, 789); + const selectedIds = selectedItems.map(item => item.id); + console.log('閫変腑鐨勫晢鍝� id:', selectedIds); + + app.MG.store.shoppingCartCreateOrder({ linkIds: selectedIds }).then(res => { + console.log(res.orderNumber, 456); + const url = '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber + wx.navigateTo({ + url + }); + + + }) + } -}) \ No newline at end of file +}); -- Gitblit v1.9.1