tool-select-link.vue
10.1 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<template>
<div class="module-box link-select" :class="styleType && 'style'+styleType">
<div class="link-select__warp">
<div class="module-box__title">
<label class="module-box__label">{{title}}</label>
</div>
<el-select class="link-select__select" :popper-append-to-body="false" v-model="selsectValue" placeholder="请选择跳转到的页面" @change="selectChanged">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</div>
<div class="link-select__confirm" v-show="confirmBtnVisible">
<div class="btn" v-if="!selectName" @click="openDialog">
<span class="iconfont"></span> 添加{{typeText}}
</div>
<div class="info" v-else>
<span class="text">{{typeText}}</span>
<span class="name">{{selectName}}</span>
<span class="iconfont" @click="openDialog"></span>
<span class="iconfont" @click="delSelect"></span>
</div>
</div>
<el-dialog width="600px" title="选择类别" :visible.sync="categoryVisible">
<category-select ref="categorySelect"></category-select>
<span slot="footer" class="dialog-footer">
<el-button @click="categoryVisible = false">取 消</el-button>
<el-button type="primary" @click="categoryChanged">确 定</el-button>
</span>
</el-dialog>
<el-dialog title="选择商品" :visible.sync="productVisible">
<product-select ref="productSelect"></product-select>
<span slot="footer" class="dialog-footer">
<el-button @click="productVisible = false">取 消</el-button>
<el-button type="primary" @click="productChanged">确 定</el-button>
</span>
</el-dialog>
<el-dialog title="选择店辅" :visible.sync="shopVisible">
<shop-select ref="shopSelect"></shop-select>
<span slot="footer" class="dialog-footer">
<el-button @click="shopVisible = false">取 消</el-button>
<el-button type="primary" @click="shopChanged">确 定</el-button>
</span>
</el-dialog>
<el-dialog title="选择自定义页面" :visible.sync="customVisible">
<custom-page-select ref="customPageSelect"></custom-page-select>
<span slot="footer" class="dialog-footer">
<el-button @click="customVisible = false">取 消</el-button>
<el-button type="primary" @click="customChanged">确 定</el-button>
</span>
</el-dialog>
<el-dialog title="选择公告" :visible.sync="noticeVisible">
<notice-select ref="noticeSelect"></notice-select>
<span slot="footer" class="dialog-footer">
<el-button @click="noticeVisible = false">取 消</el-button>
<el-button type="primary" @click="noticeChanged">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import ProductSelect from './product-select'
import ShopSelect from './shop-select'
import CategorySelect from './category-select'
import CustomPageSelect from './custom-page-select'
import NoticeSelect from "./notice-select";
export default {
name: 'tool-select-link',
components: {NoticeSelect, CustomPageSelect, CategorySelect, ShopSelect, ProductSelect },
data () {
return {
selsectValue: '',
confirmBtnVisible: false,
selectName: '',
typeText: '',
productVisible: false,
shopVisible: false,
categoryVisible: false,
customVisible: false,
noticeVisible: false
}
},
props: {
title: {
type: String,
default: '链接'
},
styleType: {
type: String,
default: ''
},
linkObj: {
type: Object,
default: () => ({
selsectValue: '',
selectName: '',
typeText: '',
url: ''
})
},
options: {
type: Array,
default: () => [
// {
// value: '/index',
// label: '首页'
// },
{
value: '/category',
label: '分类页面'
},
{
value: '/shop',
label: '店辅主页'
},
{
value: '/detail',
label: '商品详情'
},
{
value: '/notice',
label: '公告'
},
// {
// value: '/custom',
// label: '自定义页面'
// }
]
}
},
mounted () {
this.selsectValue = this.linkObj.selsectValue
this.selectName = this.linkObj.selectName
this.typeText = this.linkObj.typeText
this.confirmBtnVisible = this.selsectValue !== '/index' && this.selsectValue
},
methods: {
// 链接选择
selectChanged (value) {
this.categoryVisible = false
this.shopVisible = false
this.productVisible = false
this.confirmBtnVisible = true
this.selectName = ''
this.typeText = ''
switch (value) {
case '/category':
this.typeText = '类别'
break
case '/shop':
this.typeText = '店辅'
break
case '/detail':
this.typeText = '商品'
break
case '/custom':
this.typeText = '自定义'
case '/notice':
this.typeText = '公告'
break
default:
this.confirmBtnVisible = false
let linkObj = {
selsectValue: this.selsectValue,
selectName: '',
typeText: '',
url: '/'
}
this.$emit('update:linkObj', linkObj)
}
},
// 打开添加弹窗
openDialog () {
switch (this.typeText) {
case '类别':
this.categoryVisible = true
break
case '店辅':
this.shopVisible = true
break
case '商品':
this.productVisible = true
break
case '自定义':
this.customVisible = true
case '公告':
this.noticeVisible = true
break
}
},
// 类别选择
categoryChanged () {
let nodesObj = this.$refs.categorySelect.$refs['cascader'].getCheckedNodes()
if (nodesObj) {
var data = nodesObj[0].data
this.selectName = nodesObj[0].label
this.categoryVisible = false
let linkObj = {
selsectValue: this.selsectValue,
selectName: this.selectName,
typeText: this.typeText,
data: data
}
this.$emit('update:linkObj', linkObj)
}
},
// 商品选择
productChanged () {
console.log(this.$refs.productSelect)
var data = this.$refs.productSelect.tableRadio
this.productVisible = false
this.selectName = this.$refs.productSelect.tableRadio.productName
let linkObj = {
selsectValue: this.selsectValue,
selectName: this.selectName,
typeText: this.typeText,
data: data
}
this.$emit('update:linkObj', linkObj)
},
// 店辅选择
shopChanged () {
var data = this.$refs.shopSelect.tableRadio
this.shopVisible = false
this.selectName = this.$refs.shopSelect.tableRadio.shopName
let linkObj = {
selsectValue: this.selsectValue,
selectName: this.selectName,
typeText: this.typeText,
data: data
}
this.$emit('update:linkObj', linkObj)
},
// 自定义页面选择
customChanged () {
var data = this.$refs.customPageSelect.tableRadio
this.customVisible = false
this.selectName = this.$refs.customPageSelect.tableRadio.name
let linkObj = {
selsectValue: this.selsectValue,
selectName: this.selectName,
typeText: this.typeText,
data: data
}
this.$emit('update:linkObj', linkObj)
},
// 公告选择
noticeChanged () {
var data = this.$refs.noticeSelect.tableRadio
this.noticeVisible = false
this.selectName = this.$refs.noticeSelect.tableRadio.noticeTitle
let linkObj = {
selsectValue: this.selsectValue,
selectName: this.selectName,
typeText: this.typeText,
data: data
}
this.$emit('update:linkObj', linkObj)
},
// 删除选择
delSelect () {
let linkObj = {
selsectValue: '',
selectName: '',
typeText: '',
data: {}
}
this.$emit('update:linkObj', linkObj)
}
},
watch: {
linkObj: {
handler (newVal, oldVal) {
this.selsectValue = newVal.selsectValue
this.selectName = newVal.selectName
this.typeText = newVal.typeText
this.confirmBtnVisible = this.selsectValue !== '/index' && this.selsectValue
},
deep: true
}
}
}
</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;
.text{
color: $mainColor;
}
.name{
flex: 1;
margin-left: 10px;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
}
.iconfont{
margin-left: 10px;
cursor: pointer;
color: #666;
}
}
}
&.style1{
.link-select__warp{
display: flex;
justify-content: space-between;
width: 100%;
align-items: center;
}
width: 100%;
margin-bottom: 0;
.module-box__title{
margin-bottom: 0;
}
.link-select__select{
width: auto;
}
}
}
</style>