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 | 179 +++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 105 insertions(+), 74 deletions(-) diff --git a/pages/cart/index.js b/pages/cart/index.js index 41fcea5..db4d31b 100644 --- a/pages/cart/index.js +++ b/pages/cart/index.js @@ -1,89 +1,120 @@ -// pages/cart/index.js -const app = getApp() +const app = getApp(); +// import { getPublicImage } from '@/assets/js/middleGround/tool.js' +import { getPublicImage } from '../../assets/js/middleGround/tool'; + Page({ - - /** - * 椤甸潰鐨勫垵濮嬫暟鎹� - */ data: { - right: [ - { - text: '缂栬緫', - className: 'btn edit-btn', - }, - { - text: '鍒犻櫎', - className: 'btn delete-btn', - }, - ], + imgUrl: [], + shoppingCartData: [], + checkAll: false, + checkedList: [], + selectedCount: 0, + totalPrice: 0.00 }, - onDelete() { - wx.showToast({ title: '浣犵偣鍑讳簡鍒犻櫎', icon: 'none' }); - }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 - */ + onLoad(options) { - this.shoppingCartGet() + 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() { - - }, - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 - */ - onHide() { - - }, - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 - */ - onUnload() { - - }, - - /** - * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 - */ - onPullDownRefresh() { - - }, - - /** - * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� - */ - onReachBottom() { - - }, - - /** - * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� - */ - onShareAppMessage() { - - }, shoppingCartGet() { - - app.MG.store.getShoppingCartProductList({ + let query = { start: 0, size: 999, filterList: [], searchList: [] - }).then(res => { - console.log(res); + }; + app.MG.store.getShoppingCartProductList(query).then(res => { + res.datas.forEach(item => { + item.imgUrl = getPublicImage(item.productMonWithLinkDto.product.icon, '', '160'); + }); + + this.setData({ + shoppingCartData: res.datas + }); + }); + }, + + 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(); + }, + + 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(); + }, + + calculateSelectedCount() { + const selectedItems = this.data.shoppingCartData.filter(item => item.checked); + const selectedCount = selectedItems.length; + this.setData({ + selectedCount + }); + }, + + 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() { + + + 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