<template>
|
<div class="app-container">
|
<el-form :model="queryParams" ref="queryRef" :rules="rules" :inline="true" v-show="showSearch" label-width="68px">
|
<el-row :gutter="20">
|
<el-col :span="6">
|
<el-form-item label="料号" prop="itemCode">
|
<el-input
|
v-model="queryParams.itemCode"
|
placeholder="请输入料号"
|
clearable
|
@keyup.enter="handleQuery"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="18" style="text-align: right;">
|
<el-form-item>
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
|
<HxlhTable
|
style="width: 100%"
|
:columns="columns"
|
:data="bomList"
|
:loading="loading"
|
:height="height"
|
:treeConfig="treeConfig"
|
:row-style="getRowStyle"
|
>
|
</HxlhTable>
|
</div>
|
</template>
|
|
<script setup name="ApsBom">
|
import { listApsBom } from "@/api/basicData/bom/bom";
|
import { listAll_plant } from "@/api/basicData/plant";
|
import axios from 'axios';
|
import HxlhTable from '@/components/HxlhTable'
|
|
const { proxy } = getCurrentInstance();
|
|
const bomList = ref([]);
|
const open = ref(false);
|
const loading = ref(false);
|
const showSearch = ref(true);
|
|
const treeConfig= {
|
transform: true,
|
rowField: 'bomId',
|
parentField: 'parentBomId'
|
}
|
|
const data = reactive({
|
form: {},
|
queryParams: {
|
itemCode: null,
|
},
|
rules: {
|
itemCode: [
|
{ required: true, message: "料号不能为空", trigger: "blur" }
|
],
|
}
|
});
|
|
// 表格配置
|
const columns = ref([
|
{
|
title: 'bomId',
|
field: 'bomId',
|
minWidth: 20, treeNode: true
|
},
|
{
|
title: 'parentBomId',
|
field: 'parentBomId',
|
},
|
{
|
title: '料号',
|
field: 'itemCode',
|
},
|
{
|
title: '物料描述',
|
field: 'itemName',
|
},
|
{
|
title: '生效日期',
|
field: 'startDate',
|
},
|
{
|
title: '失效日期',
|
field: 'endDate',
|
},
|
{
|
title: '适用工厂',
|
field: 'orgCode',
|
formatter: (({ cellValue, row, column }) => {
|
if (cellValue) {
|
for(let i=0;i<plantList.value.length;i++){
|
if(cellValue===plantList.value[i].plantCode){
|
return plantList.value[i].plantName
|
}
|
}
|
}
|
return '';
|
})
|
},
|
{
|
title: '创建时间',
|
field: 'createTime',
|
},
|
]);
|
|
// 定义一个函数来获取行的层级
|
const getRowLevel = (row, dataMap) => {
|
let level = 0
|
let parentBomId = row.parentBomId
|
while (parentBomId!== null) {
|
const parentRow = dataMap.get(parentBomId)
|
if (parentRow) {
|
level++
|
parentBomId = parentRow.parentBomId
|
} else {
|
break
|
}
|
}
|
return level
|
}
|
|
// 定义一个函数来设置行的样式
|
const getRowStyle = (row, rowIndex) => {
|
if (!Array.isArray(bomList.value)) {
|
console.error('bomList 不是一个数组类型');
|
return {};
|
}
|
const dataMap = new Map(bomList.value.map(item => [item.bomId, item]))
|
const level = getRowLevel(row.row, dataMap)
|
const colors = ['#f0f9ff', '#e6f7ff', '#bae7ff', '#91d5ff', '#69c0ff']
|
return {
|
backgroundColor: colors[level % colors.length]
|
}
|
}
|
|
const { queryParams, form, rules } = toRefs(data);
|
|
const queryPlants = ref({status: 1});
|
const plantList = ref([]);
|
const height = ref(document.documentElement.clientHeight - 180 + "px;")
|
|
/** 查询BOM数据管理列表 */
|
function getList() {
|
loading.value = true;
|
axios.all([
|
listAll_plant(queryPlants.value),
|
listApsBom(queryParams.value)
|
])
|
.then(axios.spread((response1, response2) => {
|
plantList.value = response1.data;
|
bomList.value = response2.rows;
|
loading.value = false;
|
}))
|
.catch(error => {
|
console.error('请求出错:', error);
|
});
|
}
|
|
// 取消按钮
|
function cancel() {
|
open.value = false;
|
reset();
|
}
|
|
// 表单重置
|
function reset() {
|
form.value = {
|
id: null,
|
bomId: null,
|
parentBomId: null,
|
itemCode: null,
|
itemName: null,
|
startDate: null,
|
endDate: null,
|
orgCode: null,
|
delFlag: null,
|
createBy: null,
|
createTime: null,
|
updateBy: null,
|
updateTime: null
|
};
|
proxy.resetForm("ApsBomRef");
|
}
|
|
/** 搜索按钮操作 */
|
function handleQuery() {
|
proxy.$refs["queryRef"].validate(valid => {
|
if (valid) {
|
getList();
|
}
|
});
|
}
|
|
/** 重置按钮操作 */
|
function resetQuery() {
|
proxy.resetForm("queryRef");
|
bomList.value = null;
|
}
|
|
console.log("123");
|
</script>
|