add.vue
15.1 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
<template>
<div class="sms-container">
<div class="sms-content">
<glsx-combi-form :isInline="false" class="glsx-combi-form" ref="baseInfoRef" labelWidth="154px" defaultWidth="432px" :formObj.sync="formObj" :formData="formData" :formRules="myRule">
<template v-for="(item, index) in form_solt">
<div :key="index" :slot="item.name">
<el-switch @change="openSmsByHttp($event, formObj[item.attr])" v-model="formObj[item.attr].switch" :active-value="true" :inactive-value="false"></el-switch>
<div style="position: relative" class="wrapper">
<div class="topSet flex">
<span>发送时间:积分到账</span>
<div class="set-int">
<el-input @change="onchangeInput" class="intTime" v-model="formObj[item.attr].time" maxlength="4" oninput="if(value){value=value.replace(/[^\d]/g,'')} if(value<=0){value=''} if(value>1000){value=1000}" placeholder="请输入"></el-input>
</div>
<span>小时后</span>
</div>
<div class="sms-box">
<div class="left">群发内容:</div>
<div class="right">
<wTextarea maxlength="500" :value="formObj[item.attr].messageContext" :ref="item.attr" class="textarea" @updateText="updateText($event, item.attr)" :style="{ 'min-height': boxHeight + 'px' }"></wTextarea>
<div class="word-limit">
<span :class="[{ redColorText: formObj[item.attr].text.length > 500 }]">{{ formObj[item.attr].text.length || 0 }}</span>
/500
</div>
<div class="select-panel">
<div @click="handleSelectMessage($event, item.attr, '短链')" class="flex marl24">
<img src="@/images/link.png" class="link" />
<span class="">短链</span>
</div>
<div @click="handleSelectMessage($event, item.attr, '客户积分')" class="flex marl24">
<img src="@/images/jifen.png" class="link" />
<span class="">客户积分</span>
</div>
<div @click="handleSelectMessage($event, item.attr, '客户姓名')" class="flex">
<img src="@/images/username.png" class="link" />
<span class="">客户姓名</span>
</div>
</div>
<div class="showSmsModel">
<span>【{{ formObj.miniId }}】</span>
<span v-html="highText(formObj[item.attr].model)" v-if="formObj[item.attr].model"></span>
<span>拒收请回复R</span>
</div>
</div>
</div>
</div>
</div>
</template>
</glsx-combi-form>
</div>
<GLFooter>
<el-button @click="handleCancel">取消</el-button>
<el-button type="primary" @click="handleSave">确定</el-button>
</GLFooter>
</div>
</template>
<script type='text/ecmascript-6'>
import glsxCombiForm from '@/components/glsx-combi-form'
import wTextarea from './tag-textarea.vue'
// const DJ_MINI_APPID = '车生活助手'
const JF_MINI_APPID = '积分商城'
const MINI = [
// {
// confId: DJ_MINI_APPID,
// confName: '车生活助手'
// },
{
confId: JF_MINI_APPID,
confName: '积分商城'
}
]
export default {
name: 'add',
props: {},
components: {
glsxCombiForm,
wTextarea
},
data() {
return {
boxHeight: 178,
myRule: {
miniId: [{ required: true, message: '短信签名', trigger: 'change' }]
},
formObj: {
miniId: JF_MINI_APPID,
message_first: {
messageContext: '',
switch: false,
time: null,
model: null,
text: '',
name: '短信一',
msgNo: 1
},
message_second: {
messageContext: '',
switch: false,
time: null,
model: null,
text: '',
name: '短信二',
msgNo: 2
},
message_three: {
messageContext: '',
switch: false,
time: null,
model: null,
text: '',
name: '短信三',
msgNo: 3
}
},
formData: [
{
label: '短信签名',
name: 'miniId',
type: 'select',
isDisabled: false,
optionList: MINI,
optionId: 'confId',
optionLabel: 'confName',
changeAttr: val => {}
},
{
label: '短信一',
name: 'smsFirst',
addHtml: 'smsSlot1'
},
{
label: '短信二',
name: 'smsFirst',
addHtml: 'smsSlot2'
},
{
label: '短信三',
name: 'smsFirst',
addHtml: 'smsSlot3'
}
],
form_solt: [
{
name: 'smsSlot1',
attr: 'message_first'
},
{
name: 'smsSlot2',
attr: 'message_second'
},
{
name: 'smsSlot3',
attr: 'message_three'
}
]
}
},
mounted() {
this.getSMSDetail()
},
methods: {
// 信息文案处理高亮和字数限制
highText(title) {
const shortLink = '#短链#',
customerJf = '#客户积分#',
customerName = '#客户姓名#'
// 如果标题中包含,关键字就替换一下
if (title.length > 500) {
title = title.substring(0, 500)
}
if (title.includes(shortLink)) {
title = title.replaceAll(shortLink, '<font style="color:#5092FF !important;">' + shortLink + '</font>')
}
if (title.includes(customerJf)) {
title = title.replaceAll(customerJf, '<font style="color:#5850ff !important;">' + customerJf + '</font>')
}
if (title.includes(customerName)) {
title = title.replaceAll(customerName, '<font style="color:#5850ff !important;">' + customerName + '</font>')
}
return title
},
// 获取标签文案
subText(htm) {
const cutImg = htm
.replace(/<wise.+?>(.+?)(?:<\/wise>)/g, '$1')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/(\n|\s| )/g, '')
.replace(/<br>/g, '\n')
.replace(/<span>([\s\S]*?)<\/span>/g, '$1')
.replace(/<div>([\s\S]*?)<\/div>/g, '$1')
return cutImg
},
// 编辑器文案获取
updateText(html, type) {
const text = JSON.stringify(html)
const linkText = JSON.parse(this.subText(text))
if (html) {
this.formObj[type].model = linkText
} else {
this.formObj[type].model = null
}
this.formObj[type].messageContext = html
this.formObj[type].text = linkText
this.editStatus = true
},
// 点击标签
handleSelectMessage(e, type, textName) {
const _refs = this.$refs[type][0]
// if (_refs.currentText.indexOf(`#${textName}#`) != -1) {
// return
// }
_refs.addTag(`#${textName}#`)
this.editStatus = true
},
// 提交
handleSave() {
const params = this.handlerParams()
if (Array.isArray(params)) {
if(!params.length)return this.$message({ message: '请选择需要提交的短信',type: 'error'})
this.$apis.points.createSmsApi({ msgList: params }).then(res => {
if (res) {
this.editStatus = false
this.$message({
message: '提交成功',
type: 'success'
})
this.getSMSDetail()
} else {
this.$message({
message: res.message,
type: 'error'
})
}
})
}
},
handleCancel() {
if (this.editStatus) {
this.$confirm('当前有内容信息未保存,是否继续返回?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
this.$router.back()
})
.catch(() => {})
} else {
this.$router.back()
}
},
//处理提交参数
handlerParams() {
const _temp = this.$common.utils.deepClone(this.formObj)
delete _temp.miniId
let isHaveOpen = false,
needCheckList = [],
params = []
// 筛选已打开的短信模块
for (let k in _temp) {
const target = _temp[k]
if (target.switch || target.id) {
isHaveOpen = true
needCheckList.push(target)
}
}
// 检查已打开的短信模块内容
if (isHaveOpen) {
let isHaveBlack = false,
errName = '',
errTitle = '发送时间'
needCheckList.forEach(el => {
if (!el.time) {
isHaveBlack = true
errName = el.name
errTitle = '发送时间'
} else if (!el.text) {
isHaveBlack = true
errName = el.name
errTitle = '群发内容'
}
})
if (isHaveBlack) return this.$message.error(`请填写${errName}${errTitle}`)
// 比较发送时间是否填写正确短信1<短信2<短信3
let isHaveTimeErr = false,
errName2 = ''
for (let i = 0; i < needCheckList.length; i++) {
let start = needCheckList[i],
end = needCheckList[i + 1]
if (end && (Number(start.time) > Number(end.time) || Number(start.time) == Number(end.time))) {
isHaveTimeErr = true
errName = start.name
errName2 = end.name
}
}
if (isHaveTimeErr) return this.$message.error(`${errName2}发送时间需大于${errName}发送时间`)
needCheckList.forEach(el => {
let obj = {
msgType: 1,
msgNo: el.msgNo,
msgSign: this.formObj.miniId,
delayTime: el.time,
msgContent: el.text,
openType: el.switch ? 1 : 2
}
if (el.id) obj.id = el.id
params.push(obj)
})
}
return params
},
// 处理详情回显标签内容
handlerDetailTagContent(tagContent) {
const shortLink = '#短链#',
customerJf = '#客户积分#',
customerName = '#客户姓名#'
if (tagContent.includes(shortLink)) {
const rid = `r${new Date().getTime()}d${Math.ceil(Math.random() * 1000)}`
tagContent = tagContent.replaceAll(shortLink, `<span></span><wise id="${rid}">${shortLink}</wise>`)
}
if (tagContent.includes(customerJf)) {
const rid = `r${new Date().getTime()}d${Math.ceil(Math.random() * 1000)}`
tagContent = tagContent.replaceAll(customerJf, `<span></span><wise id="${rid}">${customerJf}</wise>`)
}
if (tagContent.includes(customerName)) {
const rid = `r${new Date().getTime()}d${Math.ceil(Math.random() * 1000)}`
tagContent = tagContent.replaceAll(customerName, `<span></span><wise id="${rid}">${customerName}</wise>`)
}
return tagContent
},
// 获取短信详情
getSMSDetail() {
this.$apis.points.getSmsDetailApi({ msgType: 1 }).then(res => {
if (res && Array.isArray(res)) {
res.forEach(el => {
if (el.msgNo == 1) {
this.formObj.message_first.messageContext = this.handlerDetailTagContent(el.msgContent)
this.formObj.message_first.switch = el.openType == 1 ? true : false
this.formObj.message_first.time = el.delayTime
this.formObj.message_first.model = el.msgContent
this.formObj.message_first.text = el.msgContent
this.formObj.message_first.id = el.id
} else if (el.msgNo == 2) {
this.formObj.message_second.messageContext = this.handlerDetailTagContent(el.msgContent)
this.formObj.message_second.switch = el.openType == 1 ? true : false
this.formObj.message_second.time = el.delayTime
this.formObj.message_second.model = el.msgContent
this.formObj.message_second.text = el.msgContent
this.formObj.message_second.id = el.id
} else if (el.msgNo == 3) {
this.formObj.message_three.messageContext = this.handlerDetailTagContent(el.msgContent)
this.formObj.message_three.switch = el.openType == 1 ? true : false
this.formObj.message_three.time = el.delayTime
this.formObj.message_three.model = el.msgContent
this.formObj.message_three.text = el.msgContent
this.formObj.message_three.id = el.id
}
})
}
})
},
// 短信开关触发接口
openSmsByHttp(e, item) {
if (item && item.id) {
const { id, msgNo, name } = item
const str = e ? `${name}已打开` : `${name}已关闭`
this.$apis.points.openSmsApi({ id, msgType: 1, msgNo, openType: e ? 1 : 2 }).then(res => {
if (res) {
this.editStatus = false
this.$message({
message: str,
type: 'success'
})
}
})
}
},
onchangeInput() {
this.editStatus = true
}
}
}
</script>
<style scoped lang='scss'>
.sms-content {
background: white;
padding: 38px 20px;
margin-bottom: 16px;
.textarea {
width: 592px !important;
background: white;
border-bottom: none;
}
.wrapper {
width: 778px;
box-sizing: border-box;
padding: 22px 20px 16px;
background: #f9f9f9;
.topSet {
font-weight: 400;
font-size: 14px;
color: #333333;
margin-bottom: 20px;
.set-int {
margin: 0 8px;
.intTime {
width: 80px;
height: 32px;
background: #ffffff;
font-weight: 400;
font-size: 14px;
color: #666666;
}
}
}
}
.sms-box {
display: flex;
.left {
font-weight: 400;
font-size: 14px;
color: #333333;
}
.right {
.word-limit {
background: white;
text-align: right;
font-weight: 400;
font-size: 14px;
color: #999999;
border: 1px solid #e5e5e5;
width: 592px !important;
box-sizing: border-box;
padding-right: 8px;
border-top: none;
height: 28px;
line-height: 28px;
}
.redColorText {
color: red !important;
}
.showSmsModel {
font-size: 14px;
font-weight: 400;
color: #333333;
width: 592px !important;
box-sizing: border-box;
margin-top: 8px;
line-height: 22px;
}
}
}
.select-panel {
padding-left: 20px;
background: #fafbfe;
display: flex;
font-size: 14px;
font-weight: 400;
color: #666666;
line-height: 40px;
border: 1px solid #e5e5e5;
width: 592px !important;
border-top: 0px;
box-sizing: border-box;
border-radius: 0 0 4px 4px;
cursor: pointer;
.flex {
display: flex;
align-items: center;
}
.marl24 {
margin-right: 24px;
}
.link {
width: 18px;
height: 18px;
margin-right: 4px;
}
}
}
</style>