chenlu
2025-12-02 2b30dba82ed2ac66189c39b00e81169b324fedac
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
<script setup>
import {nextTick, onMounted, reactive, ref, watch} from "vue";
import {useI18n} from "vue-i18n";
import {Search} from "@element-plus/icons-vue";
import request from "@/utils/request";
import deepClone from "@/utils/deepClone";
import {ElMessage} from "element-plus";
import useUserInfoStore from "@/stores/userInfo";
import {changeFilterEvent, filterChanged} from "@/hook";
 
const {t} = useI18n()
const userStore = useUserInfoStore()
const username = userStore.user.userId
let rowClickIndex = ref(null)
 
let props = defineProps({
  processId: null,
  technologyNumber: null
})
 
//膜系
const optionVal = ref()
//膜系
const projectNmae = ref()
//工程编号个数
let projectId = ref()
//工程编号
const Id = ref()
let oddNumbers = ref()
 
//定义接收加载表头下拉数据
const titleSelectJson = ref({
  processType: [],
})
 
const selectGlassType = () => {
  //查询膜系
  request.post(`/glassOptimize/selectGlassType`).then((res) => {
    if (res.code == 200) {
      titleSelectJson.value.processType = res.data.data
    } else {
      ElMessage.warning(res.msg)
    }
  })
}
//查询最新工程号
const getProjectId = () => {
  request.post(`/glassOptimize/getProjectId`).then((res) => {
    if (res.code == 200) {
      projectId = res.data.data[0].project_no
      // 获取字符串的最后两位数字
      let maximum = projectId.slice(-2);
      let lastTwoInteger = parseInt(maximum, 10);
       // 设置两位不够补0
      let formattedNumber = (lastTwoInteger + 1).toString().padStart(2, '0');
      // 格式化当前日期为 "yyMMdd"
      let currentDate = new Date();
      let formattedDate = currentDate.getFullYear().toString().slice(-2) +
          (currentDate.getMonth() + 1).toString().padStart(2, '0') +
          currentDate.getDate().toString().padStart(2, '0');
 
      // 拼接成最终的字符串
      oddNumbers.value = 'P' + formattedDate + formattedNumber;
 
    } else {
      ElMessage.warning(res.msg)
    }
  })
}
 
 
onMounted(() => {
  console.log(userStore.user);
  getProjectId();
  selectGlassType();
 
})
 
const xGrid = ref()
 
// 添加监听器 - 监听膜系选择变化
watch(optionVal, (newVal, oldVal) => {
  if (oldVal !== undefined && newVal !== oldVal) {
    // 当膜系改变时,自动刷新数据
    if (newVal) {
      selectFlowCardList();
    }
  }
}, { flush: 'post' });
 
 
const gridOptions = reactive({
 
  height: '100%',
  loading: false,
  border: "full",//表格加边框
  keepSource: true,//保持源数据
  align: 'center',//文字居中
  stripe: true,//斑马纹
  rowConfig: {isCurrent: true, isHover: true, height: 30, useKey: true},//鼠标移动或选择高亮
  id: 'ProcessCard',
  scrollX: {enabled: true},
  scrollY: {enabled: true, gt: 0},//开启虚拟滚动
  showOverflow: true,
  columnConfig: {
    resizable: true,
    useKey: true
  },
  filterConfig: {   //筛选配置项
    //remote: true
  },
  customConfig: {
    storage: true
  },
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },
  columns: [
 
    {field: 'select',type:'checkbox',title: t('basicData.check'), width: 80,fixed:"left"},
    {
      field: 'process_id',
      width: 150,
      title: t('processCard.processId'),
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true,
      filterMethod:filterChanged
    },
    {
      field: 'technology_number',
      width: 70,
      title: '层',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true,
      filterMethod:filterChanged
    },
    {
      field: 'TotalFloors',
      width: 150,
      title: '总层数',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true,
      filterMethod:filterChanged
    },
    {
      field: 'TotalNumber',
      width: 150,
      title: '规格',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true,
      filterMethod:filterChanged
    },
    {
      field: 'quantity',
      width: 150,
      title: t('order.quantity'),
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true,
      filterMethod:filterChanged
    },
    {
      field: 'shape',
      width: 150,
      title: t('order.shape'),
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true,
      filterMethod:filterChanged
    },
    {
      field: 'glass_child',
      width: 150,
      title: t('order.product'),
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true,
      filterMethod:filterChanged
    },
    {field: 'project', width: 150, title: t('order.project'), showOverflow: "ellipsis",filterMethod:filterChanged},
    {
      field: 'area',
      width: 150,
      title: t('order.area'),
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true,
      filterMethod:filterChanged
    },{
      field: 'patch_state',
      width: 100,
      title: '补片状态'
    },
 
 
  ],//表头参数
  data: null,//表格数据
 
  toolbarConfig: {
    buttons: [],
    slots: {
      buttons: "toolbar_buttons"
    },
  },
 
 
})
 
