index.vue
11.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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!-- 首页设置 -->
<template>
<div class="home-set marketing">
<div class="container edit-container flex">
<div class="wechat-container">
<div class="wechat-box">
<img class="w-100-per" src="./images/home-set-head.png"/>
<img class="w-100-per" src="./images/home-set-footer.png"/>
</div>
</div>
<div class="home-set-form flex-grow">
<div v-for="(item, index) in externalFormList" :key="index">
<p class="edit-sub-title">{{ item.title }}</p>
<glsx-combi-form class="edit-form-container" ref="editFormRef" :labelWidth="labelWidth" :isBlock="true" :formRef="item.editChildRef" :formObj="editForm" :formData="item.editFormData" :formRules="item.editRule">
<template slot="merchantQrcode" slot-scope="scope">
<img class="img-100" :src="editForm[scope.scope.name]" />
<el-button type="text" @click="handleImgDown(editForm[scope.scope.name])">下载</el-button>
</template>
<template slot="bannerBtn">
<el-button type="primary" @click="handleBannerAdd">新增banner</el-button>
</template>
<div :style="{ 'margin-left': labelWidth }" slot="bannerList" slot-scope="scope">
<div v-for="(subItem, subIndex) in editForm[scope.scope.name]" :key="subIndex" class="flex">
<!-- 上传图片 -->
<div class="banner-upload-box">
<div class="p-t-12">
<div class="flex">
<div v-show="!subItem.bannerImg" class="activity-img img-w-h" style="margin-bottom: 11px;">
<div class="add">+</div>
<span class="number">上传</span>
<input type="file" style="opacity: 0;" ref="file" class="activity-img img-w-h" accept="image/png, image/jpeg, image/gif, image/jpg" @change="e => handleImgChange(e, subIndex)" />
</div>
<div v-show="!subItem.bannerImg">
<el-button type="text" class="el-icon-delete" @click="handleBannerDelete(subIndex)"></el-button>
</div>
</div>
<span v-show="subItem.bannerImg" class="muti-imgs">
<img class="img-w-h" :src="subItem.bannerImg" />
<span class="img-btns">
<span class="btn-item">
<i class="el-icon-delete" @click="handleImgDelete(scope.scope.name, subIndex)"></i>
<i class="el-icon-zoom-in" @click="handleImgLook(subItem.bannerImg)"></i>
</span>
</span>
</span>
</div>
<p class="edit-tips">支持上传10MB以内的jpg,png,jpeg图片</p>
</div>
<!-- 选择商品 -->
<div v-show="subItem.bannerImg" class="flex-grow">
<div>
<span>商品链接:</span>
<el-button v-show="!subItem.goodsId" type="text" class="btn-link" @click="handleSinglePro(scope.scope, subIndex)">选择</el-button>
<el-button v-show="subItem.goodsId" type="text" class="btn-link" @click="handleSinglePro(scope.scope, subIndex)">更换</el-button>
<el-button v-show="subItem.goodsId" type="text" class="btn-link" @click="handleProDelete(subIndex)">删除</el-button>
</div>
<div class="show-pro-box flex" v-if="subItem.goodsId">
<img class="img-60" :src="subItem.goods.goodsImage">
<p class="pro-txt flex-grow one-line-ellipsis">{{ subItem.goods.goodsName }}</p>
</div>
</div>
</div>
</div>
<template slot="onlineService">
<el-button type="primary">请选择</el-button>
</template>
</glsx-combi-form>
</div>
</div>
</div>
<div class="footer" :style="{ left: footerLeft + 'px', width: footerWidth + 'px' }">
<el-button type="primary" @click="handleConfirm">确定</el-button>
</div>
<select-single-pro-dialog v-if="isSingleSelectVisible" :isSingleSelectVisible="isSingleSelectVisible" :selectedProInfo="selectedProInfo" @handleSingleSelectConfirm="handleSingleSelectConfirm" @handleSingleSelectClose="handleSingleSelectClose"></select-single-pro-dialog>
<el-dialog :visible.sync="isImgVisible">
<img class="dialog-img" width="100%" :src="dialogImageUrl" alt="" />
</el-dialog>
</div>
</template>
<script>
export default {
name: 'homeSet',
data() {
return {
footerLeft: '0',
footerWidth: '0',
// 查看大图
isImgVisible: false,
dialogImageUrl: '',
// 商品选择
isSingleSelectVisible: false,
curBanner: {
idx: '',
targetItem: {}
},
selectedProInfo: {},
// 表单
editForm: {
merchantQrcode: '',
noticeContent: '',
bannerList: []
},
bannerItem: {
bannerImg: '',
goodsId: '',
goods: {
id: '',
goodsName: '',
goodsImage: ''
}
},
labelWidth: '110px',
externalFormList: [
{
title: '门店小程序码',
// editChildRef: '',
// rules: [{}],
editFormData: [
{
// label: '',
name: 'merchantQrcode',
addHtml: 'merchantQrcode'
}
]
},
{
title: 'Banner管理',
editFormData: [
{
label: 'banner图片',
addHtml: 'bannerBtn'
},
{
label: '',
name: 'bannerList',
addHtml: 'bannerList'
}
]
},
{
title: '公告管理',
editFormData: [
{
label: '门店公告',
name: 'noticeContent',
type: 'input',
inputType: 'textarea',
width: '320px',
maxlength: '50'
}
]
},
{
title: '新车优惠政策',
editFormData: [
{
label: '优惠政策',
name: 'police',
type: 'input',
inputType: 'textarea',
width: '320px',
maxlength: '300'
}
]
},
{
title: '在线客服',
editFormData: [
{
label: '',
addHtml: 'onlineService'
}
]
}
]
}
},
mounted() {
this.footerLeft = document.querySelector('.base-container-right').offsetLeft
this.footerWidth = document.documentElement.clientWidth - this.footerLeft
this.getInfo()
},
methods: {
getInfo() {
this.$apis.homeSet.getHomeInfoListApi({}).then(res => {
this.editForm.bannerList = []
this.editForm.noticeContent = res.noticeContent
this.editForm.merchantQrcode = res.merchantQrcode
if (res.bannerList.length) {
res.bannerList.forEach(item => {
var params = {
bannerImg: item.bannerImg,
goodsId: item.goods ? item.goods.id : ''
}
if (item.goods) {
params.goods = {
id: item.goods.id,
goodsName: item.goods.goodsName,
goodsImage: item.goods.goodsImage
}
}
this.editForm.bannerList.push(params)
})
}
})
},
handleImgDown(src) {
window.open(src)
},
// 图片删除
handleImgDelete(attrName, subIndex) {
this.$messageBox.confirm('是否删除该banner?', '删除', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'error',
callback: action => {
if (action == 'confirm') {
this.editForm[attrName].splice(subIndex, 1)
}
}
})
},
// 图片查看
handleImgLook(src) {
this.isImgVisible = true
this.dialogImageUrl = src
},
handleBannerAdd() {
if (this.editForm.bannerList.length >= 4) {
this.$message({
message: '最多只能新增4个banner',
type: 'error'
})
return true
}
this.editForm.bannerList.push(this.$common.utils.deepClone(this.bannerItem))
},
handleBannerDelete(idx) {
this.editForm.bannerList.splice(idx, 1)
},
handleProDelete(idx) {
this.editForm.bannerList[idx].goodsId = ''
this.editForm.bannerList[idx].goods = {}
},
handleImgChange(e, idx) {
var reader = new FileReader()
var file = e.srcElement.files[0]
const isLt = file.size / 1024 / 1024 < 10
const isType = ['image/jpeg', 'image/png', 'image/jpg'].includes(file.type)
if (!isType) {
this.$message.error('上传图片不是jpg、jpeg或png的格式!')
return true
}
if (!isLt) {
this.$message.error('上传图片大小不能超过10MB!')
return true
}
reader.readAsDataURL(file)
reader.onload = e => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
this.editForm.bannerList[idx].bannerImg = res
})
}
},
// 商品选择
handleSinglePro(targetItem, idx) {
this.curBanner.idx = idx
this.curBanner.targetItem = targetItem
this.selectedProInfo = this.editForm.bannerList[idx].goods ? this.$common.utils.deepClone(this.editForm.bannerList[idx].goods) : {}
// this.editForm[targetItem.name][idx].goods ? (this.selectedProInfo = this.$common.utils.deepClone(this.editForm[targetItem.name][idx].goods)) : ''
this.handleSingleSelectClose()
},
handleSingleSelectConfirm(selectedProInfo) {
this.selectedProInfo = selectedProInfo
this.editForm.bannerList[this.curBanner.idx].goodsId = selectedProInfo.id
this.editForm.bannerList[this.curBanner.idx].goods = selectedProInfo
this.handleSingleSelectClose()
},
handleSingleSelectClose() {
this.isSingleSelectVisible = !this.isSingleSelectVisible
},
handleConfirm() {
this.$apis.homeSet.updateHomeApi(this.editForm).then(res => {
this.$message({
message: res.code == '0' ? '操作成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
})
}
}
}
</script>
<style scoped>
.home-set .container {
padding: 30px;
}
/* .wechat-container {
width: 375px;
margin-right: 45px;
background: #ffffff;
position: relative;
}
.wechat-container .w-100-per {
width: 100%;
}
.wechat-container .wechat-box {
border: 1px solid #cecece;
width: 100%;
border-radius: 2px;
} */
.home-set .banner-upload-box {
width: 140px;
margin-bottom: 10px;
}
.home-set .edit-tips {
line-height: 18px;
font-size: 13px;
color: #666666;
width: 240px;
}
.home-set .show-pro-box .pro-txt {
margin-left: 20px;
width: 200px;
}
.home-set .p-t-12 {
padding-top: 12px;
}
</style>