zxl
2026-03-25 19dd419f262406bc9fa1f09d731a1f44aebd8505
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
<template>
  <a-modal
    :title="title"
    :width="600"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="标签名称"
          hasFeedback
        >
          <a-select
            v-decorator="['labelName', { rules: [{ required: true, message: '请选择标签名称' }] }]"
            placeholder="请选择标签名称"
          >
            <a-select-option v-for="label in labelList" :key="label" :value="label">
              {{ label }}
            </a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>
 
<script>
import { postAction, getAction } from '@tievd/cube-block/lib/api/manage'
 
export default {
  name: 'DepartLabelModal',
  props: {
    parentCode: {
      type: String,
      default: ''
    },
    parentId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      title: '添加标签',
      visible: false,
      confirmLoading: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      form: this.$form.createForm(this),
      url: {
        add: '/jyz/departLabel/add',
        listLabels: '/jyz/departLabel/listLabels'
      },
      labelList: [],
      currentDepartId: null
    }
  },
  created() {
    this.loadLabelList()
  },
  watch: {
    parentCode() {
      this.loadLabelList()
    },
    parentId() {
      this.loadLabelList()
    }
  },
  methods: {
    loadLabelList() {
      const params = {}
      if (this.parentCode) {
        params.parentCode = this.parentCode
      }
      if (this.parentId) {
        params.parentId = this.parentId
      }
      getAction(this.url.listLabels, params).then((res) => {
        if (res.success) {
          this.labelList = res.result
        }
      })
    },
    add(record) {
      this.form.resetFields()
      this.currentDepartId = record.depart_id
      this.visible = true
    },
    handleOk() {
      const that = this
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          const params = {
            departId: that.currentDepartId,
            labelName: values.labelName
          }
          postAction(that.url.add, params).then((res) => {
            if (res.success) {
              that.$message.success('添加成功')
              that.$emit('ok')
              that.visible = false
            } else {
              that.$message.error(res.message || '添加失败')
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
      })
    },
    handleCancel() {
      this.visible = false
    }
  }
}
</script>
 
<style scoped>
</style>