chenlu
2025-03-07 3ab330b8aefb3cd781c9b8730b4ab7ac65e7e9d7
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
<script setup>
import {nextTick, onMounted, reactive, ref, watch} from "vue";
import request from "@/utils/request";
import {useI18n} from "vue-i18n";
const { t } = useI18n()
 
const xGrid = ref()
 
const checkboxCellRender = reactive({
  name: 'VxeCheckboxGroup',
  options: [
    { label: '幕墙模式', value: '1' },
    { label: '允许横排', value: '2' },
    { label: '钢化', value: '3' },
 
  ]
})
 
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: 'ComputeCard',
  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:[
    {type:'seq',fixed:"left",slots: { content:'content' },width: 50},
    {field: 'check', title: '选择', width: 250, cellRender: checkboxCellRender },
    {field: 'process_id',width: 150, title: t('processCard.processId'), sortable: true},
    {field: 'technology_number',width: 70, title: '层', sortable: true},
    {field: 'TotalFloors',width: 150, title: '总层数', sortable: true},
    {field: 'TotalNumber',width: 150, title: '规格', sortable: true},
    {field: 'quantity',width: 150, title: t('order.quantity'), sortable: true},
    {field: 'glass_child',width: 150, title: t('order.product'), sortable: true},
    {field: 'project', width:150, title: t('order.project'), showOverflow: "ellipsis"},
    {field: 'area',width: 150, title: t('order.area'), sortable: true},
 
 
  ],//表头参数
  data:null,//表格数据
 
  toolbarConfig: {
    buttons: [],
    slots:{
      buttons: "toolbar_buttons"
    },
    zoom: true,
    custom: true
  },
 
})
 
let emit = defineEmits([
  'changeDialog','upProcessId', 'sendData'
]);
 
 
 
 
 
const props = defineProps({
  tableData: Array,
  processId: null,
});
 
watch(() => props.tableData, async (newData) => {
  if (Array.isArray(newData)) {
    gridOptions.data = newData;
    await nextTick();
    if (xGrid.value) {
      const grid = xGrid.value;
      if (typeof grid.refresh === 'function') {
        grid.refresh();
      }
      
      
      // 提取所有唯一的process_id
      const processIds = Array.from(new Set(newData.map(item => item.process_id)));
      
      // 发起所有请求
      const requests = processIds.map(processId => 
        request.post(`/glassOptimize/selectComputeDetail/${processId}`)
      );
      
      try {
        const responses = await Promise.all(requests);
        
        // 整合数据
        const processData = responses.reduce((acc, res, index) => {
          const processId = processIds[index];
          
          // 检查res.data是否为对象,并且包含'data'字段
          if (typeof res.data === 'object' && res.data !== null && 'data' in res.data) {
            const data = res.data.data;
            
            // 检查data是否为数组
            if (!Array.isArray(data)) {
              console.error(`响应数据中的'data'字段不是数组,process_id: ${processId}`);
              return acc;
            }
            
            // 获取对应process_id的newData条目
            const relatedNewData = newData.filter(item => item.process_id === processId);
           
            // 初始化process_card对象
            const processCard = {
  process_no: processId,
  layers: relatedNewData.technology_number,
  total_layers: relatedNewData.TotalNumber,
  total_num: relatedNewData.quantity,
  total_area: relatedNewData.area,
  is_must: true,
  allow_rotate: relatedNewData.check === 1 ? true : false,
  priority_level: 0,
  tempering: relatedNewData.check === 2 ? true : false,
  curtain_wall: relatedNewData.check === 3 ? true : false,
  patch_state: 0,
  merge: 0,
  glass_details: []
};
 
            
            // 整合glass_details
            data.forEach(detail => {
              const matchedNewData = relatedNewData.find(
                item => item.technology_number === detail.technology_number
              );
              
              processCard.glass_details.push({
                process_id: processId,
                technology_number: detail.technology_number,
                order_number: detail.order_number,
                layers_number: detail.layers_number,
                max_width: detail.width,
                max_height: detail.height,
                child_width: detail.child_width,
                child_height: detail.child_height,
                quantity: matchedNewData ? matchedNewData.quantity : 0,
                patch_state: 0
              });
            });
            
            // 将processCard添加到acc中
            if (!acc.process_cards) {
              acc.process_cards = [];
            }
            acc.process_cards.push(processCard);
              // 设置其他字段的值
          
          } else {
            console.error(`响应数据格式不正确,process_id: ${processId}`);
          }
          return acc;
        }, {});
        if (newData.length > 0) {
          // 假设所有条目的thickness和glassType相同
          processData.glass_thickness = newData[0].thickness;
          processData.glass_type = newData[0].glassType;
        } else {
          processData.glass_thickness = "";
          processData.glass_type = "";
        }
      
     
        
        // 发送整合后的数据到父组件
        emit('sendData', processData);
      } catch (error) {
        console.error('请求失败:', error);
      }
    }
  } else {
    console.error('传递给表格的数据格式不符合要求,期望是数组格式');
  }
});
 
 
 
 
let process_id = ref()
//获取流程卡号详情
let rowClickIndex = ref(null)
const gridEvents = {
  cellClick({row}) {
    rowClickIndex.value = row
    // Emit 事件将更新后的值传递给父组件
    emit('upProcessId', rowClickIndex.value.process_id);
  }
}
 
</script>
 
<template>
  <div style="width: 100%;height: 100%">
    <span>流程卡</span>
    <vxe-grid
        size="small"
        @filter-change="filterChanged"
        height="100%"
        class="mytable-scrollbar"
        ref="xGrid"
        v-bind="gridOptions"
        v-on="gridEvents"
    >
      <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 value="0" :label="$t('basicData.unchecked')"></vxe-option>
              <vxe-option value="1" :label="$t('basicData.selected')"></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>
    </vxe-grid>
  </div>
</template>
 
<style scoped>
:deep(.vxe-tools--operate){
  height: 20px;
  margin-top: -20px;
}
 
</style>