zhaowei
2025-06-25 872362acd0e306bb2150d72cce1b556d272e6ba5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<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: false, 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;
        console.log("111",this.model.id)
        // 触发表单验证
        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>