TemplateComponent.vue
15 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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
<template>
<div name="online-form">
<v-runtime-template :template="html" />
</div>
</template>
<script>
import {mapState, mapActions} from 'vuex'
import form from '@/api/form.js'
import {Message} from 'element-ui'
import {Loading} from 'element-ui'
import VRuntimeTemplate from 'v-runtime-template'
import {Base64} from 'js-base64'
import $ from 'jquery'
export default {
name: 'templatePreview',
data() {
return {
alias: '',
html: '',
templateInfo: {},
tableData: {selectRows: [], querys: ''},
dialogExportVisible: false,
dialogSubVisible: false,
exportData: {getType: 'all', expField: []},
displayFields: [],
exportSellection: [],
tabs: [],
ents: [],
searchForm: {},
queryForm: {
queryData: '',
},
formType: false,
labelPosition: 'left',
incons: 'el-icon-arrow-down',
options: {
fullscreen: true,
lock: true,
},
rows: [],
pagination: {page: 1, pageSize: 20, showTotal: true},
total: 0,
}
},
components: {
VRuntimeTemplate,
},
watch: {
alias: function (newVal) {
if (newVal) {
this.init()
}
},
},
mounted() {
this.alias = this.$route.params.alias
},
methods: {
// 根据当前alias初始化
init() {
const loading = this.$loading(this.options)
let _me = this
form.getTemplateDataListForm(this.alias).then((result) => {
loading.close()
if (result.state) {
_me.html = result.value
console.log('_me.html', _me.html)
this.search()
}
})
form.getBpmDataTemplateInfo(this.alias).then((result) => {
loading.close()
if (result.state) {
_me.templateInfo = result.value
if (_me.templateInfo.displayField) {
let displayField = JSON.parse(_me.templateInfo.displayField)
for (var i = 0; i < displayField.length; i++) {
if (displayField[i].type) {
_me.displayFields.push(displayField[i])
}
}
}
}
})
},
handleSizeChange: function (size) {
//每页下拉显示数据
this.pagination.pageSize = size
this.search()
},
handleCurrentChange: function (currentPage) {
//点击第几页
this.pagination.page = currentPage
this.search()
},
search(str) {
const loading = this.$loading(this.options)
let params = {}
if (str == 'find') {
this.pagination.page = 1
}
//判断为合并查询还是分开查询
if (this.formType) {
params = this.getQueryFilter()
} else {
//判断是否配置了合并查询
if ($('.search-query').length > 0) {
params = this.getConditionQuery()
} else {
params = this.getQueryFilter()
}
}
form.getBpmTemplateByPagination(params).then((result) => {
loading.close()
this.rows = result.rows
this.total = result.total
this.pagination.page = result.page
this.pagination.pageSize = result.pageSize
})
},
getQueryFilter() {
let operationMap = this.getSearchItems()
let querys = [] //查询条件
let queryFilter = {}
let pageBean = {pageBean: this.pagination}
let params = {templateId: this.templateInfo.id}
params.pagination = pageBean
if ($.isEmptyObject(this.searchForm)) {
return params
} else {
for (var key in this.searchForm) {
if (
typeof this.searchForm[key] != 'undefined' &&
this.searchForm[key] != ''
) {
if (this.searchForm[key] instanceof Array) {
for (var i = 0; i < this.searchForm[key].length; i++) {
querys.push({
property: key,
value: this.searchForm[key][i],
group: 'main',
operation: operationMap[key],
relation: 'AND',
})
}
} else {
querys.push({
property: key,
value: this.searchForm[key],
group: 'main',
operation: operationMap[key],
relation: 'AND',
})
}
}
}
queryFilter = {pageBean: this.pagination, querys}
params.pagination = queryFilter
return params
}
},
getSearchItems() {
let searchItems = $('.search-item')
let operationMap = {}
let operationType = {
like: 'LIKE',
equal: 'EQUAL',
between: 'BETWEEN',
left_like: 'LEFT_LIKE',
right_like: 'RIGHT_LIKE',
}
if (searchItems) {
for (var i = 0; i < searchItems.length; i++) {
var operation = '='
if (typeof $(searchItems[i]).attr('ht-query') != 'undefined') {
operation = $(searchItems[i]).attr('operation')
operationMap[$(searchItems[i]).attr('ht-query')] =
typeof operationType[operation] != 'undefined'
? operationType[operation]
: operation
} else if (
typeof $(searchItems[i]).children().attr('ht-query') != 'undefined'
) {
operation = $(searchItems[i]).children().attr('operation')
operationMap[$(searchItems[i]).children().attr('ht-query')] =
typeof operationType[operation] != 'undefined'
? operationType[operation]
: operation
}
}
}
return operationMap
},
getConditionQuery() {
let searchAll = $('.search-query')
let values = ''
let querys = [] //查询条件
let queryFilter = {}
let pageBean = {pageBean: this.pagination}
let params = {templateId: this.templateInfo.id}
params.pagination = pageBean
if (this.queryForm.queryData == '') {
return params
} else {
if (
typeof $($(searchAll[0]).children()[0]).attr('ht-quick-search') !=
'undefined'
) {
values = $($(searchAll[0]).children()[0]).attr('ht-quick-search')
var arr = values.split(',')
for (let value of arr) {
querys.push({
property: value,
value: this.queryForm.queryData,
group: 'main',
operation: 'LIKE',
relation: 'OR',
})
}
}
}
queryFilter = {pageBean: this.pagination, querys}
params.pagination = queryFilter
return params
},
//打开高级检索
advanced() {
this.formType = !this.formType
if (this.formType) {
this.incons = 'el-icon-arrow-up'
this.queryForm.queryData = ''
} else {
this.incons = 'el-icon-arrow-down'
this.searchForm = {}
}
},
//回车查询
searchEnterFun: function (e) {
var keyCode = window.event ? e.keyCode : e.which
if (keyCode == 13) {
this.search()
}
},
reset() {
this.queryForm.queryData = ''
this.searchForm = {}
this.search()
},
handleSelectionChange(val) {
this.tableData.selectRows = val
},
deleted() {
if (
this.tableData.selectRows == null ||
this.tableData.selectRows.length == 0
) {
this.$message.warning('请选择文件删除!')
return false
}
this.$confirm('此操作将删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
var s = ''
for (var i = 0; i < this.tableData.selectRows.length; i++) {
s +=
s + this.tableData.selectRows[i][this.templateInfo.pkField] + ','
}
s = s.substring(0, s.length - 1)
let data = {ids: s, boAlias: this.templateInfo.boDefAlias}
this.$store.dispatch('form/deleteTemplateDataById', data).then(() => {
this.search()
})
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消删除',
})
})
},
del(id) {
this.$confirm('此操作将删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
let data = {ids: id, boAlias: this.templateInfo.boDefAlias}
this.$store.dispatch('form/deleteTemplateDataById', data).then(() => {
this.search()
})
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消删除',
})
})
},
operating(templateId, id, action, defId, isStartFlow) {
if (!templateId) {
templateId = this.templateInfo.id
action = 'add'
}
var url = '/statement/template/form/' + this.alias + '/' + action
if (id) {
url = url + '?id=' + id + '&'
} else {
url += '?'
}
var startFlowStr = 'startFlow=false'
if (action == 'add' && defId) {
startFlowStr = 'startFlow=true'
} else if (id && isStartFlow === false && defId) {
startFlowStr = 'startFlow=true'
}
this.$router.push(url + startFlowStr)
},
startFlow(id) {
let data = {
defKey: this.templateInfo.defId,
businessKey: id,
boAlias: this.templateInfo.boDefAlias,
}
let loadingInstance = Loading.service({fullscreen: true}) //开始
this.$store.dispatch('storeProcess/startForm', data).then((result) => {
loadingInstance.close() // 结束
if (result.state) {
this.$message.success(result.message)
this.search()
} else {
this.disabled = false
this.$message.error(result.message)
}
})
},
//点击导出按钮
exports() {
this.dialogExportVisible = true
},
//显示子表对话框
showSubList(refId) {
this.getSubEntsByFormKey(refId)
},
//确定导出
submitExport() {
if (!this.exportData || this.exportData.expField.length < 1) {
this.$message({
type: 'info',
message: '请选择要导出的字段!',
})
return
}
let expField = ''
for (var i = 0; i < this.exportData.expField.length; i++) {
if (i > 0) {
expField += ','
}
expField += this.exportData.expField[i].name
}
expField = Base64.encode(expField)
let data = {
boAlias: this.templateInfo.alias,
getType: this.exportData.getType,
expField: expField,
filterKey: '',
}
data.query = this.getQueryFilter().pagination
let loadingInstance = Loading.service({fullscreen: true}) //开始
this.$store.dispatch('form/templateExport', data).then(() => {
loadingInstance.close() // 结束
this.dialogExportVisible = false
})
},
//取消导出
exportCancel() {
this.dialogExportVisible = false
this.exportData.expField = []
},
//取消子表对话框
subCancel() {
this.dialogSubVisible = false
},
handleExportSelectionChange(val) {
this.exportData.expField = []
if (val) {
this.exportData.expField = val
}
},
//全选
handleExportSelectAll() {
this.exportData.expField = this.displayFields
},
//排序
sort(index, type) {
if ('up' == type) {
if (index === 0) {
this.$message({
message: '已经是列表中第一位',
type: 'warning',
})
} else {
let temp = this.displayFields[index - 1]
this.$set(this.displayFields, index - 1, this.displayFields[index])
this.$set(this.displayFields, index, temp)
}
} else {
if (index === this.displayFields.length - 1) {
this.$message({
message: '已经是列表中最后一位',
type: 'warning',
})
} else {
this.isTransition = true
let i = this.displayFields[index + 1]
this.$set(this.displayFields, index + 1, this.displayFields[index])
this.$set(this.displayFields, index, i)
}
}
},
getSubEntsByFormKey(refId) {
let _me = this
_me.tabs = []
if (!_me.ents || _me.ents.length < 1) {
this.$store
.dispatch('form/getSubEntsByFormKey', this.templateInfo.alias)
.then((ents) => {
_me.ents = ents
this.getSubData(_me, refId)
})
} else {
this.getSubData(_me, refId)
}
},
getSubData(_me, refId) {
_me.tabs = []
let ents = _me.ents
if (ents && ents.length > 0) {
for (var i = 0; i < ents.length; i++) {
var attributeList = ents[i].attributeList
var tab = {
name: ents[i].tableName,
title: ents[i].comment,
attributeList: attributeList,
comment: ents[i].comment,
}
this.$store
.dispatch('form/getSubData', {name: ents[i].name, refId: refId})
.then((data) => {
if (data && data.length > 0) {
tab.dataList = data
} else {
tab.dataList = []
}
_me.tabs.push(tab)
this.dialogSubVisible = true
})
}
}
},
},
}
</script>
<style lang="scss" scoped>
/deep/ th.todo-header-row {
background-color: #fafafa;
font-size: 13px;
}
/deep/ tr.todo-row {
font-size: 13px;
color: #000;
}
.el-container {
background-color: #fff;
}
.el-row {
margin-bottom: 20px;
}
.el-header {
border-bottom: 1.5px solid #ededed;
}
.i {
margin-right: 4px;
}
.todo-subject {
cursor: pointer;
}
.todo-subject:hover {
color: #2761ff;
}
/deep/ .el-dialog__body {
padding: 15px 10px;
}
/deep/ .el-checkbox {
// margin-left: 15px;
}
/deep/ .el-radio {
// margin-left: 15px;
}
/deep/ .el-button {
margin-left: 0px;
}
</style>