duhuizhe
2023-10-16 3aa55dd3f62cee2c1c4c0aa74e1570acf83f8927
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
<template>
  <win-sm :title="setting.title" @close="close">
    <el-form ref="ruleForm" :model="formData" :rules="rules" class="demo-ruleForm" label-width="120px" v-loading="loading">
<!--      <el-form-item label="父级分类名称" >-->
<!--        <el-input v-model="parentName"  disabled clearable maxlength="20" show-word-limit />-->
<!--      </el-form-item>-->
      <el-form-item label="分类名称" prop="title">
        <el-input v-model="formData.title" clearable maxlength="20" show-word-limit />
      </el-form-item>
      <el-form-item label="顺序号" prop="orderNum">
        <el-input v-model="formData.orderNum" clearable maxlength="20" type="Number" show-word-limit />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-radio-group v-model="formData.status">
          <el-radio :label="0" border>启用</el-radio>
          <el-radio :label="1" border>禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注"  prop="note">
        <el-input
          v-model="formData.note"
          type="textarea"
          :rows="3"
          maxlength="500"
          show-word-limit
        />
      </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 classify from '@/api/projectManage/classify'
export default {
  components: { winSm, myButton},
  props: {
    setting: {
      type: Object,
      default: () => {
      }
    }
  },
  data() {
    return {
      loading:false,
      formData: {
        projectId: this.setting.projectId,
        title: '',
        orderNum: null,
        note: '',
        status: 0,
        parentId:this.setting.parentId,
      },
      parentName:this.setting.parentName,
      rules: {
        title: [
          { required: true, message: '请输入分类名称', trigger: 'blur' }
        ],
        orderNum: [
          { required: true, message: '请输入分类顺序号', trigger: 'blur' }
        ],
      }
    }
  },
  created() {
    if(this.setting){
      this.getInfo();
    }
  },
  methods: {
    getInfo() {
      this.title = this.setting.title
      if (this.setting.id != null) {
        this.loading = true
        let params = {
          id: this.setting.id
        }
        // 查询数据
        classify.getdetail(params).then(res => {
          const data = res
          this.formData = Object.assign(this.formData, data)
          this.loading = false
        })
      }
    },
    close() {
      this.formData = {
        name: '',
        code: '',
        description: '',
        status: 0
      }, this.$emit('close')
    },
    save() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          const params = Object.assign({}, this.formData)
          if (params.id) {
            classify.edit(params).then(res => {
              if (res) {
                this.$message.success('保存成功!')
                this.close()
                this.$emit('search')
                this.$emit('initTreeData')
              } else {
                this.$message.error('保存失败')
              }
            })
          } else {
            classify.add(params).then(res => {
              if (res) {
                this.$message.success('保存成功!')
                this.close()
                this.$emit('search')
                this.$emit('initTreeData')
              } else {
                this.$message.error('保存失败')
              }
            })
          }
        } else {
          this.$message.error('校验未通过,请检查。')
        }
      })
    }
  }
}
</script>
 
<style scoped>
 
</style>