AddTask.vue
9.65 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
<!--
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-06-07 14:22:41
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-06-14 15:33:20
* @FilePath: \scrm-micro-home\src\views\home\components\ai\addTask.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<GLDialog :title="!isEdit ? '创建任务' : '编辑任务'" okText="保存" class="gl-form-page gl-form-min" @onOk="handleSure" :before-close="handleClose" @onCancel="handleClose" :visible.sync="dialogVisibleTask">
<el-form v-loading="loading" ref="addForm" :model="addForm" class="code-body-form" label-width="154px" :rules="addRules">
<el-form-item label="选择AI:" size="small" prop="robotId">
<el-select v-model="addForm.robotId" placeholder="请选择" @change="selectAI">
<el-option v-for="item in aiOptions" :key="item.robotId" :label="item.robotName" :value="item.robotId"></el-option>
</el-select>
</el-form-item>
<el-form-item label="话术示意:">
<div class="word-content">{{ addForm.messageContent }}</div>
</el-form-item>
<div class="el-form-item is-required el-form-item--small">
<label for="remark" class="el-form-item__label" style="width: 154px">导入客户:</label>
<div class="el-form-item__content" style="margin-left: 154px">
<div class="import-link">
<div class="upload-btn">
<el-button size="small">
<i class="el-icon-plus"></i>
{{ url ? '更换文件' : '选择文件' }}
</el-button>
<input type="file" style="opacity: 0" ref="file" accept="*" @change="uploadFile" />
</div>
<a :href="modelUrl">下载模板</a>
</div>
<div class="file-tips" v-if="!addForm.fileName && !ImportResult.error">
支持扩展名:xls,xlsx
</div>
<div class="file-tips" v-if="addForm.fileName">
<i class="el-icon-success"></i>
文件已上传({{ addForm.fileName }})
</div>
<div class="file-tips" v-if="ImportResult.error">
<i class="el-icon-error"></i>
检测到导入的号码格式错误,请修改后重新上传
</div>
</div>
</div>
<el-form-item label="门店名称:" size="small" prop="merchantNameParam">
<el-input v-model="addForm.merchantNameParam"></el-input>
<div class="file-tips">
若话术中有提及门店,将自动替换该名称
</div>
</el-form-item>
<el-form-item label="外呼启动时间:" size="small" prop="aiStartTime">
<el-date-picker v-model="addForm.aiStartTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss" :picker-options="pickerOption"></el-date-picker>
<div class="file-tips">
仅支持9:00-20:00设置AI外呼
</div>
</el-form-item>
</el-form>
<GLDialog :appendToBody="true" title="导入数据失败" :hasFooter="true" mode="small" :visible.sync="importVisible">
<div class="dialog-body-panel">
<div class="import-result">
<label>{{ ImportResult.error }}</label>
条数据异常
</div>
<div class="import-tips">数据异常的可能原因:</div>
<div class="import-reason">
<div class="import-reason-content">1、存在不正确的手机号格式数据</div>
<div class="import-reason-content">2、存在重复的手机号数据</div>
</div>
</div>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="importVisible = false">取消</el-button>
<el-button size="small" type="primary" @click="handleImport">导出错误数据</el-button>
</span>
</GLDialog>
</GLDialog>
</template>
<script>
import * as dayjs from 'dayjs'
import tabel from '@/mixins/tabel'
import util from '@/utils/util'
const validateTime = (rule, value, callback) => {
const o = +value.match(/\s(\d+):/)[1]
if (o < 9 || o > 20) {
callback(new Error('请选择9:00-20:00时间段'))
} else {
callback()
}
}
export default {
mixins: [tabel],
props: {
isEdit: Boolean,
editTaskId: Number,
dialogVisibleTask: {
type: Boolean,
default: false
}
},
data() {
return {
pickerOption: {
disabledDate: time => {
return new Date().getTime() - 24 * 60 * 60 * 1e3 > new Date(time).getTime()
}
},
loading: false,
aiOptions: [],
importVisible: false,
ImportResult: {},
modelUrl: 'https://img01.glsx.com.cn/weapp/resource/saas/scrm/xlsx/AI续保提醒 - 模板.xlsx',
url: '',
excelUrl: '',
addForm: {
autoSend: 0,
businessType: 1,
messageContent: '选择AI后展示',
fileName: '',
merchantNameParam: this.$globalState.session.merchantName
},
addRules: {
robotId: [{ required: true, message: '请选择AI', trigger: 'change' }],
merchantNameParam: [{ required: true, message: '请输入门店名称', trigger: 'blur' }],
aiStartTime: [
{ required: true, message: '请选择外呼启动时间', trigger: 'change' },
{ validator: validateTime, trigger: 'change' }
]
}
}
},
mounted() {
this.robotList()
// this.readWorkbookFromRemoteFile(this.modelUrl)
if (this.isEdit) {
this.conditionPage(this.editTaskId)
}
},
methods: {
handleImport() {
util.openUrl(this.ImportResult.errUrl.replace(/https?:/, ''))
},
//获取详情
conditionPage(id) {
this.$apis.aiCall.contentEcho({ id }).then(res => {
const { id, messageContent, robotId, aiStartTime, merchantNameParam, excelUrl, excelName } = res
this.addForm = { fileName: excelName, autoSend: 0, taskId: id, messageContent, robotId, merchantNameParam, aiStartTime: dayjs(+aiStartTime).format('YYYY-MM-DD HH:mm:ss') }
this.excelUrl = this.url = excelUrl
})
},
//选择ai
selectAI(i) {
this.addForm.messageContent = this.aiOptions.find(item => item.robotId == i).messageContent
},
handleClose() {
this.$emit('dialogClose')
},
handleSure() {
if(this.loading) return
this.$refs.addForm.validate(async valid => {
if (valid) {
this.loading = true
if (this.excelUrl && this.excelUrl != this.url) {
await this.$apis.aiCall.merchantTaskDelete({ taskId: this.addForm.taskId, deleteType: 1 })
this.addForm.taskId = null
}
let apiVal = 'createTask'
if (this.addForm.taskId) {
apiVal = 'updateTask'
}
this.$apis.aiCall[apiVal]({ ...this.addForm, url: this.url, businessType: 1 }).then(res => {
this.loading = false
if (res) this.$emit('dialogSure')
})
}
})
},
// AI列表
robotList() {
this.$apis.aiCall.robotList({}).then(res => {
this.aiOptions = (res || []).filter(item => item.messageContent)
})
},
async uploadFile(e) {
const file = e.srcElement.files[0]
let AllImgExt = '.xls|.xlsx'
let extName = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
if (AllImgExt.indexOf(extName) === -1) {
this.$message.error('上传格式不正确')
return false
}
// const size = file.size / 1024 / 1024
// await this.compareHeader(file)
const reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = event => {
const imgFile = event.target.result
const arrBase64 = imgFile.split(',')
const splitStr = file.name.split('.')
const fileUrl = splitStr[splitStr.length - 1] + '@' + arrBase64[1]
this.$apis.common.pictureUpload({ file: fileUrl }).then(res => {
if (res) {
this.phoneCheck(file.name, res)
}
this.$refs.file.value = ''
})
}
},
//检查手机号
phoneCheck(fileName, url) {
this.$apis.aiCard.phoneCheck({ url, businessType: 1 }).then(res => {
if (res) {
this.ImportResult = res
if (res.error > 0) {
this.importVisible = true
} else {
this.addForm.fileName = fileName
this.url = url
}
}
})
}
}
}
</script>
<style lang="scss" scoped>
.dialog-body-panel {
.import-result {
font-size: 16px;
font-weight: 600;
color: #333333;
line-height: 22px;
label {
color: #eb4e4e;
}
}
.import-tips {
font-size: 14px;
font-weight: 400;
color: #666666;
line-height: 20px;
margin: 6px 0px;
}
.import-reason {
height: 92px;
background: #f5f5f5;
padding: 16px;
box-sizing: border-box;
&-content {
font-size: 14px;
font-weight: 400;
color: #333333;
line-height: 20px;
}
}
}
.word-content {
width: 402px;
min-height: 80px;
background: #f0f0f2;
border: 1px solid #e8e8ea;
border-radius: 4px;
padding-left: 10px;
font-size: 14px;
color: #c6c6c6;
}
.import-link {
display: flex;
cursor: pointer;
margin-bottom: 8px;
.upload-btn {
position: relative;
display: inline-block;
input {
cursor: pointer;
position: absolute;
height: 100%;
width: 100%;
top: 0px;
left: 0px;
font-size: 0px;
}
}
a {
margin-left: 6px;
color: #5850ff;
}
}
.file-tips {
font-size: 14px;
color: #999999;
.el-icon-success {
color: #67c23a; //
}
.el-icon-error {
color: #f56c6c;
}
}
</style>