huang
2025-01-14 a006a22e0445fc74195e25436384d1d3ee0a1bdd
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
<script setup>
import {nextTick, onMounted, reactive, ref, watch} from "vue";
import {useI18n} from "vue-i18n";
import request from "@/utils/request";
import {ElMessage, ElMessageBox} from "element-plus";
import {useRoute} from "vue-router";
const { t } = useI18n()
 
const xGrid = ref()
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: 'GlassInventory',
  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", title:' ', width: 50},
    {type: 'checkbox', fixed: "left", title: t('basicData.check'), width: 80},
    {field: 'id', title: '物料编码',},
    {field:'width',title: t('order.width'),},
    {field: 'height',title: t('order.height')},
    {field: 'thickness', title: t('order.totalThickness'),},
    {field: 'model', title: t('warehouseBasicData.type'),},
    {field: 'leftTrim', title: '左修边',},
    {field: 'downTrim', title: '下修边',},
    {field: 'rigthTrim', title: '右修边',},
    {field: 'upTrim', title: '上修边',},
    {field: 'available_quantity', title: '库存数量',},
    {field: '', title: '加工数量',},
    {field: 'name', title: '名称',},
    {field: 'producer', title: '供应商',}
  ],//表头参数
  data:null,//表格数据
  //右键菜单
  menuConfig: {
    body: {
      options: [
        [
          {code: 'selectTrimming', name: '设置统一修边',},
          {code: 'Exports', name: '数据导出', prefixIcon: 'vxe-icon-download', visible: true, disabled: false},
        ],
        []
      ]
    },
  },
  toolbarConfig: {
    buttons: [],
    slots:{
      buttons: "toolbar_buttons"
    },
  },
})
 
const emit = defineEmits(['select-trimming']);
// 右键菜单
const operationConfigs = [
  {
    code: 'selectTrimming', // 设置统一修边
    successMsg: '已打开!',
    gridRef: xGrid,
    requiresRow: false,
    openTrimming: async () => {
     emit ( 'select-trimming', true)
    }
  },
  {
    code: 'Exports', // 导出文件操作的配置
    successMsg: '文件导出成功!',
    gridRef: xGrid,
    requiresRow: false,
  },
]
 
// 右键菜单点击逻辑
const gridEvents = {
  menuClick({menu}) {
    const $grid = xGrid.value;
    if ($grid) {
      const config = operationConfigs.find(c => c.code === menu.code);
      if (config) {
        if (config.code === 'Exports') {
          config.gridRef.value.exportData();
          ElMessage.success(config.successMsg);
          return;
        }
        // 添加确认提示弹窗,询问用户是否进行当前操作
        ElMessageBox.confirm('是否进行当前操作?', '确认操作', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (config.code === 'selectTrimming') {
            config.openTrimming();
            ElMessage.success(config.successMsg);
          }
        }).catch(() => {
          // 用户点击取消后执行的逻辑
          ElMessage.info('已取消操作');
        });
      } else {
        console.error(`未找到操作选项 ${menu.code} 对应的配置,请检查配置项`);
      }
    }
  },
};
 
 
const route = useRoute();
 
const thickness = ref(route.params.thickNess);
const model = ref(route.params.model);
 
 
const selectMaterialStore = () =>{
  request.post(`/glassOptimize/materialStore/${thickness.value}/${model.value}`).then((res) => {
    if (Number(res.code) === 200) {
      const rawData = res.data.data;
      if (Array.isArray(rawData) && rawData.length > 0) {
        const formattedData = rawData.map(item => {
          const formattedItem = {};
          for (const key in item) {
            if (typeof item[key] === 'string') {
              //去除字符串属性值开头和结尾的双引号
              formattedItem[key] = item[key].replace(/^\"|\"$/g, '');
            } else {
              formattedItem[key] = item[key];
            }
          }
          return formattedItem;
        });
        const data = formattedData;
        data.forEach(item => {
          item.leftTrim = 0;
          item.downTrim = 0;
          item.rigthTrim = 0;
          item.upTrim = 0;
        });
        xGrid.value.loadData(formattedData);
        gridOptions.data = formattedData;
      } else {
      }
    } else {
      ElMessage.warning(res.msg);
      console.error('请求获取库存失败,状态码:', res.code, ',错误信息:', res.msg);
    }
  });
};
 
onMounted(() => {
  selectMaterialStore();
});
 
watch(() => props.receivedData, (newData) => {
  if (newData) {
    Trimming(newData);
  }
}, { immediate: true });
 
watch(() => props.InventoryData, (newInventoryData) => {
  if (newInventoryData) {
    thickness.value = newInventoryData.selectedLabel1;
    model.value = newInventoryData.selectedLabel2;
    // 由于 thickness 和 model 的值改变了,更新表格,调用 selectMaterialStore 重新获取数据
    selectMaterialStore();
  }
});
 
const props = defineProps({
  receivedData : {
    type: Object,
    required: false,
    properties: {
      quicksetLeft: { type: Number },
      quicksetBottom: { type: Number },
      quicksetRight: { type: Number },
      quicksetTop: { type: Number }
    }
  },
  InventoryData : {
    type: Object,
    required: false,
    properties: {
      selectedLabel1: { type: String },
      selectedLabel2: { type: String },
    }
  }
});
 
//接受SetTrimming的值 (修边)
const Trimming = (receivedData) => {
  nextTick(() => {
    const data = gridOptions.data;
    if (data) {
      try {
        const updatedData = [];
        for (let i = 0; i < data.length; i++) {
          const item = data[i];
          const updatedItem = {
            ...item,
            // 从 receivedData 中获取对应的值来更新表格数据项
            leftTrim: Number(receivedData.quicksetLeft),
            downTrim: Number(receivedData.quicksetBottom),
            rigthTrim: Number(receivedData.quicksetRight),
            upTrim: Number(receivedData.quicksetTop),
          };
          updatedData.push(updatedItem);
        }
        gridOptions.data = updatedData;
        xGrid.value.loadData(updatedData);
      } catch (error) {
        console.error('更新表格数据时出错:', error);
        ElMessage.error('更新表格数据时出现错误,请检查输入或联系管理员');
      }
    } else {
      console.warn('表格数据为空,无法更新磨量值');
    }
  });
};
 
 
</script>
 
<template>
  <div style="width: 100%;height: 100%">
    <vxe-grid
        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>
 
 
</style>