【类 型】:factor

【主	题】:飞机操作模块
【描	述】:
	[原因]:
	[过程]:1.修改不用airlock监听飞机执行情况,加一个计算属性executeOrder储存正在执行的订单 2.执行订单 和 新提交订单 公用cheackOut函数(上传航线) 函数内部判断是执行订单 还是 新提交订单  调用不同的上传航线行为 3.request函数 去掉订单的 逻辑bug(分割之后取下标订单id 少+1) 4.监听executeOrder正在执行订单 行为 如有执行订单 在地图上绘制对应航线
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
szdot 2024-07-13 22:29:33 +08:00
parent 13868cd607
commit 3cd0beaed2

View File

@ -56,8 +56,8 @@
</div> </div>
<!-- 内容 --> <!-- 内容 -->
<el-form label-position="left" ref="questForm" :model="questForm" label-width="80px"> <el-form label-position="left" ref="questForm" :model="questForm" label-width="80px">
<el-form-item label="订单选择" v-if="!airLock"> <el-form-item label="订单选择" v-if="!executeOrder">
<el-select v-model="questForm.id" :filterable="isMobile" placeholder="请选择,也可输入搜索" :disabled="airLock"> <el-select v-model="questForm.id" :filterable="isMobile" placeholder="请选择,也可输入搜索" :disabled="executeOrder">
<el-option v-for="item in questList" :key="item.id" :label="item.id" :value="item.id" <el-option v-for="item in questList" :key="item.id" :label="item.id" :value="item.id"
:class="isWaring(item) ? 'danger-color' : ''"> :class="isWaring(item) ? 'danger-color' : ''">
<span class="l">{{ item.id }}</span> <span class="l">{{ item.id }}</span>
@ -282,7 +282,7 @@ export default {
questForm: { // questForm: { //
id: '' id: ''
}, },
airLock: false // a: null //
} }
}, },
props: { props: {
@ -322,11 +322,15 @@ export default {
return null return null
}, },
/** /**
* @description: 当前执行的订单 * @description: 正在执行的订单 没有未null 代表飞机空闲
*/ */
executeOrder () { executeOrder () {
const plane = this.plane 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: 航线列表 * @description: 航线列表
@ -415,59 +419,123 @@ export default {
* @description: 执行任务前 先检测订单是否 合法 例如订单重量会不会超出飞机载重上限 * @description: 执行任务前 先检测订单是否 合法 例如订单重量会不会超出飞机载重上限
*/ */
checkQuest () { 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('未选择订单任务!') this.$message.error('未选择订单任务!')
return return
} }
if (!this.currentOrder) { // 退
if (checkOrder.refund_status === '申请中') {
this.$message.error('此订单已被申请退款或者订单已经被取消!') this.$message.error('此订单已被申请退款或者订单已经被取消!')
return return
} }
if (this.currentOrder.bind_route === null) { // //
if (checkOrder.bind_route === null) {
this.$message.error('此站点,未绑定任务航点') this.$message.error('此站点,未绑定任务航点')
return return
} }
if (Number(this.currentOrder.total_weight) >= Number(this.plane.weight_max)) { //
this.$confirm('此订单总重超出本飞机的载重上限', '检测订单', { /* 如果是正在执行订单 直接调用重新提交 */
confirmButtonText: '仍然提交', if (this.executeOrder) {
cancelButtonText: '放弃提交', this.continueQuest()
type: 'warning' 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(() => { .catch((error) => {
this.$message({ console.log(error.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'
}) })
.then(() => { },
this.runQuest() // /**
}) * @description: 正在执行的任务 重新上传航线
.catch(action => { */
this.$message({ continueQuest () {
type: 'info', /* 执行写在这里 */
message: '取消提交订单' let routeData // 线
}) try {
}) /* 航线选择 */
} else { const bindRoute = (this.executeOrder.bind_route ?? '').split(',')
// const runing = (this.executeOrder.runing ?? '').split(',')
this.runQuest() 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 () { async runQuest () {
/* 插入日志 */ /* 插入日志 */
@ -479,13 +547,13 @@ export default {
/* 站点正在执行任务runing 注册 */ /* 站点正在执行任务runing 注册 */
const runing = (this.currentOrder.runing ?? '').split(',') const runing = (this.currentOrder.runing ?? '').split(',')
let foundEmpty = false let foundEmpty = false
let selIndex // 使线 let matchingIndex // 使线
runing.some((item, index, arr) => { runing.some((item, index, arr) => {
if (item === '') { if (item === '') {
arr[index] = this.plane.id arr[index] = this.plane.id
foundEmpty = true foundEmpty = true
selIndex = index matchingIndex = index
return true // 退 return true // 退
} }
}) })
@ -500,7 +568,7 @@ export default {
} }
/* 航线选择 */ /* 航线选择 */
const bindRoute = (this.currentOrder.bind_route ?? '').split(',') 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)// routeData = JSON.parse(routeData)//
// $food_sn$ // $food_sn$
this.currentOrder.telTail = this.currentOrder.tel.substr(-4)// telTail tel 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])// res = await this.questAss(this.currentOrder.id, ['shipment_status', 'by_plane_id'], ['已发货', this.plane.id])//
if (res.data.status === 1) { if (res.data.status === 1) {
this.publishFun(routeData)// this.publishFun(routeData)//
this.speakText('提交任务,注册航线。')
} }
} }
// //
@ -563,7 +630,7 @@ export default {
* @description: 取消任务 * @description: 取消任务
*/ */
reQuest () { reQuest () {
if (!this.airLock) { // "" if (!this.executeOrder) { // ""
this.$message.warning('当前没有执行任务') this.$message.warning('当前没有执行任务')
return return
} }
@ -573,33 +640,26 @@ export default {
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
/* 关联当前订单的站点 搜寻注册的飞机 并预设newRuning 用于注销runing字段航线 */ /* 关联当前订单的站点 搜寻注册的飞机 并预设newRuning 用于注销runing字段航线 */
let newRuning // newRuning //
let receiveSiteId const runingArray = this.executeOrder.runing.split(',')
let orderId //
const found = this.ShippedList.some((element) => { for (let i = 0; i < runingArray.length; i++) {
const runing = (element.runing ?? '').split(',') if (runingArray[i] === this.executeOrder.by_plane_id) {
return runing.some((item, index, arr) => { runingArray[i] = ''
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 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(() => { }).catch(() => {
this.$message.info('取消操作!') this.$message.info('取消操作!')
}) })
@ -608,7 +668,7 @@ export default {
* @description: 已送达任务 * @description: 已送达任务
*/ */
overQuest () { overQuest () {
if (!this.airLock) { // "" if (!this.executeOrder) { // ""
this.$message.warning('当前没有执行任务') this.$message.warning('当前没有执行任务')
return return
} }
@ -690,24 +750,21 @@ export default {
} }
}, },
created () { created () {
// //
if (Object.keys(this.executeOrder).length === 0) { if (this.executeOrder) { //
this.airLock = false this.makeRouteForMap()//
} else { } else { //
this.airLock = true this.publishFun('{"resetState":1}')//
} }
}, },
watch: { watch: {
airLock (val) { executeOrder (val) {
if (val) { // 线 if (val) { // 线
if (this.siteList) { this.makeRouteForMap()
this.makeRouteForMap()
}
} else { // 线 } else { // 线
this.$emit('clearRoute') this.$emit('clearRoute')
this.publishFun('{"resetState":1}')//
} }
this.$store.dispatch('fetchPaidOrderList')//
this.$store.dispatch('fetchSiteList')//
}, },
questList (val) { questList (val) {
/* 任务列表更新时 判断还有没有当前选择的id 没有就清空 */ /* 任务列表更新时 判断还有没有当前选择的id 没有就清空 */
@ -715,16 +772,9 @@ export default {
if (!found) { if (!found) {
this.questForm.id = '' this.questForm.id = ''
} }
},
executeOrder (val) {
//
if (Object.keys(val).length === 0) {
this.airLock = false
} else {
this.airLock = true
}
} }
},
destroyed () {
} }
} }