From 778faddcd404e787ef8452b30e1f73495a518c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TOP=E7=B3=AF=E7=B1=B3?= <1130395124@qq.com> Date: Sun, 9 Apr 2023 12:46:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=AD=E7=89=A9=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/service/cart.vue | 63 ++++++++++++++---------------------- src/pages/service/cate.vue | 8 ++--- src/pages/service/detail.vue | 15 +++------ src/pages/service/list.vue | 34 +++++++++---------- 4 files changed, 47 insertions(+), 73 deletions(-) diff --git a/src/pages/service/cart.vue b/src/pages/service/cart.vue index d6ff167..3315843 100644 --- a/src/pages/service/cart.vue +++ b/src/pages/service/cart.vue @@ -83,52 +83,39 @@ export default { ...mapState({ cart: (state) => state.cart.cart, }), - ...mapGetters({ - isLogin: "user/isLogin", - }), }, - onLoad() { - if (!this.isLogin) { - this.$store.commit("user/showLoginModal", true); - return; - } - this.initPage(); + onLoad() {}, + async onShow() { + await this.$store.dispatch("cart/update"); + this.list = []; + this.cart.list.forEach((item) => { + let goods = []; + item.good.forEach((v) => { + goods.push({ + id: v.gid, + name: v.title, + times: v.post_hits, + cover: v.thumbnail, + price: v.money, + number: v.number, + checked: false, + }); + }); + this.list.push({ + name: item.cate, + total: 0, + list: goods, + checked: false, + canUse: false, + }); + }); }, - onShow() {}, onReady() {}, onReachBottom() {}, onPullDownRefresh() {}, onShareTimeline() {}, onShareAppMessage() {}, methods: { - /** - * 初始化页面 - */ - async initPage(e) { - await this.$store.dispatch("cart/update"); - this.list = []; - this.cart.list.forEach((item) => { - let goods = []; - item.good.forEach((v) => { - goods.push({ - id: v.gid, - name: v.title, - times: v.post_hits, - cover: v.thumbnail, - price: v.money, - number: v.number, - checked: false, - }); - }); - this.list.push({ - name: item.cate, - total: 0, - list: goods, - checked: false, - canUse: false, - }); - }); - }, /** * 选中组 */ diff --git a/src/pages/service/cate.vue b/src/pages/service/cate.vue index 708e1da..283321b 100644 --- a/src/pages/service/cate.vue +++ b/src/pages/service/cate.vue @@ -25,7 +25,7 @@ :animation="false" :x="position.x" :y="position.y" - @click="toCartPage" + @click="utils.toPage('/pages/service/cart')" > <view class="cart-icon"> <text class="iconfont icon-gouwuche"></text> @@ -47,6 +47,7 @@ export default { name: "service-cate", data() { return { + utils: this.$utils, movableAreaStyle: { height: 0, bottom: 0, @@ -178,11 +179,6 @@ export default { this.loadCate(); }, 1000); }, - toCartPage() { - if (this.briefCart.count > 0) { - this.$utils.toPage("/pages/service/cart"); - } - }, }, }; </script> diff --git a/src/pages/service/detail.vue b/src/pages/service/detail.vue index 5c4e823..c3fd1d7 100644 --- a/src/pages/service/detail.vue +++ b/src/pages/service/detail.vue @@ -158,9 +158,12 @@ export default { this.appraise.total = this.appraise.cate[0].count; this.changeAppraiseCate(this.appraise.cate[0], 0); }); - this.initPage(); }, - onShow() {}, + onShow() { + if (this.isLogin) { + this.$store.dispatch("cart/update"); + } + }, onReady() {}, onReachBottom() { if (this.tabIndex == 0) return; @@ -170,14 +173,6 @@ export default { onShareTimeline() {}, onShareAppMessage() {}, methods: { - /** - * 初始化页面 - */ - initPage() { - if (this.isLogin) { - this.$store.dispatch("cart/update"); - } - }, /** * 分享 */ diff --git a/src/pages/service/list.vue b/src/pages/service/list.vue index b26eff1..5e871c3 100644 --- a/src/pages/service/list.vue +++ b/src/pages/service/list.vue @@ -11,7 +11,7 @@ /> </view> <view class="common-bottom-components" :style="{ paddingBottom: pageConfig.safeAreaInsets.bottom + 'px' }"> - <view class="cart" @click="toCartPage"> + <view class="cart" @click="utils.toPage('/pages/service/cart')"> <view class="cart-icon"> <text class="iconfont icon-gouwuche"></text> </view> @@ -34,6 +34,7 @@ export default { name: "service-list", data() { return { + utils: this.$utils, pageConfig: {}, data: [], currentId: 0, @@ -50,31 +51,26 @@ export default { }), }, onLoad(e) { - this.initPage(e); + this.pageConfig = getApp().globalData.pageConfig; + if (!e.id) { + return this.$utils.toast("参数错误"); + } + this.currentId = e.id; + // 初始化列表 + this.data = []; + this.loadList(this.currentId); + }, + onShow() { + if (this.isLogin) { + this.$store.dispatch("cart/update"); + } }, - onShow() {}, onReady() {}, onReachBottom() {}, onPullDownRefresh() {}, onShareTimeline() {}, onShareAppMessage() {}, methods: { - /** - * 初始化页面 - */ - initPage(e) { - this.pageConfig = getApp().globalData.pageConfig; - if (this.isLogin) { - this.$store.dispatch("cart/update"); - } - if (!e.id) { - return this.$utils.toast("参数错误"); - } - this.currentId = e.id; - // 初始化列表 - this.data = []; - this.loadList(this.currentId); - }, /** * 加载列表 */