<!-- 提醒是否创建交接单 -->
<script lang="ts" setup name="RemindCreateEIRDialog">
import type { FormInstance, FormRules } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
import { reactive, ref } from 'vue'
import batchCreateEIRDialog from './batchCreateEIRDialog.vue'
// 对外暴露的方法: 退回成功
const emits = defineEmits(['confirm', 'refresh'])
// 弹窗显示状态
const dialogVisible = ref(false)
// 提示信息
const title = ref('')
const type = ref('') // 设备交接单类型
const list = ref([]) as any// 设备信息
const $router = useRouter()
const batchCreateEIRDialogRef = ref() // 批量创建交接单组件
/**
* 初始化审批弹窗
* @param title 提示信息
* @param list 设备信息
* @param type 要创建的交接单类型 '收入'-设备收入交接单 '归还':设备归还交接单
*/
function initDialog(titleParam: string, equipmentList: any, typeParam: string) {
title.value = titleParam
type.value = typeParam
list.value = equipmentList
dialogVisible.value = true
}
// 点击确定
function confirm() {
// 需判断批量的设备是否来自于一个任务单,如果设备来源于一个任务单跳转至设备交接单新建模块
// 如果设备来源于多个任务单,生成多个交接单
if (list.value.length === 1) { // 只有一个设备直接跳转新建交接单
if ((type.value === '收入' && list.value[0].interchangeId) || (type.value === '归还' && list.value[0].backInterchangeId)) {
ElMessageBox.alert(`${list.value[0].sampleName}已有${type.value}交接单,不可重复创建!`, '提示', {
confirmButtonText: '确定',
})
}
else {
$router.push({
path: '/interchangeReceipt/add',
query: {
orderId: list.value[0].orderId,
interchangeType: type.value === '收入' ? '1' : '2',
equipmentList: JSON.stringify(list.value),
from: 'sendReceive',
},
})
}
}
else { // 多个设备判断是否同属于一个任务单
const result = list.value.every((item: { orderId: string }) => item.orderId === list.value[0].orderId)
if (result) { // 所有的设备是否同属于同一个任务单
if ((type.value === '收入' && list.value.every((item: { interchangeId: string }) => item.interchangeId !== '')) || (type.value === '归还' && list.value.every((item: { backInterchangeId: string }) => item.backInterchangeId !== ''))) {
ElMessageBox.alert(`所有设备均已有${type.value}交接单,不可重复创建!`, '提示', {
confirmButtonText: '确定',
})
}
else {
$router.push({
path: '/interchangeReceipt/add',
query: {
orderId: list.value[0].orderId,
interchangeType: type.value === '收入' ? '1' : '2',
equipmentList: JSON.stringify(list.value),
from: 'sendReceive',
},
})
}
}
else { // 所有的设备不同任务单
batchCreateEIRDialogRef.value.initDialog(type.value, list.value)
}
}
handleClose()
}
// 点击取消
function handleClose() {
dialogVisible.value = false
emits('refresh') // 刷新列表
}
// ----------------------- 以下是暴露的方法内容 ----------------------------
defineExpose({ initDialog })
</script>
<template>
<el-dialog
v-model="dialogVisible"
title="确认操作"
width="440"
:before-close="handleClose"
>
<div style="display: flex; justify-content: center;font-size: 16px;">
<div>设备{{ title }}成功!</div>
<div>是否直接创建设备{{ title.length === 4 ? title.slice(2) : title }}交接单?</div>
</div>
<template #footer>
<el-button type="primary" @click="confirm">
确 定
</el-button>
<el-button @click="handleClose">
取 消
</el-button>
</template>
</el-dialog>
<!-- 批量创建交接单组件 -->
<batch-create-e-i-r-dialog ref="batchCreateEIRDialogRef" @cancleCreate="handleClose" />
</template>
<style lang="scss" scoped>
// 样式
</style>