<script setup>
|
import {nextTick, onMounted, reactive, ref, watch} from "vue";
|
import {useI18n} from "vue-i18n";
|
import request from "@/utils/request";
|
import {ElMessage} 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,//表格数据
|
toolbarConfig: {
|
buttons: [],
|
slots:{
|
buttons: "toolbar_buttons"
|
},
|
},
|
})
|
|
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 });
|
|
const props = defineProps({
|
receivedData : {
|
type: Object,
|
required: false,
|
properties: {
|
quicksetLeft: { type: Number },
|
quicksetBottom: { type: Number },
|
quicksetRight: { type: Number },
|
quicksetTop: { type: Number }
|
}}
|
});
|
|
//接受SetTrimming的值 (修边)
|
const Trimming = (receivedData) => {
|
nextTick(() => {
|
const data = gridOptions.data;
|
console.log('接收到的receivedData:', receivedData);
|
console.log('表格原始数据:', 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"
|
>
|
|
|
<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>
|