<template>
|
<a-modal
|
:title="title"
|
:width="950"
|
:visible="visible"
|
:maskClosable="false"
|
:confirmLoading="confirmLoading"
|
@ok="handleOk"
|
@cancel="handleCancel"
|
cancelText="关闭"
|
>
|
|
<a-spin :spinning="confirmLoading">
|
<a-form :form="form">
|
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-item
|
label="上级类别:"
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
>
|
<a-tree-select
|
tree-default-expand-all
|
:disabled="true"
|
show-search
|
allow-clear
|
:dropdown-style="{ maxHeight: '500px', overflow: 'auto' }"
|
:tree-data="processParametersCategoryTree"
|
placeholder="请选择上级类别"
|
treeNodeFilterProp="title"
|
v-decorator="[ 'parentId', validatorRules.parentId]"
|
/>
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :lg="12">
|
<a-form-item
|
label="参数分类编号:"
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
>
|
<a-input
|
allow-clear
|
placeholder="请输入参数分类编号"
|
v-decorator="['num', validatorRules.num ]"
|
/>
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-item
|
label="参数分类名称:"
|
:labelCol="labelCol"
|
:wrapperCol="wrapperCol"
|
>
|
<a-input
|
allow-clear
|
placeholder="请输入参数分类名称"
|
v-decorator="['name', validatorRules.name ]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-item
|
:labelCol="{span:3}"
|
:wrapperCol="{span:21}"
|
label="备注:"
|
>
|
<a-textarea
|
placeholder="请输入备注"
|
allow-clear
|
v-decorator="['remark', validatorRules.remark]"
|
/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
</a-form>
|
</a-spin>
|
|
<template slot="footer">
|
<a-button
|
:style="{marginRight: '8px'}"
|
@click="handleCancel"
|
>
|
关闭
|
</a-button>
|
<a-button
|
:disabled="confirmLoading"
|
:loading="confirmLoading"
|
@click="handleOk"
|
type="primary"
|
>确定</a-button>
|
</template>
|
|
</a-modal>
|
</template>
|
|
<script>
|
import pick from 'lodash.pick'
|
import { getAction, postAction, requestPut } from '@/api/manage'
|
import { duplicateCheck } from '@/api/api'
|
|
export default {
|
name: 'ProcessParametersCategoryModel',
|
props: {
|
nodeSelected: {
|
type: Object,
|
default: {}
|
}
|
},
|
data() {
|
return {
|
title: "操作",
|
visible: false,
|
model: {},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 6 },
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 18 },
|
},
|
confirmLoading: false,
|
form: this.$form.createForm(this),
|
validatorRules: {
|
parentId: {
|
rules: [
|
{ required: true, message: '请输入上级类别!' },
|
]
|
},
|
num: {
|
rules: [
|
{ required: true, message: '请输入分类编号!' },
|
{ min: 0, max: 30, message: '长度不超过 30 个字符', trigger: 'blur' },
|
{ validator: this.validateNum },
|
]
|
},
|
name: {
|
rules: [
|
{ required: true, message: '请输入分类名称!' },
|
{ min: 0, max: 30, message: '长度不超过 30 个字符', trigger: 'blur' },
|
{ validator: this.validateName },
|
]
|
},
|
description: {
|
rules: [
|
{ min: 0, max: 100, message: '长度不超过 100 个字符', trigger: 'blur' }
|
]
|
}
|
},
|
url: {
|
add: "/eam/processParametersCategory/add",
|
edit: "/eam/processParametersCategory/edit",
|
loadProcessParametersCategoryTree: '/eam/processParametersCategory/loadTree',
|
},
|
processParametersCategoryTree: [],
|
}
|
},
|
created() {
|
},
|
methods: {
|
|
loadProcessParametersCategoryTree() {
|
this.loading = true;
|
this.cardLoading = true;
|
getAction(this.url.loadProcessParametersCategoryTree, {}).then((res) => {
|
if (res.success) {
|
let array = res.result;
|
this.processParametersCategoryTree = array;
|
} else {
|
this.$message.warn(res.message);
|
}
|
}).finally(() => {
|
this.loading = false;
|
this.cardLoading = false;
|
})
|
},
|
|
add(parentId) {
|
this.edit({ 'parentId': parentId });
|
},
|
|
edit(record) {
|
console.log("record==", record)
|
this.loadProcessParametersCategoryTree();
|
this.form.resetFields();
|
this.model = Object.assign({}, record);
|
this.visible = true;
|
this.$nextTick(() => {
|
this.form.setFieldsValue(pick(this.model, 'parentId', 'num', 'name', 'remark'));
|
});
|
},
|
|
handleOk() {
|
const that = this;
|
// 触发表单验证
|
that.form.validateFields((err, values) => {
|
if (!err) {
|
let formData = Object.assign(this.model, values);
|
if (formData.parentId == formData.id) {
|
that.$message.warning("请不要选择当前操作数据为上级类别!");
|
} else {
|
that.confirmLoading = true;
|
let obj;
|
if (!that.model.id) {
|
obj = postAction(that.url.add, formData);
|
} else {
|
obj = requestPut(that.url.edit, formData, { id: that.model.id });
|
}
|
obj.then((res) => {
|
if (res.success) {
|
that.$message.success(res.message);
|
that.$emit('ok', new Date());
|
} else {
|
that.$message.warning(res.message);
|
}
|
}).finally(() => {
|
that.confirmLoading = false;
|
that.close();
|
})
|
}
|
}
|
})
|
},
|
|
handleCancel() {
|
this.close();
|
},
|
|
close() {
|
this.$emit('close');
|
this.visible = false;
|
},
|
|
//验证 编号
|
validateNum(rule, value, callback) {
|
var params = {
|
tableName: 'mom_eam_process_parameters_category',
|
fieldName: 'num',
|
fieldVal: value,
|
dataId: this.model.id,
|
//数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false 假删除:true
|
delFlag: '0',
|
};
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback();
|
} else {
|
callback("工艺参数分类编号已存在!");
|
}
|
})
|
},
|
|
//验证 名称
|
validateName(rule, value, callback) {
|
var params = {
|
tableName: 'mom_eam_process_parameters_category',
|
fieldName: 'name',
|
fieldVal: value,
|
dataId: this.model.id,
|
//数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false 假删除:true
|
delFlag: '0',
|
};
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback();
|
} else {
|
callback("工艺参数分类名称已存在!");
|
}
|
})
|
},
|
|
}
|
|
}
|
</script>
|
|
<style scoped>
|
.ant-btn {
|
padding: 0 10px;
|
margin-left: 3px;
|
}
|
|
.ant-form-item-control {
|
line-height: 0px;
|
}
|
|
/** 主表单行间距 */
|
.ant-form .ant-form-item {
|
margin-bottom: 10px;
|
}
|
|
/** Tab页面行间距 */
|
.ant-tabs-content .ant-form-item {
|
margin-bottom: 0px;
|
}
|
</style>
|