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
<template>
  <div class="add_wordshop">
    <el-dialog :title="editConfig.dialogTitle + editConfig.dialogTitleType" :visible.sync="editConfig.visible" width="30%"
      :before-close="handleClose">
      <el-form :inline="true" label-width="20%" style="width: 100%;" :model="editConfig.infomitton" :rules="rules"
        ref="ruleForm">
        <template v-if="editConfig.infomitton.TabsIndex === 0 || editConfig.infomitton.TabsIndex === 1">
          <el-form-item prop="number" label="编码" style="width: 100%;">
            <el-input :disabled="editConfig.dialogTitle != '新增'" v-model="editConfig.infomitton.number"
              placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item prop="name" label="名称" style="width: 100%;">
            <el-input :disabled="editConfig.dialogTitle === '查看'" v-model="editConfig.infomitton.name"
              placeholder="请输入字母或数字,不允许有空格、中文"></el-input>
          </el-form-item>
        </template>
 
        <template v-if="editConfig.infomitton.TabsIndex === 2">
          <el-form-item prop="name" label="带号颜色" style="width: 100%;">
            <el-input :disabled="editConfig.dialogTitle === '查看'" v-model="editConfig.infomitton.name"
              placeholder="请输入字母或数字,不允许有空格、中文"></el-input>
          </el-form-item>
        </template>
 
        <template v-if="editConfig.infomitton.TabsIndex === 3">
          <el-form-item prop="name" label="规格" style="width: 100%;">
            <el-input :disabled="editConfig.dialogTitle === '查看'" v-model="editConfig.infomitton.name"
              placeholder="请输入字母或数字,不允许有空格、中文"></el-input>
          </el-form-item>
        </template>
 
        <el-form-item label="描述" style="width: 100%;">
          <el-input :disabled="editConfig.dialogTitle === '查看'" v-model="editConfig.infomitton.remark" type="textarea"
            :rows="4" style="resize: none !important;" placeholder="请输入">
          </el-input>
        </el-form-item>
 
      </el-form>
      <span slot="footer" class="dialog-footer" v-if="editConfig.dialogTitle != '查看'">
        <el-button @click="editConfig.visible = false">取 消</el-button>
        <el-button type="primary" @click="commitForm('ruleForm')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import { addDict, editDict } from "@/api/systemSetting/dataDictionary"
export default {
  props: {
    editDiaConfig: {
      type: Object,
      default: () => {
        return {
          visible: false,
          dialogTitle: "添加",
          infomitton: {
          }
        }
      }
    }
  },
  data() {
    const checkSpace = (rule, value, callback) => {  
      if (value.includes(' ')) {  
        callback(new Error('名称不能包含空格'));  
      } else {  
        callback();  
      }  
    };  
    return {
      editConfig: this.editDiaConfig,
      rules: {
        number: [
          { required: true, message: '请填写编码', trigger: 'change' }
        ],
        name: [
          {validator: checkSpace, required: true, message: '请填写名称并且不能有空格', trigger: 'change' }
        ]
      }
    };
  },
  computed: {
 
  },
  created() {
 
  },
  mounted() {
  },
  watch: {
 
  },
  methods: {
    handleClose(done) {
      done();
    },
    saveParams(type) {
      let params = {}
      if (type === 0 || type === 1) {
        params = {
          dictType: this.editConfig.infomitton.TabsIndex,
          name: this.editConfig.infomitton.name,
          number: this.editConfig.infomitton.number,
          remark: this.editConfig.infomitton.remark,
        }
      } else if (type === 2) {
        params = {
          dictType: this.editConfig.infomitton.TabsIndex,
          name: this.editConfig.infomitton.name,
          remark: this.editConfig.infomitton.remark,
        }
      } else if (type === 3) {
        params = {
          dictType: this.editConfig.infomitton.TabsIndex,
          name: this.editConfig.infomitton.name,
          remark: this.editConfig.infomitton.remark,
        }
      }
      return params
    },
    commitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let params = this.saveParams(this.editConfig.infomitton.TabsIndex)
          if (this.editConfig.dialogTitle === "新增") {
            addDict(params).then((res) => {
              if (res && res.code === 200) {
                this.editConfig.visible = false
                this.$parent.getData()
                this.$message({
                  message: `新增${this.editConfig.dialogTitleType}成功!`,
                  type: 'success'
                });
              }
            })
          } else if (this.editConfig.dialogTitle === "修改") {
            editDict({ ...params, id: this.editConfig.infomitton.ID }).then((res) => {
              if (res && res.code === 200) {
                this.editConfig.visible = false
                this.$parent.getData()
                this.$message({
                  message: `修改${this.editConfig.dialogTitleType}成功!`,
                  type: 'success'
                });
              }
            })
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
 
    }
  },
  components: {
 
  },
};
</script>
 
<style scoped lang="scss">
::v-deep .el-form-item__content {
  width: 70% !important;
}
</style>