chengxiangling
2025-05-16 af1c9e588f1de0240390648f9bb56aa486870aff
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
<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>