huang
4 天以前 9dcde5b27b70a4b0c0885347af5405eb2d1ef089
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<template>
  <el-dialog v-model="dialogVisible" :title="$t('film.originalInformation')" top="7vh" width="95%" @close="handleClose">
    <div style="margin-left: 750px;margin-top: 10px;font-size: large;margin-bottom: 10px;">
      {{ $t('Mounting.originalQueueNotBound') }}
    </div>
    <div class="dialog-container">
      <!-- 左侧部分 -->
      <div class="left-side">
        <el-form class="glass-form" label-position="right" label-width="auto" :model="formData" :rules="formRules" ref="formRef">
 
          <el-row :gutter="20" class="form-row">
            <el-col :span="12">
              <div id="dt" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.stationColon')" :required="true" style="width: 17vw;">
                    <el-input v-model="formData.slot" :disabled="isViewMode" :placeholder="$t('film.stationEnter')"
                              autocomplete="off" class="form-input"/>
                  </el-form-item>
                </div>
              </div>
            </el-col>
              <el-col :span="9">
              <div id="dta" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.shelfNumberColon')" :required="true" style="width: 17vw;">
                    <el-input v-model="formData.shelf" :disabled="isViewMode" :placeholder="$t('film.shelfNumberEnter')"
                              autocomplete="off" class="form-input"/>
                  </el-form-item>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="20" class="form-row">
            <el-col :span="12">
              <div id="dt" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.widthColon')" :required="true" style="width: 17vw;">
                    <el-input v-model="formData.rawWidth" :placeholder="$t('film.widthEnter')" autocomplete="off"
                              class="form-input"/>
                  </el-form-item>
                </div>
              </div>
            </el-col>
            <el-col :span="9">
              <div id="dta" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.heightColon')" :required="true" style="width: 17vw;">
                    <el-input v-model="formData.rawHeight" :placeholder="$t('film.heightEnter')" autocomplete="off"
                              class="form-input"/>
                  </el-form-item>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="20" class="form-row">
            <el-col :span="12">
              <div id="dt" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.thicknessColon')" :required="true" style="width: 17vw;">
                    <el-input v-model="formData.rawThickness" :placeholder="$t('film.thicknessEnter')"
                              autocomplete="off" class="form-input"/>
                  </el-form-item>
                </div>
              </div>
            </el-col>
            <el-col :span="9">
              <div id="dta" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.filmsColon')" :required="true" style="width: 17vw;">
                    <el-input v-model="formData.filmsId" :placeholder="$t('film.filmsEnter')" autocomplete="off"
                              class="form-input"/>
                  </el-form-item>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="20" class="form-row">
            <el-col :span="12">
              <div id="dt" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.originalEdgeColon')" style="width: 17vw;" prop="rawMargin">
                    <el-input 
                      v-model="formData.rawMargin" 
                      :placeholder="rawMarginPlaceholder"
                      autocomplete="off" 
                      class="form-input"
                      @blur="validateRawMargin"
                    />
                  </el-form-item>
                </div>
              </div>
            </el-col>
            <el-col :span="9">
              <div id="dta" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.remainQuantityColon')" :required="true" style="width: 17vw;">
                    <el-input v-model="formData.remainQuantity" :placeholder="$t('film.remainQuantityEnter')"
                              autocomplete="off" class="form-input"/>
                  </el-form-item>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="20" class="form-row">
            <el-col :span="12">
              <div id="dt" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.manufacturerColon')" :required="true" style="width: 17vw;">
                    <el-input v-model="formData.manufacturer" autocomplete="off" class="form-input"/>
                  </el-form-item>
                </div>
              </div>
            </el-col>
            <el-col :span="9">
              <div id="dta" style="font-size: 15px;">
                <div>
                  <el-form-item :label="$t('film.originalFilmNumberColon')" :required="true" style="width: 17vw;">
                    <el-input v-model="formData.rawNumber" autocomplete="off" class="form-input"/>
                  </el-form-item>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-form>
        <div id="dialog-footer" style="margin-top: 20px;">
          <el-button type="primary" @click="EditClick">
            {{ $t('Mounting.confirm') }}
          </el-button>
          <el-button @click="handleClose">{{ $t('Mounting.cancel') }}</el-button>
        </div>
        <el-button style="display: block; margin: 20px auto;" type="primary" @click="handleDelete">{{
            $t('film.shelfEmpty')
          }}
        </el-button>
      </div>
      <!-- 右侧部分 -->
      <div class="right-side">
        <div style="display: flex;">
          <el-input v-model="rawWidth" style="margin-left: 10px;margin-bottom: 10px;width: 240px;" :placeholder="$t('film.widthEnter')" />
          <el-input v-model="rawHeight" style="margin-left: 10px;margin-bottom: 10px;width: 240px;" :placeholder="$t('film.heightEnter')"/>
          <el-input v-model="rawThickness" style="margin-left: 10px;margin-bottom: 10px;width: 240px;" :placeholder="$t('film.thicknessEnter')"/>
          <el-input v-model="filmsId" style="margin-left: 10px;margin-bottom: 10px;width: 240px;" :placeholder="$t('film.filmsEnter')"/>
          <el-button type="primary" style="margin-left: 10px;margin-bottom: 10px;" @click="fetchFlowCardSearch">
            {{$t('order.inquire')}}</el-button>
        </div>
        <el-table ref="table" :data="tableData" :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129' }"
                  style="width: 100%;height: 90%;">
          <el-table-column prop="rawWidth" align="center" :label="$t('Mounting.originalWidth')" min-width="80" />
          <el-table-column prop="rawHeight" align="center" :label="$t('film.height')" min-width="80" />
          <el-table-column prop="rawThickness" align="center" :label="$t('film.thickness')" min-width="80" />
          <el-table-column prop="filmsId" align="center" :label="$t('searchOrder.membraneSystem')" min-width="80" />
          <!-- <el-table-column prop="rawMargin" align="center" :label="$t('film.originalEdge')" min-width="100" /> -->
          <el-table-column prop="manufacturer" align="center" :label="$t('film.manufacturer')" min-width="100" />
          <el-table-column prop="rawNumber" align="center" :label="$t('film.originalFilmNumber')" min-width="100" />
          <el-table-column prop="remainQuantity" align="center" :label="$t('film.remainQuantity')" min-width="100" />
          <el-table-column fixed="right" :label="$t('Mounting.operate')" align="center" width="100">
            <template #default="scope">
              <el-button type="text" plain @click="handleAddRow(scope.row)">{{ $t('Mounting.add') }}</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </el-dialog>
