From beae44494c474a9c3eaf304069efb5416c868522 Mon Sep 17 00:00:00 2001 From: lxf Date: Mon, 25 Aug 2025 09:46:45 +0800 Subject: [PATCH] fix: 通知 --- pages/goodSource/add.vue | 35 ++++++++++++++++++++++++++++++++--- pages/goodSource/grab-record.vue | 51 ++++++++++++++++++++++++++------------------------- pages/order/add.vue | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 150 insertions(+), 42 deletions(-) diff --git a/pages/goodSource/add.vue b/pages/goodSource/add.vue index c11c13f..94da56b 100644 --- a/pages/goodSource/add.vue +++ b/pages/goodSource/add.vue @@ -375,6 +375,29 @@ export default { url: `/pages/goodSource/select-remark`, }); }, + // 订阅消息 + subscribeMessage(afterFun) { + uni.requestSubscribeMessage({ + tmplIds: ['CtqtbxU3RFUk7s1QF2RQQiAqyE8w96xHGbbJogTLZX0'], + success(res) { + uni.getSetting({ + withSubscriptions: true, + success(res) { + if (!res.subscriptionsSetting) { + uni.showModal({ + title: '提示', + content: '未开启小程序订阅消息接收,请前往微信设置接以接收消息!', + showCancel: false, + }); + } + }, + }); + }, + complete() { + afterFun(); + }, + }); + }, submitAddFun() { if (this.loading) return; this.loading = true; @@ -396,9 +419,15 @@ export default { uni.$u.api.freightGoodsSourceV2[opType]({ ...this.form, ...startAddressObj, ...endAddressObj }) .then(res => { if (res.success) { - // uni.showToast({ title: '成功', icon: 'none' }); - this.getOpenerEventChannel().emit('refreshData'); - setTimeout(() => uni.navigateBack(), 500); + let afterFun = () => { + this.getOpenerEventChannel().emit('refreshData'); + setTimeout(() => uni.navigateBack(), 500); + }; + if (opType === 'add') { + this.subscribeMessage(afterFun); + } else { + afterFun(); + } } else { this.loading = false; } diff --git a/pages/goodSource/grab-record.vue b/pages/goodSource/grab-record.vue index 7c255ca..dcd58e0 100644 --- a/pages/goodSource/grab-record.vue +++ b/pages/goodSource/grab-record.vue @@ -211,33 +211,33 @@ export default { }, // 确认-发布需求 toSubmit(item) { - let form = { - ...item, - goodsWeight: item.biddingWeight, - goodsSourceCode: item.goodsSourceCode, - goodsSourceBiddingCode: item.code, - loadTime: dayjs(item.biddingTime).add(3, 'hour').format('YYYY-MM-DD HH:mm:ss'), - waypoints: [ - { - cityCode: item.startCityCode, - areaCode: item.startAreaCode, - address: item.startAddress, - lng: item.startLng, - lat: item.startLat, - }, - { - cityCode: item.endCityCode, - areaCode: item.endAreaCode, - address: item.endAddress, - lng: item.endLng, - lat: item.endLat, - }, - ], - }; uni.navigateTo({ - url: `/pages/order/add?eventCode=${item.code}`, + url: `/pages/order/add?biddingSource=record&biddingCode=${item.code}`, success(res) { - res.eventChannel.emit('get-item', form); + res.eventChannel.emit('get-item', item); + }, + }); + }, + // 订阅消息 + subscribeMessage(afterFun) { + uni.requestSubscribeMessage({ + tmplIds: ['CtqtbxU3RFUk7s1QF2RQQiAqyE8w96xHGbbJogTLZX0'], + success(res) { + uni.getSetting({ + withSubscriptions: true, + success(res) { + if (!res.subscriptionsSetting) { + uni.showModal({ + title: '提示', + content: '未开启小程序订阅消息接收,请前往微信设置接以接收消息!', + showCancel: false, + }); + } + }, + }); + }, + complete() { + afterFun && afterFun(); }, }); }, @@ -252,6 +252,7 @@ export default { this.loading = false; uni.showToast({ title: '取消成功', icon: 'none' }); this.onSearch({ showLoading: true }); + this.subscribeMessage(); }) .catch(() => { this.loading = false; diff --git a/pages/order/add.vue b/pages/order/add.vue index f1c42a2..1bcca87 100644 --- a/pages/order/add.vue +++ b/pages/order/add.vue @@ -218,7 +218,8 @@ export default { exceed: false, exceedStr: '', openExternalInsuranceFlag: true, - eventCode: '', + biddingSource: '', // 从货源列表(record),从订阅消息(msg) + biddingCode: '', // 抢单编号 loading: false, showModal: '', showModal2: '', @@ -289,16 +290,30 @@ export default { }, onLoad(option) { // 从抢单来的数据 - if (option.eventCode) { - this.eventCode = option.eventCode; + if (option.biddingCode) { + this.biddingCode = option.biddingCode; + this.biddingSource = option.biddingSource; uni.setNavigationBarTitle({ title: '确定指派' }); - const eventChannel = this.getOpenerEventChannel(); - eventChannel.on('get-item', detail => { - this.setFormValue(detail, ['priceType', 'weightUnitPrice', 'goodsSourceCode', 'goodsSourceBiddingCode', 'loadTime', 'paidAmount']); - this.getAllowDriverSeeFreightAmount(); - this.clipboard(`手机号:${detail.driverMobile || ''}车牌:${detail.vehicleLicenseNum || ''}车挂:${detail.trailerLicenseNum || ''}`); - this.computedService(); - }); + if (option.biddingSource === 'record') { + const eventChannel = this.getOpenerEventChannel(); + eventChannel.on('get-item', item => { + this.sourceInitForm(item); + }); + } else if (option.biddingSource === 'wx_sub_msg') { + uni.$u.api.freightGoodsSourceV2 + .biddingPage({ + status: 'WAIT_ASSIGN', + code: option.biddingCode, + }) + .then(res => { + if (res.result && res.result.length > 0) { + let item = res.result[0]; + this.sourceInitForm(item); + } else { + uni.showToast({ title: '该抢单已处理,请返回', icon: 'none' }); + } + }); + } } else { if (option.code) { this.initData(option.code); @@ -307,6 +322,35 @@ export default { } }, methods: { + sourceInitForm(item) { + let detail = { + ...item, + goodsWeight: item.biddingWeight, + goodsSourceCode: item.goodsSourceCode, + goodsSourceBiddingCode: item.code, + loadTime: dayjs(item.biddingTime).add(3, 'hour').format('YYYY-MM-DD HH:mm:ss'), + waypoints: [ + { + cityCode: item.startCityCode, + areaCode: item.startAreaCode, + address: item.startAddress, + lng: item.startLng, + lat: item.startLat, + }, + { + cityCode: item.endCityCode, + areaCode: item.endAreaCode, + address: item.endAddress, + lng: item.endLng, + lat: item.endLat, + }, + ], + }; + this.setFormValue(detail, ['priceType', 'weightUnitPrice', 'goodsSourceCode', 'goodsSourceBiddingCode', 'loadTime', 'paidAmount']); + this.getAllowDriverSeeFreightAmount(); + this.clipboard(`手机号:${detail.driverMobile || ''}车牌:${detail.vehicleLicenseNum || ''}车挂:${detail.trailerLicenseNum || ''}`); + this.computedService(); + }, setFormValue(detail, moreList = []) { ['goodsName', 'waypoints', 'allowDriverSeeFreightAmountNode', 'projectCode', 'projectName', 'remark', 'goodsPiece', 'goodsWeight', 'goodsVolume', ...moreList].forEach(key => { this.form[key] = detail[key]; @@ -632,7 +676,7 @@ export default { uni.$u.debounce(this.getServiceAmountInfo, 500); }, computedPaid() { - if (this.eventCode && this.form.priceType === 'TON') { + if (this.biddingCode && this.form.priceType === 'TON') { this.form.paidAmount = Number(Number(this.form.goodsWeight) * Number(this.form.weightUnitPrice)).toFixed(2); this.computedService(); } @@ -666,12 +710,35 @@ export default { } }); }, + // 订阅消息 + subscribeMessage(afterFun) { + uni.requestSubscribeMessage({ + tmplIds: ['CtqtbxU3RFUk7s1QF2RQQiAqyE8w96xHGbbJogTLZX0'], + success(res) { + uni.getSetting({ + withSubscriptions: true, + success(res) { + if (!res.subscriptionsSetting) { + uni.showModal({ + title: '提示', + content: '未开启小程序订阅消息接收,请前往微信设置接以接收消息!', + showCancel: false, + }); + } + }, + }); + }, + complete() { + afterFun(); + }, + }); + }, submitAddFun(confirmAddFlag = false) { this.exceed = false; if (this.loading) return; this.loading = true; let totalAmount = Number(this.form.paidAmount || 0) + Number(this.form.serviceAmount || 0) + Number(this.form.securityServiceAmount || 0); - let addFun = this.eventCode ? uni.$u.api.freightGoodsSourceV2.addOrder : uni.$u.api.freightOrder.add; + let addFun = this.biddingCode ? uni.$u.api.freightGoodsSourceV2.addOrder : uni.$u.api.freightOrder.add; addFun({ ...this.form, totalAmount, payeeId: this.payeeModel.driverId, confirmAddFlag }) .then(res => { if (res.result) { @@ -680,8 +747,19 @@ export default { this.exceed = true; } else { uni.showToast({ title: '下单成功', icon: 'none' }); - this.getOpenerEventChannel().emit('refreshData'); - setTimeout(() => uni.navigateBack(), 1500); + let afterFun = () => { + if (this.biddingSource === 'record') { + this.getOpenerEventChannel().emit('refreshData'); + setTimeout(() => uni.navigateBack(), 1000); + } else { + uni.switchTab({ url: '/pages/goodSource/index' }); + } + }; + if (this.biddingCode) { + this.subscribeMessage(afterFun); + } else { + afterFun(); + } } }) .catch(e => { -- libgit2 0.21.0