wangzhibo
2026-10-08 220e4fab27b7f419b3e89e2f2d28ae789aac09d7
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
<template>
  <CustomDialog
    :title="title"
    :visible.sync="dialogVisible"
    width="600px"
    @confirm="submit"
    @close="cancel"
    :confirmLoading="saving"
  >
    <el-form :model="form" :rules="rules" ref="form" label-width="auto" label-position="left">
      <el-form-item :label="$t('dictDataDialog.dictLabel')" prop="dictLabel" class="form-item">
        <el-input v-model="form.dictLabel" :placeholder="$t('dictDataDialog.dictLabelPlaceholder')" />
      </el-form-item>
      <el-form-item :label="$t('dictDataDialog.dictValue')" prop="dictValue" class="form-item">
        <el-input v-model="form.dictValue" :placeholder="$t('dictDataDialog.dictValuePlaceholder')" />
      </el-form-item>
      <el-form-item :label="$t('dictDataDialog.sort')" prop="sort" class="form-item">
        <el-input-number v-model="form.sort" :min="0" :max="999" class="custom-input-number"></el-input-number>
      </el-form-item>
    </el-form>
  </CustomDialog>
</template>
 
<script>
import CustomDialog from './CustomDialog.vue';
export default {
  name: 'DictDataDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: () => this.$t('dictDataDialog.addDictData')
    },
    dictData: {
      type: Object,
      default: () => ({})
    },
    dictTypeId: {
      type: [Number, String],
      default: null
    }
  },
  components: {
    CustomDialog
  },
  data() {
    return {
      dialogVisible: this.visible,
      saving: false,
      form: {
        id: null,
        dictTypeId: null,
        dictLabel: '',
        dictValue: '',
        sort: 0
      },
      rules: {
        dictLabel: [{ required: true, message: this.$t('dictDataDialog.requiredDictLabel'), trigger: 'blur' }],
        dictValue: [{ required: true, message: this.$t('dictDataDialog.requiredDictValue'), trigger: 'blur' }]
      }
    };
  },
  watch: {
    visible(val) {
      this.dialogVisible = val;
    },
    dialogVisible(val) {
      this.$emit('update:visible', val);
      if (!val) {
        this.saving = false;
      }
    },
    dictData: {
      handler(val) {
        if (val) {
          this.form = { ...val };
        }
      },
      immediate: true
    },
    dictTypeId: {
      handler(val) {
        if (val) {
          this.form.dictTypeId = val;
        }
      },
      immediate: true
    }
  },
  methods: {
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.saving = true;
          this.$emit('save', this.form);
        }
      });
    },
    cancel() {
      this.saving = false;
      this.$emit('cancel');
    },
    resetSaving() {
      this.saving = false;
    }
  }
};
</script>
 
<style scoped lang="scss">
.custom-input-number {
  width: 100%;
}
</style>