【类 型】: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>
<!-- 内容 -->
<el-form label-position="left" ref="questForm" :model="questForm" label-width="80px">
<el-form-item label="订单选择" v-if="!airLock">
<el-select v-model="questForm.id" :filterable="isMobile" placeholder="请选择,也可输入搜索" :disabled="airLock">
<el-form-item label="订单选择" v-if="!executeOrder">
<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"
:class="isWaring(item) ? 'danger-color' : ''">
<span class="l">{{ item.id }}</span>
@ -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 () {
}
}