materialGroup.vue
7.66 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
<template>
<div class="material-group" :style="{ height: groupHeight + 'px' }">
<el-button class="add_btn" icon="el-icon-plus" :size="size" @click="handleAddGroup(1)">素材组</el-button>
<div class="all-group">
<div @click="getList">
<img src="@/assets/material/groupIcon.png" alt="" />
全部素材组 ({{ groupCounter.length }})
</div>
<div @click="groupVisible = !groupVisible">
<i class="el-icon-arrow-down" v-show="groupVisible"></i>
<i class="el-icon-arrow-up" v-show="!groupVisible"></i>
</div>
</div>
<ul v-show="groupVisible" :style="{ height: groupHeight - 110 + 'px' }">
<li class="group-list" v-for="(item, index) in groupCounter" :class="index === currentIndex ? 'active' : ''" :key="index" @click="handleGroup(item, index)">
<div>
<img src="@/assets/material/file.png" alt="" style="vertical-align: middle;height:24px;width:24px" />
<div class="group-name">{{ item.materialGroupName }}</div>
</div>
<div>
<el-popover placement="right" trigger="click">
<div>
<!-- <GLButton class="group-btn" :size="size" type="text" fn="置顶" @click="handleStick(item)">{{ item.orderTime ? '取消置顶' : '置顶' }}</GLButton>
<GLButton class="group-btn" :size="size" type="text" fn="修改" @click="handleAddGroup(2, item)">修改</GLButton>
<GLButton class="group-btn" :size="size" type="text" fn="删除" v-if="item.isDefault == -1" @click="handleDeleteGroup(item.id)">删除</GLButton> -->
<el-button class="group-btn" :size="size" type="text" fn="置顶" @click="handleStick(item)">{{ item.orderTime ? '取消置顶' : '置顶' }}</el-button>
<el-button class="group-btn" :size="size" type="text" fn="修改" @click="handleAddGroup(2, item)">修改</el-button>
<el-button class="group-btn" :size="size" type="text" fn="删除" v-if="item.isDefault == -1" @click="handleDeleteGroup(item.id)">删除</el-button>
</div>
<div slot="reference">
<img class="more-icon" src="@/assets/material/more.png" alt="" />
</div>
</el-popover>
</div>
</li>
</ul>
</div>
</template>
<script>
import * as dayjs from 'dayjs'
export default {
name: 'materialGroup',
props: { eventBus: Object, groupHeight: Number },
data() {
return {
// 素材组数量
groupCounter: [],
materialGroup: {
id: '',
materialGroupName: '',
orderValue: '',
isDefault: '' // 默认素材组 0 是 -1 否(进入页面如果素材组数量为0,就会创建默认素材组,默认素材组不可删除)
},
currentIndex: null,
groupVisible: true
}
},
mounted() {
// 新建素材组
this.eventBus.$on('addMaterialGroup', data => {
// data.businessType = data.businessType.toString()
this.$apis.material.addMaterialGroup(data).then(res => {
if (res) {
this.getMaterialList()
}
})
})
// 编辑素材组
this.eventBus.$on('editMaterialGroup', data => {
// data.businessType = data.businessType.toString()
this.$apis.material.editMaterialGroup(data).then(res => {
if (res) {
this.getMaterialList()
}
})
})
this.materialInsert()
this.getMaterialList()
},
methods: {
// 创建素材组
materialInsert() {
var params = {}
params.isDefault = 0
this.$apis.material.addMaterialGroup(params).then(res => {
if (res) {
this.getMaterialList()
}
})
},
// 获取全部素材组
getMaterialList() {
this.$apis.material.getMaterialList({}).then(res => {
this.groupCounter = res
})
},
// 点击素材组获取素材
handleGroup(item, index) {
this.currentIndex = index
var params = {}
params.groupId = item.id
params.pageNum = 1
params.pageSize = 1000
this.$emit('getList', params, item)
},
// 打开1-新增, 2-编辑 素材组弹框
handleAddGroup(addOrEdit, value) {
console.log(addOrEdit, value)
this.$emit('openAddDialog', addOrEdit, value, this.groupCounter)
},
// 素材组置顶
handleStick(row) {
var params = {}
params.id = row.id
// 置顶
if (!row.orderTime) {
var date = new Date()
var stickDate = dayjs(date).format('YYYY-MM-DD HH:mm:ss')
params.orderTime = stickDate // orderTime 排序时间
params.orderFlag = true // orderFlag置顶标识 false 取消置顶 true 置顶或修改名称
this.secondConfirm('提示', '确定置顶该素材组吗?', 'material', 'editMaterialGroup', params)
return
}
// 取消置顶
params.orderFlag = false
this.secondConfirm('提示', '确定取消置顶该素材组吗?', 'material', 'editMaterialGroup', params)
},
// 素材组删除
handleDeleteGroup(rowId) {
this.$confirm('删除素材组,该素材组下的所有素材均会被删除,请谨慎操作', '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
type: 'warning'
}).then(() => {
this.$apis.material.deleteMaterialList({ id: rowId }).then(res => {
this.$message({
message: res.code == '0' ? '操作成功' : '操作失败',
type: res.code == '0' ? 'success' : 'error'
})
if (res.code == '0') {
this.getMaterialList()
// 素材组删除后素材列表刷新
this.$emit('getListApi')
}
})
})
},
// 点击全部素材组获取全部素材
getList() {
this.$emit('getListApi')
this.currentIndex = ''
},
// 二次确认
secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
this.$confirm(txt, title, {
confirmButtonText: '是',
cancelButtonText: '否',
type: 'warning',
callback: action => {
if (action == 'confirm') {
this.$apis[apiModule][apiName](apiParams).then(res => {
this.$message({
message: res.code == '0' ? '操作成功' : '操作失败',
type: res.code == '0' ? 'success' : 'error'
})
if (res.code == '0') {
fn && fn()
this.getMaterialList()
}
})
}
}
})
}
}
}
</script>
<style lang="scss" scoped>
.status-words {
margin-left: 5px;
}
.material-group {
/deep/.el-popover {
min-width: 50px;
&:hover {
cursor: pointer;
}
}
.all-group {
font-size: 16px;
height: 44px;
line-height: 44px;
padding: 0 17px 0 16px;
display: flex;
justify-content: space-between;
cursor: pointer;
img {
width: 24px;
height: 24px;
vertical-align: middle;
}
i {
color: #999999;
}
}
ul {
overflow: auto;
.group-list {
cursor: pointer;
text-align: left;
padding: 8px 8px 8px 18px;
margin: 0 10px;
display: flex;
justify-content: space-between;
&.active {
background-color: #ebeaff;
}
.more-icon {
vertical-align: middle;
padding-top: 3px;
}
&:hover {
background-color: #ebeaff;
}
}
}
}
.add_btn {
color: #5850ff;
border-color: #5850ff;
margin: 20px 0 12px 16px;
}
.group-name {
display: inline-flex;
margin-left: 8px;
}
.group-btn {
color: #333333;
display: block;
padding: 8px 0px;
text-align: left;
width: 100%;
&:hover {
background-color: #ebeaff;
}
}
.el-button + .el-button {
margin-left: 0;
}
</style>