add.vue
6.14 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
<template>
<div class="case-ctnr">
<div class="main-wrap">
<div class="global-title">{{ formObj.id ? '编辑分类' : '新增分类' }}</div>
<glsx-combi-form :isInline="false" class="glsx-combi-form" ref="baseInfoRef" labelWidth="154px"
defaultWidth="432px" :formObj.sync="formObj" :formData="formData" :formRules="myRule">
<div slot="videoCoverSlot">
<glsx-preview :picOptions="posterOptions" :imageUrlArr="formObj.videoCoverArr"
@change="changeChannelImg"></glsx-preview>
<div class="text-tip" style="margin: 0;">建议尺寸:120*120</div>
</div>
<div slot="selectBrandSlot" class="mode-slot">
<div class="mode-item" v-for="item in modeList" :key="item.id">
<el-radio v-model="formObj.categoryStyle" :label="item.id">{{item.name}}</el-radio>
<div>
<el-popover
popper-class="tool-gltip"
placement="top-start"
width="200"
trigger="hover">
<img :src="require(`@/assets/category/${item.url}.png`)" style="width:300px;height:300px;"/>
<img slot="reference" :src="require(`@/assets/category/${item.url}.png`)">
</el-popover>
</div>
</div>
</div>
</glsx-combi-form>
</div>
<GLFooter>
<el-button @click="handleCancel">取消</el-button>
<el-button type="primary" @click="handleSave">确定</el-button>
</GLFooter>
</div>
</template>
<script>
import glsxCombiForm from '@/components/glsx-combi-form'
const MODE_LIST = [
{
id: 0,
url: 'vertical',
name: '商品-竖向排列'
},
{
id: 1,
url: 'transverse',
name: '商品-横向排列'
},
{
id: 2,
url: 'recommend',
name: '种草样式A'
},
{
id: 3,
url: 'recommend2',
name: '种草样式B'
}
]
export default {
name: 'add',
components: {
glsxCombiForm,
},
data() {
return {
dialogVisible: false,
modeList: MODE_LIST,
formObj: {
id: '',
categoryType: 1,
categoryName: '',
categoryStyle: 0,
videoCoverArr: []
},
brandList: [],
posterOptions: {
width: '120px',
height: '120px',
key: 'posterImg',
isClose: true
},
myRule: {
categoryName: [{required: true, message: '请输入分类名称', trigger: 'change'}],
categoryImage: [{
required: true, validator: (rule, value, callback) => {
if (this.formObj.videoCoverArr?.length != 1) {
callback(new Error(`请上传分类图标`))
} else {
callback()
}
}, trigger: 'change'
}],
categoryStyle: [{
required: true, validator: (rule, value, callback) => {
if (this.formObj.brandType == 'null') {
callback(new Error(`请选择布局样式`))
} else {
callback()
}
}, trigger: 'blur'
}],
},
formData: [
{
label: '分类名称',
name: 'categoryName',
maxlength: 20,
showLimit: true,
type: 'input',
isDisabled: false
},
{
label: '分类归属',
name: 'categoryType',
type: 'radio',
optionList: [
{
label: '配置升级',
id: 1
},
{
label: '车主优选',
id: 2
},
],
optionId: 'id',
optionLabel: 'label'
},
{
label: '分类图标',
name: 'categoryImage',
addHtml: 'videoCoverSlot'
},
{
label: '布局样式',
name: 'categoryStyle',
addHtml: 'selectBrandSlot'
}
],
}
},
created() {
this.formObj.id = this.$route.query.id || ''
if (this.formObj.id) {
this.getCaseDetailApi()
}
},
methods: {
changeChannelImg(val) {
this.$refs.baseInfoRef.$refs.formRef.validateField('coverUrl')
},
handleSave() {
this.$refs.baseInfoRef.$refs.formRef.validate(valid => {
if (valid) {
let params = JSON.parse(JSON.stringify(this.formObj))
params.categoryLevel = 1 //分类等级(1:一级分类,2:二级分类)
params.categoryImage = this.formObj.videoCoverArr[0]
delete params.videoCoverArr
if (!params.id) delete params.id
this.$apis.category.addCategoryApi(params).then(res => {
if (res) {
this.$message.success('操作成功')
this.handleCancel()
}
})
}
})
},
handleCancel() {
this.$route.query.name = '2';
this.$router.back()
},
getCaseDetailApi() {
this.$apis.category.batchDetailApi({id: this.$route.query.id}).then(res => {
if (res) {
const attrList = ['id', 'categoryName', 'categoryStyle', 'categoryType']
attrList.forEach(key => {
this.formObj[key] = res[key]
})
this.formObj.videoCoverArr = [res.categoryImage]
}
})
}
}
}
</script>
<style scoped lang="scss">
.case-ctnr {
.glsx-combi-form {
padding: 20px;
background-color: #fff;
margin-bottom: 16px;
.brand-wrap {
margin-top: 8px;
width: 580px;
height: 80px;
background: #FFFFFF;
border: 1px solid #E8E8EA;
border-radius: 4px;
padding: 6px 8px;
overflow-y: auto;
.brand-item {
display: inline-block;
padding: 0 8px;
height: 24px;
color: #666666;
line-height: 24px;
background: #FAFBFE;
border: 1px solid #E5E5E5;
border-radius: 4px;
margin-right: 4px;
}
}
}
}
.mode-slot{
display: flex;
.mode-item{
width: 145px;
img{
width: 103.97px;
height: 86.5px;
}
}
}
.category-style {
img {
width: 104px;
height: 102.6px;
margin-right: 65px;
}
}
</style>
<style>
.tool-gltip {
max-width: 340px!important;
width: 340px!important;
}
</style>