<template>
|
<a-spin :spinning="confirmLoading">
|
<j-form-container :disabled="formDisabled">
|
<a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
|
<a-row>
|
<a-col :span="12">
|
<a-form-model-item label="上级分类编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-input :disabled="true" v-model="model.parentNum" placeholder="请输入上级分类编号" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-model-item label="上级分类名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-input :disabled="true" v-model="model.parentName" placeholder="请输入上级分类名称" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-model-item label="分类编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classifyId">
|
<a-input v-model="model.classifyId" placeholder="请输入分类编码" :disabled="classifyIdShow"></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-model-item label="分类名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="typeName">
|
<a-input v-model="model.typeName" placeholder="请输入分类名称" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12" v-show="leafFlagShow">
|
<a-form-model-item label="是否为叶子节点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leafFlag">
|
<a-radio-group v-model="model.leafFlag" placeholder="请选择是否叶子节点" @change="leafFlagChange">
|
<a-radio :value="'1'">是</a-radio>
|
<a-radio :value="'2'">否</a-radio>
|
</a-radio-group>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12" v-show="encodingTypeShow">
|
<a-form-model-item label="编码方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="encodingType">
|
<a-radio-group v-model="model.encodingType" placeholder="请选择编码方式" @change="encodingTypeChange">
|
<a-radio :value="'1'">系统生成</a-radio>
|
<a-radio :value="'2'">按编码生成</a-radio>
|
<a-radio :value="'3'">手动编码</a-radio>
|
</a-radio-group>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-model-item label="显示序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="seq">
|
<a-input-number v-model="model.seq" placeholder="请输入显示序号" style="width:100%" :min=0 ></a-input-number>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12" v-show="paraTypeFlagShow">
|
<a-form-model-item label="参数模板" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paraTypeFlag">
|
<j-dict-select-tag
|
type="list"
|
v-model="model.paraTypeFlag"
|
:triggerChange="true"
|
dictCode="tool_para_type"
|
placeholder="请选择参数模板"
|
@change="handleTypeChange"
|
/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="24">
|
<a-form-model-item label="备注" :labelCol="{span:3}" :wrapperCol="{span:20}" prop="remark">
|
<a-textarea v-model="model.remark" placeholder="请输入备注" ></a-textarea>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
</a-form-model>
|
</j-form-container>
|
</a-spin>
|
</template>
|
|
<script>
|
|
import { httpAction, getAction } from '@/api/manage'
|
import { validateDuplicateValue } from '@/utils/util'
|
import JDictSelectTag from '@/components/dict/JDictSelectTag'
|
import { duplicateCheck } from '@/api/api'//重复校验
|
|
export default {
|
name: 'ToolsClassifyForm',
|
components: {
|
JDictSelectTag,
|
},
|
props: {
|
//表单禁用
|
disabled: {
|
type: Boolean,
|
default: false,
|
required: false
|
}
|
},
|
data () {
|
return {
|
paraTypeFlagShow:false,
|
model:{
|
},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 6 },
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 },
|
},
|
confirmLoading: false,
|
toolsId:'',
|
classifyIdShow:true,
|
encodingTypeShow:true,
|
leafFlagShow:true,
|
validatorRules: {
|
classifyId: [
|
{ required: true, message: '请输入工具分类编号!'},
|
{ validator: this.validateNum },
|
],
|
typeName: [
|
{ required: true, message: '请输入工具分类名称!'},
|
],
|
leafFlag: [
|
{ required: true, message: '请选择是否为叶子节点!'},
|
],
|
paraTypeFlag: [
|
{ required: true, message: '请选择参数模板!' },
|
],
|
encodingType: [
|
{ required: true, message: '请选择编码方式!' },
|
],
|
},
|
url: {
|
add: "/tms/toolsClassify/add",
|
edit: "/tms/toolsClassify/edit",
|
queryById: "/tms/toolsClassify/queryById"
|
},
|
}
|
},
|
computed: {
|
formDisabled(){
|
return this.disabled
|
},
|
},
|
created () {
|
//备份model原始值
|
this.modelDefault = JSON.parse(JSON.stringify(this.model));
|
},
|
methods: {
|
add (nodeSelected) {
|
this.modelDefault.parentId = nodeSelected.key
|
this.modelDefault.parentNum = nodeSelected.entity.classifyId
|
this.modelDefault.parentName = nodeSelected.entity.typeName
|
this.modelDefault.leafFlag = "2"
|
this.modelDefault.encodingType = "1"
|
this.edit(this.modelDefault);
|
this.encodingTypeShow = true
|
this.leafFlagShow = true
|
},
|
edit (record) {
|
this.toolsId = record.id
|
this.model = Object.assign({}, record);
|
this.visible = true;
|
this.encodingTypeShow = false
|
this.classifyIdShow = true
|
this.leafFlagShow = false
|
if(record.leafFlag == "1"){
|
this.paraTypeFlagShow = true
|
}
|
},
|
submitForm () {
|
const that = this;
|
// 触发表单验证
|
this.$refs.form.validate(valid => {
|
if (valid) {
|
that.confirmLoading = true;
|
let httpurl = '';
|
let method = '';
|
if(!this.model.id){
|
httpurl+=this.url.add;
|
method = 'post';
|
}else{
|
httpurl+=this.url.edit;
|
method = 'put';
|
}
|
httpAction(httpurl,this.model,method).then((res)=>{
|
if(res.success){
|
that.$message.success(res.message);
|
that.$emit('ok');
|
}else{
|
that.$message.warning(res.message);
|
}
|
}).finally(() => {
|
that.confirmLoading = false;
|
})
|
}
|
|
})
|
},
|
//是否叶子节点变化时,控制参数模板显示隐藏
|
leafFlagChange(e){
|
this.modelDefault.paraTypeFlag = ""
|
if(e.target.value == 1){
|
this.paraTypeFlagShow = true
|
this.validatorRules.paraTypeFlag[0].required = true
|
}else{
|
this.paraTypeFlagShow = false
|
this.validatorRules.paraTypeFlag[0].required = false
|
}
|
},
|
//编码方式变化时,控制分类编码生成方式
|
encodingTypeChange(e){
|
this.classifyId = ""
|
if(e.target.value == 1){
|
this.classifyIdShow = true
|
this.validatorRules.classifyId[0].required = false
|
}else if(e.target.value == 2){
|
this.classifyIdShow = false
|
this.validatorRules.classifyId[0].required = true
|
}else if(e.target.value == 3){
|
this.classifyIdShow = false
|
this.validatorRules.classifyId[0].required = true
|
}
|
},
|
handleTypeChange(value) {
|
|
},
|
//验证分类编码是否重复
|
validateNum(rule, value, callback) {
|
var params = {
|
tableName: 'tms_tools_classify',
|
fieldName: 'classify_id',
|
fieldVal: value,
|
dataId: this.toolsId
|
};
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback()
|
} else {
|
callback("分类编码已存在!")
|
}
|
})
|
},
|
}
|
}
|
</script>
|