This commit is contained in:
2025-11-20 14:44:10 +08:00
parent b2984ed4cf
commit b926559a7d
27 changed files with 2790 additions and 756 deletions

View File

@@ -1,114 +1,395 @@
<!--
* @Author: zwq
* @Date: 2021-11-18 14:16:25
* @LastEditors: zwq
* @LastEditTime: 2025-11-12 15:35:21
* @Description:
-->
<template>
<el-form
:model="dataForm"
:rules="dataRule"
ref="dataForm"
@keyup.enter.native="dataFormSubmit()"
label-width="80px">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="产品编码" prop="code">
<el-input
v-model="dataForm.code"
clearable
placeholder="请输入产品编码" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品名称" prop="name">
<el-input
v-model="dataForm.name"
clearable
placeholder="请输入产品名称" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="产品规格" prop="address">
<el-input
v-model="dataForm.address"
clearable
placeholder="请输入产品规格" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品类型" prop="name">
<el-select
v-model="dataForm.name"
disabled
:style="{ width: '100%' }"
placeholder="请选择产品类型">
<el-option
v-for="item in typeArr"
:key="item.name"
:label="item.label"
:value="item.name"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="启用状态" prop="enabled">
<el-select
:style="{ width: '100%' }" v-model="dataForm.enabled" placeholder="请选择启用状态">
<el-option
v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)"
:key="dict.value"
:label="dict.label"
:value="dict.value" />
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<el-drawer
:visible.sync="visible"
:show-close="false"
:wrapper-closable="false"
class="drawer"
size="60%">
<small-title slot="title" :no-padding="true">
{{ isdetail ? '详情' : !dataForm.id ? '新增' : '编辑' }}
</small-title>
<div class="content">
<div class="visual-part">
<el-form
ref="dataForm"
:model="dataForm"
:rules="dataRule"
label-width="100px"
label-position="top"
@keyup.enter.native="dataFormSubmit">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="配方编码" prop="processCode">
<el-input
v-model="dataForm.processCode"
clearable
:disabled="isdetail"
placeholder="请输入配方编码" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="配方名称" prop="processName">
<el-input
v-model="dataForm.processName"
clearable
:disabled="isdetail"
placeholder="请输入配方名称" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品" prop="materialId">
<el-select
style="width: 100%"
v-model="dataForm.materialId"
:disabled="isdetail"
@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-col>
<el-col :span="12">
<el-form-item label="配方描述" prop="processDesc">
<el-input
v-model="dataForm.processDesc"
clearable
:disabled="isdetail"
placeholder="请输入配方描述" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<small-title
style="margin: 16px 0; padding-left: 8px"
:no-padding="true"
v-if="dataForm.id">
产品属性列表
</small-title>
<div class="attr-list" v-if="dataForm.id">
<base-table
:table-props="tableProps"
:page="listQuery.pageNo"
:limit="listQuery.pageSize"
:add-button-show="isdetail ? null : '添加属性'"
@emitButtonClick="addNew()"
:table-data="productAttributeList">
<method-btn
v-if="!isdetail"
slot="handleBtn"
:width="120"
label="操作"
:method-list="tableBtn"
@clickBtn="handleClick" />
</base-table>
<pagination
v-show="listQuery.total > 0"
:total="listQuery.total"
:page.sync="listQuery.pageNo"
:limit.sync="listQuery.pageSize"
:page-sizes="[5, 10, 15]"
@pagination="getList" />
</div>
</div>
</div>
<div class="drawer-body__footer">
<el-button style="" @click="goback()">取消</el-button>
<el-button v-if="isdetail" type="primary" @click="goEdit()">
编辑
</el-button>
<el-button v-else type="primary" @click="dataFormSubmit()">
确定
</el-button>
</div>
<product-attr-add
v-if="addOrUpdateVisible"
ref="addOrUpdate"
:process-id="dataForm.id"
@refreshDataList="getList" />
</el-drawer>
</template>
<script>
import basicAdd from '@/mixins/basic-add';
import {
createFactory,
updateFactory,
getFactory,
getCode,
} from '@/api/core/base/factory';
updateProcess,
createProcess,
getProcess,
getProcessMaterialPage,
deleteProcessMaterial,
getProductPage,
} from '@/api/ssdl/product&recipe';
import productAttrAdd from './attr-add';
import { parseTime } from '@/filter/code-filter';
import SmallTitle from './SmallTitle';
const tableBtn = [
{
type: 'edit',
btnName: '编辑',
},
{
type: 'delete',
btnName: '删除',
},
];
const tableProps = [
{
prop: 'createTime',
label: '添加时间',
filter: parseTime,
},
{
prop: 'equipmentName',
label: '设备名称',
},
{
prop: 'materialName',
label: '原料名称',
},
{
prop: 'quantity',
label: '数量',
},
];
export default {
mixins: [basicAdd],
components: { productAttrAdd, SmallTitle },
data() {
return {
urlOptions: {
isGetCode: true,
codeURL: getCode,
createURL: createFactory,
updateURL: updateFactory,
infoURL: getFactory,
},
visible: false,
addOrUpdateVisible: false,
tableBtn,
tableProps,
productAttributeList: [],
dataForm: {
id: undefined,
code: undefined,
name: undefined,
address: undefined,
enabled:'1',
remark: undefined,
id: null,
processName: '', // 配方名称
processCode: '', // 配方编码
processDesc: '', // 配方描述
materialId: '', // 物料id
materialName: '', // 物料名称
materialCode: '', // 物料编码
},
productArr: [],
listQuery: {
pageSize: 10,
pageNo: 1,
total: 0,
},
typeArr: [],
dataRule: {
code: [
{ required: true, message: '产品编码不能为空', trigger: 'blur' },
processCode: [
{
required: true,
message: '配方编码不能为空',
trigger: 'blur',
},
],
name: [
{ required: true, message: '产品名称不能为空', trigger: 'blur' },
processName: [
{
required: true,
message: '配方名称不能为空',
trigger: 'blur',
},
],
materialId: [
{
required: true,
message: '物料不能为空',
trigger: 'change',
},
],
},
isdetail: false,
};
},
methods: {},
methods: {
initData() {
this.productAttributeList.splice(0);
this.listQuery.total = 0;
},
init(id, isdetail) {
this.initData();
getProductPage({ pageNo: 1, pageSize: 100 }).then((res) => {
this.productArr = res.data.list;
});
this.isdetail = isdetail || false;
this.dataForm.id = id || null;
this.visible = true;
this.$nextTick(() => {
this.$refs['dataForm'].resetFields();
if (this.dataForm.id) {
// 获取产品详情
getProcess(id).then((response) => {
this.dataForm = response.data;
});
// 获取产品的属性列表
this.getList();
}
});
},
setMaterial() {
const data = this.productArr.find(
(i) => i.id === this.dataForm.materialId
);
this.dataForm.materialName = data.materialName;
this.dataForm.materialCode = data.materialCode;
},
getList() {
// 获取产品的属性列表
getProcessMaterialPage({
...this.listQuery,
productId: this.dataForm.id,
}).then((response) => {
this.productAttributeList = response.data.list;
this.listQuery.total = response.data.total;
});
},
handleClick(raw) {
if (raw.type === 'delete') {
this.$confirm(
`确定对${
raw.data.name
? '[名称=' + raw.data.name + ']'
: '[序号=' + raw.data._pageIndex + ']'
}进行删除操作?`,
'提示',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
deleteProcessMaterial(raw.data.id).then(({ data }) => {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.getList();
},
});
});
})
.catch(() => {});
} else {
this.addNew(raw.data.id);
}
},
// 表单提交
dataFormSubmit() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
// 修改的提交
if (this.dataForm.id) {
updateProcess(this.dataForm).then((response) => {
this.$modal.msgSuccess('修改成功');
this.visible = false;
this.$emit('refreshDataList');
});
return;
}
// 添加的提交
createProcess(this.dataForm).then((response) => {
this.$modal.msgSuccess('新增成功');
this.$confirm(`是否新增产品属性?`, '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
this.dataForm.id = response.data;
this.addNew();
})
.catch(() => {
this.visible = false;
this.$emit('refreshDataList');
});
});
}
});
},
goEdit() {
this.isdetail = false;
},
// 新增 / 修改
addNew(id) {
if (this.dataForm.id) {
this.addOrUpdateVisible = true;
this.$nextTick(() => {
this.$refs.addOrUpdate.init(id);
});
} else {
this.$message('请先创建配方!');
}
},
goback() {
this.$emit('refreshDataList');
this.visible = false;
this.initData();
},
},
};
</script>
<style scoped>
.drawer >>> .el-drawer {
border-radius: 8px 0 0 8px;
display: flex;
flex-direction: column;
}
.drawer >>> .el-form-item__label {
padding: 0;
}
.drawer >>> .el-drawer__header {
margin: 0;
padding: 32px 32px 24px;
border-bottom: 1px solid #dcdfe6;
}
.drawer >>> .el-drawer__body {
flex: 1;
height: 1px;
display: flex;
flex-direction: column;
}
.drawer >>> .content {
padding: 30px 24px;
flex: 1;
display: flex;
flex-direction: column;
/* height: 100%; */
}
.drawer >>> .visual-part {
flex: 1 auto;
max-height: 76vh;
overflow: hidden;
overflow-y: scroll;
padding-right: 10px; /* 调整滚动条样式 */
}
.drawer >>> .el-form,
.drawer >>> .attr-list {
padding: 0 16px;
}
.drawer-body__footer {
display: flex;
justify-content: flex-end;
padding: 18px;
}
</style>