【类 型】: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:
parent
13868cd607
commit
3cd0beaed2
@ -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)) { // 检查重量
|
||||
|
||||
/* 如果是正在执行订单 直接调用重新提交 */
|
||||
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: '放弃提交',
|
||||
confirmButtonText: '继续',
|
||||
cancelButtonText: '放弃',
|
||||
type: 'warning'
|
||||
})
|
||||
.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'
|
||||
})
|
||||
.then(() => {
|
||||
this.runQuest() // 提交订单
|
||||
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()
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message)
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @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后退出内层循环
|
||||
// 分割字符串成数组
|
||||
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字段飞机航线注销 重置飞机状态 */
|
||||
if (found) {
|
||||
this.$store.dispatch('fetchLockSite', { id: receiveSiteId, shop_id: this.plane.shop_id, runing: newRuning }).then(res => { // 退回到已接单 并更新订单列表
|
||||
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(orderId, ['shipment_status', 'by_plane_id'], ['已接单', '']).then(res => { // 注销航线
|
||||
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()
|
||||
}
|
||||
} 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 () {
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user