/
index.vue
119 lines (117 loc) · 2.97 KB
/
index.vue
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
<template>
<div class="pg-to-buy-list">
<h2 class="pg-to-buy-list__title">待購清單</h2>
<div class="pg-to-buy-list__new-item-container">
<el-input class="pg-to-buy-list__new-item"
v-model="newItem"
placeholder="輸入待購項目"></el-input>
<el-button class="pg-to-buy-list__add-btn"
type="primary"
icon="el-icon-plus"
size="small"
@click="handleAdd">新增</el-button>
</div>
<div class="pg-to-buy-list__card-container">
<to-buy-list-card :key="item.id"
v-for="item in cardList"
:cardData="item" />
</div>
</div>
</template>
<script>
import ToBuyListCard from '@/components/ToBuyListCard'
export default {
name: 'Buy',
components: { ToBuyListCard },
data() {
return {
cardList: [
{
id: 'want',
title: '想要',
list: ['iPhone 11 Pro Max', 'BOSE Lifestyle 600'],
color: '#ffaa55'
},
{
id: 'need',
title: '需要',
list: ['筆電背包', '眼鏡', '手錶'],
color: '#67a7da'
},
{
id: 'satisfy',
title: '滿足',
list: ['空氣清淨機', '電磁爐', 'Brita 濾水壺'],
color: '#67bb77'
},
{
id: 'sublimate',
title: '昇華',
list: ['任天堂 Switch', 'PS4', 'AirPods'],
color: '#bb6777'
}
],
newItem: ''
}
},
methods: {
handleDrag() {
this.$dragula(
[
document.getElementById('want'),
document.getElementById('need'),
document.getElementById('satisfy'),
document.getElementById('sublimate')
],
{
removeOnSpill: true
}
)
.on('drag', function(el) {
el.className.replace('ex-moved', '')
})
.on('drop', function(el) {
el.className += 'ex-moved'
})
.on('over', function(el, container) {
container.className += 'ex-over'
})
.on('out', function(el, container) {
container.className.replace('ex-over', '')
})
},
handleAdd() {
if (this.newItem === '') return
this.cardList[0].list.push(this.newItem)
this.newItem = ''
}
},
mounted() {
this.handleDrag()
}
}
</script>
<style lang="scss">
.pg-to-buy-list {
&__new-item-container {
display: flex;
justify-content: center;
width: 100%;
}
&__new-item {
width: 15rem;
}
&__add-btn {
margin-left: 0.71rem;
}
&__title {
margin-bottom: 1.5rem;
}
&__card-container {
max-width: 68.57rem;
margin: 2rem auto;
display: flex;
justify-content: space-around;
}
}
</style>