materialGroup.vue
5.2 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
<template>
<div class="material-group">
<div class="all-group">
<div>全部素材组 ({{ groupCounter.length ? groupCounter.length : 1}})</div>
<div>
<el-button class="add_btn" icon="el-icon-plus" :size="size" @click="handleAddGroup(1)">新建</el-button>
</div>
</div>
<ul>
<li v-if="groupCounter.length == 0">
<img src="@/assets/material/file.png" alt="">
<div class="group-name">新车素材组</div>
<el-popover placement="right" width="20" trigger="click">
<div>
<ul>
<!-- <li @click="handleStick()">置顶</li> -->
<li @click="handleAddGroup(2)">修改</li>
</ul>
</div>
<i slot="reference" class="el-icon-more"></i>
</el-popover>
</li>
<li v-for="(item, index) in groupCounter" :key="index" @click="handleGroup(item)">
<img src="@/assets/material/file.png" alt="">
<div class="group-name">{{ item.materialGroupName }}</div>
<el-popover placement="right" trigger="hover">
<div>
<ul>
<li @click="handleStick(item)">{{ item.orderTime ? '取消置顶' : '置顶' }}</li>
<li @click="handleAddGroup(2,item)">修改</li>
<li @click="handleDeleteGroup(item.id)">删除</li>
</ul>
</div>
<i slot="reference" class="el-icon-more"></i>
</el-popover>
</li>
</ul>
</div>
</template>
<script>
import * as dayjs from 'dayjs'
export default {
name: 'materialGroup',
props: { eventBus: Object },
data() {
return {
// 素材组数量
groupCounter: [],
materialGroup: {
id: "",
materialGroupName: "",
orderValue: "",
isDefault: ""
}
}
},
mounted() {
this.eventBus.$on('addMaterialGroup', data => {
this.$apis.material.addMaterialGroup(data).then(res => {
if (res) {
this.getMaterialList()
}
})
})
this.eventBus.$on('editMaterialGroup', data => {
this.$apis.material.addMaterialGroup(data).then(res => {
if (res) {
this.getMaterialList()
}
})
})
this.getMaterialList()
},
methods: {
// 获取全部素材组
getMaterialList() {
this.$apis.material.getMaterialList({}).then(res => {
console.log(res);
this.groupCounter = res
})
},
// 点击素材组获取素材
handleGroup(item) {
var params = {}
params.groupId = item.id
params.pageNum = 1
params.pageSize = 10
this.$emit('getList', params, item)
},
// 打开1-新增, 2-编辑 素材组弹框
handleAddGroup(addOrEdit, value) {
console.log(addOrEdit, value)
this.$emit('openAddDialog', addOrEdit, value, this.groupCounter)
},
// 素材组置顶
handleStick(row) {
console.log(row, 'orderFlagorderFlag');
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
params.orderFlag = true
console.log(params);
this.secondConfirm('提示', '确定置顶该素材组吗?', 'material', 'editMaterialGroup', params)
return
}
// 取消置顶
params.orderFlag = false
this.secondConfirm('提示', '确定取消置顶该素材组吗?', 'material', 'editMaterialGroup', params)
},
// 素材组删除
handleDeleteGroup(rowId) {
this.secondConfirm('提示', '删除素材组,该素材组下的所有素材均会被删除,请谨慎操作', 'material', 'deleteMaterialList', { id: rowId })
},
// 二次确认
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">
.el-popover {
min-width: 80px;
&:hover {
cursor: pointer
}
}
.material-group {
.all-group {
font-size: 16px;
font-weight: 600;
padding: 24px 16px 0 16px;
display: flex;
justify-content: space-between;
.el-button {
margin-top: -13px;
}
}
ul {
li {
text-align: left;
padding: 18px 16px 16px 18px;
i {
font-size: 16px;
padding-top: 6px;
position: absolute;
right: 16px;
transform:rotate(90deg);
}
}
}
}
ul {
padding: 0;
text-align: center;
margin-block-start: 0;
margin-block-end: 0;
li {
list-style: none;
padding: 5px;
position: relative;
&:hover {
color: #5850FF;
}
}
}
.add_btn {
color: #5850FF;
}
.group-name {
display: inline-flex;
}
</style>