From 89a420209a025b1250a6453397750269d32e791d Mon Sep 17 00:00:00 2001 From: wangfukang <15630117759@163.com> Date: Tue, 23 Jun 2026 18:27:51 +0800 Subject: [PATCH] 1 --- components/tab-bar/delivery.vue | 667 ++++++++++++++++++++++++++------ components/tab-bar/myCenter.vue | 33 +- components/tab-bar/tab-bar.vue | 136 +++++-- 3 files changed, 672 insertions(+), 164 deletions(-) diff --git a/components/tab-bar/delivery.vue b/components/tab-bar/delivery.vue index 99c72d4..478afa9 100644 --- a/components/tab-bar/delivery.vue +++ b/components/tab-bar/delivery.vue @@ -3,12 +3,15 @@ - + - 待取货 + + 待取货 + {{deliveryStatusCounts.daiqu}} + - 待送达 + + 待送达 + {{deliveryStatusCounts.daisong}} + - @@ -58,22 +63,39 @@ 跑腿 - | - - - 接单规则 + + + + + 今日接单状态 + + {{isOnLine == 1 ? '已上线' : '已离线'}} + + + {{deliveryStatusText}} + + {{zhipaiCheck ? '自动派单已开启' : '自动派单未开启'}} + 覆盖 {{totalRuleCount}} 条路线 + 最低 {{minRuleFeeText}} 起 + - - - 已上线 + + + 我的接单范围 - - 已离线 + + {{isOnLine == 1 ? '下线休息' : '上线接单'}} + + 赚钱地盘 + 还没划定赚钱地盘 + 设置接单路线,用户下单时即可直接指派给你 + 去设置接单范围 + {{item.numberCode.length>14 ?'多订单':item.numberCode | delPlus}} @@ -199,7 +221,8 @@ - 用户申请退款中 + + 用户申请退款中 @@ -235,22 +258,31 @@ - + - - 设置指派单规则 + + 选择参与自动派单的接单范围 + + + 开启后,系统只会把符合你设置区域和最低佣金的订单派给你。未勾选路线不会参与指派。 - 接受指派单 + 开启接受指派单 - + + 当前离线,保存后需要上线才会收到系统派单。 + + + 你还没有接单范围 + 先去划定想送的楼栋和最低配送费,设置后才能开启自动派单。 + + - 外卖规则 + 外卖接单范围 全选 @@ -279,6 +311,7 @@ {{item.putAreaName}} + 最低¥{{item.orderBkge || 0}} @@ -288,7 +321,7 @@ - 跑腿规则 + 快递接单范围 全选 @@ -317,6 +350,7 @@ {{item.putAreaName}} + 最低¥{{item.orderBkge || 0}} @@ -325,16 +359,16 @@ style="margin-left:5px;"> --> - + 没有更多了 - - - 补充规则 + + + 补充范围 - - 确认规则 + + 确认并保存 @@ -377,6 +411,16 @@ + + + + + + + + + @@ -389,7 +433,9 @@ bigImg: '', zhipaiCheck: false, tab1Checked: 'daiqu', - menuButtonInfo: {}, + menuButtonInfo: { + top: 44 + }, scrollTop: 0, oldScrollTop: 0, isLoadingPage: false, @@ -409,6 +455,10 @@ }, waimaRuleList: [], tab1Checked1: '', + deliveryStatusCounts: { + daiqu: 0, + daisong: 0 + }, pageData: [], deliveryItem: [], deliveryItem1: [], @@ -435,11 +485,16 @@ }, watch: { + }, + mounted() { + this.loadDeliveryStatusCounts() + uni.$on('deliveryStatusCountsChange', this.setDeliveryStatusCounts) }, onReachBottom() { this.onReachPage(); }, beforeDestroy() { + uni.$off('deliveryStatusCountsChange', this.setDeliveryStatusCounts) if (this.refreshLoadingTimer) { clearTimeout(this.refreshLoadingTimer) this.refreshLoadingTimer = null @@ -449,6 +504,37 @@ uni.hideLoading() } }, + computed: { + totalRuleCount() { + return (this.waimaRuleList ? this.waimaRuleList.length : 0) + (this.paotuiRuleList ? this.paotuiRuleList.length : 0) + }, + activeRuleCount() { + const list = (this.waimaRuleList || []).concat(this.paotuiRuleList || []) + return list.filter(item => item.getPushOrder == 1 || item.isChecked).length + }, + minRuleFeeText() { + const fees = (this.waimaRuleList || []).concat(this.paotuiRuleList || []) + .map(item => parseFloat(item.orderBkge)) + .filter(item => !isNaN(item) && item > 0) + if (fees.length == 0) return '' + return '¥' + Math.min.apply(null, fees).toFixed(2).replace(/\.?0+$/, '') + }, + deliveryStatusText() { + if (this.totalRuleCount == 0) { + return '未设置区域,用户下单时将无法按范围指派你' + } + if (this.isOnLine != 1) { + return '已设置范围,但当前离线,系统不会派单' + } + if (!this.zhipaiCheck) { + return '已上线,未开启自动派单,系统不会派单' + } + if (this.activeRuleCount == 0) { + return '已上线,但还没有勾选参与派单的路线' + } + return '已准备好接收符合范围和佣金的订单' + } + }, filters: { formatHourMinute(value) { if (!value) return ''; @@ -492,6 +578,26 @@ } }, methods: { + loadDeliveryStatusCounts() { + this.setDeliveryStatusCounts(uni.getStorageSync('deliveryStatusCounts') || {}) + }, + setDeliveryStatusCounts(counts) { + this.deliveryStatusCounts = { + daiqu: Number(counts.daiqu) || 0, + daisong: Number(counts.daisong) || 0 + } + uni.setStorageSync('deliveryStatusCounts', this.deliveryStatusCounts) + }, + decreaseDeliveryStatusCount(status) { + if (status == 2) { + this.deliveryStatusCounts.daiqu = Math.max(0, Number(this.deliveryStatusCounts.daiqu) - 1) + this.deliveryStatusCounts.daisong = Number(this.deliveryStatusCounts.daisong) + 1 + } else if (status == 3) { + this.deliveryStatusCounts.daisong = Math.max(0, Number(this.deliveryStatusCounts.daisong) - 1) + } + uni.setStorageSync('deliveryStatusCounts', this.deliveryStatusCounts) + uni.$emit('deliveryStatusCountsChange', this.deliveryStatusCounts) + }, formatTimeText(value) { if (!value) return ''; const date = new Date(value); @@ -539,13 +645,14 @@ }, init() { if (!this.ensureLogin()) return + this.menuButtonInfo = uni.getMenuButtonBoundingClientRect() let worker = uni.getStorageSync('worker') if (worker == '' || worker == undefined || worker == null) { this.tui.toast('您还没有注册兼职') return } - this.menuButtonInfo = uni.getMenuButtonBoundingClientRect() this.isOnLine = uni.getStorageSync('worker').isOnLine + this.zhipaiCheck = uni.getStorageSync('worker').getPushOrder == 1 ? true : false if (uni.getStorageSync('area')) { this.searchForm.regionId = JSON.parse(uni.getStorageSync('area')).id; } @@ -553,12 +660,85 @@ this.searchForm.workerId = uni.getStorageSync('worker').workerId } this.$forceUpdate() + this.loadWorkerRules() this.getDelivery() this.$nextTick(() => { this.measureScrollView() }) }, + goRuleSetting() { + this.goPartTimeRegister() + }, + goPartTimeRegister() { + if (uni.getStorageSync('worker')) { + uni.navigateTo({ + url: '/package2/myCenter/partTimeJobRegister' + }) + return + } + this.$refs.jianzhiPopup.open() + }, + createPartTimeWorker() { + if (!this.ensureLogin()) return + let worker = uni.getStorageSync('worker') + if (worker) { + this.$refs.jianzhiPopup.close() + uni.navigateTo({ + url: '/package2/myCenter/partTimeJobRegister' + }) + return + } + const area = uni.getStorageSync('area') ? JSON.parse(uni.getStorageSync('area')) : {} + this.tui.request("/worker/admin/add", "POST", { + userId: uni.getStorageSync('id'), + isChangeArea: 1, + region: area.id + }, false, true).then((res) => { + if (res.code == 200) { + if (res.result != null) { + uni.setStorageSync('worker', res.result) + } + this.$refs.jianzhiPopup.close() + uni.navigateTo({ + url: '/package2/myCenter/partTimeJobRegister' + }) + } else { + this.tui.toast(res.message) + } + uni.hideLoading() + }).catch((res) => {}) + }, + ensureWorkerRegistered() { + if (!this.ensureLogin()) return false + const worker = uni.getStorageSync('worker') + if (worker && worker.workerId) return true + this.$refs.jianzhiPopup.open() + return false + }, + loadWorkerRules(openAfterLoad) { + const worker = uni.getStorageSync('worker') + if (!worker || !worker.workerId) return + let that = this + that.tui.request("/app/workerRelaPrice/getByWorkerId?workerId=" + worker.workerId, + "GET", {}, false, true).then((res) => { + if (res.code == 200) { + let list = res.result && res.result.workerRelaPriceList ? res.result.workerRelaPriceList : [] + for (let i = 0; i < list.length; i++) { + list[i].isChecked = list[i].getPushOrder == 1 + } + that.waimaRuleList = list.filter(item => item.orderType == 0) + that.paotuiRuleList = list.filter(item => item.orderType == 1) + that.zhipaiCheck = uni.getStorageSync('worker').getPushOrder == 1 ? true : false + that.$forceUpdate() + if (openAfterLoad) { + that.$refs.carPopup.open() + } + } else { + that.tui.toast(res.message) + } + }).catch((res) => {}) + }, // 获取用户位置 getUserLocation(item) { if (!this.ensureLogin()) return @@ -611,7 +791,7 @@ }) }, chooseType(type) { - if (!this.ensureLogin()) return + if (!this.ensureWorkerRegistered()) return if (this.tab1Checked1 == type) { this.tab1Checked1 = '' this.searchForm.deliveryType = null @@ -707,9 +887,7 @@ }, buchong() { this.$refs.carPopup.close() - uni.navigateTo({ - url: '/package2/myCenter/partTimeJobRegister' - }) + this.goPartTimeRegister() }, selectRule(item) { @@ -794,72 +972,10 @@ if (!this.ensureLogin()) return const worker = uni.getStorageSync('worker') if (!worker || !worker.workerId) { - this.tui.toast('您还没有注册兼职') + this.$refs.jianzhiPopup.open() return } - if (this.isOnLine != 1) { - this.tui.toast('请先上线后配置'); - return; - } - let that = this - that.tui.request("/app/workerRelaPrice/getByWorkerId?workerId=" + worker.workerId, - "GET", {}, false, true).then((res) => { - if (res.code == 200) { - if (res.result != null) { - let data = res.result; - let list = data.workerRelaPriceList || []; - for (let i = 0; i < list.length; i++) { - list[i].isChecked = false - } - let waimaList = list.filter(item => item.orderType == 0); - let paotuiList = list.filter(item => item.orderType == 1); - - if (waimaList.length > 0) { - that.waimaRuleList = waimaList; - } - if (paotuiList.length > 0) { - that.paotuiRuleList = paotuiList; - } - - that.$forceUpdate(); - } - this.zhipaiCheck = uni.getStorageSync('worker').getPushOrder == 1 ? true : false - /* if(uni.getStorageSync('waimaiData')){ - let waimaiData = uni.getStorageSync('waimaiData') - for(let i=0;i {}) + this.loadWorkerRules(true) }, checkArea() { this.isArea = !this.isArea @@ -884,6 +1000,7 @@ }, false, true).then((res) => { if (res.code == 200) { this.pageData.splice(index, 1) + this.decreaseDeliveryStatusCount(2) this.tui.toast(res.message, 200) this.$forceUpdate() } else { @@ -915,6 +1032,7 @@ if (res.code == 200) { if (status == 2 || status == 3) { that.pageData.splice(index, 1) + that.decreaseDeliveryStatusCount(status) } else { that.pageData[index].arriveTime = "qq" } @@ -930,7 +1048,7 @@ }).catch((res) => {}); }, checkTab1(type) { - if (!this.ensureLogin()) return + if (!this.ensureWorkerRegistered()) return this.tab1Checked = type if (type == 'daiqu') { this.searchForm.status = 1 @@ -942,7 +1060,7 @@ this.getDelivery() }, refreshCurrentTab() { - if (!this.ensureLogin()) return + if (!this.ensureWorkerRegistered()) return if (this.refreshLoading) return this.refreshLoading = true this.refreshLoadingStartTime = Date.now() @@ -1073,13 +1191,13 @@ } .delivery-title-tabs { - width: 380rpx; + width: 460rpx; display: flex; align-items: center; } .delivery-title-tabs .tab1 { - width: 260rpx; + width: 340rpx; flex-shrink: 0; } @@ -1127,6 +1245,35 @@ font-weight: 700; color: #777; flex: 1; + min-width: 0; + display: flex; + justify-content: center; + align-items: center; + white-space: nowrap; + } + + .tab-label { + display: flex; + align-items: center; + justify-content: center; + white-space: nowrap; + } + + .tab-count { + min-width: 32rpx; + height: 32rpx; + line-height: 32rpx; + margin-left: 8rpx; + padding: 0 8rpx; + display: inline-block; + border-radius: 999rpx; + background: linear-gradient(135deg, #ff8a1f 0%, #ff3f5f 100%); + color: #fff; + font-size: 20rpx; + font-weight: 900; + text-align: center; + vertical-align: middle; + box-sizing: border-box; } .delivery-filter-row { @@ -1138,6 +1285,111 @@ line-height: 64rpx; } + .delivery-status-card { + width: 95%; + margin: 18rpx auto 0; + padding: 22rpx; + box-sizing: border-box; + display: flex; + align-items: center; + border-radius: 28rpx; + background: + radial-gradient(circle at 92% 20%, rgba(166, 255, 234, 0.58) 0, rgba(166, 255, 234, 0) 160rpx), + linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(244, 255, 250, 0.92)); + box-shadow: 0 16rpx 36rpx rgba(0, 35, 28, 0.1); + } + + .delivery-status-main { + flex: 1; + min-width: 0; + } + + .delivery-status-title-row { + display: flex; + align-items: center; + } + + .delivery-status-title { + font-size: 30rpx; + font-weight: 900; + color: #00231C; + } + + .delivery-status-pill { + margin-left: 14rpx; + height: 40rpx; + line-height: 40rpx; + padding: 0 16rpx; + border-radius: 40rpx; + background: rgba(255, 117, 88, 0.14); + color: #d34a32; + font-size: 22rpx; + font-weight: 800; + } + + .delivery-status-pill--on { + background: rgba(166, 255, 234, 0.72); + color: #00624f; + } + + .delivery-status-desc { + margin-top: 10rpx; + color: #4c625d; + font-size: 24rpx; + line-height: 34rpx; + } + + .delivery-status-meta { + margin-top: 12rpx; + display: flex; + flex-wrap: wrap; + gap: 10rpx; + color: #0b6b5a; + font-size: 20rpx; + font-weight: 700; + } + + .delivery-status-meta text { + padding: 4rpx 12rpx; + border-radius: 999rpx; + background: rgba(166, 255, 234, 0.36); + } + + .delivery-status-meta .delivery-status-meta--warn { + background: rgba(255, 117, 88, 0.12); + color: #d96b5c; + } + + .delivery-status-actions { + width: 180rpx; + margin-left: 18rpx; + flex-shrink: 0; + } + + .delivery-status-action { + height: 62rpx; + line-height: 62rpx; + margin-top: 12rpx; + border-radius: 62rpx; + background: #fff; + color: #00231C; + font-size: 22rpx; + font-weight: 800; + text-align: center; + border: 2rpx solid rgba(0, 35, 28, 0.08); + box-shadow: 0 8rpx 18rpx rgba(0, 35, 28, 0.08); + } + + .delivery-status-action:first-child { + margin-top: 0; + } + + .delivery-status-action--primary { + background: linear-gradient(90deg, rgba(227, 255, 150, 1), rgba(166, 255, 234, 1)); + border-color: rgba(166, 255, 234, 0.8); + box-shadow: 0 10rpx 22rpx rgba(0, 112, 91, 0.14); + } + .filter-divider { flex-shrink: 0; padding: 0 14rpx 0 2rpx; @@ -1168,6 +1420,52 @@ flex-shrink: 0; } + .delivery-empty-guide { + margin: 20rpx auto; + padding: 44rpx 30rpx; + border-radius: 30rpx; + background: #fff; + text-align: center; + box-shadow: 0 12rpx 30rpx rgba(0, 35, 28, 0.06); + } + + .delivery-empty-illustration { + width: 180rpx; + height: 180rpx; + line-height: 180rpx; + margin: 0 auto 24rpx; + border-radius: 50%; + background: linear-gradient(135deg, #e3ff96, #a6ffea); + color: #07372f; + font-size: 28rpx; + font-weight: 900; + } + + .delivery-empty-title { + font-size: 34rpx; + font-weight: 900; + color: #00231C; + } + + .delivery-empty-desc { + margin-top: 14rpx; + color: #6d7b77; + font-size: 24rpx; + line-height: 38rpx; + } + + .delivery-empty-btn { + width: 320rpx; + height: 78rpx; + line-height: 78rpx; + margin: 28rpx auto 0; + border-radius: 78rpx; + background: linear-gradient(90deg, rgba(227, 255, 150, 1), rgba(166, 255, 234, 1)); + color: #00231C; + font-size: 28rpx; + font-weight: 900; + } + .box1 { width: 100%; margin: 20rpx auto 20rpx; @@ -1240,21 +1538,33 @@ .refund-status { width: 100%; - height: 100rpx; - margin-top: 32rpx; + margin-top: 24rpx; display: flex; align-items: center; } .refund-status-text { - height: 56rpx; - line-height: 56rpx; - padding: 0 24rpx; - background: rgba(255, 117, 88, 0.12); - color: #ff4d35; - border: 1px solid rgba(255, 117, 88, 0.35); - border-radius: 16rpx; - font-weight: 700; + width: 100%; + min-height: 72rpx; + padding: 0 22rpx; + display: flex; + align-items: center; + background: rgba(255, 244, 236, 0.96); + color: #c56a35; + border: 1px solid rgba(255, 181, 120, 0.52); + border-radius: 18rpx; + font-size: 26rpx; + font-weight: 800; + box-sizing: border-box; + } + + .refund-status-dot { + width: 14rpx; + height: 14rpx; + margin-right: 12rpx; + border-radius: 50%; + background: #ff9a4a; + box-shadow: 0 0 0 8rpx rgba(255, 154, 74, 0.12); } .order-action { @@ -1316,12 +1626,125 @@ } .guize-list { - width: 600rpx; - padding: 20rpx 20rpx 0; + width: 100%; + padding: 30rpx 28rpx 0; background: #fff; - border-radius: 20rpx; - height: 1000rpx; + border-radius: 36rpx 36rpx 0 0; + height: 76vh; position: relative; + display: flex; + flex-direction: column; + box-sizing: border-box; + } + + .dispatch-popup-title { + line-height: 48rpx; + font-size: 34rpx; + font-weight: 900; + text-align: center; + color: #00231C; + } + + .dispatch-popup-desc { + margin: 12rpx 0 8rpx; + padding: 18rpx 20rpx; + border-radius: 18rpx; + background: rgba(166, 255, 234, 0.22); + color: #526964; + font-size: 24rpx; + line-height: 36rpx; + } + + .dispatch-warning { + margin: 12rpx 0; + padding: 14rpx 18rpx; + border-radius: 16rpx; + background: rgba(255, 233, 89, 0.24); + color: #926500; + font-size: 24rpx; + font-weight: 700; + } + + .dispatch-empty { + margin: 20rpx 0; + padding: 34rpx 20rpx; + border-radius: 22rpx; + background: rgba(247, 248, 248, 0.9); + text-align: center; + } + + .dispatch-empty-title { + font-size: 30rpx; + font-weight: 900; + color: #00231C; + } + + .dispatch-empty-desc { + margin-top: 10rpx; + color: #7b8a85; + font-size: 24rpx; + line-height: 36rpx; + } + + .dispatch-rule-fee { + height: 40rpx; + line-height: 40rpx; + margin: 20rpx 16rpx 0 0; + padding: 0 12rpx; + border-radius: 40rpx; + background: rgba(255, 233, 89, 0.32); + color: #8a5a00; + font-size: 20rpx; + font-weight: 800; + flex-shrink: 0; + } + + .dispatch-rule-scroll { + flex: 1; + min-height: 0; + height: auto; + overflow-y: scroll; + } + + .dispatch-scroll-bottom { + width: 100%; + height: 60rpx; + line-height: 60rpx; + color: #9ca6a2; + text-align: center; + } + + .dispatch-actions { + display: flex; + gap: 18rpx; + padding: 18rpx 0 calc(132rpx + constant(safe-area-inset-bottom)); + padding: 18rpx 0 calc(132rpx + env(safe-area-inset-bottom)); + background: #fff; + flex-shrink: 0; + z-index: 2; + } + + .dispatch-action-btn { + flex: 1; + height: 78rpx; + line-height: 78rpx; + border-radius: 78rpx; + text-align: center; + font-size: 28rpx; + font-weight: 900; + box-sizing: border-box; + } + + .dispatch-action-btn--secondary { + background: rgba(166, 255, 234, 0.28); + color: #00624f; + border: 2rpx solid rgba(166, 255, 234, 0.88); + } + + .dispatch-action-btn--primary { + background: linear-gradient(90deg, rgba(227, 255, 150, 1), rgba(166, 255, 234, 1)); + color: #00231C; + box-shadow: 0 10rpx 22rpx rgba(0, 112, 91, 0.14); } .zhipai-box { @@ -1628,4 +2051,16 @@ font-weight: 700; text-align: center; } + + .jianzhi-content { + width: 300px; + height: 350px; + position: relative; + } + + .jianzhi-close { + position: absolute; + bottom: -50px; + left: 130px; + } \ No newline at end of file diff --git a/components/tab-bar/myCenter.vue b/components/tab-bar/myCenter.vue index f66f728..ccc60fd 100644 --- a/components/tab-bar/myCenter.vue +++ b/components/tab-bar/myCenter.vue @@ -52,7 +52,8 @@ workerCounts: 0, shopCounts: 0, balance: 0, - worker: uni.getStorageSync('worker') + worker: uni.getStorageSync('worker'), + balanceRefreshId: 0 } }, props: { @@ -60,8 +61,19 @@ }, watch: { + }, + mounted() { + uni.$on('myCenterCountsChange', this.setPendingCounts) + }, + beforeDestroy() { + uni.$off('myCenterCountsChange', this.setPendingCounts) }, methods: { + setPendingCounts(counts) { + this.workerCounts = Number(counts.workerCounts) || 0 + this.shopCounts = Number(counts.shopCounts) || 0 + this.$forceUpdate() + }, init() { this.schoolShop = uni.getStorageSync('schoolShop') @@ -71,30 +83,33 @@ this.workerCounts = 0 this.shopCounts = 0 if (worker) { - this.workerCounts = uni.getStorageSync('workerCounts') + this.workerCounts = Number(uni.getStorageSync('workerCounts')) || 0 } if (shopId) { - this.shopCounts = uni.getStorageSync('shopCounts') + this.shopCounts = Number(uni.getStorageSync('shopCounts')) || 0 } this.balance = 0 + const refreshId = ++this.balanceRefreshId this.tui.request("/worker/getAllDepo/", "GET", { userId: uni.getStorageSync('id') }, false, true).then((res) => { + if (refreshId != this.balanceRefreshId) return if (res.code == 200) { + let balance = 0 if (res.result.user) { - this.balance += Number(res.result.user.depoBal) + balance += Number(res.result.user.depoBal) || 0 } if (res.result.worker) { - this.balance += Number(res.result.worker.depoBal) - this.balance += Number(res.result.worker.depoBalRel) + balance += Number(res.result.worker.depoBal) || 0 + balance += Number(res.result.worker.depoBalRel) || 0 } if (res.result.shop) { for (let i = 0; i < res.result.shop.length; i++) { - this.balance += Number(res.result.shop[i].balance) + balance += Number(res.result.shop[i].balance) || 0 } } - this.balance = this.balance.toFixed(2); - that.$forceUpdate(); + this.balance = balance.toFixed(2); + this.$forceUpdate(); } else { this.tui.toast(res.message) } diff --git a/components/tab-bar/tab-bar.vue b/components/tab-bar/tab-bar.vue index 56d33c2..7afcea5 100644 --- a/components/tab-bar/tab-bar.vue +++ b/components/tab-bar/tab-bar.vue @@ -60,7 +60,8 @@ }], indexZhipaiCount:0, indexWorkerCount:0, - indexMyCount:0 + indexMyCount:0, + countRefreshId:0 } }, props: { @@ -87,6 +88,13 @@ } } }, + mounted() { + uni.$on('deliveryStatusCountsChange', this.setDeliveryStatusCounts) + this.setDeliveryStatusCounts(uni.getStorageSync('deliveryStatusCounts') || {}) + }, + beforeDestroy() { + uni.$off('deliveryStatusCountsChange', this.setDeliveryStatusCounts) + }, methods: { hasLogin() { const token = uni.getStorageSync('hiver_token') @@ -103,6 +111,10 @@ const value = Number(count) || 0 return value > 99 ? '99+' : value }, + setDeliveryStatusCounts(counts) { + this.indexWorkerCount = (Number(counts.daiqu) || 0) + (Number(counts.daisong) || 0) + this.$forceUpdate() + }, //点击tab切换 clickBar(index) { if (index !== 0 && !this.hasLogin()) { @@ -132,76 +144,122 @@ } }, getWorkerCounts(){ - if(!uni.getStorageSync('worker')){ - return; - } + const refreshId = ++this.countRefreshId this.indexZhipaiCount = 0 this.indexWorkerCount = 0 this.indexMyCount = 0 - let that = this + let deliveryStatusCounts = { + daiqu: 0, + daisong: 0 + } let shopId = uni.getStorageSync('shopId') let worker = uni.getStorageSync('worker') + let workerResult = { + zhipaiCount: 0, + workerTabCount: 0, + myCount: 0, + workerCounts: 0, + deliveryStatusCounts + } + let shopCounts = 0 + let tasks = [] if(worker){ - this.tui.request("/mall/delivery/countOrderByStatus", "POST", {workerId:uni.getStorageSync('worker').workerId,regionId:JSON.parse(uni.getStorageSync('area')).id}, false, true).then((res) => { + const area = uni.getStorageSync('area') ? JSON.parse(uni.getStorageSync('area')) : {} + tasks.push(this.tui.request("/mall/delivery/countOrderByStatus", "POST", {workerId:worker.workerId,regionId:area.id}, false, true).then((res) => { if (res.code == 200) { + let result = { + zhipaiCount: 0, + workerTabCount: 0, + myCount: 0, + workerCounts: 0, + deliveryStatusCounts: { + daiqu: 0, + daisong: 0 + } + } if(res.result != null){ for(let i = 0;i {}); + }).catch((res) => {})); + }else{ + uni.setStorageSync('workerCounts', 0) + uni.setStorageSync('deliveryStatusCounts', deliveryStatusCounts) + uni.$emit('deliveryStatusCountsChange', deliveryStatusCounts) } if(shopId){ - this.tui.request("/mall/order/countByShop/"+uni.getStorageSync('shopId'), "GET", {}, false, true).then((res) => { + tasks.push(this.tui.request("/mall/order/countByShop/"+shopId, "GET", {}, false, true).then((res) => { if (res.code == 200) { this.shopData = res.result - let shopCounts = 0 - for(let i=0;i {}) + }).catch((res) => {})) + }else{ + uni.setStorageSync('shopCounts', 0) } + return Promise.all(tasks).then(() => { + if (refreshId != this.countRefreshId) return + this.indexZhipaiCount = workerResult.zhipaiCount + this.indexWorkerCount = workerResult.workerTabCount + this.indexMyCount = workerResult.myCount + shopCounts + uni.setStorageSync('workerCounts', workerResult.workerCounts) + uni.setStorageSync('shopCounts', shopCounts) + uni.setStorageSync('deliveryStatusCounts', workerResult.deliveryStatusCounts) + uni.$emit('deliveryStatusCountsChange', workerResult.deliveryStatusCounts) + uni.$emit('myCenterCountsChange', { + workerCounts: workerResult.workerCounts, + shopCounts: shopCounts + }) + this.$forceUpdate() + }) } } }