carbon.js
21.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
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'fastflow-base'], function ($, undefined, Backend, Table, Form, FastflowBase) {
var tableBill = $("#table-bill");
var tableList = $("#table-list");
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init();
this.table.bill();
this.table.list();
$('.today-carbon-jump').click(function () {
tableList.bootstrapTable('refreshOptions', []);
$('input[name="id"]').val($(this).data('id'));
$("#box-list button[type='submit']").trigger("click");
});
$('.fastflow-unread-btn').click(function (e) {
tableList.bootstrapTable('refreshOptions', []);
$('select[name="is_read"]').val(0);
$("#box-list button[type='submit']").trigger("click");
});
$('.fastflow-read-btn').click(function (e) {
tableList.bootstrapTable('refreshOptions', []);
$('select[name="is_read"]').val(1);
$("#box-list button[type='submit']").trigger("click");
});
$('.fastflow-today-btn').click(function (e) {
tableList.bootstrapTable('refreshOptions', []);
$('input[name="sendtime"]').val($(this).data('range'));
$("#box-list button[type='submit']").trigger("click");
});
$('.fastflow-all-btn').click(function (e) {
$("#box-list button[type='reset']").trigger("click");
});
tableList.on('post-body.bs.table', function (e, data) {
FastflowBase.api.renderbadge();
});
},
table: {
bill: function () {
tableBill.bootstrapTable({
url: 'fastflow/carbon/bill',
toolbar: '#toolbar-bill',
sortName: 'id',
search: false,
showExport: false,
pageList: [10],
pageSize: 10,
showToggle: false,
singleSelect: true,
showColumns: false,
columns: [
[
{
field: 'id', formatter: function (value, row, index) {
return '<i class="fa fa-file-text text-gray"></i>';
}
},
{
field: 'bill_name', title: __('Bill_name'), formatter: function (value, row, index) {
return '<span class="text-bold" style="color: #0a5ba6" data-toggle="tooltip" data-placement="top" title="" data-original-title="点击筛选">' + value + '</span>';
}
},
{
field: 'carbons',
title: __('未读抄送'),
width: 100,
formatter: function (value, row, index) {
if (value == 0) {
return '';
} else {
return '<small class="badge bg-red">' + value + '</small>'
}
}
},
]
]
});
// 为表格1绑定事件
Table.api.bindevent(tableBill);
tableBill.on('click-row.bs.table', function (e, row, ele) {
$('.row-active').removeClass('row-active');
$(ele).addClass('row-active');
tableList.bootstrapTable('refreshOptions', []);
$("#box-list .form-commonsearch input[name='bill']").val(row['bill_table']);
$("#box-list button[type='submit']").trigger("click");
});
},
list: function () {
tableList.bootstrapTable({
url: 'fastflow/carbon/index',
extend: {
index_url: 'fastflow/carbon/index' + location.search,
del_url: 'fastflow/carbon/del',
multi_url: 'fastflow/carbon/multi',
table: 'fastflow_carbon',
},
toolbar: '#toolbar-list',
sortName: 'sendtime',
search: false,
sortOrder: 'desc',
pageSize: 10,
showToggle: false,
searchFormVisible: true,
columns: [
[
{checkbox: true},
{field: 'id', title: __('ID')},
{field: 'sender_name', title: __('Sender_name'), operate: false},
{field: 'bill_name', title: __('Bill_name'), operate: false,},
{field: 'bill', title: __('Bill'), visible: false},
{
field: 'bill_id', title: __('Bill_id'), formatter: function (value, row, index) {
if (row['bill_row_title'] != '') {
return value + '(' + row['bill_row_title'] + ')';
} else {
return value;
}
}
},
{field: 'sender_id', title: __('Sender_id'), visible: false},
{
field: 'sendtime',
title: __('Sendtime'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false
},
{
field: 'is_read',
title: __('Is_read'),
searchList: {"0": __('Is_read 0'), "1": __('Is_read 1')},
formatter: Table.api.formatter.label,
custom: {'0': 'danger', '1': 'success'}
},
{
field: '',
title: __('View'),
operate: false,
table: tableList,
events: Controller.api.events.detail,
formatter: Controller.api.formatter.detail
},
{
field: 'operate',
title: __('Operate'),
table: tableList,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate
},
]
]
});
// 为表格2绑定事件
Table.api.bindevent(tableList);
tableList.on('load-success.bs.table', function (e, data) {
$("#fastflow-all").text(data.extend.all);
$("#fastflow-unread").text(data.extend.unread);
$("#fastflow-read").text(data.extend.read);
});
$('.btn-display-all').on('click', function (e) {
$("#box-list button[type='reset']").trigger("click");
});
tableList.on('dbl-click-row.bs.table', function (e, row, element, field) {
$('.btn-detail', element).trigger("click");
});
}
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
detail: function () {
//调整窗口大小---
var footer = $('.footer');
$('.layui-layer-content', parent.document).after(footer);
footer.css('display', 'block');
var dialogHeight = $('.layui-layer-iframe', parent.document).height();
$('.layui-layer-iframe', parent.document).height(dialogHeight - 53);
var iframeHeight = $('.layui-layer-content iframe', parent.document).height();
$('.layui-layer-content iframe', parent.document).height(iframeHeight - 53);
$('.layui-layer-resize', parent.document).css('bottom', '-53px');
//---调整窗口大小
Controller.api.bindPrintEvent();
//不放在bindPrintEvent方法内,防止反复弹出打印页
$('#bill-print', parent.document).click(function () {
Controller.api.print('bill');
});
$('#merge-print', parent.document).click(function () {
Controller.api.mergePrint();
});
$('#export-word', parent.document).click(function () {
Controller.api.exportWord();
});
Controller.api.bindEbillTabEvent();
var index = layer.load();
$.ajax({
type: "get",
url: Config.controller_url + "/edit",
data: {ids: Config.bill_id, way: 'detail'},
success: function (data) {
$('#fastflow-right-content #bill-edit').append($('#edit-form', data));
$('[name^="row"]', $('#edit-form', '#fastflow-right-content')).attr('disabled', 'disabled');
$('button', $('#edit-form', '#fastflow-right-content')).addClass('hidden');
Form.api.bindevent($("#edit-form"));
require(['backend/fastflow/fastflow_yongyou_baojiadan_detail'], function (YongyouQuotationHook) {
if (YongyouQuotationHook && typeof YongyouQuotationHook.attach === 'function') {
YongyouQuotationHook.attach(Config);
}
});
$('a.btn', $('#edit-form', '#fastflow-right-content')).addClass('hidden');
$(document).on("fa.event.appendfieldlist", function () {
var textArea = $('textarea[disabled="disabled"]');
textArea.closest('.form-group').find('.btn-remove').addClass('hidden');
textArea.closest('.form-group').find('.btn-dragsort').addClass('hidden');
textArea.closest('.form-group').find('.btn-append').addClass('hidden');
textArea.closest('.form-group').find('input').attr('disabled', 'disabled');
});
layer.close(index);
},
error: function (e) {
layer.close(index);
}
});
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
bindEbillTabEvent: function () {
$('#ebill-tab').click(function (e) {
if (Config.ebill_id === null) {
return;
}
$('.ebill-empty-hint').addClass('hidden');
$('#ebill-content').removeClass('hidden');
var src = $('#ebill-iframe').data('src');
$('#ebill-iframe').attr('src', src + '?action=detail' + '&id=' + Config.ebill_id + '&bill=' + Config.bill + '&bill_id=' + Config.bill_id + '&' + Config.bill_row);
$('#toolbar', '#ebill').removeClass('hidden');
});
},
bindPrintEvent: function () {
$('#table-print').click(function () {
Controller.api.print('table');
});
$('#timeline-print').click(function () {
Controller.api.print('timeline');
});
$('#ebill-print').click(function () {
Controller.api.print('ebill');
});
Controller.api.bindDownloadEbillEvent();
},
print: function (type) {
var originalHtml = $('body', window.document).html();
$('#' + type + '-print').addClass('hidden');
if (type === 'table' || type === 'timeline') {
$('.detail-table').css('table-layout', 'unset');
//提取资料地址
var fileSpan = $('.flow-file', $('.' + type));
$(fileSpan).each(function (index, item) {
var fileUrl = $('a', $(item)).attr('href');
var fileName = $('a', $(item)).html();
$(item).html("<label data-name='" + fileName + "'>" + Config.domain + "<span>" + fileUrl + "</span>" + "</label>");
});
$('body').css('padding','30px');
}
if (type == 'bill') {
$('.bill-legend').removeClass('hidden');
$('body').css('padding','30px');
}
if (type == 'ebill') {
var ebillContent = $('#ebill-iframe').contents().find('#ebill-content');
var ebillImageBase64 = ebillContent.css('backgroundImage').replace('url("', '').replace('")', '');
var ebillImage = document.createElement('img');
var ebillWidth = ebillContent.css('width');
var ebillHeight = ebillContent.css('height');
$(ebillImage).css('width', ebillWidth).css('height', ebillHeight).attr('src', ebillImageBase64).attr('id', 'ebill-image');
$('#ebill-iframe').before(ebillImage);
$('#ebill-iframe').remove();
}
var html = $('body', window.document).html();
var printStart = "<!--" + type + "PrintStart-->";
var printEnd = "<!--" + type + "PrintEnd-->";
var printHtml = html.substr(html.indexOf(printStart));
printHtml = printHtml.substring(0, printHtml.indexOf(printEnd));
window.document.body.innerHTML = printHtml;
window.print();
//还原
window.document.body.innerHTML = originalHtml;
$('body').css('padding','unset');
Controller.api.bindPrintEvent();
Controller.api.bindEbillTabEvent();
},
mergePrint: function () {
var originalHtml = $('body', window.document).html();
$('#table-print').addClass('hidden');
$('.detail-table').css('table-layout', 'unset');
//提取资料地址
var fileSpan = $('.flow-file', $('.table'));
$(fileSpan).each(function (index, item) {
var fileUrl = $('a', $(item)).attr('href');
var fileName = $('a', $(item)).html();
$(item).html("<label data-name='" + fileName + "'>" + Config.domain + "<span>" + fileUrl + "</span>" + "</label>");
});
$('.bill-legend').removeClass('hidden');
var html = $('body', window.document).html();
//table
var tableStart = "<!--tablePrintStart-->";
var tableEnd = "<!--tablePrintEnd-->";
var tableHtml = html.substr(html.indexOf(tableStart));
tableHtml = tableHtml.substring(0, tableHtml.indexOf(tableEnd));
//bill
var billStart = "<!--billPrintStart-->";
var billEnd = "<!--billPrintEnd-->";
var billHtml = html.substr(html.indexOf(billStart));
billHtml = billHtml.substring(0, billHtml.indexOf(billEnd));
window.document.body.innerHTML = tableHtml + billHtml;
$('body').css('padding','30px');
window.print();
//还原
window.document.body.innerHTML = originalHtml;
$('body').css('padding','unset');
Controller.api.bindPrintEvent();
Controller.api.bindEbillTabEvent();
},
exportWord: function () {
$.ajax({
type: "get",
url: "fastflow/flow/flow/exportWord",
data: {
bill: Config.bill,
bill_id: Config.bill_id
},
success: function (data) {
if (data['code'] == 1) {
let url = data['data']['url'];
let a = document.createElement('a');
a.href = url;
a.download = data['data']['fileName'] + '审批详情.docx';
a.click();
delete a;
} else if (data['code'] == 0) {
Toastr.error(data['msg']);
}
},
error: function (e) {
}
});
},
bindDownloadEbillEvent: function () {
require.config({
paths: {
'jspdf': "../addons/fastflow/plugins/jsPDF-master/dist/jspdf.umd.min",
},
});
require(['jspdf'], function ({jsPDF}) {
$('#ebill-download-pdf').on('click', function () {
var ebillContent = $('#ebill-iframe').contents().find('#ebill-content');
var contentWidth = ebillContent.css('width').replace('px', '');
var contentHeight = ebillContent.css('height').replace('px', '');
var a4_width = 595.28;
var a4_height = 841.89;
var orientation = 'p';// l表示横版,p:纵向 (默认纵向)
var fsWidth = ebillContent.css('width').replace('px', '');
if (parseInt(fsWidth) >= 1122){
a4_width = 841.89;
a4_height = 595.28;
orientation = 'l';
}
var pageData = ebillContent.css('backgroundImage').replace('url("', '').replace('")', '');
var pageHeight = contentWidth / a4_width * a4_height;//pdf一页高度对应的html高度,等比缩放
// 未生成pdf的html页面高度
var leftHeight = contentHeight;
// 页面偏移
var position = 0;
// a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
var imgWidth = a4_width;
var imgHeight = a4_width / contentWidth * contentHeight;//需要生成的pdf总高度,等比缩放
// l表示横版,p:纵向 (默认纵向)
var pdf = new jsPDF(orientation, 'pt', 'a4');
// 有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
// 当内容未超过pdf一页显示的范围,无需分页
if (leftHeight < pageHeight) {
pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight);
} else {
while (leftHeight > 0) {
pdf.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight);
leftHeight -= pageHeight;
position -= a4_height;
//避免添加空白页
if (leftHeight > 0) {
pdf.addPage();
}
}
}
var title = ebillContent.data('title');
pdf.save(title, pdf);
});
});
},
formatter: {
detail: function (value, row, index) {
html = '<a href="fastflow/carbon/detail?id=' + row['id'] + '" class="btn btn-xs btn-success btn-dialog btn-detail" data-area=["80%","90%"] title="查阅"><i class="fa fa-envelope"></i></a>';
return html;
},
},
events: {
detail: {
'click .btn-detail': function (e, value, row, index) {
e.stopPropagation();
e.preventDefault();
var table = $("#table-bill");
var options = table.bootstrapTable('getOptions');
var ids = row[options.pk];
row = $.extend({}, row ? row : {}, {ids: ids});
Fast.api.open(Table.api.replaceurl($(this).attr('href'), row, table), $(this).data("original-title") || $(this).attr("title"), $(this).data() || {});
if (row['is_read'] == 0) {
setTimeout(function (e) {
$("#box-list .btn-refresh").trigger("click")
tableBill.bootstrapTable('refresh');
FastflowBase.api.renderbadge();
}, 1000);
}
},
},
},
}
};
return Controller;
});