<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>
|