bonus-ui/src/views/stockManagement/entryApply/apply.vue

158 lines
4.6 KiB
Vue
Raw Normal View History

2025-12-23 17:52:01 +08:00
<template>
<div class="app-container">
<el-card style="margin-bottom: 20px;border-radius: 8px;" shadow="never">
<GoBack :title="title" @goBack="goBack" />
<el-tabs v-model="activeName" :before-leave="beforeClick">
<el-tab-pane label="施工装备" name="EquipmentAdd"></el-tab-pane>
<el-tab-pane label="数量工具" name="AddNum"></el-tab-pane>
<el-tab-pane label="编码工具" name="AddCode"></el-tab-pane>
</el-tabs>
</el-card>
2025-12-24 14:22:42 +08:00
<component ref="componentRef" :is="isShowComponent" />
2025-12-23 17:52:01 +08:00
</div>
</template>
<script>
import GoBack from '@/components/GoBack/index2'
2025-12-23 17:52:01 +08:00
import EquipmentAdd from '@/views/stockManagement/entryApply/components/EquipmentAdd'
import AddNum from '@/views/stockManagement/entryApply/components/AddNum'
import AddCode from '@/views/stockManagement/entryApply/components/AddCode'
export default {
name: 'ApplyDetails',
components: {
GoBack,
EquipmentAdd,
AddNum,
AddCode,
},
data() {
return {
isShowComponent: 'EquipmentAdd',
2025-12-24 14:22:42 +08:00
activeName: 'EquipmentAdd',
leaving: false,
2025-12-24 16:32:22 +08:00
title: '入库申请'
2025-12-23 17:52:01 +08:00
}
},
created() {
let title = '新增'
const routerParams = this.$route.query
if (routerParams.isEdit) {
title = '编辑'
2025-12-24 16:32:22 +08:00
} else if (routerParams.isView) {
title = '详情'
this.title = '入库审批'
2025-12-23 17:52:01 +08:00
}
const obj = Object.assign({}, this.$route, { title })
this.$tab.updatePage(obj)
},
methods: {
goBack() {
2026-01-23 18:04:05 +08:00
this.$router.push({ path: '/stockManagement/entryApply' }).then(() => {
2025-12-23 17:52:01 +08:00
this.$tab.closePage({ path: '/stockManagement/entryApply/apply' })
})
},
2025-12-24 14:22:42 +08:00
async beforeClick(activeName, oldActiveName) {
if (this.leaving) return false
2025-12-23 17:52:01 +08:00
// 如果是同一个 tab直接放行
if (activeName === oldActiveName) return true
let isEmpty = false
let allHasOrderId = false
2025-12-24 14:22:42 +08:00
if (oldActiveName == 'EquipmentAdd') {
2025-12-23 17:52:01 +08:00
const tableList = this.$refs.componentRef.tableData || []
isEmpty = tableList.length === 0
2025-12-24 14:22:42 +08:00
allHasOrderId = tableList.every((item) => !!item.maId)
} else if (oldActiveName == 'AddNum' || oldActiveName == 'AddCode') {
2025-12-23 17:52:01 +08:00
const tableList = this.$refs.componentRef.dialogList || []
isEmpty = tableList.length === 0
2025-12-24 14:22:42 +08:00
allHasOrderId = tableList.every((item) => !!item.id)
2025-12-23 17:52:01 +08:00
}
2025-12-24 14:22:42 +08:00
2025-12-23 17:52:01 +08:00
if (isEmpty || allHasOrderId) {
2025-12-24 14:22:42 +08:00
this.isShowComponent = activeName
2025-12-23 17:52:01 +08:00
return true
}
2025-12-24 14:22:42 +08:00
const confirm = await this.confirmLeave()
if (!confirm) {
// ❌ 用户取消
this.isShowComponent = activeName
return true
}
try {
let result = null
if (oldActiveName == 'EquipmentAdd') {
// 调用保存
const tableList = this.$refs.componentRef.tableData || []
for (let i = 0; i < tableList.length; i++) {
const row = tableList[i]
const res = await this.$refs.componentRef.submitRow(row)
if (!res) {
result = false
break
}
2025-12-23 17:52:01 +08:00
}
2025-12-24 14:22:42 +08:00
} else if (oldActiveName == 'AddNum' || oldActiveName == 'AddCode') {
result = await this.$refs.componentRef.submit()
console.log('🚀 ~ result:', result)
2025-12-23 17:52:01 +08:00
}
2025-12-24 14:22:42 +08:00
if (!result) {
setTimeout(() => {
this.leaving = true
this.activeName = oldActiveName
setTimeout(() => {
this.leaving = false
}, 200)
}, 200)
return false
} else {
this.isShowComponent = activeName
return true
2025-12-23 17:52:01 +08:00
}
2025-12-24 14:22:42 +08:00
} catch (error) {
console.log('error', error)
setTimeout(() => {
this.activeName = oldActiveName
}, 200)
return false
}
2025-12-23 17:52:01 +08:00
},
confirmLeave(message = '是否暂存已添加的装备?', title = '提示') {
return new Promise((resolve, reject) => {
this.$confirm(message, title, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
console.log('用户点击「确定」')
resolve(true)
})
.catch(() => {
console.log('用户点击「取消」')
resolve(false)
})
})
},
},
}
</script>
<style lang="scss" scoped>
.app-container{
background: #F0F0F0;
}
::v-deep.el-button--primary{
background-color: #2CBAB2;
border-color: #2CBAB2;
}
::v-deep.el-button--danger{
background-color: #FF5129;
border-color: #FF5129;
}
::v-deep .el-tabs__nav-wrap::after {
height: 0px;
}
</style>