WangHan
2024-12-19 ed6c6350015d52ea1cb033c7558f72b721ece84a
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
<template>
  <win-sm :title="setting.title" @close="close" :width="'800px'" :loading="loading">
    <el-form ref="ruleForm" :model="formData" :rules="rules" class="demo-ruleForm" label-width="100px">
      <el-form-item v-if="setting.pid" label="上级分类" prop="fatherCategoryName" :key="key">
        <el-input
            v-model="formData.fatherCategoryName"
            clearable
            maxlength="20"
            show-word-limit
            style="width: 100%"
            disabled
        />
      </el-form-item>
      <el-form-item label="分类名称" prop="categoryName">
        <el-input v-model="formData.categoryName" placeholder="请输入分类名称" clearable maxlength="20" show-word-limit
                  style="width: 100%"/>
      </el-form-item>
      <!-- 只有第三级分类信息维护时需要选类别 -->
      <el-form-item label="价值类别" prop="classification" v-if="plevels==2">
        <el-select v-model="formData.classification" placeholder="请选择价值类别" clearable style="width: 100%">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="顺序" prop="orderNumber">
        <el-input
            type="number"
            v-model="formData.orderNumber"
            placeholder="请填写顺序号"
            clearable
            maxlength="20"
            show-word-limit
            style="width: 100%"
        />
      </el-form-item>
      <el-form-item label="状态" prop="states">
        <el-radio-group v-model="formData.states">
          <el-radio :label="1" border>启用</el-radio>
          <el-radio :label="0" border>禁用</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer" align="center" class="dialog-footer">
      <my-button name="取消" site="form" @click="close"/>
      <my-button name="保存" site="form" @click="save"/>
    </div>
  </win-sm>
</template>
 
<script>
import winSm from '@/components/win/win-sm';
import myButton from '@/components/myButton/myButton';
import * as finsystenant from '@/api/baseSetting/finsystenant';
import {getDicts} from '@/api/system/dict/data';
import {getCategoryDetail} from '@/api/foudation/classification';
 
export default {
  components: {winSm, myButton},
  props: {
    setting: {
      type: Object,
      default: () => {
      },
    },
  },
  data() {
    return {
      loading: false,
      checkAll: false,
      checkedList: [],
      options: [], // 类别列表
      formData: {
        fatherCategoryId: '', // 上级分类
        fatherCategoryName: '',
        categoryName: '', //分类名称
        classification: '', //类别
        orderNumber: '', // 顺序
        states: 1, // 状态
      },
      rules: {
        fatherCategoryName: [{required: true, message: '请输入', trigger: 'blur'}],
        categoryName: [{required: true, message: '请输入', trigger: 'blur'}],
        classification: [{required: true, message: '请选择', trigger: 'change'}],
        orderNumber: [{required: true, message: '请输入', trigger: 'blur'}],
      },
      key: Math.random(),
      plevels: 1
    };
  },
  created() {
    if (this.setting.title == '编辑') {
      this.formData = Object.assign({}, JSON.parse(this.setting.info));
    } else {
      this.formData.fatherCategoryId = this.setting.pid;
    }
    this.getCategoryName();
    getDicts('GOODS_PRICE').then((res) => {
      this.options = res.map((v) => {
        v.label = v.dict_label;
        v.value = v.dict_value;
        return v;
      });
    });
  },
  methods: {
    getEditInfo(id) {
    },
    // 分类名称获取
    getCategoryName() {
      if (!this.formData.fatherCategoryId) return
      getCategoryDetail({id: this.formData.fatherCategoryId}).then((res) => {
        this.formData.fatherCategoryName = res.categoryName;
        this.key = Math.random();
        this.plevels = res.levels
      });
    },
    close() {
      this.$emit('close');
    },
    save() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          const params = Object.assign({}, this.formData);
          if (this.loading) return
          this.loading = true
          if (this.setting.id) {
            // 编辑接口
            finsystenant.edit(params).then((res) => {
              this.loading = false
              this.$message.success('保存成功!');
              this.close();
              this.$emit('search');
            }).catch((err) => {
              this.loading = false
            });
          } else {
            params.orgId = this.setting.orgId;
            finsystenant.add(params).then((res) => {
                  this.loading = false
                  this.$message.success('保存成功!');
                  this.close();
                  this.$emit('search');
                })
          }
        } else {
          this.$message.error('校验未通过,请检查。');
        }
      });
    },
  },
};
</script>