const gridEvents = {
  cellClick({row}) {
    rowClickIndex.value = row
    // Emit 事件将更新后的值传递给父组件
    emit('updateProcessId', rowClickIndex.value.process_id);
    emit('updateTechnologyNumber', rowClickIndex.value.technology_number);
  }
}
const emit = defineEmits(['updateProcessId', 'updateTechnologyNumber', 'updateState']);
 
 
//小圆点单选框
let radio = ref(1);
let isButtonDisabledAdd = ref(false);
let isButtonDisabledUpdate = ref(true);
 
const selectFlowCardList = async () => {
  request.post(`/glassOptimize/getFlowCardList/${optionVal.value}/${radio.value}`).then((res) => {
    if (res.code == 200) {
      getProjectId()
      isButtonDisabledAdd.value=false
      isButtonDisabledUpdate.value = true
      xGrid.value.loadData(res.data.data)
    } else {
      ElMessage.warning(res.msg)
    }
  })
}
 
const getUpdateFlowCardList = async (projectNumber, type, thickness) => {
  // 重置状态
  radio.value = 1;
  isButtonDisabledAdd.value = true;
  isButtonDisabledUpdate.value = false;
 
  // 清空现有数据
  if (xGrid.value) {
    xGrid.value.loadData([]);
  }
 
  // 强制更新表单字段
  oddNumbers.value = projectNumber;
  projectNmae.value = ''; // 先清空工程名称
 
  // 构造正确的膜系值
  const glassTypeValue = `${thickness}mm${type}`;
  optionVal.value = glassTypeValue;
 
  request.post(`/glassOptimize/getUpdateFlowCardList/${type}/${thickness}/${radio.value}/${projectNumber}`).then((res) => {
    if (res.code == 200) {
      // 更新工程编号
      oddNumbers.value = projectNumber;
 
      // 更新工程名称(如果后端返回)
      if (res.data.projectName) {
        projectNmae.value = res.data.projectName;
      }
 
      // 确保膜系选择正确
      optionVal.value = glassTypeValue;
 
      isButtonDisabledAdd.value = true;
      isButtonDisabledUpdate.value = false;
 
      // 使用 $nextTick 确保DOM更新后再加载数据
      nextTick(() => {
        if (xGrid.value) {
          xGrid.value.loadData(deepClone(res.data.data));
          // 设置选中状态
          nextTick(() => {
            const tableData = xGrid.value.getTableData().fullData;
            tableData.forEach(item => {
              if(item.occupyState === 0){
                xGrid.value.setCheckboxRow(item, true);
              }
            });
          });
        }
      });
    } else {
      ElMessage.warning(res.msg);
    }
  }).catch(error => {
    ElMessage.error('获取流程卡数据失败');
    console.error(error);
  });
};
 
//创建工程
const addProject = (type) => {
  const $table = xGrid.value
  if ($table) {
    const selectRecords = $table.getCheckboxRecords()
    if($table.getCheckedFilters().length!==0){
      ElMessage.error(t('order.msg.pleaseCancelTheFilteringFirst'))
      return
    }
    // if (selectRecords.length == 0) {
    //   ElMessage.warning(t('reportingWorks.selectProcessCardData'))
    //   return;
    // }
 
    let projectData = ref({
      projectdetail: selectRecords,
      userName : username,
      projectType: type
    })
    let inputProject = projectNmae.value
    if (inputProject == undefined) {
      inputProject = null
    }
    request.post(`/glassOptimize/addProject/${optionVal.value}/${oddNumbers.value}/${inputProject}`, projectData.value).then((res) => {
      if (res.code == 200 && res.data === "true") {
        emit('updateState', 1);
        ElMessage.success(t('basicData.msg.saveSuccess'))
        selectFlowCardList()
        getProjectId();
      }else if(res.data === "false1") {
        ElMessage.warning("工程号已存在请重新刷新界面")
      } else {
        ElMessage.warning(res.msg)
      }
    })
 
  }
}
 
