yudao-dev/src/views/extend/processFlowView/components/BomSelector.vue

218 lines
5.0 KiB
Vue
Raw Normal View History

2023-11-17 16:48:00 +08:00
<!--
filename: BomSelector.vue
author: liubin
date: 2023-11-17 16:23:28
description:
-->
<template>
<div class="bom-selector">
<el-row>
<el-col :span="8">
<el-input
v-model="searchText"
placeholder="搜索"
style="margin-bottom: 12px; user-select: none">
<i slot="prefix" class="el-input__icon el-icon-search"></i>
</el-input>
</el-col>
</el-row>
2023-11-20 11:26:27 +08:00
<el-row style="border: 1px solid #ccc; display: flex">
2023-11-17 16:48:00 +08:00
<el-col :span="8">
<div class="select-list">
<div class="sl__header" style="background: #f3f4fb; padding: 12px">
<span style="">可分配设备</span>
2023-11-20 11:26:27 +08:00
<span>{{ selectedEquipments.length }}/{{ bomList.length }}</span>
2023-11-17 16:48:00 +08:00
</div>
<el-checkbox-group v-model="selectedEquipments" class="sl__body">
<el-checkbox
2023-11-20 11:26:27 +08:00
v-for="eq in bomList"
:key="eq.id"
:label="`${eq.name} (${
selectedMBom[currentEquipment].length +
selectedPBom[currentEquipment].length
} / 2)`"
@change="(e) => handleEquipmentChange(eq, e)"
2023-11-17 16:48:00 +08:00
class="sl__body-item"></el-checkbox>
</el-checkbox-group>
</div>
</el-col>
2023-11-20 11:26:27 +08:00
<el-col :span="8" style="border-left: 1px solid #ccc">
2023-11-17 16:48:00 +08:00
<div class="select-list">
<div class="sl__header" style="background: #f3f4fb; padding: 12px">
<span style="">物料BOM</span>
</div>
2023-11-20 11:26:27 +08:00
<el-checkbox-group
v-model="selectedMBom[currentEquipment]"
class="sl__body">
2023-11-17 16:48:00 +08:00
<el-checkbox
2023-11-20 11:26:27 +08:00
v-for="mb in materialsBomList"
:key="mb.id"
:label="mb.name"
:disabled="mb.disabled || false"
@change="
(e) =>
handleMaterialBomChange(mb, materialsBomList.equipmentId, e)
"
2023-11-17 16:48:00 +08:00
class="sl__body-item"></el-checkbox>
</el-checkbox-group>
</div>
</el-col>
<el-col :span="8" style="border-left: 1px solid #ccc">
<div class="select-list">
<div class="sl__header" style="background: #f3f4fb; padding: 12px">
<span style="">参数BOM</span>
</div>
2023-11-20 11:26:27 +08:00
<el-checkbox-group
v-model="selectedPBom[currentEquipment]"
class="sl__body">
2023-11-17 16:48:00 +08:00
<el-checkbox
2023-11-20 11:26:27 +08:00
v-for="vb in valuesBomList"
:key="vb.id"
:label="vb.name"
:disabled="vb.disabled || false"
@change="
(e) => handleValueBomChange(vb, valuesBomList.equipmentId, e)
"
2023-11-17 16:48:00 +08:00
class="sl__body-item"></el-checkbox>
</el-checkbox-group>
</div>
</el-col>
</el-row>
</div>
</template>
2023-11-17 17:07:52 +08:00
;
2023-11-17 16:48:00 +08:00
<script>
export default {
name: 'BomSelector',
components: {},
2023-11-20 11:26:27 +08:00
props: {
bomList: {
type: Array,
default: () => [],
},
},
2023-11-17 16:48:00 +08:00
data() {
return {
searchText: '',
selectedEquipments: [],
2023-11-20 11:26:27 +08:00
selectedMBom: { default: [] },
selectedPBom: { default: [] },
2023-11-17 17:07:52 +08:00
selected: [],
2023-11-20 11:26:27 +08:00
materialsBomList: [],
valuesBomList: [],
currentEquipment: 'default',
2023-11-17 16:48:00 +08:00
};
},
2023-11-17 17:07:52 +08:00
watch: {
selected: {
handler(val) {
console.log(val);
},
deep: true,
},
},
2023-11-17 16:48:00 +08:00
computed: {},
2023-11-20 11:26:27 +08:00
created() {},
mounted() {
// 准备v-model
this.bomList.forEach((item) => {
this.$set(this.selectedMBom, item.id, []);
this.$set(this.selectedPBom, item.id, []);
});
},
2023-11-17 17:07:52 +08:00
methods: {
2023-11-20 11:26:27 +08:00
handleEquipmentChange(eq, selected) {
this.currentEquipment = eq.id;
this.materialsBomList =
// [
// {
// id: 1,
// name: 'mb-1',
// },
// {
// id: 2,
// name: 'mb-2',
// },
// {
// id: 3,
// name: 'mb-3',
// },
// ] ||
eq.materialsBom || [];
this.valuesBomList = eq.valuesBom || [];
// 重新确保equipmentId已经被加载上去了
this.materialsBomList.equipmentId = eq.id;
this.valuesBomList.equipmentId = eq.id;
console.log('eq', selected, eq, this.selectedEquipments);
if (selected) {
2023-11-17 17:07:52 +08:00
this.selected.push({
2023-11-20 11:26:27 +08:00
equipmentId: eq.id,
equValueBomId: null,
equMaterialBomId: null,
2023-11-17 17:07:52 +08:00
});
2023-11-20 11:26:27 +08:00
} else {
// 清空选择状态
this.selected = this.selected.filter(
(item) => item.equipmentId !== eq.id
);
this.selectedMBom[eq.id] = [];
this.selectedPBom[eq.id] = [];
2023-11-17 17:07:52 +08:00
}
},
2023-11-20 11:26:27 +08:00
handleValueBomChange(vb, equipmentId, selected) {
const selectedItem = this.selected.find(
(item) => item.equipmentId == equipmentId
);
selectedItem.equValueBomId = selected ? vb.id : null;
this.valuesBomList.forEach((item) => {
item.disabled = selected ? item.id !== vb.id : false;
});
},
handleMaterialBomChange(mb, equipmentId, selected) {
debugger;
const selectedItem = this.selected.find(
(item) => item.equipmentId == equipmentId
);
selectedItem.equMaterialBomId = selected ? mb.id : null;
this.materialsBomList.forEach((item) => {
item.disabled = selected ? item.id !== mb.id : false;
});
},
2023-11-17 17:07:52 +08:00
},
2023-11-17 16:48:00 +08:00
};
</script>
<style scoped lang="scss">
.bom-selector {
min-height: 200px;
}
.select-list {
}
.sl__body {
display: flex;
flex-direction: column;
gap: 6px;
padding: 6px;
2023-11-17 17:07:52 +08:00
2023-11-17 16:48:00 +08:00
> .el-checkbox {
2023-11-17 17:07:52 +08:00
margin: 0;
padding: 3px 6px;
2023-11-17 16:48:00 +08:00
border-radius: 4px;
2023-11-17 17:07:52 +08:00
transition: background 0.3s ease-in-out;
2023-11-17 16:48:00 +08:00
&:hover {
background: #0001;
}
}
}
.sl__header {
2023-11-17 17:07:52 +08:00
border-bottom: 1px solid #ccc;
2023-11-17 16:48:00 +08:00
}
</style>