</template>
<script lang="ts" setup>
import request from "@/utils/request"
import type {PropType} from 'vue'
import {ref, watch, computed, nextTick} from 'vue'
import {ElMessage, type FormInstance} from 'element-plus'
import {useRouter} from "vue-router"
import {useI18n} from 'vue-i18n'
const {t} = useI18n()
const loading = ref(false)
const router = useRouter()
const rawWidth = ref('')
const rawHeight = ref('')
const rawThickness = ref('')
const filmsId = ref('')
const tableData = ref<any[]>([])
const formRef = ref<FormInstance>()
interface FormData {
  slot?: string
  deviceId?: string
  shelf?: string
  rawWidth?: string
  rawHeight?: string
  rawThickness?: string
  filmsId?: string
  rawMargin?: string
  remainQuantity?: string
  manufacturer?: string
  rawNumber?: string
  id?: string
  isRightSide?: boolean
}
interface TableRow {
  rawWidth?: string
  rawHeight?: string
  rawThickness?: string
  filmsId?: string
  rawMargin?: string
  manufacturer?: string
  rawNumber?: string
  remainQuantity?: string
  [key: string]: any
}
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  rowData: {
    type: Object as PropType<any>,
    default: () => ({})
  },
  tableDataQueryUnBind: {
    type: Array as PropType<TableRow[]>,
    default: () => []
  },
  isViewMode: {
    type: Boolean,
    default: false
  }
})
const emit = defineEmits(['update:visible', 'confirm', 'add-row', 'delete-row', 'close', 'clean'])
const dialogVisible = ref(props.visible)
const formData = ref<FormData>({})
// 计算属性:根据是否是右侧设置不同的占位符
const rawMarginPlaceholder = computed(() => {
  return props.rowData?.isRightSide 
    ? t('film.rightRawMarginPlaceholder') // 请输入200-2000的值
    : t('film.leftRawMarginPlaceholder')  // 请输入大于等于2500的值
})
// 计算属性:根据是否是右侧设置不同的验证规则
const formRules = computed(() => {
  const rawMarginRule = props.rowData?.isRightSide ? 
    [
      { 
        validator: (rule: any, value: any, callback: any) => {
          if (value && value !== '') {
            const numValue = Number(value)
            if (isNaN(numValue) || numValue < 200 || numValue >= 2000) {
              callback(new Error(t('film.rightRawMarginError'))) // 右侧原片边距必须大于等于200且小于2000
            } else {
              callback()
            }
          } else {
            callback()
          }
        }, 
        trigger: 'blur' 
      }
    ] : 
    [
      { 
        validator: (rule: any, value: any, callback: any) => {
          if (value && value !== '') {
            const numValue = Number(value)
            if (isNaN(numValue) || numValue < 2500) {
              callback(new Error(t('film.leftRawMarginError'))) // 左侧原片边距必须大于等于2500
            } else {
              callback()
            }
          } else {
            callback()
          }
        }, 
        trigger: 'blur' 
      }
    ]
  return {
    rawMargin: rawMarginRule
  }
})
// 监听props.visible变化
watch(() => props.visible, async (val) => {
  dialogVisible.value = val
  if (val) {
    tableData.value = [...props.tableDataQueryUnBind]
    // 当弹窗打开时,如果有rowData.id,则调用接口获取数据
    if (props.rowData?.id) {
      await fetchRawDetailsById(props.rowData.id)
    }
  }
})
const fetchRawDetailsById = async (id: string) => {
  if (!id) return
  loading.value = true
  try {
      const response = await request.post("/glassStorage/rawGlassStorageDetails/queryRawDetailsById", id)
    if (response.code === 200 && response.data) {
      // 将接口返回的数据设置到formData中
      const data = response.data
      formData.value = {
        slot: data.slot || '',
        deviceId: data.deviceId || '',
        shelf: data.shelf || '',
        rawWidth: data.rawWidth || '',
        rawHeight: data.rawHeight || '',
        rawThickness: data.rawThickness || '',
        filmsId: data.filmsId || '',
        rawMargin: data.rawMargin || (props.rowData?.isRightSide ? '200' : '2500'),
        remainQuantity: data.remainQuantity || '',
        manufacturer: data.manufacturer || '',
        rawNumber: data.rawNumber || '',
        id: data.id || '',
        isRightSide: props.rowData?.isRightSide || false
      }
    } else {
      ElMessage.error(response.message || t('film.fetchDataFailed'))
    }
  } catch (error) {
    ElMessage.error(t('film.fetchDataFailed'))
  } finally {
    loading.value = false
  }
}
// 监听dialogVisible变化,同步到父组件
watch(dialogVisible, (val) => {
  emit('update:visible', val)
})
// 监听rowData变化
watch(() => props.rowData, (val) => {
  if (val) {
    // 根据点击的是左侧还是右侧设置不同的默认值
    const defaultRawMargin = val.isRightSide ? '200' : '2500'
    formData.value = {
      slot: val.slot || '',
      deviceId: val.deviceId || '',
      shelf: val.shelf || '',
      rawWidth: val.rawWidth || '',
      rawHeight: val.rawHeight || '',
      rawThickness: val.rawThickness || '',
      filmsId: val.filmsId || '',
      rawMargin: val.rawMargin || defaultRawMargin, // 设置不同的默认值
      remainQuantity: val.remainQuantity || '',
      manufacturer: val.manufacturer || '',
      rawNumber: val.rawNumber || '',
      id: val.id || '',
      isRightSide: val.isRightSide || false
    }
  }
}, { immediate: true, deep: true })
// 监听props.tableDataQueryUnBind变化,更新本地表格数据
watch(() => props.tableDataQueryUnBind, (val) => {
  tableData.value = [...val]
}, { immediate: true })
// 手动验证原片边距
const validateRawMargin = () => {
  if (!formData.value.rawMargin) return true
  const numValue = Number(formData.value.rawMargin)
  if (props.rowData?.isRightSide) {
    // 右侧验证:200 <= value < 2000
    if (numValue < 200 || numValue >= 2000) {
      ElMessage.error(t('film.rightRawMarginError'))
      return false
    }
  } else {
    // 左侧验证:value >= 2500
    if (numValue < 2500) {
      ElMessage.error(t('film.leftRawMarginError'))
      return false
    }
  }
  return true
}
const handleAddRow = (row: TableRow) => {
  // 根据当前是左侧还是右侧设置不同的默认值
  const defaultRawMargin = props.rowData?.isRightSide ? '200' : '2500'
  formData.value = {
    ...formData.value,
    rawWidth: row.rawWidth,
    rawHeight: row.rawHeight,
    rawThickness: row.rawThickness,
    filmsId: row.filmsId,
    rawMargin: row.rawMargin || defaultRawMargin, // 使用行数据中的值或默认值
    remainQuantity: row.remainQuantity,
    manufacturer: row.manufacturer,
    rawNumber: row.rawNumber,
  }
}
const EditClick = async () => {
  // 验证表单
  if (formRef.value) {
    try {
      await formRef.value.validate()
      // 额外验证原片边距
      if (!validateRawMargin()) {
        return
      }
      emit('confirm', formData.value)
    } catch (error) {
      ElMessage.error(t('film.checkData'))
    }
  } else {
    // 如果没有表单引用,只验证原片边距
    if (!validateRawMargin()) {
      return
    }
    emit('confirm', formData.value)
  }
}
const deleteWareHousing = (row: TableRow) => {
  emit('delete-row', row)
}
const handleClose = () => {
  emit('close')
  const { slot, deviceId, shelf } = formData.value
  formData.value = { slot, deviceId, shelf }
  rawWidth.value = ''
  rawHeight.value = ''
  rawThickness.value = ''
  filmsId.value = ''
}
const handleDelete = () => {
  emit('clean')
}
const fetchFlowCardSearch = async () => {
  try {
    const response = await request.post('glassStorage/rawGlassStorageDetails/queryUnBindRawGlassList',{
      rawWidth: rawWidth.value,
      rawHeight: rawHeight.value,
      rawThickness: rawThickness.value,
      filmsId: filmsId.value
    });
    if (response.code == 200) {
      ElMessage.success(response.message);
      tableData.value = response.data;
    } else {
      ElMessage.error();
    }
  } catch (error) {
  }
};
</script>
<style scoped>
.dialog-container {
  display: flex;
  height: 70vh;
}
.left-side {
  width: 40%;
  padding: 0 10px;
  overflow-y: auto;
}
.right-side {
  width: 60%;
  padding: 0 10px;
}
#dialog-footer {
  text-align: center;
  margin-top: -15px;
}
.form-row {
  margin-bottom: 12px; /* 表单行间距 */
}
.glass-form {
  margin-left: 20px;
}
.glass-form :deep(.el-form-item__label) {
  /* max-width: 180px;  */
  margin-right: -10px;
}
.form-input {
  width: 200px !important;
}
</style>