|
@@ -0,0 +1,953 @@
|
|
|
|
+$(document).ready(function() {
|
|
|
|
+ class FilingObj {
|
|
|
|
+ constructor(setting) {
|
|
|
|
+ // 原始数据整理后的树结构,用来整理zTree显示
|
|
|
|
+ this.dragTree = createDragTree({
|
|
|
|
+ id: 'id',
|
|
|
|
+ pid: 'tree_pid',
|
|
|
|
+ level: 'tree_level',
|
|
|
|
+ order: 'tree_order',
|
|
|
|
+ rootId: '-1'
|
|
|
|
+ });
|
|
|
|
+ // 界面显示的zTree
|
|
|
|
+ this.setting = setting;
|
|
|
|
+ this.filingTree = null;
|
|
|
|
+ this.pageCount = 15;
|
|
|
|
+ this.expandKey = 'filing-' + window.location.pathname.split('/')[2];
|
|
|
|
+ const cache = getLocalCache(this.expandKey);
|
|
|
|
+ this.expandCache = cache ? cache.split(',') : [];
|
|
|
|
+ }
|
|
|
|
+ analysisFiling(data) {
|
|
|
|
+ const self = this;
|
|
|
|
+ this.dragTree.loadDatas(data);
|
|
|
|
+ this.dragTree.recursiveFun(this.dragTree.children, x => {
|
|
|
|
+ if (x.children && x.children.length > 0) {
|
|
|
|
+ x.total_file_count = x.children.map(y => {
|
|
|
|
+ return y.total_file_count;
|
|
|
|
+ }).reduce((pre, value) => {
|
|
|
|
+ return pre + value
|
|
|
|
+ }, 0);
|
|
|
|
+ } else {
|
|
|
|
+ x.total_file_count = x.file_count;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ const sortNodes = this.dragTree.nodes.map(x => {
|
|
|
|
+ const result = {
|
|
|
|
+ id: x.id,
|
|
|
|
+ tree_pid: x.tree_pid,
|
|
|
|
+ name: x.name + (x.total_file_count > 0 ? `(${x.total_file_count})` : ''),
|
|
|
|
+ spid: x.spid,
|
|
|
|
+ source_node: x,
|
|
|
|
+ };
|
|
|
|
+ if (result.source_node.is_fixed) result.isParent = true;
|
|
|
|
+ if (result.source_node.is_folder || result.source_node.is_fixed) result.open = self.expandCache.indexOf(result.id) >= 0;
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ this.filingTree = $.fn.zTree.init($('#filing'), this.setting, sortNodes);
|
|
|
|
+ }
|
|
|
|
+ _getFileHtml(file) {
|
|
|
|
+ const html = [];
|
|
|
|
+ html.push(`<tr fid="${file.id}">`);
|
|
|
|
+ html.push(`<td><input type="checkbox" name="bd-check" fid="${file.id}"></td>`);
|
|
|
|
+ const editHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="edit-file" fid="${file.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
|
|
|
|
+ const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
|
|
|
|
+ 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.canEdit ? `<a href="javascript: void(0);" class="mr-1 text-danger" name="del-file" fid="${file.id}"><i class="fa fa-trash-o fa-fw"></i></a>` : '';
|
|
|
|
+ html.push(`<td><div class="d-flex justify-content-between align-items-center table-file"><div name="filename" fid="${file.id}">${file.filename}${file.fileext}</div><div class="btn-group-table" style="display: none;">${editHtml}${viewHtml}${downHtml}${delHtml}</div></div></td>`);
|
|
|
|
+ html.push(`<td>${file.user_name}</td>`);
|
|
|
|
+ html.push(`<td>${moment(file.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
|
|
|
|
+ html.push(`<td>${file.fileext_str}</td>`);
|
|
|
|
+ html.push('</tr>');
|
|
|
|
+ return html.join('');
|
|
|
|
+ }
|
|
|
|
+ refreshFilesTable() {
|
|
|
|
+ const html = [];
|
|
|
|
+ const files = this.curFiling.source_node.files;
|
|
|
|
+ if (!files || files.length === 0) {
|
|
|
|
+ $('#file-list').html('');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const startIndex = (this.curPage - 1)*this.pageCount;
|
|
|
|
+ const endIndex = this.curPage*this.pageCount;
|
|
|
|
+ for (const [i, f] of files.entries()) {
|
|
|
|
+ if (i < startIndex || i >= endIndex) continue;
|
|
|
|
+ html.push(this._getFileHtml(f));
|
|
|
|
+ }
|
|
|
|
+ $('#file-list').html(html.join(''));
|
|
|
|
+ }
|
|
|
|
+ refreshPages() {
|
|
|
|
+ if (!filingObj.curFiling) return;
|
|
|
|
+
|
|
|
|
+ filingObj.curTotalPage = Math.ceil(filingObj.curFiling.source_node.file_count / this.pageCount);
|
|
|
|
+ $('#curPage').html(filingObj.curPage);
|
|
|
|
+ $('#curTotalPage').html(filingObj.curTotalPage);
|
|
|
|
+ if (filingObj.curTotalPage > 1) {
|
|
|
|
+ $('#showPage').show();
|
|
|
|
+ } else {
|
|
|
|
+ $('#showPage').hide();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ async loadFiles(node, page) {
|
|
|
|
+ if (node.source_node.children && node.source_node.children.length > 0) return;
|
|
|
|
+ if (!node.source_node.files) node.source_node.files = [];
|
|
|
|
+
|
|
|
|
+ if (!node.source_node.file_count) return;
|
|
|
|
+ if (node.source_node.files && node.source_node.files.length === node.source_node.file_count) return;
|
|
|
|
+
|
|
|
|
+ const needFiles = Math.min(page*this.pageCount, node.source_node.file_count);
|
|
|
|
+ if (node.source_node.files && needFiles <= node.source_node.files.length) return;
|
|
|
|
+
|
|
|
|
+ const files = await postDataAsync('file/load', { filing_id: node.id, page, count: this.pageCount });
|
|
|
|
+ files.forEach(x => {
|
|
|
|
+ const file = node.source_node.files.find(f => {return x.id === f.id; });
|
|
|
|
+ if (file) {
|
|
|
|
+ Object.assign(file, x);
|
|
|
|
+ } else {
|
|
|
|
+ node.source_node.files.push(x);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ node.source_node.files.sort((x, y) => {
|
|
|
|
+ return x.create_time - y.create_time;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ addSiblingFiling(node) {
|
|
|
|
+ const self = this;
|
|
|
|
+ postData('filing/add', { tree_pid: node.tree_pid, tree_pre_id: node.id }, function(result) {
|
|
|
|
+ const refreshData = self.dragTree.loadPostData(result);
|
|
|
|
+ const newNode = refreshData.create[0];
|
|
|
|
+ self.filingTree.addNodes(node.getParentNode(), node.getIndex() + 1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid, source_node: newNode}]);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ addChildFiling(node) {
|
|
|
|
+ const self = this;
|
|
|
|
+ postData('filing/add', { tree_pid: node.id }, function(result) {
|
|
|
|
+ const refreshData = self.dragTree.loadPostData(result);
|
|
|
|
+ const newNode = refreshData.create[0];
|
|
|
|
+ self.filingTree.addNodes(node, -1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid, source_node: newNode}]);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ delFiling(node, callback) {
|
|
|
|
+ const self = this;
|
|
|
|
+ postData('filing/del', { id: node.id }, function(result) {
|
|
|
|
+ self.dragTree.loadPostData(result);
|
|
|
|
+ self.filingTree.removeNode(node);
|
|
|
|
+ if (callback) callback();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ async renameFiling(node, newName) {
|
|
|
|
+ const result = await postDataAsync('filing/save', { id: node.id, name: newName });
|
|
|
|
+ node.source_node.name = newName;
|
|
|
|
+ node.name = node.source_node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ updateFilingFileCount(filing, count) {
|
|
|
|
+ let differ = count - filing.source_node.file_count;
|
|
|
|
+ filing.source_node.file_count = count;
|
|
|
|
+ filing.source_node.total_file_count = count;
|
|
|
|
+ filing.name = filing.source_node.name + (filing.source_node.total_file_count > 0 ? `(${filing.source_node.total_file_count})` : '');
|
|
|
|
+ filingObj.filingTree.updateNode(filing);
|
|
|
|
+ let parent = filing.getParentNode();
|
|
|
|
+ while (!!parent) {
|
|
|
|
+ parent.source_node.total_file_count = parent.source_node.total_file_count + differ;
|
|
|
|
+ parent.name = parent.source_node.name + (parent.source_node.total_file_count > 0 ? `(${parent.source_node.total_file_count})` : '');
|
|
|
|
+ filingObj.filingTree.updateNode(parent);
|
|
|
|
+ parent = parent.getParentNode();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ uploadFiles(files, callback) {
|
|
|
|
+ const formData = new FormData();
|
|
|
|
+ formData.append('filing_id', filingObj.curFiling.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 (data) {
|
|
|
|
+ filingObj.curFiling.source_node.files.unshift(...data.files);
|
|
|
|
+ filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
|
|
|
|
+ filingObj.refreshFilesTable();
|
|
|
|
+ filingObj.refreshPages();
|
|
|
|
+ if (callback) callback();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ delFiles(files, callback) {
|
|
|
|
+ postData('file/del', { del: files }, async function(data) {
|
|
|
|
+ for (const id of data.del) {
|
|
|
|
+ const fIndex = filingObj.curFiling.source_node.files.findIndex(x => { return x.id === id });
|
|
|
|
+ if (fIndex >= 0) filingObj.curFiling.source_node.files.splice(fIndex, 1);
|
|
|
|
+ }
|
|
|
|
+ filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
|
|
|
|
+ await filingObj.loadFiles(filingObj.curFiling, filingObj.curPage);
|
|
|
|
+ filingObj.refreshFilesTable();
|
|
|
|
+ filingObj.refreshPages();
|
|
|
|
+ if (callback) callback();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ renameFile(fileId, filename) {
|
|
|
|
+ const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fileId });
|
|
|
|
+ if (!file) return;
|
|
|
|
+
|
|
|
|
+ const filenameDiv = $(`[name=filename][fid=${fileId}]`);
|
|
|
|
+ if (filename === file.filename + file.fileext) {
|
|
|
|
+ filenameDiv.html(file.filename + file.fileext);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ postData('file/save', { id: fileId, filename }, function(data) {
|
|
|
|
+ file.filename = data.filename;
|
|
|
|
+ file.fileext = data.fileext;
|
|
|
|
+ filenameDiv.html(file.filename + file.fileext);
|
|
|
|
+ }, function() {
|
|
|
|
+ filenameDiv.html(file.filename + file.fileext);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ relaFiles(files, callback) {
|
|
|
|
+ postData('file/rela', { filing_id: this.curFiling.id, files: files }, async function(data) {
|
|
|
|
+ filingObj.curFiling.source_node.files.unshift(...data.files);
|
|
|
|
+ filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
|
|
|
|
+ filingObj.refreshFilesTable();
|
|
|
|
+ filingObj.refreshPages();
|
|
|
|
+ if (callback) callback();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ async setCurFiling(node) {
|
|
|
|
+ filingObj.curFiling = node;
|
|
|
|
+ filingObj.curPage = 1;
|
|
|
|
+ filingObj.refreshPages();
|
|
|
|
+
|
|
|
|
+ if (filingObj.curFiling.source_node.children && filingObj.curFiling.source_node.children.length > 0) {
|
|
|
|
+ $('#file-view').hide();
|
|
|
|
+ } else {
|
|
|
|
+ $('#file-view').show();
|
|
|
|
+ await filingObj.loadFiles(node, 1);
|
|
|
|
+ filingObj.refreshFilesTable();
|
|
|
|
+ }
|
|
|
|
+ if (filingObj.curFiling.source_node.filing_type === 5) {
|
|
|
|
+ $('#rela-file-btn').show();
|
|
|
|
+ } else {
|
|
|
|
+ $('#rela-file-btn').hide();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ prePage() {
|
|
|
|
+ if (this.curPage === 1) return;
|
|
|
|
+ this.curPage = this.curPage - 1;
|
|
|
|
+ this.refreshPages();
|
|
|
|
+ this.refreshFilesTable();
|
|
|
|
+ }
|
|
|
|
+ async nextPage() {
|
|
|
|
+ if (this.curPage === this.curTotalPage) return;
|
|
|
|
+ await filingObj.loadFiles(this.curFiling, this.curPage + 1);
|
|
|
|
+ this.curPage = this.curPage + 1;
|
|
|
|
+ this.refreshPages();
|
|
|
|
+ this.refreshFilesTable();
|
|
|
|
+ }
|
|
|
|
+ getCurFilingFullPath(){
|
|
|
|
+ let cur = filingObj.curFiling;
|
|
|
|
+ const result = [];
|
|
|
|
+ while (cur) {
|
|
|
|
+ result.unshift(cur.source_node.name);
|
|
|
|
+ cur = cur.getParentNode();
|
|
|
|
+ }
|
|
|
|
+ return result.join('/');
|
|
|
|
+ }
|
|
|
|
+ expandFiling(node, expand) {
|
|
|
|
+ if (expand) {
|
|
|
|
+ this.expandCache.push(node.id);
|
|
|
|
+ } else{
|
|
|
|
+ const index = this.expandCache.indexOf(node.id);
|
|
|
|
+ if (index >= 0) this.expandCache.splice(index, 1);
|
|
|
|
+ }
|
|
|
|
+ setLocalCache(this.expandKey, this.expandCache.join(','));
|
|
|
|
+ }
|
|
|
|
+ moveFiling(node, tree_order) {
|
|
|
|
+ if (tree_order === node.source_node.tree_order) return;
|
|
|
|
+
|
|
|
|
+ const self = this;
|
|
|
|
+ postData('filing/move', { id: node.id, tree_order }, function(result) {
|
|
|
|
+ self.dragTree.loadPostData(result);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ const levelTreeSetting = {
|
|
|
|
+ view: {
|
|
|
|
+ selectedMulti: false
|
|
|
|
+ },
|
|
|
|
+ data: {
|
|
|
|
+ simpleData: {
|
|
|
|
+ idKey: 'id',
|
|
|
|
+ pIdKey: 'tree_pid',
|
|
|
|
+ rootPId: '-1',
|
|
|
|
+ enable: true,
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ edit: {
|
|
|
|
+ enable: true,
|
|
|
|
+ showRemoveBtn: function(treeId, treeNode) {
|
|
|
|
+ if (!canFiling) return false;
|
|
|
|
+ return !treeNode.source_node.is_fixed;
|
|
|
|
+ },
|
|
|
|
+ showRenameBtn: function(treeId, treeNode) {
|
|
|
|
+ if (!canFiling) return false;
|
|
|
|
+ return !treeNode.source_node.is_fixed;
|
|
|
|
+ },
|
|
|
|
+ renameTitle: '编辑',
|
|
|
|
+ drag: {
|
|
|
|
+ isCopy: false,
|
|
|
|
+ isMove: true,
|
|
|
|
+ pre: true,
|
|
|
|
+ next: true,
|
|
|
|
+ inner: false,
|
|
|
|
+ },
|
|
|
|
+ editNameSelectAll: true,
|
|
|
|
+ },
|
|
|
|
+ callback: {
|
|
|
|
+ onClick: async function (e, key, node) {
|
|
|
|
+ if (filingObj.curFiling && filingObj.curFiling.id === node.id) return;
|
|
|
|
+
|
|
|
|
+ filingObj.setCurFiling(node);
|
|
|
|
+ },
|
|
|
|
+ beforeEditName: function(key, node) {
|
|
|
|
+ node.name = node.source_node.name;
|
|
|
|
+ },
|
|
|
|
+ beforeRename: async function(key, node, newName, isCancel) {
|
|
|
|
+ if (!isCancel) await filingObj.renameFiling(node, newName);
|
|
|
|
+ return true;
|
|
|
|
+ },
|
|
|
|
+ onRename: function(e, key, node, isCancel) {
|
|
|
|
+ node.name = node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
|
|
|
|
+ filingObj.filingTree.updateNode(node);
|
|
|
|
+ },
|
|
|
|
+ beforeRemove: function(e, key, node, isCancel) {
|
|
|
|
+ $('#del-filing').modal('show');
|
|
|
|
+ return false;
|
|
|
|
+ },
|
|
|
|
+ onExpand(e, key, node) {
|
|
|
|
+ filingObj.expandFiling(node, true);
|
|
|
|
+ },
|
|
|
|
+ onCollapse: function(e, key, node) {
|
|
|
|
+ filingObj.expandFiling(node, false);
|
|
|
|
+ },
|
|
|
|
+ beforeDrop: function(key, nodes, target, moveType, isCopy) {
|
|
|
|
+ if (!target) return false;
|
|
|
|
+ if (nodes[0].tree_pid !== target.tree_pid) return false;
|
|
|
|
+
|
|
|
|
+ const order = target.getIndex() + 1;
|
|
|
|
+ const max = target.getParentNode().children.length;
|
|
|
|
+ if (moveType === 'prev') {
|
|
|
|
+ filingObj.moveFiling(nodes[0], order === 1 ? 1 : order - 1)
|
|
|
|
+ } else if (moveType === 'next') {
|
|
|
|
+ filingObj.moveFiling(nodes[0], order === max ? max : order + 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ const filingObj = new FilingObj(levelTreeSetting);
|
|
|
|
+ filingObj.analysisFiling(filing);
|
|
|
|
+ $('#add-slibing').click(() => {
|
|
|
|
+ if (!filingObj.curFiling) return;
|
|
|
|
+ if (filingObj.curFiling.source_node.is_fixed) {
|
|
|
|
+ toastr.error('固定分类不可添加同级');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ filingObj.addSiblingFiling(filingObj.curFiling);
|
|
|
|
+ });
|
|
|
|
+ $('#add-child').click(() => {
|
|
|
|
+ if (!filingObj.curFiling) return;
|
|
|
|
+ if (filingObj.curFiling.source_node.file_count > 0) {
|
|
|
|
+ toastr.error('该分类下已导入文件,不可添加子级');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ filingObj.addChildFiling(filingObj.curFiling);
|
|
|
|
+ });
|
|
|
|
+ // $('#del-filing-btn').click(() => {
|
|
|
|
+ // if (!filingObj.curFiling) return;
|
|
|
|
+ // if (filingObj.curFiling.source_node.is_fixed) {
|
|
|
|
+ // toastr.error('固定分类不可删除');
|
|
|
|
+ // return;
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // $('#del-filing').modal('show');
|
|
|
|
+ // });
|
|
|
|
+ $('#del-filing-ok').click(() => {
|
|
|
|
+ filingObj.delFiling(filingObj.curFiling, function() {
|
|
|
|
+ $('#del-filing').modal('hide');
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ $('#add-file-ok').click(() => {
|
|
|
|
+ const input = $('#upload-file');
|
|
|
|
+ filingObj.uploadFiles(input[0].files, function() {
|
|
|
|
+ $(input).val('');
|
|
|
|
+ $('#add-file').modal('hide');
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ $('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', "a[name=del-file]", function() {
|
|
|
|
+ const del = [this.getAttribute('fid')];
|
|
|
|
+ filingObj.delFiles(del);
|
|
|
|
+ });
|
|
|
|
+ $('body').on('click', "a[name=edit-file]", function() {
|
|
|
|
+ const check = $('[name=filename] input[fid]');
|
|
|
|
+ if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
|
|
|
|
+
|
|
|
|
+ const id = this.getAttribute('fid');
|
|
|
|
+ const filename = $(`[name=filename][fid=${id}]`);
|
|
|
|
+ const file = filingObj.curFiling.source_node.files.find(x => { return x.id === id });
|
|
|
|
+ filename.html(`<input type="text" class="form-control form-control-sm" maxlength="100" value="${file.filename + file.fileext}" fid="${id}">`);
|
|
|
|
+ });
|
|
|
|
+ $('body').on('blur', "[name=filename] input[fid]", function() {
|
|
|
|
+ filingObj.renameFile(this.getAttribute('fid'), this.value);
|
|
|
|
+ });
|
|
|
|
+ $('body').on('keypress', "[name=filename] input[fid]", function(e) {
|
|
|
|
+ if (e.keyCode == 13) {
|
|
|
|
+ filingObj.renameFile(this.getAttribute('fid'), this.value);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $('.page-select').click(function() {
|
|
|
|
+ const content = this.getAttribute('content');
|
|
|
|
+ switch(content) {
|
|
|
|
+ case 'pre': filingObj.prePage(); break;
|
|
|
|
+ case 'next': filingObj.nextPage(); break;
|
|
|
|
+ default: return;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $('#batch-download').click(function () {
|
|
|
|
+ const self = this;
|
|
|
|
+ const files = [];
|
|
|
|
+ const checkes = $('[name=bd-check]:checked');
|
|
|
|
+ checkes.each(function() {
|
|
|
|
+ const fid = this.getAttribute('fid');
|
|
|
|
+ const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid; });
|
|
|
|
+ file && files.push(file);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (files.length === 0) return;
|
|
|
|
+
|
|
|
|
+ $(self).attr('disabled', 'true');
|
|
|
|
+ AliOss.zipFiles(files, filingObj.curFiling.source_node.name + '.zip', (fails) => {
|
|
|
|
+ $(self).removeAttr('disabled');
|
|
|
|
+ if (fails.length === 0) {
|
|
|
|
+ toastr.success('下载成功');
|
|
|
|
+ } else {
|
|
|
|
+ toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
|
|
|
|
+ }
|
|
|
|
+ }, () => {
|
|
|
|
+ $(self).removeAttr('disabled');
|
|
|
|
+ toastr.error('批量下载失败');
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ $('#batch-del-file').on('show.bs.modal', function(e) {
|
|
|
|
+ const checkes = $('[name=bd-check]:checked');
|
|
|
|
+ if (checkes.length === 0) {
|
|
|
|
+ e.preventDefault();
|
|
|
|
+ } else {
|
|
|
|
+ for (const c of checkes) {
|
|
|
|
+ const fid = c.getAttribute('fid');
|
|
|
|
+ const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
|
|
|
|
+ if (!file) continue;
|
|
|
|
+
|
|
|
|
+ if (file.user_id !== userID) {
|
|
|
|
+ toastr.error(`文件【${file.filename + file.fileext}】不是您上传的文件,请勿删除`);
|
|
|
|
+ e.preventDefault();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $('#batch-del-file-ok').click(function() {
|
|
|
|
+ const del = [];
|
|
|
|
+ const checkes = $('[name=bd-check]:checked');
|
|
|
|
+ checkes.each(function() {
|
|
|
|
+ del.push(this.getAttribute('fid'));
|
|
|
|
+ });
|
|
|
|
+ filingObj.delFiles(del, function() {
|
|
|
|
+ $('#batch-del-file').modal('hide');
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ class RelaFileLoader {
|
|
|
|
+ constructor() {
|
|
|
|
+ const self = this;
|
|
|
|
+ // 可导入的标段
|
|
|
|
+ this.treeSetting = {
|
|
|
|
+ view: {
|
|
|
|
+ selectedMulti: false
|
|
|
|
+ },
|
|
|
|
+ data: {
|
|
|
|
+ simpleData: {
|
|
|
|
+ idKey: 'id',
|
|
|
|
+ pIdKey: 'tree_pid',
|
|
|
|
+ rootPId: '-1',
|
|
|
|
+ enable: true,
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ edit: {
|
|
|
|
+ enable: false,
|
|
|
|
+ },
|
|
|
|
+ callback: {
|
|
|
|
+ onClick: async function (e, key, node) {
|
|
|
|
+ if (this.curTender && this.curTender.id === node.id) return;
|
|
|
|
+
|
|
|
|
+ self.setCurTender(node);
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ $('body').on('click', '[name=rf-check]', function () {
|
|
|
|
+ self.selectFile(this.getAttribute('rfid'), this.checked);
|
|
|
|
+ });
|
|
|
|
+ $('#tf-type').change(function() {
|
|
|
|
+ self.selectTfType(this.value);
|
|
|
|
+ });
|
|
|
|
+ $('#tf-sub-type').change(function() {
|
|
|
|
+ self.selectTfSubType(this.value);
|
|
|
|
+ });
|
|
|
|
+ $('#tf-stage').change(function() {
|
|
|
|
+ self.selectTfStage(this.value);
|
|
|
|
+ });
|
|
|
|
+ $('#rela-file-ok').click(function() {
|
|
|
|
+ const selectFiles = self.getSelectRelaFile();
|
|
|
|
+ filingObj.relaFiles(selectFiles, function() {
|
|
|
|
+ $('#rela-file').modal('hide');
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ clearFileSelect() {
|
|
|
|
+ if (!this.tenderTree) return;
|
|
|
|
+
|
|
|
|
+ const nodes = this.tenderTree.getNodes();
|
|
|
|
+ nodes.forEach(node => {
|
|
|
|
+ const x = node.source_node;
|
|
|
|
+ x.selectFiles = [];
|
|
|
|
+ if (x.att) x.att.forEach(la => { la.checked = false });
|
|
|
|
+ if (x.advance) {
|
|
|
|
+ x.advance.forEach(a => {
|
|
|
|
+ if (a.att) a.att.forEach(aa => { aa.checked = false });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (x.stage) {
|
|
|
|
+ x.stage.forEach(s => {
|
|
|
|
+ if (s.att) s.att.forEach(sa => { sa.checked = false });
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ refreshSelectHint(){
|
|
|
|
+ if (this.curTender) {
|
|
|
|
+ $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
|
|
|
|
+ } else {
|
|
|
|
+ $('#cur-tender-hint').html('');
|
|
|
|
+ }
|
|
|
|
+ const nodes = this.tenderTree.getNodes();
|
|
|
|
+ const selectTenders = nodes.filter(x => { return x.source_node.selectFiles.length > 0; });
|
|
|
|
+ if (selectTenders.length > 0) {
|
|
|
|
+ const count = selectTenders.reduce((rst, x) => { return rst + x.source_node.selectFiles.length; }, 0);
|
|
|
|
+ $('#rela-file-hint').html(`已选择${selectTenders.length}个标段,共${count}个文件`);
|
|
|
|
+ } else {
|
|
|
|
+ $('#rela-file-hint').html('未选择标段、文件');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ selectFile(fileId, isSelect) {
|
|
|
|
+ const file = this.curFiles.find(x => { return x.rf_id == fileId });
|
|
|
|
+ if (file) {
|
|
|
|
+ file.checked = isSelect;
|
|
|
|
+ if (isSelect) {
|
|
|
|
+ this.curTender.source_node.selectFiles.push(file);
|
|
|
|
+ } else {
|
|
|
|
+ const index = this.curTender.source_node.selectFiles.findIndex(x => { return x.rf_id === file.rf_id });
|
|
|
|
+ this.curTender.source_node.selectFiles.splice(index, 1);
|
|
|
|
+ }
|
|
|
|
+ this.refreshSelectHint();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ async showRelaFile(){
|
|
|
|
+ $('#rela-filing-hint').html(`当前目录:${filingObj.getCurFilingFullPath()}`);
|
|
|
|
+ if (!this.tenderTree) {
|
|
|
|
+ const tenders = await postDataAsync('file/rela/tender', {});
|
|
|
|
+ const sortNodes = tenders.map(x => {
|
|
|
|
+ return { id: x.id, tree_pid: -1, name: x.name, source_node: x };
|
|
|
|
+ });
|
|
|
|
+ this.tenderTree = this.filingTree = $.fn.zTree.init($('#rela-tender'), this.treeSetting, sortNodes);
|
|
|
|
+ }
|
|
|
|
+ this.clearFileSelect();
|
|
|
|
+ this.refreshSelectHint();
|
|
|
|
+ const firstNode = this.filingTree.getNodes()[0];
|
|
|
|
+ if (firstNode) {
|
|
|
|
+ this.filingTree.selectNode(firstNode);
|
|
|
|
+ await this.setCurTender(firstNode);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ refreshTenderFileStage() {
|
|
|
|
+ if (this.rfType.sub_type) {
|
|
|
|
+ const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
|
|
|
|
+ const subType = type.subType ? type.subType.find(x => { return x.value === this.rfType.sub_type; }) : null;
|
|
|
|
+ if (subType) {
|
|
|
|
+ this.rfType.stage = subType.stage[0].value;
|
|
|
|
+ const html= [];
|
|
|
|
+ for (const stage of subType.stage) {
|
|
|
|
+ html.push(`<option value="${stage.value}">${stage.text}</option>`);
|
|
|
|
+ }
|
|
|
|
+ $('#tf-stage').html(html.join('')).show();
|
|
|
|
+ } else {
|
|
|
|
+ $('#tf-stage').html('').hide();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $('#tf-stage').html('').hide();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ refreshTenderFileSubType() {
|
|
|
|
+ const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
|
|
|
|
+ if (type.subType && type.subType.length > 0) {
|
|
|
|
+ this.rfType.sub_type = type.subType[0].value;
|
|
|
|
+ const html= [];
|
|
|
|
+ for (const tfst of type.subType) {
|
|
|
|
+ html.push(`<option value="${tfst.value}">${tfst.text}</option>`);
|
|
|
|
+ }
|
|
|
|
+ $('#tf-sub-type').html(html.join('')).show();
|
|
|
|
+ } else {
|
|
|
|
+ $('#tf-sub-type').html('').hide();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ refreshTenderFileType() {
|
|
|
|
+ const html= [];
|
|
|
|
+ for (const tft of this.tenderFileType) {
|
|
|
|
+ html.push(`<option value="${tft.value}">${tft.text}</option>`);
|
|
|
|
+ }
|
|
|
|
+ $('#tf-type').html(html.join(''));
|
|
|
|
+ }
|
|
|
|
+ refreshSelects(tender) {
|
|
|
|
+ this.tenderFileType = [];
|
|
|
|
+ this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
|
|
|
|
+ if (tender.stage && tender.stage.length > 0) {
|
|
|
|
+ const stages = tender.stage.map(x => { return {value: x.id, text: `第${x.order}期`}; });
|
|
|
|
+ this.tenderFileType.push({
|
|
|
|
+ value: 'stage', text: '计量期',
|
|
|
|
+ subType: [
|
|
|
|
+ { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
|
|
|
|
+ ],
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (tender.advance && tender.advance.length > 0) {
|
|
|
|
+ const advanceType = [];
|
|
|
|
+ tender.advance.forEach(x => {
|
|
|
|
+ let at = advanceType.find(y => { return y.value === x.type });
|
|
|
|
+ if (!at) {
|
|
|
|
+ at = { value: x.type, text: x.type_str, stage: [] };
|
|
|
|
+ advanceType.push(at);
|
|
|
|
+ }
|
|
|
|
+ at.stage.push({ value: x.id, text: `第${x.order}期`});
|
|
|
|
+ });
|
|
|
|
+ this.tenderFileType.push({
|
|
|
|
+ value: 'advance', text: '预付款', subType: advanceType
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ this.rfType = { type: this.tenderFileType[0].value };
|
|
|
|
+ this.refreshTenderFileType();
|
|
|
|
+ this.refreshTenderFileSubType();
|
|
|
|
+ this.refreshTenderFileStage();
|
|
|
|
+ }
|
|
|
|
+ async selectTfStage(stage){
|
|
|
|
+ this.rfType.stage = stage;
|
|
|
|
+ await this.loadFiles();
|
|
|
|
+ this.refreshFileTable();
|
|
|
|
+ }
|
|
|
|
+ async selectTfSubType(sub_type){
|
|
|
|
+ this.rfType.sub_type = sub_type;
|
|
|
|
+ this.refreshTenderFileStage();
|
|
|
|
+ await this.loadFiles();
|
|
|
|
+ this.refreshFileTable();
|
|
|
|
+ }
|
|
|
|
+ async selectTfType(type){
|
|
|
|
+ this.rfType.type = type;
|
|
|
|
+ this.refreshTenderFileSubType();
|
|
|
|
+ this.refreshTenderFileStage();
|
|
|
|
+ await this.loadFiles();
|
|
|
|
+ this.refreshFileTable();
|
|
|
|
+ }
|
|
|
|
+ refreshFileTable() {
|
|
|
|
+ const html = [];
|
|
|
|
+ const typeStr = [];
|
|
|
|
+ const selectOption = $('option:selected');
|
|
|
|
+ selectOption.each((i, x) => {
|
|
|
|
+ typeStr.push(x.innerText);
|
|
|
|
+ });
|
|
|
|
+ for (const f of this.curFiles) {
|
|
|
|
+ html.push('<tr>');
|
|
|
|
+ const checked = f.checked ? "checked" : '';
|
|
|
|
+ html.push(`<td><input type="checkbox" name="rf-check" rfid="${f.rf_id}" ${checked}></td>`);
|
|
|
|
+ html.push(`<td>${f.filename}${f.fileext}</td>`);
|
|
|
|
+ html.push(`<td>${typeStr.join(' - ')}</td>`);
|
|
|
|
+ html.push('</tr>');
|
|
|
|
+ }
|
|
|
|
+ $('#rf-files').html(html.join(''));
|
|
|
|
+ };
|
|
|
|
+ initFilesId(files){
|
|
|
|
+ const tender_id = this.curTender.id;
|
|
|
|
+ const rfType = this.rfType;
|
|
|
|
+ files.forEach((f, i) => {
|
|
|
|
+ f.rf_id = `${tender_id}-${rfType.type}-${rfType.sub_type}-${rfType.stage}-${i}`;
|
|
|
|
+ f.rf_key = {
|
|
|
|
+ tender_id, ...rfType, id: f.id,
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ async _loadRelaFiles(rfType) {
|
|
|
|
+ return await postDataAsync('file/rela/files', { tender_id: this.curTender.id, ...rfType });
|
|
|
|
+ }
|
|
|
|
+ async _loadLedgerFile() {
|
|
|
|
+ if (!this.curTender.source_node.att) this.curTender.source_node.att = await this._loadRelaFiles(this.rfType);
|
|
|
|
+ this.curFiles = this.curTender.source_node.att;
|
|
|
|
+ }
|
|
|
|
+ async _loadStageFile() {
|
|
|
|
+ const rfType = this.rfType;
|
|
|
|
+ const stage = this.curTender.source_node.stage.find(x => {
|
|
|
|
+ return x.id === rfType.stage;
|
|
|
|
+ });
|
|
|
|
+ if (!stage) {
|
|
|
|
+ this.curFiles = [];
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (!stage[this.rfType.sub_type]) stage[this.rfType.sub_type] = await this._loadRelaFiles(rfType);
|
|
|
|
+ this.curFiles = stage[this.rfType.sub_type];
|
|
|
|
+ }
|
|
|
|
+ async _loadAdvanceFile() {
|
|
|
|
+ const rfType = this.rfType;
|
|
|
|
+ const advance = this.curTender.source_node.advance.find(x => {
|
|
|
|
+ return x.id === rfType.stage;
|
|
|
|
+ });
|
|
|
|
+ if (!advance) {
|
|
|
|
+ this.curFiles = [];
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (!advance.files) advance.files = await this._loadRelaFiles(rfType);
|
|
|
|
+ this.curFiles = advance.files;
|
|
|
|
+ }
|
|
|
|
+ async loadFiles() {
|
|
|
|
+ switch (this.rfType.type) {
|
|
|
|
+ case 'ledger': await this._loadLedgerFile(); break;
|
|
|
|
+ case 'stage': await this._loadStageFile(); break;
|
|
|
|
+ case 'advance': await this._loadAdvanceFile(); break;
|
|
|
|
+ }
|
|
|
|
+ this.initFilesId(this.curFiles);
|
|
|
|
+ }
|
|
|
|
+ async setCurTender(node) {
|
|
|
|
+ this.curTender = node;
|
|
|
|
+ this.refreshSelects(node.source_node);
|
|
|
|
+ await this.loadFiles();
|
|
|
|
+ this.refreshSelectHint();
|
|
|
|
+ this.refreshFileTable();
|
|
|
|
+ }
|
|
|
|
+ getSelectRelaFile() {
|
|
|
|
+ const data = [];
|
|
|
|
+ const nodes = this.tenderTree.getNodes();
|
|
|
|
+ nodes.forEach(node => {
|
|
|
|
+ if (node.source_node.selectFiles.length === 0) return;
|
|
|
|
+
|
|
|
|
+ node.source_node.selectFiles.forEach(x => {
|
|
|
|
+ data.push({
|
|
|
|
+ filename: x.filename, fileext: x.fileext, filepath: x.filepath, filesize: x.filesize,
|
|
|
|
+ rela_info: x.rf_key,
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ const relaFileLoader = new RelaFileLoader();
|
|
|
|
+ $('#rela-file').on('show.bs.modal', function() {
|
|
|
|
+ relaFileLoader.showRelaFile(this.getAttribute('content'));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 授权相关
|
|
|
|
+ class FilingPermission {
|
|
|
|
+ constructor (setting) {
|
|
|
|
+ this.setting = setting;
|
|
|
|
+ const self = this;
|
|
|
|
+ $(setting.modal).on('show.bs.modal', () => {
|
|
|
|
+ self.loadPermission();
|
|
|
|
+ });
|
|
|
|
+ $(`${setting.modal}-ok`).click(() => {
|
|
|
|
+ self.savePermission();
|
|
|
|
+ });
|
|
|
|
+ $('[name=ftName]').click(function () {
|
|
|
|
+ const filingId = this.getAttribute('ftid');
|
|
|
|
+ self.setCurFiling(filingId);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $('.book-list').on('click', 'dt', function () {
|
|
|
|
+ const idx = $(this).find('.acc-btn').attr('data-groupid');
|
|
|
|
+ const type = $(this).find('.acc-btn').attr('data-type');
|
|
|
|
+ if (type === 'hide') {
|
|
|
|
+ $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
|
|
|
|
+ $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
|
|
|
|
+ $(this).find('.acc-btn').attr('data-type', 'show')
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
|
|
|
|
+ $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
|
|
|
|
+ $(this).find('.acc-btn').attr('data-type', 'hide')
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ });
|
|
|
|
+ $('dl').on('click', 'dd', function () {
|
|
|
|
+ const type = $(this).data('type');
|
|
|
|
+ if (type === 'all') {
|
|
|
|
+ const cid = parseInt($(this).data('id'));
|
|
|
|
+ const company = self.company.find(x => { return x.id === cid });
|
|
|
|
+ for (const u of company.users) {
|
|
|
|
+ if (u.filing_type.indexOf(self.curFiling) < 0) u.filing_type.push(self.curFiling);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ const uid = $(this).data('id');
|
|
|
|
+ const pu = self.permissionUser.find(x => { return x.id === uid });
|
|
|
|
+ if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
|
|
|
|
+ }
|
|
|
|
+ self.loadCurFiling();
|
|
|
|
+ });
|
|
|
|
+ $('#sync-filing').click(function() {
|
|
|
|
+ const selectFiling = $('[name=cbft]:checked');
|
|
|
|
+ if (selectFiling.length === 0) {
|
|
|
|
+ toastr.warning('请先选择文档类别');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const selectFilingId = [];
|
|
|
|
+ selectFiling.each((i, x) => { selectFilingId.push(x.value); });
|
|
|
|
+ self.syncFiling(self.curFiling, selectFilingId);
|
|
|
|
+ toastr.success('同步成功');
|
|
|
|
+ $('[name=cbft]').each((i, x) => { x.checked = false; });
|
|
|
|
+ });
|
|
|
|
+ $('#batch-del-filing').click(() => {
|
|
|
|
+ const selectUser = $('[name=ftu-check]:checked');
|
|
|
|
+ if (selectUser.length === 0) {
|
|
|
|
+ toastr.warning('请先选择用户');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ const userId = [];
|
|
|
|
+ selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
|
|
|
|
+ self.delFiling(self.curFiling, userId);
|
|
|
|
+ self.loadCurFiling();
|
|
|
|
+ });
|
|
|
|
+ $('body').on('click', '[name=del-filing]', function() {
|
|
|
|
+ const id = this.getAttribute('uid');
|
|
|
|
+ self.delFiling(self.curFiling, id);
|
|
|
|
+ self.loadCurFiling();
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ analysisFiling(data) {
|
|
|
|
+ this.permissionUser = data;
|
|
|
|
+ this.permissionUser.forEach(x => { x.filing_type = x.filing_type ? x.filing_type.split(',') : []; });
|
|
|
|
+
|
|
|
|
+ this.company = [];
|
|
|
|
+ for (const pu of this.permissionUser) {
|
|
|
|
+ let c = this.company.find(x => { return x.company === pu.company });
|
|
|
|
+ if (!c) {
|
|
|
|
+ c = { id: this.company.length + 1, company: pu.company, users: [] };
|
|
|
|
+ this.company.push(c);
|
|
|
|
+ }
|
|
|
|
+ c.users.push(pu);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ loadCurFiling() {
|
|
|
|
+ const html = [];
|
|
|
|
+ for (const f of this.permissionUser) {
|
|
|
|
+ if (f.filing_type.indexOf(this.curFiling) < 0) continue;
|
|
|
|
+ html.push('<tr>');
|
|
|
|
+ html.push(`<td><input uid="${f.id}" type="checkbox" name="ftu-check"></td>`);
|
|
|
|
+ html.push(`<td>${f.name}</td>`);
|
|
|
|
+ html.push(`<td>${moment(f.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
|
|
|
|
+ html.push(`<td>${f.file_permission}</td>`);
|
|
|
|
+ html.push(`<td><button class="btn btn-sm btn-outline-danger" uid="${f.id}" name="del-filing">移除</button></td>`);
|
|
|
|
+ html.push('</tr>');
|
|
|
|
+ }
|
|
|
|
+ $(this.setting.list).html(html.join(''));
|
|
|
|
+ }
|
|
|
|
+ setCurFiling(filingType) {
|
|
|
|
+ this.curFiling = filingType;
|
|
|
|
+ $('[name=ftName]').removeClass('bg-warning-50');
|
|
|
|
+ $(`[ftid=${filingType}]`).addClass('bg-warning-50');
|
|
|
|
+ this.loadCurFiling();
|
|
|
|
+ }
|
|
|
|
+ loadPermissionUser() {
|
|
|
|
+ const html = [];
|
|
|
|
+ for (const c of this.company) {
|
|
|
|
+ html.push(`<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${c.id}" data-type="hide"><i class="fa fa-plus-square"></i></a> ${c.company}</dt>`);
|
|
|
|
+ html.push(`<div class="dd-content" data-toggleid="${c.id}">`);
|
|
|
|
+ html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${c.id}" data-type="all"><p class="mb-0 d-flex"><span class="text-primary">添加单位下全部用户</span></p></dd>`);
|
|
|
|
+ for (const u of c.users) {
|
|
|
|
+ html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${u.id}" >`);
|
|
|
|
+ html.push(`<p class="mb-0 d-flex"><span class="text-primary">${u.name}</span><span class="ml-auto">${u.mobile}</span></p>`);
|
|
|
|
+ html.push(`<span class="text-muted">${u.role}</span>`);
|
|
|
|
+ html.push(`</dd>`);
|
|
|
|
+ }
|
|
|
|
+ html.push('</div>');
|
|
|
|
+ }
|
|
|
|
+ $('#puList').html(html.join(''));
|
|
|
|
+ }
|
|
|
|
+ loadPermission() {
|
|
|
|
+ const self = this;
|
|
|
|
+ postData('permission', {}, function(result) {
|
|
|
|
+ self.analysisFiling(result);
|
|
|
|
+ if (!self.curFiling) {
|
|
|
|
+ self.setCurFiling($('[name=ftName]').attr('ftid'));
|
|
|
|
+ } else {
|
|
|
|
+ self.loadCurFiling();
|
|
|
|
+ }
|
|
|
|
+ self.loadPermissionUser();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ syncFiling(sourceId, targetIds) {
|
|
|
|
+ for (const pu of this.permissionUser) {
|
|
|
|
+ if (pu.filing_type.indexOf(sourceId) >= 0) {
|
|
|
|
+ targetIds.forEach(id => {
|
|
|
|
+ if (pu.filing_type.indexOf(id) < 0) pu.filing_type.push(id);
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ targetIds.forEach(id => {
|
|
|
|
+ if (pu.filing_type.indexOf(id) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(id), 1);
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ delFiling(filingId, userId) {
|
|
|
|
+ const userIds = userId instanceof Array ? userId : [userId];
|
|
|
|
+ for (const id of userIds) {
|
|
|
|
+ const pu = this.permissionUser.find(x => { return x.id === id });
|
|
|
|
+ if (!pu) continue;
|
|
|
|
+ if (pu.filing_type.indexOf(filingId) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(filingId), 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ savePermission() {
|
|
|
|
+ const self = this;
|
|
|
|
+ const data = this.permissionUser.map(x => {
|
|
|
|
+ return { id: x.id, filing_type: x.filing_type.join(',') };
|
|
|
|
+ });
|
|
|
|
+ postData('permission/save', data, function(result) {
|
|
|
|
+ $(self.setting.modal).modal('hide');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ const filingPermission = new FilingPermission({
|
|
|
|
+ modal: '#filing-permission',
|
|
|
|
+ list: '#filing-valid',
|
|
|
|
+ });
|
|
|
|
+});
|