packageRecommend.vue
11 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
<template>
<div class="package-form">
<div class="content">
<table
cellspacing="0"
cellpadding="0"
class="table-box"
>
<tr>
<th>序号</th>
<th><span class="required">*</span>套餐类型</th>
<th><span class="required">*</span>套餐名称</th>
<th><span class="required">*</span>套餐内容</th>
<th><span class="required">*</span>价格/元</th>
<th><span class="required">*</span>套餐简介</th>
<th><span class="required">*</span>话术介绍</th>
<th>操作</th>
</tr>
<tr v-for="(pItem, pindex) in infoList" :key="pindex">
<td>{{ pindex + 1 }}</td>
<td>
<el-select class="type-select" v-model="pItem.type" placeholder="请选择">
<el-option
v-for="item in packageTypeOption"
:key="item.confId"
:label="item.confName"
:value="item.confId">
</el-option>
</el-select>
</td>
<td>
<el-input v-model.trim="pItem.name" class="textarea-input" rows="5" type="textarea" maxlength="15" placeholder="请输入(15字以内)" />
</td>
<td>
<el-input
type="textarea"
rows="5"
class="textarea-input"
v-model="pItem.content"
maxlength="200"
placeholder="请输入(200字以内)">
</el-input>
</td>
<td class="input-td">
<div>
<span class="label">市场价</span>
<el-input
class="price-input"
@input="priceInput($event, pindex, 'marketPrice')"
v-model="pItem.marketPrice"
placeholder="请输入"
></el-input>
</div>
<div>
<span class="label">套餐价</span>
<el-input
class="price-input"
@input="priceInput($event, pindex, 'packagePrice')"
v-model="pItem.packagePrice"
placeholder="请输入"
></el-input>
</div>
<div>
<span class="label">优惠金额</span>
<el-input
disabled
class="price-input"
:value="calculateDiscount(pItem)"
></el-input>
</div>
</td>
<td>
<el-input
type="textarea"
class="textarea-input"
rows="5"
v-model="pItem.briefIntroduction"
maxlength="20"
placeholder="请输入(20字以内)"
></el-input>
</td>
<td>
<el-input
type="textarea"
rows="5"
class="textarea-input"
v-model="pItem.scriptIntroduction"
maxlength="200"
placeholder="对驻店套餐话术介绍(200字以内)"
></el-input>
</td>
<td style="width: 90px;">
<el-button
type="text"
@click="handleDel(pindex)"
>
删除
</el-button>
<el-button type="text" @click="handlePinToTop(pindex)" :disabled="pItem.topFlag == 'Y'">{{ pItem.topFlag == 'Y' ? '已置顶' : '置顶' }}</el-button>
</td>
</tr>
</table>
<div class="package-add">
<el-button
icon="el-icon-plus"
type="text"
v-if="infoList.length < 10"
@click="handleAdd(infoList.length - 1)"
>
新增套餐
</el-button>
</div>
</div>
<div class="footer">
<el-button type="primary" @click="handleSave">提交</el-button>
<el-button type="primary" plain @click="handleReset">重置</el-button>
<el-button class="width_100 cancel-btn" @click="handleCancel"
>取消</el-button
>
</div>
</div>
</template>
<script>
import { limitPrice } from '@/common/format'
import BigNumber from 'bignumber.js'
import { packageRecommendDetail, updatePackageRecommend } from '@api/contentManager'
import { deepClone } from "@/common/util"
export default{
name: 'PackageRecommend',
props: {
pageQuery: {
type: Object
}
},
data() {
return {
packageTypeOption: [{
confId: 1,
confName: '必推'
}, {
confId: 2,
confName: '可选'
}],
infoList: [],
initObj: {
type: '',
name: '',
content: '',
marketPrice: '',
packagePrice: '',
briefIntroduction: '',
scriptIntroduction: ''
}
}
},
mounted() {
// 获取套餐推荐配置详情数据
console.log(this.pageQuery)
this.getPackageDetail(this.pageQuery?.merchantId)
},
methods: {
getPackageDetail(merchantId) {
packageRecommendDetail({ merchantId }).then(res => {
if (res?.length) {
this.infoList = res || []
} else {
this.initFormData()
}
})
},
initFormData() {
this.infoList = [deepClone(this.initObj)]
},
priceInput(newValue, index, key) {
newValue = newValue.replace(/[^\d.]/g, '')
let oldValue = `${this.infoList[index][`old${key}`]}`
this.$set(this.infoList[index], key, limitPrice(newValue, oldValue, 6, 2, 0, 100000))
this.$set(this.infoList[index], `old${key}`, this.infoList[index][key])
},
// 计算优惠金额
calculateDiscount(pItem) {
const marketPrice = Number(pItem.marketPrice) || 0
const packagePrice = Number(pItem.packagePrice) || 0
return pItem.marketPrice && pItem.packagePrice ? new BigNumber(marketPrice).minus(packagePrice).toNumber() : ''
},
// 新增一行
handleAdd(i) {
if (i < 0) return this.infoList.push(deepClone(this.initObj))
if (this.infoList?.length >= 10) return this.$message.error('最多支持新增10个套餐')
const result = this.validateForm(i)
if (result) this.infoList.push(result)
},
// 置顶
handlePinToTop(index) {
if (this.infoList[index]?.topFlag == 'Y') return
const newList = this.infoList.map((item, idx) => ({
...item,
topFlag: idx === index ? 'Y' : 'N'
}))
this.infoList = newList
},
validateForm(i) {
const keys = Object.keys(this.infoList[i])
let validateList = {
type: "请选择套餐类型",
name: "请输入套餐名称",
content: "请输入套餐内容",
marketPrice: "请输入市场价",
packagePrice: "请输入套餐价",
briefIntroduction: "请输入套餐简介",
scriptIntroduction: "请输入话术介绍"
}
for (let k in validateList) {
if (keys.includes(k) && !this.infoList[i][k]) {
this.$message.error("请校验并输入套餐信息必填项")
return false
}
}
if (this.infoList[i].marketPrice == 0) {
this.$message.error(`${this.infoList[i]?.name}市场价不能为0`)
return false
}
if (this.infoList[i]?.packagePrice == 0) {
this.$message.error(`${this.infoList[i]?.name}套餐价不能为0`)
return false
}
if (this.calculateDiscount(this.infoList[i]) <= 0) {
this.$message.error(`${this.infoList[i]?.name}优惠金额≤0,请核实后重新录入`)
return false
}
return deepClone(this.initObj)
},
handleDel(i) {
this.infoList.splice(i, 1)
},
// 提交
handleSave() {
let list = []
this.infoList?.forEach((val, index) => {
if (!this.validateForm(index)) throw new Error("请完善信息")
val.discountPrice = new BigNumber(Number(val.marketPrice)).minus(Number(val.packagePrice)).toNumber()
list.push({
type: val.type,
name: val.name,
content: val.content,
marketPrice: val.marketPrice,
packagePrice: val.packagePrice,
discountPrice: val.discountPrice,
briefIntroduction: val.briefIntroduction,
scriptIntroduction: val.scriptIntroduction,
topFlag: val.topFlag == 'Y' ? 'Y' : 'N'
})
})
const params = {
merchantConfigId: this.pageQuery.id,
list
}
// 请求保存接口
updatePackageRecommend(params).then(res => {
this.notice.okTips()
this.handleCancel()
})
},
// 重置 将内容置为默认门店的数据
handleReset() {
this.$confirm("是否对该门店重置配置?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
this.getPackageDetail()
this.isUpStatus = true
this.$message.success("重置成功")
})
.catch((err) => {
console.log(err)
})
},
// 取消按钮返回列表页
handleCancel() {
this.$router.push({
name: "packageConfig",
params: {
tabPane: '1',
tabLabel: 'UpgradeLightly'
}
})
},
}
}
</script>
<style lang="scss">
.package-form {
.content {
background: #FFFFFF;
min-height: 64vh;
padding: 20px 20px 0;
.table-box {
border: 1px solid #ebeef5;
width: 100%;
color: #666666;
font-size: 14px;
tr {
line-height: 60px;
&:first-child {
line-height: 30px;
background: #f5f7fa;
}
th,
td {
padding: 10px 20px;
text-align: center;
border-bottom: 1px solid #ebeef5;
.el-textarea {
vertical-align: middle;
::v-deep.el-textarea__inner {
min-height: 80px !important;
}
}
.required {
color: #ff0000;
}
.el-icon-edit-outline {
cursor: pointer;
color: #185efe;
}
.flex {
display: flex;
justify-content: center;
&.disabled {
cursor: not-allowed;
pointer-events: none;
}
::v-deep.photo-activity {
position: static;
}
::v-deep.activity-img-box {
display: block;
margin-bottom: 6px;
}
}
}
.input-td {
width: 180px;
div{
line-height: 45px;
}
}
}
.type-select {
width: 120px;
}
.label {
display: inline-block;
width: 70px;
margin-right: 4px;
text-align: right;
}
.price-input {
width: 105px;
height: 45px;
}
}
}
.footer {
position: fixed;
bottom: 0;
left: 50%;
text-align: center;
padding: 10px;
}
.package-add {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #e5e5e5;
border-top: 0;
}
}
</style>