更新
This commit is contained in:
195
src/views/product&recipe/recipe/attr-add.vue
Normal file
195
src/views/product&recipe/recipe/attr-add.vue
Normal file
@@ -0,0 +1,195 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:visible.sync="visible"
|
||||
:width="'35%'"
|
||||
:append-to-body="true"
|
||||
:close-on-click-modal="false"
|
||||
class="dialog">
|
||||
<template #title>
|
||||
<slot name="title">
|
||||
<div class="titleStyle">
|
||||
{{ !dataForm.id ? '新增' : '编辑' }}
|
||||
</div>
|
||||
</slot>
|
||||
</template>
|
||||
|
||||
<el-form
|
||||
ref="dataForm"
|
||||
:model="dataForm"
|
||||
:rules="dataRule"
|
||||
label-width="100px"
|
||||
@keyup.enter.native="dataFormSubmit()">
|
||||
<el-form-item label="设备" prop="equipmentId">
|
||||
<el-select
|
||||
style="width: 100%"
|
||||
v-model="dataForm.equipmentId"
|
||||
@change="setEquipment"
|
||||
placeholder="请选择设备">
|
||||
<el-option
|
||||
v-for="item in equipmentArr"
|
||||
:key="item.id"
|
||||
:label="item.equipmentName"
|
||||
:value="item.id"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="原料" prop="materialId">
|
||||
<el-select
|
||||
style="width: 100%"
|
||||
v-model="dataForm.materialId"
|
||||
@change="setMaterial"
|
||||
placeholder="请选择原料">
|
||||
<el-option
|
||||
v-for="item in productArr"
|
||||
:key="item.id"
|
||||
:label="item.materialName"
|
||||
:value="item.id"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="数量" prop="quantity">
|
||||
<el-input-number
|
||||
v-model="dataForm.quantity"
|
||||
:step="1"
|
||||
step-strictly
|
||||
:min="0"></el-input-number>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row style="text-align: right">
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
getProductPage,
|
||||
createProcessMaterial,
|
||||
getProcessMaterial,
|
||||
updateProcessMaterial,
|
||||
getEquipmentPage
|
||||
} from '@/api/ssdl/product&recipe';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
processId: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
dataForm: {
|
||||
id: 0,
|
||||
equipmentId: '',
|
||||
equipmentCode: '',
|
||||
equipmentName: '',
|
||||
materialId: '',
|
||||
materialCode: '',
|
||||
materialName: '',
|
||||
quantity: '',
|
||||
},
|
||||
productArr: [],
|
||||
equipmentArr: [],
|
||||
dataRule: {
|
||||
equipmentId: [
|
||||
{ required: true, message: '设备不能为空', trigger: 'change' },
|
||||
],
|
||||
materialId: [
|
||||
{ required: true, message: '原料不能为空', trigger: 'change' },
|
||||
],
|
||||
quantity: [
|
||||
{ required: true, message: '数量不能为空', trigger: 'blur' },
|
||||
],
|
||||
},
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
init(id) {
|
||||
this.dataForm.id = id || '';
|
||||
this.visible = true;
|
||||
getProductPage({ pageNo: 1, pageSize: 100 }).then((res) => {
|
||||
this.productArr = res.data.list;
|
||||
});
|
||||
getEquipmentPage({ pageNo: 1, pageSize: 100 }).then((res) => {
|
||||
this.equipmentArr = res.data.list;
|
||||
});
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].resetFields();
|
||||
if (this.dataForm.id) {
|
||||
getProcessMaterial(this.dataForm.id).then((res) => {
|
||||
this.dataForm = res.data;
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
setMaterial() {
|
||||
const data = this.productArr.find(
|
||||
(i) => i.id === this.dataForm.materialId
|
||||
);
|
||||
this.dataForm.materialName = data.materialName;
|
||||
this.dataForm.materialCode = data.materialCode;
|
||||
},
|
||||
setEquipment() {
|
||||
const data = this.equipmentArr.find(
|
||||
(i) => i.id === this.dataForm.equipmentId
|
||||
);
|
||||
this.dataForm.equipmentName = data.equipmentName;
|
||||
this.dataForm.equipmentCode = data.equipmentCode;
|
||||
},
|
||||
// 表单提交
|
||||
dataFormSubmit() {
|
||||
this.$refs['dataForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
// 修改的提交
|
||||
if (this.dataForm.id) {
|
||||
updateProcessMaterial({
|
||||
...this.dataForm,
|
||||
processId: this.processId,
|
||||
}).then((response) => {
|
||||
this.$modal.msgSuccess('修改成功');
|
||||
this.visible = false;
|
||||
this.$emit('refreshDataList');
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 添加的提交
|
||||
createProcessMaterial({
|
||||
...this.dataForm,
|
||||
processId: this.processId,
|
||||
}).then((response) => {
|
||||
this.$modal.msgSuccess('新增成功');
|
||||
this.visible = false;
|
||||
this.$emit('refreshDataList');
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dialog >>> .el-dialog__body {
|
||||
padding: 30px 24px;
|
||||
}
|
||||
.dialog >>> .el-dialog__header {
|
||||
font-size: 16px;
|
||||
color: rgba(0, 0, 0, 0.85);
|
||||
font-weight: 500;
|
||||
padding: 13px 24px;
|
||||
border-bottom: 1px solid #e9e9e9;
|
||||
}
|
||||
.dialog >>> .el-dialog__header .titleStyle::before {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
width: 4px;
|
||||
height: 16px;
|
||||
background-color: #0b58ff;
|
||||
border-radius: 1px;
|
||||
margin-right: 8px;
|
||||
position: relative;
|
||||
top: 2px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user