add.vue
13.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<!--
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2023-05-10 17:17:31
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-07-19 15:47:50
* @FilePath: \outbound\src\views\calendar\add.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<div>
<div class="main-box">
<glsx-combi-form class="edit-form-container" :isBlock="true" ref="editFormRef" formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule">
<template slot="activityTimeHtml">
<div class="activity-time-container" :style="{ 'margin-left': defaultLabelWidth }">
<el-date-picker v-model="editForm.activityTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy/MM/dd"></el-date-picker>
</div>
</template>
<div slot="selectGoodsBtn">
<div class="play-panel">
<div class="card-panel">
<el-tabs type="card" v-model="editForm.couponTemplateId" @tab-click="changeCouponTemplate">
<el-tab-pane :label="item.name" :name="item.id" v-for="item in couponTemplateList" :key="item.id"></el-tab-pane>
</el-tabs>
<div class="chose-panel" v-loading="goodsLoading">
<el-button type="default" size="small" class="el-icon-plus select-btn" @click="handleGoodsAdd">选择福利券</el-button>
<div style="width: 772px" v-if="selectedGoodsList && selectedGoodsList.length">
<div class="goods-panel">
<el-table :data="selectedGoodsList" border style="width: 100%">
<el-table-column type="index" label="序号" width="70"></el-table-column>
<el-table-column prop="brandName" label="品牌" width="130"></el-table-column>
<el-table-column prop="goodsName" label="商户名称" width="150"></el-table-column>
<el-table-column prop="couponAmount" label="数量" width="70"></el-table-column>
<el-table-column prop="denomination" label="劵面额" width="90">
<template slot-scope="scope">{{ (scope.row.denomination / 100).toFixed(2) }}元</template>
</el-table-column>
<el-table-column prop="effectiveDays" label="有效期" width="80">
<template slot-scope="scope">{{ scope.row.effectiveDays }}天</template>
</el-table-column>
<el-table-column prop="status" label="状态" width="80">
<template slot-scope="scope">{{ scope.row.status == 1 ? '未生效' : scope.row.status == 2 ? '生效中' : scope.row.status == 3 ? '已失效' : '' }}</template>
</el-table-column>
<el-table-column label="操作" width="100">
<template slot-scope="scope">
<el-button @click="handleDeleteGoods(scope.row)" type="text" size="small">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</div>
</div>
</div>
</div>
</glsx-combi-form>
<div class="preview-panel">
<PhoneView :editForm="editForm" ref="preview" :selectedGoodsList="selectedGoodsList"></PhoneView>
</div>
</div>
<GLFooter>
<el-button @click="handleCancel">取消</el-button>
<el-button type="primary" @click="handleSave">提交</el-button>
</GLFooter>
<select-goods-dialog v-if="isSelectGoodsVisible" :isSelectGoodsVisible="isSelectGoodsVisible" :selectedGoodsLists="selectedGoodsList" @handleGoodsConfirm="handleGoodsConfirm" @handleGoodsClose="handleGoodsClose"></select-goods-dialog>
</div>
</template>
<script>
import selectGoodsDialog from './components/SelectGoodsDialog'
import PhoneView from './components/PhoneView'
import getUploadImgColor from '@/utils/color'
const RENEWAL = [1, 2, 3, 4, 5, 6, 7, 8]
const WIDTH = 280
const RATIO = 375 / WIDTH
export default {
name: 'addCalendar',
data() {
return {
isSelectGoodsVisible: false,
goodsLoading: false,
editForm: {},
couponTemplateList: [],
selectedGoodsList: [],
editFormData: [
{
label: '营销标题',
name: 'title',
type: 'input',
maxlength: 10
},
{
label: '营销副标题',
name: 'subTitle',
type: 'input',
maxlength: 20
},
{
label: '活动时间',
name: 'activityTime',
addHtml: 'activityTimeHtml',
isHide: false
},
{
label: '关键字',
name: 'keywords',
type: 'input',
maxlength: 20
},
{
label: '场景选择',
name: 'marketingType',
type: 'radio',
optionList: [
{
optionId: 1,
optionLabel: '道路救援'
},
{
optionId: 2,
optionLabel: '定保招揽'
},
{
optionId: 5,
optionLabel: '续保招揽'
},
{
optionId: 6,
optionLabel: '节假日关怀'
}
],
optionId: 'optionId',
optionLabel: 'optionLabel'
},
{
label: '平台福利',
name: 'goodsList',
addHtml: 'selectGoodsBtn',
tips: '平台提供了种类丰富的权益商品,可进一步提升产品套餐的受众,强烈推荐!'
},
{
label: '销售价格/元',
name: 'platformBenefits',
type: 'input',
maxlength: 20,
isDisabled: true
}
],
editRule: {
title: [{ required: true, message: '请输入营销主题', trigger: 'input' }],
subTitle: [{ required: true, message: '请输入营销副标题', trigger: 'input' }],
activityTime: [{ required: true, message: '请选择活动时间', trigger: 'change' }],
keywords: [{ required: true, message: '请输入关键词', trigger: 'input' }],
marketingType: [{ required: true, message: '请选择场景', trigger: 'change' }]
}
}
},
components: {
selectGoodsDialog,
PhoneView
},
mounted() {
this.couponTemplate()
const { id } = this.$route.query
this.calendarDetail(id)
},
watch: {
//金额根据已选择状态为“生效中”福利券:sum(券面额*数量计算)
selectedGoodsList(val) {
this.editForm.goodsList = val.length ? 1 : null
const platformBenefits = val.reduce((prev, cur) => {
console.log(prev, cur.denomination * cur.couponAmount)
if (cur.status == 2) prev = prev + cur.denomination * cur.couponAmount
return prev
}, 0)
this.editForm.platformBenefits = (platformBenefits / 100).toFixed(2)
}
},
methods: {
calendarDetail(id) {
this.$apis.calendar.calendarDetail({ id }).then(res => {
this.editForm = this.$common.utils.deepClone(res) || {}
if (res.startTime) {
this.$set(this.editForm, 'activityTime', [res.startTime, res.endTime])
}
getUploadImgColor(res.backgroundImg, color => {
this.editForm.mainColor = color
})
this.selectedGoodsList = this.editForm.couponItemList || []
this.selectedGoodsList.forEach(item => {
item.id = item.couponId
})
})
},
handleCancel() {
this.$router.push('/calendar/index')
},
handleSave() {
this.$refs.editFormRef.$refs.editChildRef.validate(valid => {
if (valid) {
this.addOrUpdate()
}
})
},
getCouponInfoParams() {
var param = this.$common.utils.deepClone(this.editForm)
const d = param.activityTime
if (d && d.length > 0) {
param.startTime = d[0]
param.endTime = d[1]
}
param.platformBenefits = (param.platformBenefits * 100).toFixed(0) //存的分,需乘100
param.couponItemList = this.selectedGoodsList.map(item => {
return {
couponId: item.id || item.couponId,
couponAmount: item.couponAmount
}
})
if (param.titleStyle && RENEWAL.includes(param.codeId)) {
const style1 = this.$refs.preview.draggableList[0]
const style2 = this.$refs.preview.draggableList[1]
const titleStyle = JSON.parse(param.titleStyle)
const subTitleStyle = JSON.parse(param.subTitleStyle)
const styles = [style1, style2]
for (const style of styles) {
style.x = parseInt(style.x * RATIO)
style.y = parseInt(style.y * RATIO)
style.size = parseInt(style.size * RATIO)
style.width = parseInt(style.width * RATIO)
}
param.titleStyle = JSON.stringify(Object.assign(titleStyle, { x: style1.x, y: style1.y, size: style1.size, width: style1.width }))
param.subTitleStyle = JSON.stringify(Object.assign(subTitleStyle, { x: style2.x, y: style2.y, size: style2.size, width: style2.width }))
}
console.log(param.titleStyle)
delete param.goodsList
delete param.couponTemplateName
delete param.couponTemplateId
delete param.activityTime
delete param.status
delete param.platformBenefits
return param
},
addOrUpdate() {
this.loading = true
var params = this.getCouponInfoParams()
this.$apis.calendar
.calendarUpdate(params)
.then(res => {
if (res) {
this.$message.success('操作成功')
this.handleCancel()
}
})
.finally(() => {
this.loading = false
})
},
//选择商品优惠券
handleGoodsAdd() {
this.handleGoodsClose()
},
handleGoodsClose() {
this.isSelectGoodsVisible = !this.isSelectGoodsVisible
},
handleGoodsConfirm(selectedData) {
this.$refs.editFormRef.$refs.editChildRef.clearValidate('goodsList')
this.selectedGoodsList = selectedData || []
// this.setNameHide('goodsListBlock')
this.handleGoodsClose()
},
handleDeleteGoods(row) {
const index = this.selectedGoodsList.findIndex(k => k.id == row.id)
this.selectedGoodsList.splice(index, 1)
// this.setNameHide('goodsListBlock')
},
//获取优惠券模板
couponTemplate() {
this.$apis.calendar.couponTemplate({ pageSize: 10000, pageNum: 1 }).then(res => {
this.couponTemplateList = res.list || []
})
},
changeCouponTemplate(tab, event) {
// this.$refs.editFormRef.$refs[this.editChildRef].clearValidate('goodsList')
const templateId = tab.name
this.editForm.couponTemplateId = templateId
this.editForm.couponTemplateName = tab.label
this.couponTemplateDetails(templateId)
},
//获取优惠券模板详情
couponTemplateDetails(templateId) {
this.goodsLoading = true
this.$apis.calendar.couponTemplateDetails({ templateId, pageSize: 10000, pageNum: 1 }).then(res => {
this.selectedGoodsList = res.list || []
this.selectedGoodsList.forEach(item => (item.id = item.couponId))
this.goodsLoading = false
})
}
}
}
</script>
<style lang="scss">
.main-box {
background: #fff;
padding: 20px;
min-height: calc(100vh - 180px);
display: flex;
margin-bottom: 16px;
.el-form-item__content {
width: auto;
}
.preview-panel {
width: 400px;
margin-left: auto;
.preview-bg {
width: 280px;
height: 556px;
}
}
.play-panel {
.card-panel {
width: 710px;
.el-tabs__nav {
border: none;
}
.el-tabs__header {
margin: 0;
}
.el-tabs__item {
background: #fafafa;
border: 1px solid #e5e5e5;
border-radius: 4px 4px 0 0;
border-right: 1px solid #e5e5e5;
border-top: 1px solid #e5e5e5;
border-left: 1px solid #e5e5e5 !important;
border-bottom: none;
margin-right: 1px;
width: auto;
&.is-active {
color: #5850ff;
background: #fff;
font-weight: 600;
}
}
}
.choseRow {
display: flex;
height: auto;
.choseItem {
display: inline-block;
cursor: pointer;
line-height: 40px;
height: 40px;
background: #fafafa;
border-radius: 4px 4px 0 0;
border: 1px solid #e5e5e5;
border-bottom: none;
margin-right: 1px;
padding: 0 20px;
&.active {
color: #5850ff;
background: #fff;
font-weight: 600;
}
}
}
.chose-panel {
.select-btn {
margin-bottom: 10px;
}
.waiting-box {
width: 278px;
height: 278px;
margin: 15px auto 0;
}
padding: 20px;
width: 784px;
min-height: 296px;
background: #ffffff;
border: 1px solid #e5e5e5;
border-radius: 0 4px 4px 4px;
}
}
.activity-time-container {
width: 400px;
}
}
</style>