<template>
|
<el-dialog
|
v-model="visible"
|
:title="dialogTitle"
|
width="500px"
|
:close-on-click-modal="false"
|
@close="handleClose"
|
>
|
<div class="mes-confirm-content">
|
<p class="operation-text">{{ operationText }}</p>
|
|
<div class="info-section">
|
<div class="info-row" v-for="(item, index) in displayInfo" :key="index">
|
<span class="info-label">{{ item.label }}:</span>
|
<span class="info-value">{{ item.value }}</span>
|
</div>
|
</div>
|
|
<div v-if="errorMessage" class="error-message">
|
<el-icon><Warning /></el-icon>
|
<span>{{ errorMessage }}</span>
|
</div>
|
</div>
|
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="handleClose">取消</el-button>
|
<el-button
|
type="primary"
|
:loading="loading"
|
@click="handleConfirm"
|
>
|
确认执行
|
</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script>
|
import { defineComponent, ref, computed, watch } from 'vue';
|
import { Warning } from '@element-plus/icons-vue';
|
|
/**
|
* MES确认对话框组件
|
* 用于在执行MES操作(进站/出站/绑定/解绑/NG上报)前显示确认信息
|
*/
|
export default defineComponent({
|
name: 'MesConfirmDialog',
|
|
components: {
|
Warning
|
},
|
|
props: {
|
modelValue: {
|
type: Boolean,
|
default: false
|
},
|
/**
|
* 操作类型: inbound(进站) | outbound(出站) | bind(绑定) | unbind(解绑) | ngReport(NG上报)
|
*/
|
operationType: {
|
type: String,
|
required: true
|
},
|
/**
|
* 托盘码
|
*/
|
palletCode: {
|
type: String,
|
required: true
|
},
|
/**
|
* 库存信息对象(用于进站/出站操作)
|
*/
|
stockInfo: {
|
type: Object,
|
default: null
|
},
|
/**
|
* 库存明细信息对象(用于绑定/解绑/NG上报操作)
|
*/
|
detailInfo: {
|
type: Object,
|
default: null
|
}
|
},
|
|
emits: ['update:modelValue', 'confirm'],
|
|
setup(props, { emit }) {
|
const visible = ref(false);
|
const loading = ref(false);
|
const errorMessage = ref('');
|
|
// 监听modelValue变化,同步到visible
|
watch(
|
() => props.modelValue,
|
(newVal) => {
|
visible.value = newVal;
|
// 对话框打开时重置错误信息
|
if (newVal) {
|
errorMessage.value = '';
|
}
|
},
|
{ immediate: true }
|
);
|
|
// 监听visible变化,同步到modelValue
|
watch(visible, (newVal) => {
|
emit('update:modelValue', newVal);
|
});
|
|
/**
|
* 操作类型配置映射
|
*/
|
const operationConfig = {
|
inbound: { title: '托盘进站', text: '您即将执行托盘进站操作' },
|
outbound: { title: '托盘出站', text: '您即将执行托盘出站操作' },
|
bind: { title: '电芯绑定', text: '您即将执行电芯绑定操作' },
|
unbind: { title: '电芯解绑', text: '您即将执行电芯解绑操作' },
|
ngReport: { title: 'NG上报', text: '您即将执行NG电芯上报操作' }
|
};
|
|
/**
|
* 对话框标题
|
*/
|
const dialogTitle = computed(() => {
|
return operationConfig[props.operationType]?.title || '确认操作';
|
});
|
|
/**
|
* 操作提示文本
|
*/
|
const operationText = computed(() => {
|
return operationConfig[props.operationType]?.text || '';
|
});
|
|
/**
|
* 显示的信息列表
|
*/
|
const displayInfo = computed(() => {
|
const info = [
|
{ label: '托盘码', value: props.palletCode || '-' }
|
];
|
|
// 如果有明细信息,显示电芯数量
|
if (props.detailInfo) {
|
info.push({
|
label: '电芯数量',
|
value: props.detailInfo.sfcCount !== undefined ? props.detailInfo.sfcCount : '-'
|
});
|
}
|
|
// 如果有库存信息,可以显示库位等信息
|
if (props.stockInfo) {
|
info.push({
|
label: '库位',
|
value: props.stockInfo.location || '-'
|
});
|
}
|
|
return info;
|
});
|
|
/**
|
* 关闭对话框
|
*/
|
const handleClose = () => {
|
visible.value = false;
|
errorMessage.value = '';
|
loading.value = false;
|
};
|
|
/**
|
* 确认执行操作
|
* 触发confirm事件,传递操作回调和错误处理函数
|
*/
|
const handleConfirm = () => {
|
loading.value = true;
|
errorMessage.value = '';
|
|
// 触发confirm事件,传递操作参数和回调函数
|
emit('confirm', {
|
operationType: props.operationType,
|
palletCode: props.palletCode,
|
stockInfo: props.stockInfo,
|
detailInfo: props.detailInfo,
|
onSuccess: () => {
|
// 操作成功:关闭对话框并重置状态
|
visible.value = false;
|
loading.value = false;
|
errorMessage.value = '';
|
},
|
onError: (error) => {
|
// 操作失败:显示错误信息并保持对话框打开
|
errorMessage.value = error || '操作失败,请重试';
|
loading.value = false;
|
}
|
});
|
};
|
|
return {
|
visible,
|
loading,
|
errorMessage,
|
dialogTitle,
|
operationText,
|
displayInfo,
|
handleClose,
|
handleConfirm
|
};
|
}
|
});
|
</script>
|
|
<style lang="less" scoped>
|
.mes-confirm-content {
|
padding: 10px 0;
|
}
|
|
.operation-text {
|
font-size: 14px;
|
color: #303133;
|
margin-bottom: 20px;
|
font-weight: 500;
|
}
|
|
.info-section {
|
background: #f8fafc;
|
border-radius: 8px;
|
padding: 16px;
|
margin-bottom: 16px;
|
}
|
|
.info-row {
|
display: flex;
|
margin-bottom: 12px;
|
font-size: 14px;
|
|
&:last-child {
|
margin-bottom: 0;
|
}
|
}
|
|
.info-label {
|
color: #909399;
|
width: 80px;
|
flex-shrink: 0;
|
}
|
|
.info-value {
|
color: #303133;
|
font-weight: 500;
|
}
|
|
.error-message {
|
display: flex;
|
align-items: center;
|
gap: 8px;
|
padding: 12px;
|
background: #fef0f0;
|
border: 1px solid #fde2e2;
|
border-radius: 6px;
|
color: #f56c6c;
|
font-size: 14px;
|
|
.el-icon {
|
font-size: 18px;
|
}
|
}
|
</style>
|