jiangping
2025-05-27 3d6a8e384d31432a23f5a8c1a3135a58cbe617b5
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
<template>
    <GlobalWindow
        :title="title"
        width="50%"
        :visible.sync="visible"
        :confirm-working="isWorking"
        @confirm="confirm"
    >
        <div class="box">
            <div class="box-info">
                <i class="el-icon-info"></i>
                <span>最多可添加50个标签</span>
            </div>
            <div class="box-serch">
                <el-input v-model="value" placeholder="请输入请输入新标签"></el-input>
                <el-button type="primary" style="margin-left: 15px;" @click="add">添加</el-button>
            </div>
            <div class="box-list">
                <div class="box-list-item" v-for="(item, index) in list" :key="index">
                    <span>{{item.name}}</span>
                    <i class="el-icon-circle-close" @click="dele(item.id)"></i>
                </div>
            </div>
        </div>
      <template v-slot:footer>
        <el-button @click="close">返回</el-button>
      </template>
    </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import { createLabels, list, labelsDeleteById } from '@/api/business/knowledge'
export default {
  name: 'tagLibrary',
  extends: BaseOpera,
  components: { GlobalWindow },
  data () {
    return {
      value: '',
      list: []
    }
  },
  created () {
    this.config({
      api: '/business/knowledge',
      'field.id': 'id'
    })
  },
  methods: {
    async open (title, target) {
      this.title = title
      await this.getData()
      this.visible = true
    },
    async getData () {
      this.list = await list()
    },
    // 添加标签
    async add () {
      if (!this.value) return this.$message.warning('请先输入内容')
       createLabels({ name: this.value })
        .then(() => {
          this.$message.success('添加成功')
          this.$emit('success')
          this.getData()
          this.$emit('refresh')
          this.value = ''
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
    },
    // 删除
    async dele (id) {
     labelsDeleteById(id)
        .then(() => {
          this.$message.success('删除成功')
          this.$emit('success')
          this.getData()
          this.$emit('refresh')
          this.value = ''
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
    }
  }
}
</script>
 
<style lang="scss" scoped>
    .box {
        width: 100%;
        .box-info {
            width: 100%;
            display: flex;
            align-items: center;
            margin-bottom: 15px;
            span {
                color: rgba(154,154,154,1);
                font-size: 14px;
                margin-left: 6px;
            }
        }
        .box-serch {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 20px;
        }
        .box-list {
            width: 100%;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            .box-list-item {
                padding: 5px 10px;
                box-sizing: border-box;
                border-radius: 20px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                background-color: rgba(239,239,239,1);
                cursor: pointer;
                margin-right: 15px;
                margin-bottom: 15px;
                span {
                    color: rgba(16,16,16,1);
                    font-size: 16px;
                    margin-right: 10px;
                }
                i {
                    font-size: 20px;
                    color: red;
                }
            }
        }
    }
</style>