From 3cd0beaed2674c6bc9a4addab72ebe817d7ca47c Mon Sep 17 00:00:00 2001 From: szdot Date: Sat, 13 Jul 2024 22:29:33 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=09=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afactor=20=E3=80=90=E4=B8=BB=09=E9=A2=98=E3=80=91?= =?UTF-8?q?=EF=BC=9A=E9=A3=9E=E6=9C=BA=E6=93=8D=E4=BD=9C=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=20=E3=80=90=E6=8F=8F=09=E8=BF=B0=E3=80=91=EF=BC=9A=20=09[?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0]=EF=BC=9A=20=09[=E8=BF=87=E7=A8=8B]=EF=BC=9A?= =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E4=B8=8D=E7=94=A8airlock=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E9=A3=9E=E6=9C=BA=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5,?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E4=B8=AA=E8=AE=A1=E7=AE=97=E5=B1=9E=E6=80=A7?= =?UTF-8?q?executeOrder=E5=82=A8=E5=AD=98=E6=AD=A3=E5=9C=A8=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E7=9A=84=E8=AE=A2=E5=8D=95=202.=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=20=E5=92=8C=20=E6=96=B0=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=20=E5=85=AC=E7=94=A8cheackOut=E5=87=BD?= =?UTF-8?q?=E6=95=B0(=E4=B8=8A=E4=BC=A0=E8=88=AA=E7=BA=BF)=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=86=85=E9=83=A8=E5=88=A4=E6=96=AD=E6=98=AF=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E8=AE=A2=E5=8D=95=20=E8=BF=98=E6=98=AF=20=E6=96=B0?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=AE=A2=E5=8D=95=20=20=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E7=9A=84=E4=B8=8A=E4=BC=A0=E8=88=AA=E7=BA=BF?= =?UTF-8?q?=E8=A1=8C=E4=B8=BA=203.request=E5=87=BD=E6=95=B0=20=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E8=AE=A2=E5=8D=95=E7=9A=84=20=E9=80=BB=E8=BE=91bug(?= =?UTF-8?q?=E5=88=86=E5=89=B2=E4=B9=8B=E5=90=8E=E5=8F=96=E4=B8=8B=E6=A0=87?= =?UTF-8?q?=E8=AE=A2=E5=8D=95id=20=E5=B0=91+1)=204.=E7=9B=91=E5=90=ACexecu?= =?UTF-8?q?teOrder=E6=AD=A3=E5=9C=A8=E6=89=A7=E8=A1=8C=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=20=E8=A1=8C=E4=B8=BA=20=E5=A6=82=E6=9C=89=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=20=E5=9C=A8=E5=9C=B0=E5=9B=BE=E4=B8=8A?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E5=AF=B9=E5=BA=94=E8=88=AA=E7=BA=BF=20=09[?= =?UTF-8?q?=E5=BD=B1=E5=93=8D]=EF=BC=9A=20=E3=80=90=E7=BB=93=09=E6=9D=9F?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动 --- src/components/ControllerTabs.vue | 242 ++++++++++++++++++------------ 1 file changed, 146 insertions(+), 96 deletions(-) diff --git a/src/components/ControllerTabs.vue b/src/components/ControllerTabs.vue index e6f171b..fd1879a 100644 --- a/src/components/ControllerTabs.vue +++ b/src/components/ControllerTabs.vue @@ -56,8 +56,8 @@ - - + + {{ item.id }} @@ -282,7 +282,7 @@ export default { questForm: { // 送餐任务表单 id: '' }, - airLock: false // 当前飞机是否被锁定 + a: null // 当前飞机是否被锁定 } }, props: { @@ -322,11 +322,15 @@ export default { return null }, /** - * @description: 当前执行的订单 + * @description: 正在执行的订单 没有未null 代表飞机空闲 */ executeOrder () { const plane = this.plane - return plane ? this.ShippedList.find((item) => item.by_plane_id === plane.id) : {} + if (plane) { + const order = this.ShippedList.find((item) => item.by_plane_id === plane.id) + return order && Object.keys(order).length === 0 ? null : order || null + } + return null }, /** * @description: 航线列表 @@ -415,59 +419,123 @@ export default { * @description: 执行任务前 先检测订单是否 合法 例如:订单重量会不会超出飞机载重上限 */ checkQuest () { - if (this.questForm.id === '') { + let checkOrder // 提交要检查的任务 + // 有正在执行的 检查正在执行的 否则检查当前选中的 + if (this.executeOrder) { + checkOrder = this.executeOrder + } else { + checkOrder = this.currentOrder + } + // 检查是否选则了 订单 + if (this.questForm.id === '' && !checkOrder) { this.$message.error('未选择订单任务!') return } - if (!this.currentOrder) { + // 退款状态检查 + if (checkOrder.refund_status === '申请中') { this.$message.error('此订单已被申请退款或者订单已经被取消!') return } - if (this.currentOrder.bind_route === null) { // 判断站点是否已经绑定站点 未绑定 中断操作 + // 判断站点是否已经绑定站点 未绑定 中断操作 + if (checkOrder.bind_route === null) { this.$message.error('此站点,未绑定任务航点') return } - if (Number(this.currentOrder.total_weight) >= Number(this.plane.weight_max)) { // 检查重量 - this.$confirm('此订单总重超出本飞机的载重上限', '检测订单', { - confirmButtonText: '仍然提交', - cancelButtonText: '放弃提交', - type: 'warning' + + /* 如果是正在执行订单 直接调用重新提交 */ + if (this.executeOrder) { + this.continueQuest() + return + } + + /* 综合检查 这部分针对 新提交订单 */ + // 飞机载重 上限检查 + const weightCheck = new Promise((resolve, reject) => { + if (Number(checkOrder.total_weight) >= Number(this.plane.weight_max)) { + this.$confirm('此订单总重超出本飞机的载重上限', '检测订单', { + confirmButtonText: '继续', + cancelButtonText: '放弃', + type: 'warning' + }) + .then(() => { + resolve() + }) + .catch(action => { + this.$message({ + type: 'info', + message: '取消提交订单' + }) + reject(new Error('Weight check failed')) + }) + } else { + resolve() + } + }) + // 检查站点是否有飞机正在执行 + const runningCheck = new Promise((resolve, reject) => { + if ((checkOrder.runing ?? '').split(',').some(item => item !== '')) { + this.$confirm('此订单的目标站点,已经有飞机正在执行任务。请注意安全!', '检测订单', { + confirmButtonText: '继续', + cancelButtonText: '放弃', + type: 'warning' + }) + .then(() => { + resolve() + }) + .catch(action => { + this.$message({ + type: 'info', + message: '取消提交订单' + }) + reject(new Error('Running check failed')) + }) + } else { + resolve() + } + }) + // 选择订单检查 执行订单任务 + Promise.all([weightCheck, runningCheck]) + .then(() => { + this.runQuest() }) - .then(() => { - this.$message({ - type: 'warning', - message: '存在超重风险,仍然提交订单' - }) - this.runQuest()// 提交订单 - }) - .catch(action => { - this.$message({ - type: 'info', - message: '取消提交订单' - }) - }) - } else if ((this.currentOrder.runing ?? '').split(',').some(item => item !== '')) { // 检查此站点上有否有飞机正在执行任务 - this.$confirm('此订单的目标站点,已经有飞机正在执行任务。请注意安全!', '检测订单', { - confirmButtonText: '仍然提交', - cancelButtonText: '放弃提交', - type: 'warning' + .catch((error) => { + console.log(error.message) }) - .then(() => { - this.runQuest() // 提交订单 - }) - .catch(action => { - this.$message({ - type: 'info', - message: '取消提交订单' - }) - }) - } else { - // 合法 直接提交订单 - this.runQuest() + }, + /** + * @description: 正在执行的任务 重新上传航线 + */ + continueQuest () { + /* 执行写在这里 */ + let routeData // 航线数据内容 + try { + /* 航线选择 */ + const bindRoute = (this.executeOrder.bind_route ?? '').split(',') + const runing = (this.executeOrder.runing ?? '').split(',') + const matchingIndex = runing + .map((route, index) => route === this.executeOrder.by_plane_id ? index : -1) + .filter(index => index !== -1)// 找到注册飞机与绑定航线对应索引 + routeData = this.routeList.find(element => element.id === bindRoute[matchingIndex]).route_data + routeData = JSON.parse(routeData)// 反序列化 + // 处理声音航点 航点里面的表达式 如$food_sn$ 正则替换成订单对应的字段 + this.executeOrder.telTail = this.executeOrder.tel.substr(-4)// 手动加一个手机尾号telTail字段 从 tel字段截取后四位 + routeData.questAss.tasks.forEach((x, index) => { + if (x.sound) { + const str = this.voiceRouteParse(this.executeOrder, x.sound) + routeData.questAss.tasks[index].sound = str// 重新写入声音航点 + } + }) + routeData = JSON.stringify(routeData)// 重新序列化 + // 发送航点信息主题 + this.publishFun(routeData) + // 主动获取飞机状态 + this.publishFun('{getPlaneState:1}') + } catch (error) { + this.$message.error('操作失败,航线异常') } }, /** - * @description: 执行订单任务 + * @description: 选择订单的 执行订单任务 ps:改变订单状态 站点runing状态 上传航线 */ async runQuest () { /* 插入日志 */ @@ -479,13 +547,13 @@ export default { /* 站点正在执行任务runing 注册 */ const runing = (this.currentOrder.runing ?? '').split(',') let foundEmpty = false - let selIndex // 记录执行飞机注册的索引 此索引对应要使用的航线的索引 + let matchingIndex // 记录执行飞机注册的索引 此索引对应要使用的航线的索引 runing.some((item, index, arr) => { if (item === '') { arr[index] = this.plane.id foundEmpty = true - selIndex = index + matchingIndex = index return true // 找到空位后退出循环 } }) @@ -500,7 +568,7 @@ export default { } /* 航线选择 */ const bindRoute = (this.currentOrder.bind_route ?? '').split(',') - routeData = this.routeList.find(element => element.id === bindRoute[selIndex]).route_data + routeData = this.routeList.find(element => element.id === bindRoute[matchingIndex]).route_data routeData = JSON.parse(routeData)// 反序列化 // 处理声音航点 航点里面的表达式 如$food_sn$ 正则替换成订单对应的字段 this.currentOrder.telTail = this.currentOrder.tel.substr(-4)// 手动加一个手机尾号telTail字段 从 tel字段截取后四位 @@ -520,7 +588,6 @@ export default { res = await this.questAss(this.currentOrder.id, ['shipment_status', 'by_plane_id'], ['已发货', this.plane.id])// 订单改为发货状态和执行订 并更新订单列表 if (res.data.status === 1) { this.publishFun(routeData)// 发送航点信息主题 - this.speakText('提交任务,注册航线。') } } // 主动获取飞机状态 @@ -563,7 +630,7 @@ export default { * @description: 取消任务 */ reQuest () { - if (!this.airLock) { // 只有飞机锁定状态 才向下执行 "取消"操作 + if (!this.executeOrder) { // 只有飞机锁定状态 才向下执行 "取消"操作 this.$message.warning('当前没有执行任务') return } @@ -573,33 +640,26 @@ export default { type: 'warning' }).then(() => { /* 关联当前订单的站点 搜寻注册的飞机 并预设newRuning 用于注销runing字段航线 */ - let newRuning // 确保newRuning在函数块外定义 - let receiveSiteId - let orderId - const found = this.ShippedList.some((element) => { - const runing = (element.runing ?? '').split(',') - return runing.some((item, index, arr) => { - if (item === this.plane.id.toString()) { - arr[index] = '' // 将匹配的id替换为空字符串 - newRuning = runing.join(',') - orderId = element.id - receiveSiteId = element.receive_site_id - return true // 找到id后退出内层循环 - } - }) - }) - /* 确认 把订单从发货退回到已接单 站点runing字段飞机航线注销 重置飞机状态 */ - if (found) { - this.$store.dispatch('fetchLockSite', { id: receiveSiteId, shop_id: this.plane.shop_id, runing: newRuning }).then(res => { // 退回到已接单 并更新订单列表 - if (res.data.status === 1) { - this.questAss(orderId, ['shipment_status', 'by_plane_id'], ['已接单', '']).then(res => { // 注销航线 - if (res.data.status === 1) { - this.publishFun('{"resetState":1}')// 发送设置飞机状态主题 状态设为闲置 - } - }) - } - }) + // 分割字符串成数组 + const runingArray = this.executeOrder.runing.split(',') + // 遍历数组并替换相等的值 + for (let i = 0; i < runingArray.length; i++) { + if (runingArray[i] === this.executeOrder.by_plane_id) { + runingArray[i] = '' + } } + // 将数组重新组合成字符串 + const newRuning = runingArray.join(',') + /* 确认 把订单从发货退回到已接单 站点runing字段飞机航线注销 重置飞机状态 */ + this.$store.dispatch('fetchLockSite', { id: this.executeOrder.receive_site_id, shop_id: this.plane.shop_id, runing: newRuning }).then(res => { // 退回到已接单 并更新订单列表 + if (res.data.status === 1) { + this.questAss(this.executeOrder.id, ['shipment_status', 'by_plane_id'], ['已接单', 'null']).then(res => { // 注销航线 + if (res.data.status === 1) { + this.publishFun('{"resetState":1}')// 发送设置飞机状态主题 状态设为闲置 + } + }) + } + }) }).catch(() => { this.$message.info('取消操作!') }) @@ -608,7 +668,7 @@ export default { * @description: 已送达任务 */ overQuest () { - if (!this.airLock) { // 只有飞机锁定状态 才向量下执行 "已送达"操作 + if (!this.executeOrder) { // 只有飞机锁定状态 才向量下执行 "已送达"操作 this.$message.warning('当前没有执行任务') return } @@ -690,24 +750,21 @@ export default { } }, created () { - // 判断当前飞机有没有挂载的任务 判断是否是锁定状态 - if (Object.keys(this.executeOrder).length === 0) { - this.airLock = false - } else { - this.airLock = true + // 初始化 + if (this.executeOrder) { // 有正在执行单点 + this.makeRouteForMap()// 绘制地图 + } else { // 没有执行订单 + this.publishFun('{"resetState":1}')// 发送设置飞机状态主题 状态设为闲置 } }, watch: { - airLock (val) { + executeOrder (val) { if (val) { // 如果当前飞机正在执行任务 把航线绘制到地图上 - if (this.siteList) { - this.makeRouteForMap() - } + this.makeRouteForMap() } else { // 如果没有执行任务 把地图上航线清除 this.$emit('clearRoute') + this.publishFun('{"resetState":1}')// 发送设置飞机状态主题 状态设为闲置 } - this.$store.dispatch('fetchPaidOrderList')// 刷新订单列表 - this.$store.dispatch('fetchSiteList')// 刷新站点列表 }, questList (val) { /* 任务列表更新时 判断还有没有当前选择的id 没有就清空 */ @@ -715,16 +772,9 @@ export default { if (!found) { this.questForm.id = '' } - }, - executeOrder (val) { - // 判断当前飞机有没有挂载的任务 判断是否是锁定状态 - if (Object.keys(val).length === 0) { - this.airLock = false - } else { - this.airLock = true - } } - + }, + destroyed () { } }