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 ''; } }, { field: 'bill_name', title: __('Bill_name'), formatter: function (value, row, index) { return '' + value + ''; } }, { field: 'carbons', title: __('未读抄送'), width: 100, formatter: function (value, row, index) { if (value == 0) { return ''; } else { return '' + value + '' } } }, ] ] }); // 为表格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(""); }); $('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 = ""; var 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(""); }); $('.bill-legend').removeClass('hidden'); var html = $('body', window.document).html(); //table var tableStart = ""; var tableEnd = ""; var tableHtml = html.substr(html.indexOf(tableStart)); tableHtml = tableHtml.substring(0, tableHtml.indexOf(tableEnd)); //bill var billStart = ""; var billEnd = ""; 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 = ''; 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; });