|
@@ -131,6 +131,7 @@ $(document).ready(function() {
|
|
|
loadRelaData() {
|
|
|
this.refreshOperationValid();
|
|
|
SpreadJsObj.saveTopAndSelect(this.sheet, this.ckBillsSpread);
|
|
|
+ attObj.setSafeBills();
|
|
|
}
|
|
|
refreshTree(data) {
|
|
|
const sheet = this.sheet;
|
|
@@ -572,9 +573,221 @@ $(document).ready(function() {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ class AttObj {
|
|
|
+ constructor() {
|
|
|
+ this.atts = [];
|
|
|
+ this.billsIndexes = {};
|
|
|
+ this.pageCount = 15;
|
|
|
+ this.activeTab = 'cur';
|
|
|
+ this.curPageIndex = 1;
|
|
|
+ this.curTotalPage = 1;
|
|
|
+ this.allPageIndex = 1;
|
|
|
+ this.allTotalPage = 1;
|
|
|
+ }
|
|
|
+ refreshShowPage() {
|
|
|
+ const prefix = this.activeTab;
|
|
|
+ $('#totalPage').html(this[prefix + 'TotalPage']);
|
|
|
+ $('#currentPage').html(this[prefix + 'PageIndex']);
|
|
|
+ if (this[prefix + 'TotalPage'] > 1) {
|
|
|
+ $('#showPage').show();
|
|
|
+ } else {
|
|
|
+ $('#showPage').hide();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reCalcPage() {
|
|
|
+ this.allTotalPage = Math.ceil(this.atts.length / this.pageCount);
|
|
|
+ const curNode = SpreadJsObj.getSelectObject(billsObj.sheet);
|
|
|
+ const curAttIndex = this.billsIndexes[curNode.safe_id] || [];
|
|
|
+ this.curTotalPage = Math.ceil(curAttIndex.length / this.pageCount);
|
|
|
+ this.refreshShowPage();
|
|
|
+ }
|
|
|
+ loadDatas(datas) {
|
|
|
+ for (const d of datas) {
|
|
|
+ this.atts.push(d);
|
|
|
+ if (!this.billsIndexes[d.safe_id]) {
|
|
|
+ this.billsIndexes[d.safe_id] = [];
|
|
|
+ }
|
|
|
+ this.billsIndexes[d.safe_id].push(d);
|
|
|
+ }
|
|
|
+ this.refreshTable();
|
|
|
+ }
|
|
|
+ loadUpdateAtt(files) {
|
|
|
+ for (const d of files) {
|
|
|
+ this.atts.unshift(d);
|
|
|
+ if (!this.billsIndexes[d.safe_id]) {
|
|
|
+ this.billsIndexes[d.safe_id] = [];
|
|
|
+ }
|
|
|
+ this.billsIndexes[d.safe_id].unshift(d);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ loadDeleteAtt(file) {
|
|
|
+ let fileIndex = this.atts.findIndex(x => { return x.id === file.id; });
|
|
|
+ this.atts.splice(fileIndex, 1);
|
|
|
+ if (this.billsIndexes[file.safe_id]) {
|
|
|
+ fileIndex = this.billsIndexes[file.safe_id].findIndex(x => { return x.id === file.id; });
|
|
|
+ this.billsIndexes[file.safe_id].splice(fileIndex, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ getFileHtml(file) {
|
|
|
+ const html = [];
|
|
|
+ const downHtml = `<a href="javascript: void(0);" onclick="AliOss.downloadFile('${file.filepath}', '${file.filename + file.fileext}')" class="mr-1"><i class="fa fa-download fa-fw"></i></a>`;
|
|
|
+ const delHtml = file.uid === userID ? `<a href="javascript: void(0);" class="mr-1 text-danger" name="del-file" file_id="${file.id}"><i class="fa fa-trash-o fa-fw"></i></a>` : '';
|
|
|
+ html.push('<tr>');
|
|
|
+ html.push(`<td><input type="checkbox" name="check-att" file_id="${file.id}"></td>`);
|
|
|
+ html.push(`<td><div class="d-flex justify-content-between align-items-center table-file"><a href="javascript: void(0);" file_id="${file.id}">${file.filename}${file.fileext}</a><div class="btn-group-table" style="display: none;">${downHtml}${delHtml}</div></div></td>`);
|
|
|
+ html.push(`<td>${file.u_name}</td>`);
|
|
|
+ html.push('</tr>');
|
|
|
+ return html.join('');
|
|
|
+ }
|
|
|
+ refreshCurTable() {
|
|
|
+ const curNode = SpreadJsObj.getSelectObject(billsObj.sheet);
|
|
|
+ const html = [];
|
|
|
+ if (curNode) {
|
|
|
+ const attIndex = this.billsIndexes[curNode.safe_id] || [];
|
|
|
+ const beginIndex = (this.allPageIndex - 1) * this.pageCount;
|
|
|
+ const endIndex = (this.allPageIndex) * this.pageCount - 1;
|
|
|
+ for (const [i, ai] of attIndex.entries()) {
|
|
|
+ if (i < beginIndex) continue;
|
|
|
+ if (i > endIndex) continue;
|
|
|
+ html.push(this.getFileHtml(ai));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#cur-att-list').html(html.join(''));
|
|
|
+ }
|
|
|
+ refreshAllTable() {
|
|
|
+ const html = [];
|
|
|
+ const attIndex = this.atts;
|
|
|
+ const beginIndex = (this.allPageIndex - 1) * this.pageCount;
|
|
|
+ const endIndex = (this.allPageIndex) * this.pageCount - 1;
|
|
|
+ for (const [i, ai] of attIndex.entries()) {
|
|
|
+ if (i < beginIndex) continue;
|
|
|
+ if (i > endIndex) continue;
|
|
|
+ html.push(this.getFileHtml(ai));
|
|
|
+ }
|
|
|
+ $('#all-att-list').html(html.join(''));
|
|
|
+ }
|
|
|
+ prePage(){
|
|
|
+ const pageIndex = this.activeTab + 'PageIndex';
|
|
|
+ if (this[pageIndex] <= 1) return;
|
|
|
+ this[pageIndex] = this[pageIndex] - 1;
|
|
|
+ this.refreshShowTable();
|
|
|
+ this.refreshShowPage();
|
|
|
+ }
|
|
|
+ nextPage() {
|
|
|
+ const pageIndex = this.activeTab + 'PageIndex';
|
|
|
+ if (this[pageIndex] >= this[this.activeTab + 'TotalPage']) return;
|
|
|
+ this[pageIndex] = this[pageIndex] + 1;
|
|
|
+ this.refreshShowTable();
|
|
|
+ this.refreshShowPage();
|
|
|
+ }
|
|
|
+ refreshTable() {
|
|
|
+ this.reCalcPage();
|
|
|
+ this.refreshCurTable();
|
|
|
+ this.refreshAllTable();
|
|
|
+ }
|
|
|
+ refreshShowTable() {
|
|
|
+ if (this.activeTab === 'cur') {
|
|
|
+ this.refreshCurTable();
|
|
|
+ } else {
|
|
|
+ this.refreshAllTable();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ batchDownload() {
|
|
|
+ const checkes = $('[name=check-att]:checked');
|
|
|
+ const files = [], fileIds = [];
|
|
|
+ for (const c of checkes) {
|
|
|
+ const file = this.atts.find(x => { return x.id === parseInt(c.getAttribute('file_id'))});
|
|
|
+ if (file && fileIds.indexOf(file.id) < 0) {
|
|
|
+ fileIds.push(file.id);
|
|
|
+ files.push({ filename: file.filename, fileext: file.fileext, filepath: c.viewpath || file.filepath});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ AliOss.zipFiles(files, '安全生产费-附件.zip');
|
|
|
+ }
|
|
|
+ uploadAtt(files, callback) {
|
|
|
+ const curNode = SpreadJsObj.getSelectObject(billsObj.sheet);
|
|
|
+ const formData = new FormData();
|
|
|
+ if (curNode) formData.append('safe_id', curNode.safe_id);
|
|
|
+ for (const file of files) {
|
|
|
+ if (file === undefined) {
|
|
|
+ toastr.error('未选择上传文件。');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (file.size > 30 * 1024 * 1024) {
|
|
|
+ toastr.error('上传文件大小超过30MB。');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
|
|
|
+ if (whiteList.indexOf(fileext) === -1) {
|
|
|
+ toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ formData.append('size', file.size);
|
|
|
+ formData.append('file[]', file);
|
|
|
+ }
|
|
|
+ postDataWithFile('file/upload', formData, function (files) {
|
|
|
+ attObj.loadUpdateAtt(files);
|
|
|
+ attObj.refreshTable();
|
|
|
+ if (callback) callback();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ deleteAtt(file_id) {
|
|
|
+ const file = this.atts.find(x => { return x.id === file_id; });
|
|
|
+ if (!file) return;
|
|
|
+
|
|
|
+ postData('file/delete', {id: file_id}, function() {
|
|
|
+ attObj.loadDeleteAtt(file);
|
|
|
+ attObj.refreshTable();
|
|
|
+ })
|
|
|
+ }
|
|
|
+ setTab(tab) {
|
|
|
+ this.activeTab = tab;
|
|
|
+ this.refreshShowPage();
|
|
|
+ }
|
|
|
+ setSafeBills() {
|
|
|
+ this.curPageIndex = 1;
|
|
|
+ this.reCalcPage();
|
|
|
+ this.refreshCurTable();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const attObj = new AttObj();
|
|
|
+ $('#upload-ok').click(function() {
|
|
|
+ const input = $('#upload-file');
|
|
|
+ attObj.uploadAtt(input[0].files, function() {
|
|
|
+ $(input).val('');
|
|
|
+ $('#upload').modal('hide');
|
|
|
+ });
|
|
|
+ });
|
|
|
+ $('#batch-download-att').click(() => {
|
|
|
+ attObj.batchDownload();
|
|
|
+ });
|
|
|
+ $('body').on('mouseenter', ".table-file", function(){
|
|
|
+ $(this).children(".btn-group-table").css("display","block");
|
|
|
+ });
|
|
|
+ $('body').on('mouseleave', ".table-file", function(){
|
|
|
+ $(this).children(".btn-group-table").css("display","none");
|
|
|
+ });
|
|
|
+ $('body').on('click', '[name=del-file]', function() {
|
|
|
+ attObj.deleteAtt(parseInt(this.getAttribute('file_id')));
|
|
|
+ });
|
|
|
+ $('.page-select').click(function() {
|
|
|
+ const content = this.getAttribute('content');
|
|
|
+ if (content === 'pre') {
|
|
|
+ attObj.prePage();
|
|
|
+ } else if (content === 'next') {
|
|
|
+ attObj.nextPage();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('[fujian-content]').click(function() {
|
|
|
+ const content = this.getAttribute('fujian-content');
|
|
|
+ attObj.setTab(content.replace('-att', ''));
|
|
|
+ });
|
|
|
+
|
|
|
// 加载安全生产费数据
|
|
|
- postData('load', { filter: 'bills' }, function(result) {
|
|
|
+ postData('load', { filter: 'bills;att' }, function(result) {
|
|
|
billsObj.loadData(result.bills);
|
|
|
+ attObj.loadDatas(result.att);
|
|
|
});
|
|
|
|
|
|
const stdGclSetting = {
|
|
@@ -677,8 +890,6 @@ $(document).ready(function() {
|
|
|
if (tab.attr('content') === '#std-gcl') {
|
|
|
if (!stdGcl) stdGcl = $.stdLib(stdGclSetting);
|
|
|
stdGcl.spread.refresh();
|
|
|
- } else if (tab.attr('content') === '#fujian') {
|
|
|
- // todo 附件
|
|
|
}
|
|
|
} else { // 收起工具栏
|
|
|
tab.removeClass('active');
|