watch(optionVal, (newVal, oldVal) => {
  if (newVal) {
    // 当膜系改变时,更新工程名称为当前膜系值
    projectNmae.value = newVal;
 
    // 当膜系改变时,自动刷新数据
    selectFlowCardList();
  }
}, { flush: 'post' });
 
const handleRowClassName = ({ row, rowIndex }) => {
  if (row.patch_state === 1) {
    return 'high-score';
  }
  if (row.occupyState === 0) {
    return 'high-score2';
  }
}
 
//抛出方法到父界面
defineExpose({getProjectId,selectFlowCardList,selectGlassType,getUpdateFlowCardList})
</script>
 
<template>
  <div style="width: 100%;height: 110%; margin-top: -36px">
    <div>
      流程卡列表
      <span style="margin-left: 140px;font-size: 14px">工程编号:</span>
<!--      <span>{{oddNumbers}}</span>-->
      <el-input disabled v-model="oddNumbers" style="width: 100px"></el-input>
<!--      <vxe-input :disabled="isDisabled" placeholder="" v-model="oddNumbers" size="small" style="color:black;"></vxe-input>&nbsp;-->
      <span style="font-size: 14px">工程名称:</span>
      <el-input style="width: 150px" placeholder="" v-model="projectNmae" size="small"></el-input>
      <el-button style="margin-left: 20px" type="primary" :disabled="isButtonDisabledAdd" @click="addProject(1)">创建</el-button>
      <el-button style="margin-left: 20px;" type="primary"  :disabled="isButtonDisabledUpdate"  @click="addProject(2)">修改</el-button>
    </div>
    <vxe-grid
        ref="xGrid"
        class="mytable-scrollbar"
        height="100%"
        size="small"
        v-bind="gridOptions"
        v-on="gridEvents"
        :row-class-name="handleRowClassName"
    >
      <template #num2_filter="{ column, $panel }">
        <div>
          <div v-for="(option, index) in column.filters" :key="index">
            <vxe-select v-model="option.data" :placeholder="$t('processCard.pleaseSelect')"
                        @change="changeFilterEvent($event, option, $panel)">
              <vxe-option :label="$t('basicData.unchecked')" value="0"></vxe-option>
              <vxe-option :label="$t('basicData.selected')" value="1"></vxe-option>
            </vxe-select>
          </div>
        </div>
      </template>
 
      <template #num1_filter="{ column, $panel }">
        <div>
          <div v-for="(option, index) in column.filters" :key="index">
            <input type="type" v-model="option.data" @keyup.enter.native="$panel.confirmFilter()" @input="changeFilterEvent($event, option, $panel)"/>
          </div>
        </div>
      </template>
 
      <template #toolbar_buttons>
        <h2>膜系筛选:</h2>
        <el-select v-model="optionVal" clearable default-value="default_city" placeholder="选择膜系"
                   style="width: 120px">
          <el-option
              v-for="item in titleSelectJson['processType']"
              :key="item.id"
              :label="item.glassType"
              :value="item.glassType"
          />
        </el-select>
        <el-button :icon="Search" style="margin-left: 20px" type="primary" @click="selectFlowCardList">查询</el-button>
        <vxe-radio-group v-model="radio" style="margin-left: 20px">
          <vxe-radio content="全部" label="1"></vxe-radio>
          <vxe-radio content="正单" label="2"></vxe-radio>
          <vxe-radio content="补单" label="3"></vxe-radio>
        </vxe-radio-group>
      </template>
 
    </vxe-grid>
  </div>
</template>
 
<style lang="css">
.high-score {
  background-color: #d4baba !important;
}
.high-score2 {
  background-color: #a5aec9 !important;
}
</style>