Files
klp-oa/klp-ui/src/components/KLPService/RawMaterialSelect/index.vue

195 lines
5.7 KiB
Vue
Raw Normal View History

2025-07-18 17:22:56 +08:00
<template>
2025-08-19 15:39:59 +08:00
<span>
<el-select v-model="selected" :placeholder="placeholder" filterable clearable :loading="loading" @change="onChange"
style="width: 100%" :value-key="'rawMaterialId'">
<template #empty>
<el-button v-if="canAdd" @click="add" icon="el-icon-plus">未搜索到原材料点击添加</el-button>
<div v-else style="padding: 10px;">未搜索到原材料</div>
</template>
<el-option v-for="item in options" :key="item.rawMaterialId"
:label="`${item.rawMaterialName}${item.rawMaterialCode}`" :value="item.rawMaterialId">
<div class="option-label">
<span class="material-name">{{ item.rawMaterialName }}</span>
<span class="material-code">{{ item.rawMaterialCode }}</span>
</div>
</el-option>
</el-select>
<el-dialog v-if="canAdd" :visible.sync="addDialogVisible" title="添加原材料" width="700px" append-to-body>
<el-steps align-center :active="activeStep" finish-status="success">
<!-- 新增原材料的步骤 -->
<el-step title="创建原材料"></el-step>
<!-- 创建BOM的步骤 -->
<el-step title="填写BOM信息"></el-step>
</el-steps>
<el-form ref="form" v-if="activeStep === 0" :model="addForm" :rules="rules" label-width="120px">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="原材料编号" prop="rawMaterialCode">
<el-input v-model="addForm.rawMaterialCode" placeholder="请输入原材料编号" />
2025-08-19 15:39:59 +08:00
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="原材料名称" prop="rawMaterialName">
<el-input v-model="addForm.rawMaterialName" placeholder="请输入原材料名称" />
2025-08-19 15:39:59 +08:00
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="负责人" prop="owner">
<el-input v-model="addForm.owner" :multiple="false" placeholder="请填写负责人" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="计量单位" prop="unit">
<el-input v-model="addForm.unit" placeholder="请输入计量单位" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div v-if="activeStep === 0" slot="footer" class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm">创建原材料</el-button>
<el-button @click="cancel"> </el-button>
2025-07-21 10:56:50 +08:00
</div>
2025-08-19 15:39:59 +08:00
<BomPanel v-if="activeStep === 1" :id="bomId" :itemId="itemId" :type="addForm.type" @addBom="handleBom" />
</el-dialog>
</span>
2025-07-18 17:22:56 +08:00
</template>
<script>
2025-07-30 10:53:06 +08:00
import { mapGetters } from "vuex";
2025-08-19 15:39:59 +08:00
import { addRawMaterial } from '@/api/wms/rawMaterial';
import BomPanel from '../BomPanel/index.vue';
2025-07-21 11:55:04 +08:00
2025-07-18 17:22:56 +08:00
export default {
name: "RawMaterialSelect",
props: {
2025-07-21 10:56:50 +08:00
value: [String, null],
2025-07-18 17:22:56 +08:00
placeholder: {
type: String,
default: "请选择原材料"
2025-08-19 15:39:59 +08:00
},
canAdd: {
type: Boolean,
default: false
2025-07-18 17:22:56 +08:00
}
},
components: {
BomPanel
},
2025-07-18 17:22:56 +08:00
data() {
return {
options: [],
2025-07-21 11:55:04 +08:00
selected: this.value,
2025-08-19 15:39:59 +08:00
loading: false,
addForm: {
rawMaterialCode: undefined,
rawMaterialName: undefined,
2025-08-19 15:39:59 +08:00
owner: undefined,
unit: undefined,
type: 'raw_material'
2025-08-19 15:39:59 +08:00
},
addDialogVisible: false,
rules: {
rawMaterialCode: [
2025-08-19 15:39:59 +08:00
{ required: true, message: "原材料编号不能为空", trigger: "blur" }
],
rawMaterialName: [
2025-08-19 15:39:59 +08:00
{ required: true, message: "原材料名称不能为空", trigger: "blur" }
],
owner: [
{ required: true, message: "负责人不能为空", trigger: "blur" }
],
},
buttonLoading: false,
itemId: undefined,
activeStep: 0,
2025-08-19 15:39:59 +08:00
bomId: undefined,
2025-07-18 17:22:56 +08:00
};
},
watch: {
value(val) {
this.selected = val;
2025-07-21 10:56:50 +08:00
},
selected(val) {
this.$emit("input", val);
2025-07-18 17:22:56 +08:00
}
},
mounted() {
2025-07-30 10:53:06 +08:00
this.options = this.rawMaterialList;
},
computed: {
...mapGetters(['rawMaterialList'])
2025-07-18 17:22:56 +08:00
},
methods: {
2025-07-22 11:49:48 +08:00
async onChange(val) {
const rawMaterial = this.options.find(p => p.rawMaterialId === val);
this.$emit('change', rawMaterial);
2025-07-21 11:55:04 +08:00
},
2025-08-19 15:39:59 +08:00
add() {
this.addDialogVisible = true;
this.addForm = {
rawMaterialCode: undefined,
rawMaterialName: undefined,
2025-08-19 15:39:59 +08:00
owner: undefined,
unit: undefined,
type: 'raw_material'
2025-08-19 15:39:59 +08:00
};
this.bomId = undefined;
this.itemId = undefined;
},
handleBom(bom) {
this.bomId = bom.bomId;
},
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
this.buttonLoading = true;
// console.log(this.addForm);
addRawMaterial(this.addForm).then(res => {
this.$modal && this.$modal.msgSuccess("创建原材料成功");
this.$store.dispatch('category/getRawMaterialMap');
console.log(res);
this.itemId = res.rawMaterialId;
this.$emit('input', res.rawMaterialId);
this.activeStep = 1;
}).finally(() => {
this.buttonLoading = false;
});
}
});
},
cancel() {
this.addDialogVisible = false;
this.addForm = {
rawMaterialCode: undefined,
rawMaterialName: undefined,
2025-08-19 15:39:59 +08:00
owner: undefined,
unit: undefined,
type: 'raw_material'
2025-08-19 15:39:59 +08:00
};
}
2025-07-18 17:22:56 +08:00
}
};
</script>
2025-07-21 10:56:50 +08:00
<style scoped>
.option-label {
display: flex;
justify-content: space-between;
align-items: center;
}
2025-08-19 15:39:59 +08:00
2025-07-21 10:56:50 +08:00
.material-name {
font-size: 14px;
color: #333;
}
2025-08-19 15:39:59 +08:00
2025-07-21 10:56:50 +08:00
.material-code {
font-size: 12px;
color: #999;
margin-left: 10px;
}
</style>