index.vue
11.9 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
485
486
487
488
489
490
491
492
<template>
<div class="container">
<div class="sticky">
<GLCombiForm
ref="showSearch"
:rowNumber="1"
:formObj="searchForm"
:formData="searchFormData"
@handleOk="handleSearch"
@handleRest="handleReset"
></GLCombiForm>
<div class="sticky-btns">
<div class="btns">
<el-button
type="default"
plain
@click="editForm"
>新建问卷</el-button>
<el-button
type="default"
@click="handleExport"
>导出</el-button>
</div>
</div>
</div>
<div class="tabelList">
<div class="table-title">问卷列表</div>
<GLTable
ref="listRef"
:getListApi="getListApi"
:searchForm="searchForm"
:noDataImg="url"
:tableParams="tableParams"
:pageConf="pageConf"
>
<template
slot="qrcode"
slot-scope="scope"
>
<el-popover
placement="top"
trigger="click"
>
<img
class="img-plus"
:src="scope.scope.qrcode"
/>
<div
class="download-img "
@click="download(scope.scope.qrcode)"
>下载二维码</div>
<div
slot="reference"
class="qr"
>
<img :src="scope.scope.qrcode" />
</div>
</el-popover>
</template>
<template
slot="status"
slot-scope="scope"
>
<div :class="`status status-${scope.scope.status}`">
{{{
'-1':'已结束',
'0':'待发布',
'1':'已发布'
}[scope.scope.status]}}
</div>
</template>
<span
slot="auth-button"
slot-scope="scope"
>
<GLTableButton
:buttonList="tableButtonList"
:buttonItem="scope.scope"
:buttonNum="3"
></GLTableButton>
</span>
</GLTable>
</div>
<data-table :dataObj.sync="dataObj" />
<GLDialog
:title="updateParams.title"
@onOk="updateQiestionStatus"
@onCancel="updateParams.show = false"
:visible.sync="updateParams.show"
mode="small"
>
<template #default>
<div class="over-box">
<div class="el-icon-warning"></div>
{{updateParams.text}}
<div class="tips">{{updateParams.tips}}</div>
</div>
</template>
</GLDialog>
<GLDialog
title="复制问卷"
@onCancel="copyParmas.show = false"
:visible.sync="copyParmas.show"
mode="small"
>
<template #default>
<div class="copy-box">
<div class="input">
<el-form
ref="copyFormRef"
inline
@submit.native.prevent
:model="copyParmas">
<el-form-item label="问卷名称" prop="name" :rules="rules">
<el-input
placeholder="请输入"
size="small"
v-model.trim="copyParmas.name"
maxlength="50"
>
</el-input>
</el-form-item>
</el-form>
</div>
<el-button class="tips" type="text" @click="copyParmas.name = copyParmas.data.name">使用原问卷名称</el-button>
</div>
</template>
<template #footer>
<el-button
type="primary"
size="small"
@click="copyQiestion"
>提交</el-button>
</template>
</GLDialog>
</div>
</template>
<script type='text/ecmascript-6'>
import url from '@/assets/empty.png'
import DataTable from './components/DataTable/index.vue'
import { exportFn } from '@/common/constant'
import util from '@/utils/util'
export default {
name: 'Questionnaire',
components: { DataTable },
data () {
return {
url,
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' },
searchForm: {
merchantName: '',
name: '',
statuses: '-1,0,1'
},
searchFormData: [
{
label: '问卷名称',
name: 'name',
type: 'input',
maxlength: 100
},
{
label: '所属渠道',
name: 'merchantName',
type: 'input',
maxlength: 100
},
{
label: '状态',
name: 'statuses',
type: 'select',
maxlength: 100,
optionList: [
{ text: '全部', id: '-1,0,1' },
{ text: '待发布', id: '0' },
{ text: '已发布', id: '1' },
{ text: '已结束', id: '-1' },
],
optionId: 'id',
optionLabel: 'text'
},
],
getListApi: this.$apis.questionnaire.getQuestionnaireList,
tableParams: {
listName: 'data',
tableOption: true,
tableColumns: [
{
label: '问卷名称',
prop: 'name',
minWidth: 100
},
{
label: '所属渠道',
minWidth: 100,
formatter: cell => `${cell.merchantId}/${cell.merchantName}`
},
{
label: '卡片标题',
prop: 'cardTitle',
minWidth: 100
},
{
label: '状态',
minWidth: 100,
addHtml: 'status'
},
{
label: '二维码',
minWidth: 100,
addHtml: 'qrcode'
},
]
},
// 表格按钮
tableButtonList: [
{
type: 'el-button',
name: '数据',
attrs: {
type: 'text',
},
condition: row => row.status != 0,
listeners: {
click: row => this.dataObj = {
show: true,
...row
}
}
},
{
type: 'el-button',
name: '结束',
attrs: {
type: 'text',
},
condition: row => row.status == 1,
listeners: {
click: row => this.updateParams = {
show: true,
id: row.id,
title: '结束',
status: -1,
text: '请确认是否结束该调查问卷?',
tips: '结束后,客户点击将提示:问卷活动已结束'
}
}
},
{
type: 'el-button',
name: '发布',
attrs: {
type: 'text',
},
condition: row => row.status == 0,
listeners: {
click: row => this.updateParams = {
show: true,
id: row.id,
title: '发布问卷',
status: 1,
text: '请确认是否发布以下调查问卷?',
tips: `问卷名称:${row.name}`
}
}
},
{
type: 'el-button',
name: '编辑',
attrs: {
type: 'text',
},
condition: row => row.status == 0,
listeners: {
click: row => this.editForm(row, 'edit')
}
},
{
type: 'el-button',
name: '复制',
attrs: {
type: 'text',
},
listeners: {
click: async row => {
const data = await this.$apis.questionnaire.getQuestionnaireDetail({
id: row.id
})
if (data) {
this.copyParmas = {
show: true,
data,
name: ''
}
this.$nextTick(() => this.$refs?.copyFormRef?.clearValidate('name'))
} else this.$message.error('复制失败,请重试!')
}
}
},
{
type: 'el-button',
name: '详情',
attrs: {
type: 'text',
},
listeners: {
click: row => this.editForm(row)
}
},
],
dataObj: {},
updateParams: {
show: false
},
copyParmas: {
show: false,
name: ''
},
rules: [{ required: true, message: '请输入问卷名称' }]
}
},
mounted () {
},
methods: {
handleSearch () {
this.$refs.listRef.refreshTable()
},
handleReset () {
this.searchForm = this.$options.data.call(this).searchForm
this.handleSearch()
},
updateQiestionStatus () {
const { id, status } = this.updateParams
this.Interceptor(async () => await this.$apis.questionnaire.updateQuestionnaireStatus({ id, status }), {
target: 'updateParams',
successText: '操作成功!',
errorText: '操作失败,请重试。'
})
},
copyQiestion () {
const { data, name } = this.copyParmas
this.$refs.copyFormRef.validate(valid => {
if (valid) {
delete data.id
delete data.status
data.name = name
this.Interceptor(async () => await this.$apis.questionnaire.addQuestionnaire(data), {
target: 'copyParmas',
successText: '复制成功!',
errorText: '复制失败!'
})
}
})
},
async Interceptor (fun, params) {
let loading = this.$loading()
try {
const res = await fun()
if (res) {
this.$message({
message: params.successText,
type: 'success'
})
this[params.target] = this.$options.data.call(this)[params.target]
loading.close()
this.handleSearch()
} else throw params.errorText
} catch (error) {
loading.close()
if (error) this.$message.error(error)
}
},
handleExport () {
this.$apis.questionnaire.exportQuestionnaireList({ ...this.searchForm, ...this.$refs.listRef.page }).then(res => {
exportFn(res)
})
},
download (url) {
util.downloadIamge(url)
},
editForm (row, type = '') {
this.$router.push({
path: '/questionnaire/add',
query: {
$title: row.id ? type == 'edit' ? '编辑问卷' : '问卷详情' : '新建问卷',
id: row.id,
type
}
})
}
}
}
</script>
<style scoped lang='scss'>
.container {
height: 100%;
background-color: #fff;
-webkit-box-sizing: border-box;
box-sizing: border-box;
padding: 20px;
.table-title {
font-weight: 700;
font-size: 16px;
color: #333333;
padding-bottom: 18px;
}
.sticky {
position: relative;
z-index: 2;
&-btns {
position: absolute;
right: 0;
bottom: -23px;
overflow: hidden;
.el-button + .el-button {
margin-left: 8px;
}
.btns {
transition: all 0.25s;
.el-button {
padding: 8px 15px;
min-width: 60px;
}
}
}
}
.qr {
width: 36px;
height: 36px;
img {
width: 100%;
height: 100%;
vertical-align: top;
}
}
}
.img-plus {
width: 200px;
height: 200px;
}
.download-img {
cursor: pointer;
margin-top: 10px;
font-size: 14px;
font-weight: 600;
color: #5850ff;
line-height: 20px;
text-align: center;
}
.status {
display: flex;
align-items: center;
&::before {
content: '';
width: 8px;
height: 8px;
border-radius: 100%;
margin-right: 8px;
background: #999999;
}
}
.status-0 {
&::before {
background: #f8b757;
}
}
.status-1 {
&::before {
background: #4aca74;
}
}
/deep/.copy-box {
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
font-size: 16px;
color: #333333;
.input {
transform: translateY(-4px);
margin: 0 auto;
}
.tips {
font-size: 12px;
color: #5850ff;
margin-left: 148px;
width: fit-content;
}
}
</style>