wanshenmean
3 天以前 ce1292c9cf37195b6abd2699dfc5d6cb3e143c9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<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>