tool-select-category.vue
4.95 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
<template>
<div class="module-box link-select">
<div class="module-box__title">
<label class="module-box__label">{{title}}</label>
</div>
<div class="link-select__confirm">
<div class="btn" v-if="selectedCategoryList && selectedCategoryList.length === 0" @click="openDialog">
<span class="iconfont"></span> 添加类别
</div>
<div class="info" v-else>
<div><span>{{selectedCategoryList[0].categoryName}}</span><span v-if="selectedCategoryList.length > 1">+{{selectedCategoryList.length-1}}</span></div>
<div class="operation">
<i class="iconfont" @click="openDialog"></i>
<i class="iconfont" @click="deleteCategory"></i>
</div>
</div>
</div>
<el-dialog width="500" title="选择类别" :visible.sync="categoryVisible">
<el-select v-if="terminal === 4"
v-model="categoryValue"
multiple
collapse-tags
placeholder="请选择">
<el-option
v-for="item in categoryList"
:key="item.id"
:label="item.categoryName"
:value="item.id">
</el-option>
</el-select>
<el-cascader v-else
ref="cascader"
:options="categoryList" :props="{ multiple: true,label: 'categoryName',value: 'id',children: 'childs' }"
clearable></el-cascader>
<span slot="footer" class="dialog-footer">
<el-button @click="categoryVisible = false">取 消</el-button>
<el-button type="primary" @click="categoryChanged">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import api from '@@/components/canvasShow/config/api'
import {sendReqMixin} from '@@/components/canvasShow/config/mixin'
import {checkEmptyChild} from '@@/config/common'
import { mapGetters } from 'vuex'
export default {
name: 'tool-select-category',
mixins: [sendReqMixin],
data () {
return {
props: { multiple: true },
selectName: '',
categoryValue: [],
selectedCategoryList: [],
categoryList: [],
categoryVisible: false
}
},
props: {
title: {
type: String,
default: '链接'
},
category: {
type: Array,
default: () => []
}
},
mounted () {
this.getCategory()
this.selectedCategoryList = this.category
},
computed: {
...mapGetters([
'terminal'
])
},
methods: {
// 获取类别
getCategory () {
var _this = this
let params = {
url: api.getClassify,
method: 'GET'
}
this.sendReq(params, (res) => {
_this.categoryList = res.data
checkEmptyChild(_this.categoryList)
})
},
// 打开添加弹窗
openDialog () {
this.categoryVisible = true
},
// 类别选择
categoryChanged () {
this.categoryVisible = false
if (this.terminal === 4) {
this.selectedCategoryList = this.categoryList.filter((item) => {
for (let i = 0; i < this.categoryValue.length; i++) {
if (this.categoryValue[i] === item.id) {
return true
}
}
})
} else {
let nodesArr = this.$refs['cascader'].getCheckedNodes()
if (nodesArr) {
nodesArr = nodesArr.filter((item) => {
return item.children.length === 0
})
this.selectedCategoryList = []
for (let i = 0; i < nodesArr.length; i++) {
this.selectedCategoryList.push(nodesArr[i].data)
}
}
}
this.$emit('update:category', this.selectedCategoryList)
},
// 删除选择
deleteCategory () {
this.categoryValue = []
this.$emit('update:category', [])
}
}
}
</script>
<style lang="scss" scoped>
.link-select{
&__select{
width: 100%;
}
&__confirm{
margin-top: 10px;
.btn{
text-align: center;
background-color: $mainColor;
color: #fff;
height: 36px;
line-height: 36px;
border-radius: 4px;
cursor: pointer;
}
.info{
height: 36px;
line-height: 36px;
border-radius: 4px;
padding: 0 10px;
border:1px solid $mainColor;
display: flex;
justify-content: space-between;
span{
background-color: #f4f4f5;
border:1px solid #e9e9eb;
color: #909399;
height: 26px;
padding: 0 8px;
line-height: 24px;
border-radius: 4px;
margin: 5px 6px 5px 0px;
display: inline-block;
}
.operation{
float: right;
i{
width: 35px;
display: inline-block;
height: 35px;
line-height: 35px;
text-align: center;
cursor: pointer;
}
}
}
}
}
</style>