sortTab-editor.vue
1.7 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
<template>
<div>
<draggable v-model="list" @start="drag=true" @end="drag=false">
<div class="item" v-for="(i,index) in list" :key="i.id">
<sort-tab-item :value="i" :id="index" @on-remove="onDeleteBtn"
@on-change="(v) => (onChange(index, v))"></sort-tab-item>
</div>
</draggable>
<Button style="margin-top:20px" type="primary" @click="onAddBtn">添加一组</Button>
</div>
</template>
<script>
import sortTabItem from './sortTab-editor-item';
import util from '@/libs/util';
import draggable from 'vuedraggable';
export default {
props: ['value'],
data() {
return {
list: util.clone(this.value),
drag: false,
};
},
methods: {
onAddBtn() {
this.list.push({
category_name: '',
product_ids: '',
more_url: {
action: 'go.ufo',
params: {
pagename: 'productList',
productListTitle: '',
sort: 0
}
},
id: this.$bus.genId()
});
console.log(this.list);
},
onDeleteBtn(index) {
this.list.splice(index, 1);
},
getValue() {
return this.list;
},
setValue(val) {
this.list = val;
},
onChange(i, v) {
this.$set(this.list, i, v);
}
},
components: {
sortTabItem,
draggable
}
};
</script>
<style>
.item {
border: 1px solid #dddee1;
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
}
.item:hover {
background-color: #ebf7ff;
}
</style>