file_detail.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. $(document).ready(function() {
  2. autoFlashHeight();
  3. $('#filing').height($(".sjs-height-0").height() - $('#add-slibing').parent().parent().height() - 10);
  4. class FilingObj {
  5. constructor(setting) {
  6. // 原始数据整理后的树结构,用来整理zTree显示
  7. this.dragTree = createDragTree({
  8. id: 'id',
  9. pid: 'tree_pid',
  10. level: 'tree_level',
  11. order: 'tree_order',
  12. rootId: '-1'
  13. });
  14. // 界面显示的zTree
  15. this.setting = setting;
  16. this.filingTree = null;
  17. this.pageCount = 15;
  18. this.expandKey = 'filing-' + window.location.pathname.split('/')[2];
  19. const cache = getLocalCache(this.expandKey);
  20. this.expandCache = cache ? _.uniq(cache.split(',')) : [];
  21. this.curFilingKey = 'cur-filing-' + window.location.pathname.split('/')[2];
  22. $('#filing').height($(".sjs-height-0").height()-$('.d-flex',".sjs-height-0").height());
  23. }
  24. calcTotalFileCount() {
  25. this.dragTree.recursiveFun(this.dragTree.children, x => {
  26. if (x.children && x.children.length > 0) {
  27. x.total_file_count = x.children.reduce((pre, c) => {
  28. return pre + c.total_file_count
  29. }, 0);
  30. // x.total_file_count = x.children.map(y => {
  31. // return y.total_file_count;
  32. // }).reduce((pre, value) => {
  33. // return pre + value
  34. // }, 0);
  35. } else {
  36. x.total_file_count = x.file_count;
  37. }
  38. });
  39. }
  40. _loadFilingSourceNode() {
  41. const self = this;
  42. const loadChildren = function(children) {
  43. for (const child of children) {
  44. if (child.children && child.children.length > 0) loadChildren(child.children);
  45. child.source_node = self.dragTree.getItems(child.id);
  46. }
  47. };
  48. const nodes = this.filingTree.getNodes();
  49. loadChildren(nodes);
  50. }
  51. loadFiling() {
  52. const self = this;
  53. if (this.filingTree) $.fn.zTree.destroy(this.setting.treeId);
  54. const sortNodes = this.dragTree.nodes.map(x => {
  55. const result = {
  56. id: x.id,
  57. tree_pid: x.tree_pid,
  58. name: x.name + (x.total_file_count > 0 ? `(${x.total_file_count})` : ''),
  59. spid: x.spid,
  60. };
  61. if (x.is_fixed) result.isParent = true;
  62. if (x.is_folder || x.is_fixed) result.open = self.expandCache.indexOf(result.id) >= 0;
  63. return result;
  64. });
  65. this.filingTree = $.fn.zTree.init($('#filing'), this.setting, sortNodes);
  66. this._loadFilingSourceNode();
  67. const curCache = getLocalCache(this.curFilingKey);
  68. const curNode = curCache ? this.filingTree.getNodeByParam('id', curCache) : null;
  69. if (curNode){
  70. this.filingTree.selectNode(curNode);
  71. filingObj.setCurFiling(curNode);
  72. }
  73. }
  74. analysisFiling(data) {
  75. this.dragTree.loadDatas(data);
  76. this.calcTotalFileCount();
  77. this.loadFiling();
  78. }
  79. _getFileNameHtml(file) {
  80. 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>` : '';
  81. const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
  82. 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>`;
  83. 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>` : '';
  84. return `<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>`;
  85. }
  86. _getEditFileNameHtml(file) {
  87. const inputHtml = `<input type="text" class="form-control form-control-sm form-control-width" maxlength="100" value="${file.filename + file.fileext}" fid="${file.id}">`;
  88. const btnHtml = `<div class="btn-group-table" style="display: none;"><a href="javascript: void(0)" class="mr-1" name="edit-file-ok"><i class="fa fa-check fa-fw"></i></a><a href="javascript: void(0)" class="mr-1" name="edit-file-cancel"><i class="fa fa-remove fa-fw"></i></a></div>`;
  89. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  90. }
  91. _getFileHtml(file) {
  92. const html = [];
  93. html.push(`<tr fid="${file.id}">`);
  94. html.push(`<td class="text-center"><input type="checkbox" name="bd-check" fid="${file.id}"></td>`);
  95. html.push(`<td fid="${file.id}">${this._getFileNameHtml(file)}</td>`);
  96. html.push(`<td class="text-center">${file.user_name}</td>`);
  97. html.push(`<td class="text-center">${moment(file.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  98. html.push(`<td class="text-center">${file.fileext_str}</td>`);
  99. html.push('</tr>');
  100. return html.join('');
  101. }
  102. refreshFilesTable() {
  103. const html = [];
  104. const files = this.curFiling.source_node.files;
  105. if (!files || files.length === 0) {
  106. $('#file-list').html('');
  107. return;
  108. }
  109. const startIndex = (this.curPage - 1)*this.pageCount;
  110. const endIndex = this.curPage*this.pageCount;
  111. for (const [i, f] of files.entries()) {
  112. if (i < startIndex || i >= endIndex) continue;
  113. html.push(this._getFileHtml(f));
  114. }
  115. $('#file-list').html(html.join(''));
  116. }
  117. refreshPages() {
  118. if (!filingObj.curFiling) return;
  119. filingObj.curTotalPage = Math.ceil(filingObj.curFiling.source_node.file_count / this.pageCount);
  120. $('#curPage').html(filingObj.curPage);
  121. $('#curTotalPage').html(filingObj.curTotalPage);
  122. if (filingObj.curTotalPage > 1) {
  123. $('#showPage').show();
  124. } else {
  125. $('#showPage').hide();
  126. }
  127. }
  128. async loadFiles(node, page) {
  129. if (node.source_node.children && node.source_node.children.length > 0) return;
  130. if (!node.source_node.files) node.source_node.files = [];
  131. if (!node.source_node.file_count) return;
  132. if (node.source_node.files && node.source_node.files.length === node.source_node.file_count) return;
  133. const needFiles = Math.min(page*this.pageCount, node.source_node.file_count);
  134. if (node.source_node.files && needFiles <= node.source_node.files.length) return;
  135. const files = await postDataAsync('file/load', { filing_id: node.id, page, count: this.pageCount });
  136. files.forEach(x => {
  137. const file = node.source_node.files.find(f => {return x.id === f.id; });
  138. if (file) {
  139. Object.assign(file, x);
  140. } else {
  141. node.source_node.files.push(x);
  142. }
  143. });
  144. node.source_node.files.sort((x, y) => {
  145. return x.create_time - y.create_time;
  146. });
  147. }
  148. addSiblingFiling(node) {
  149. const self = this;
  150. postData('filing/add', { tree_pid: node.tree_pid, tree_pre_id: node.id }, function(result) {
  151. const refreshData = self.dragTree.loadPostData(result);
  152. const newNode = refreshData.create[0];
  153. const nodes = self.filingTree.addNodes(node.getParentNode(), node.getIndex() + 1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid }]);
  154. nodes[0].source_node = newNode;
  155. });
  156. }
  157. addChildFiling(node) {
  158. const self = this;
  159. postData('filing/add', { tree_pid: node.id }, function(result) {
  160. const refreshData = self.dragTree.loadPostData(result);
  161. const newNode = refreshData.create[0];
  162. const nodes = self.filingTree.addNodes(node, -1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid}]);
  163. nodes[0].source_node = newNode;
  164. });
  165. }
  166. delFiling(node, callback) {
  167. const self = this;
  168. postData('filing/del', { id: node.id }, function(result) {
  169. self.dragTree.loadPostData(result);
  170. self.filingTree.removeNode(node);
  171. if (callback) callback();
  172. });
  173. }
  174. async renameFiling(node, newName) {
  175. const result = await postDataAsync('filing/save', { id: node.id, name: newName });
  176. node.source_node.name = newName;
  177. node.name = node.source_node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
  178. return result;
  179. }
  180. updateFilingFileCount(filing, count) {
  181. let differ = count - filing.source_node.file_count;
  182. filing.source_node.file_count = count;
  183. filing.source_node.total_file_count = count;
  184. filing.name = filing.source_node.name + (filing.source_node.total_file_count > 0 ? `(${filing.source_node.total_file_count})` : '');
  185. filingObj.filingTree.updateNode(filing);
  186. let parent = filing.getParentNode();
  187. while (!!parent) {
  188. parent.source_node.total_file_count = parent.source_node.total_file_count + differ;
  189. parent.name = parent.source_node.name + (parent.source_node.total_file_count > 0 ? `(${parent.source_node.total_file_count})` : '');
  190. filingObj.filingTree.updateNode(parent);
  191. parent = parent.getParentNode();
  192. }
  193. }
  194. uploadFiles(files, callback) {
  195. const formData = new FormData();
  196. formData.append('filing_id', filingObj.curFiling.id);
  197. for (const file of files) {
  198. if (file === undefined) {
  199. toastr.error('未选择上传文件。');
  200. return false;
  201. }
  202. if (file.size > 50 * 1024 * 1024) {
  203. toastr.error('上传文件大小超过50MB。');
  204. return false;
  205. }
  206. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  207. if (whiteList.indexOf(fileext) === -1) {
  208. toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
  209. return false;
  210. }
  211. formData.append('size', file.size);
  212. formData.append('file[]', file);
  213. }
  214. postDataWithFile('file/upload', formData, function (data) {
  215. filingObj.curFiling.source_node.files.unshift(...data.files);
  216. filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
  217. filingObj.refreshFilesTable();
  218. filingObj.refreshPages();
  219. if (callback) callback();
  220. });
  221. }
  222. delFiles(files, callback) {
  223. postData('file/del', { del: files }, async function(data) {
  224. for (const id of data.del) {
  225. const fIndex = filingObj.curFiling.source_node.files.findIndex(x => { return x.id === id });
  226. if (fIndex >= 0) filingObj.curFiling.source_node.files.splice(fIndex, 1);
  227. }
  228. filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
  229. await filingObj.loadFiles(filingObj.curFiling, filingObj.curPage);
  230. filingObj.refreshFilesTable();
  231. filingObj.refreshPages();
  232. if (callback) callback();
  233. });
  234. }
  235. renameFile(fileId, filename) {
  236. const self = this;
  237. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fileId });
  238. if (!file) return;
  239. const td = $(`td[fid=${fileId}]`);
  240. if (filename === file.filename + file.fileext) {
  241. td.html(this._getFileNameHtml(file));
  242. return;
  243. }
  244. postData('file/save', { id: fileId, filename }, function(data) {
  245. file.filename = data.filename;
  246. file.fileext = data.fileext;
  247. td.html(self._getFileNameHtml(file));
  248. }, function() {
  249. td.html(self._getFileNameHtml(file));
  250. });
  251. }
  252. relaFiles(files, callback) {
  253. postData('file/rela', { filing_id: this.curFiling.id, files: files }, async function(data) {
  254. filingObj.curFiling.source_node.files.unshift(...data.files);
  255. filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
  256. filingObj.refreshFilesTable();
  257. filingObj.refreshPages();
  258. if (callback) callback();
  259. });
  260. }
  261. async setCurFiling(node) {
  262. filingObj.curFiling = node;
  263. filingObj.curPage = 1;
  264. filingObj.refreshPages();
  265. if (filingObj.curFiling.source_node.children && filingObj.curFiling.source_node.children.length > 0) {
  266. $('#file-view').hide();
  267. } else {
  268. $('#file-view').show();
  269. await filingObj.loadFiles(node, 1);
  270. filingObj.refreshFilesTable();
  271. }
  272. if (filingObj.curFiling.source_node.filing_type === 5) {
  273. $('#rela-file-btn').show();
  274. } else {
  275. $('#rela-file-btn').hide();
  276. }
  277. setLocalCache(this.curFilingKey, filingObj.curFiling.id);
  278. }
  279. prePage() {
  280. if (this.curPage === 1) return;
  281. this.curPage = this.curPage - 1;
  282. this.refreshPages();
  283. this.refreshFilesTable();
  284. }
  285. async nextPage() {
  286. if (this.curPage === this.curTotalPage) return;
  287. await filingObj.loadFiles(this.curFiling, this.curPage + 1);
  288. this.curPage = this.curPage + 1;
  289. this.refreshPages();
  290. this.refreshFilesTable();
  291. }
  292. getCurFilingFullPath(){
  293. let cur = filingObj.curFiling;
  294. const result = [];
  295. while (cur) {
  296. result.unshift(cur.source_node.name);
  297. cur = cur.getParentNode();
  298. }
  299. return result.join('/');
  300. }
  301. expandFiling(node, expand) {
  302. if (expand) {
  303. this.expandCache.push(node.id);
  304. } else{
  305. this.expandCache = this.expandCache.filter(x => { return x !== node.id });
  306. }
  307. setLocalCache(this.expandKey, this.expandCache.join(','));
  308. }
  309. expandByLevel(level) {
  310. this.expandByCustom(x => {
  311. return x.level + 1 < level;
  312. })
  313. }
  314. expandByCustom(fun) {
  315. const self = this;
  316. const expandCache = [];
  317. const expandChildren = function(children) {
  318. for (const child of children) {
  319. if (!child.children || child.children.length === 0) continue;
  320. const expand = fun(child);
  321. if (expand) expandCache.push(child.id);
  322. self.filingTree.expandNode(child, expand, false, false);
  323. expandChildren(child.children);
  324. }
  325. };
  326. const nodes = this.filingTree.getNodes();
  327. expandChildren(nodes);
  328. this.expandCache = expandCache;
  329. setLocalCache(this.expandKey, this.expandCache.join(','));
  330. }
  331. moveFiling(node, tree_pid, tree_order) {
  332. if (tree_pid === node.source_node.tree_pid && tree_order === node.source_node.tree_order) return;
  333. const self = this;
  334. postData('filing/move', { id: node.id, tree_pid, tree_order }, function(result) {
  335. const refresh = self.dragTree.loadPostData(result);
  336. self.calcTotalFileCount();
  337. const updated = [];
  338. for (const u of refresh.update) {
  339. const node = self.filingTree.getNodeByParam('id', u.id);
  340. if (node) {
  341. const path = node.getPath();
  342. for (const p of path) {
  343. if (updated.indexOf(p.id) >= 0) continue;
  344. p.name = p.source_node.name + (p.source_node.total_file_count > 0 ? `(${p.source_node.total_file_count})` : '');
  345. filingObj.filingTree.updateNode(p);
  346. updated.push(p.id);
  347. }
  348. }
  349. }
  350. });
  351. }
  352. }
  353. const levelTreeSetting = {
  354. treeId: 'filing',
  355. view: {
  356. selectedMulti: false
  357. },
  358. data: {
  359. simpleData: {
  360. idKey: 'id',
  361. pIdKey: 'tree_pid',
  362. rootPId: '-1',
  363. enable: true,
  364. }
  365. },
  366. edit: {
  367. enable: true,
  368. showRemoveBtn: function(treeId, treeNode) {
  369. if (!canFiling) return false;
  370. return !treeNode.source_node.is_fixed;
  371. },
  372. showRenameBtn: function(treeId, treeNode) {
  373. if (!canFiling) return false;
  374. return !treeNode.source_node.is_fixed;
  375. },
  376. renameTitle: '编辑',
  377. drag: {
  378. isCopy: false,
  379. isMove: true,
  380. pre: true,
  381. next: true,
  382. inner: false,
  383. },
  384. editNameSelectAll: true,
  385. },
  386. callback: {
  387. onClick: async function (e, key, node) {
  388. if (filingObj.curFiling && filingObj.curFiling.id === node.id) return;
  389. filingObj.setCurFiling(node);
  390. },
  391. beforeEditName: function(key, node) {
  392. node.name = node.source_node.name;
  393. },
  394. beforeRename: async function(key, node, newName, isCancel) {
  395. if (!isCancel) await filingObj.renameFiling(node, newName);
  396. return true;
  397. },
  398. onRename: function(e, key, node, isCancel) {
  399. node.name = node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
  400. filingObj.filingTree.updateNode(node);
  401. },
  402. beforeRemove: function(e, key, node, isCancel) {
  403. $('#del-filing').modal('show');
  404. return false;
  405. },
  406. onExpand(e, key, node) {
  407. filingObj.expandFiling(node, true);
  408. },
  409. onCollapse: function(e, key, node) {
  410. filingObj.expandFiling(node, false);
  411. },
  412. beforeDrop: function(key, nodes, target, moveType, isCopy) {
  413. if (!canFiling) return false;
  414. if (!target) return false;
  415. if (nodes[0].level < 1) {
  416. toastr.error('顶层节点请勿移动');
  417. return false;
  418. }
  419. if (nodes[0].source_node.filing_type !== target.source_node.filing_type) {
  420. toastr.error('请勿跨越最顶层节点移动');
  421. return false;
  422. }
  423. if (target.source_node.file_count > 0 && moveType === 'inner') {
  424. toastr.error(`节点[${target.source_node.name}]下存在文件,不可添加子级`);
  425. return false;
  426. }
  427. const order = nodes[0].getIndex() + 1;
  428. const targetOrder = target.getIndex() + 1;
  429. const targetMax = target.getParentNode().children.length;
  430. if (moveType === 'prev') {
  431. if (target.tree_pid === nodes[0].tree_pid) {
  432. if (targetOrder > order) {
  433. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder - 1);
  434. } else {
  435. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
  436. }
  437. } else {
  438. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
  439. }
  440. } else if (moveType === 'next') {
  441. if (target.tree_pid === nodes[0].tree_pid) {
  442. if (targetOrder < order) {
  443. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder + 1);
  444. } else {
  445. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder);
  446. }
  447. } else {
  448. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder + 1);
  449. }
  450. } else if (moveType === 'inner') {
  451. filingObj.moveFiling(nodes[0], target.tree_id, targetMax + 1);
  452. }
  453. }
  454. }
  455. };
  456. const filingObj = new FilingObj(levelTreeSetting);
  457. filingObj.analysisFiling(filing);
  458. $('#add-slibing').click(() => {
  459. if (!filingObj.curFiling) return;
  460. if (filingObj.curFiling.source_node.is_fixed) {
  461. toastr.error('固定分类不可添加同级');
  462. return;
  463. }
  464. filingObj.addSiblingFiling(filingObj.curFiling);
  465. });
  466. $('#add-child').click(() => {
  467. if (!filingObj.curFiling) return;
  468. if (filingObj.curFiling.source_node.file_count > 0) {
  469. toastr.error('该分类下已导入文件,不可添加子级');
  470. return;
  471. }
  472. filingObj.addChildFiling(filingObj.curFiling);
  473. });
  474. // $('#del-filing-btn').click(() => {
  475. // if (!filingObj.curFiling) return;
  476. // if (filingObj.curFiling.source_node.is_fixed) {
  477. // toastr.error('固定分类不可删除');
  478. // return;
  479. // }
  480. //
  481. // $('#del-filing').modal('show');
  482. // });
  483. $('#del-filing-ok').click(() => {
  484. filingObj.delFiling(filingObj.curFiling, function() {
  485. $('#del-filing').modal('hide');
  486. });
  487. });
  488. $('#add-file-ok').click(() => {
  489. const input = $('#upload-file');
  490. filingObj.uploadFiles(input[0].files, function() {
  491. $(input).val('');
  492. $('#add-file').modal('hide');
  493. });
  494. });
  495. $('body').on('mouseenter', ".table-file", function(){
  496. $(this).children(".btn-group-table").css("display","block");
  497. });
  498. $('body').on('mouseleave', ".table-file", function(){
  499. $(this).children(".btn-group-table").css("display","none");
  500. });
  501. $('body').on('click', "a[name=del-file]", function() {
  502. const del = [this.getAttribute('fid')];
  503. filingObj.delFiles(del);
  504. });
  505. $('body').on('click', "a[name=edit-file]", function() {
  506. const check = $('[name=filename] input[fid]');
  507. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  508. const id = this.getAttribute('fid');
  509. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === id });
  510. $(`td[fid=${id}]`).html(filingObj._getEditFileNameHtml(file));
  511. });
  512. $('body').on('click', "a[name=edit-file-ok]", function() {
  513. const td = $(this).parent().parent().parent();
  514. const fid = td.attr('fid');
  515. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  516. if (!file) return;
  517. filingObj.renameFile(fid, $('input', td).val());
  518. });
  519. $('body').on('click', "a[name=edit-file-cancel]", function() {
  520. const td = $(this).parent().parent().parent();
  521. const fid = td.attr('fid');
  522. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  523. if (!file) return;
  524. td.html(filingObj._getFileNameHtml(file));
  525. });
  526. // $('body').on('blur', "[name=filename] input[fid]", function() {
  527. // filingObj.renameFile(this.getAttribute('fid'), this.value);
  528. // });
  529. // $('body').on('keypress', "[name=filename] input[fid]", function(e) {
  530. // if (e.keyCode == 13) {
  531. // filingObj.renameFile(this.getAttribute('fid'), this.value);
  532. // }
  533. // });
  534. $('.page-select').click(function() {
  535. const content = this.getAttribute('content');
  536. switch(content) {
  537. case 'pre': filingObj.prePage(); break;
  538. case 'next': filingObj.nextPage(); break;
  539. default: return;
  540. }
  541. });
  542. $('#batch-download').click(function () {
  543. const self = this;
  544. const files = [];
  545. const checkes = $('[name=bd-check]:checked');
  546. checkes.each(function() {
  547. const fid = this.getAttribute('fid');
  548. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid; });
  549. file && files.push(file);
  550. });
  551. if (files.length === 0) return;
  552. $(self).attr('disabled', 'true');
  553. AliOss.zipFiles(files, filingObj.curFiling.source_node.name + '.zip', (fails) => {
  554. $(self).removeAttr('disabled');
  555. if (fails.length === 0) {
  556. toastr.success('下载成功');
  557. } else {
  558. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  559. }
  560. }, () => {
  561. $(self).removeAttr('disabled');
  562. toastr.error('批量下载失败');
  563. });
  564. });
  565. $('#batch-del-file-btn').click(() => {
  566. const checkes = $('[name=bd-check]:checked');
  567. if (checkes.length === 0) {
  568. return;
  569. } else {
  570. for (const c of checkes) {
  571. const fid = c.getAttribute('fid');
  572. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  573. if (!file) continue;
  574. if (file.user_id !== userID) {
  575. toastr.error(`文件【${file.filename + file.fileext}】不是您上传的文件,请勿删除`);
  576. return;
  577. }
  578. }
  579. }
  580. $('#batch-del-file').modal('show');
  581. });
  582. $('#batch-del-file-ok').click(function() {
  583. const del = [];
  584. const checkes = $('[name=bd-check]:checked');
  585. checkes.each(function() {
  586. del.push(this.getAttribute('fid'));
  587. });
  588. filingObj.delFiles(del, function() {
  589. $('#batch-del-file').modal('hide');
  590. });
  591. });
  592. class RelaFileLoader {
  593. constructor() {
  594. const self = this;
  595. // 可导入的标段
  596. this.treeSetting = {
  597. view: {
  598. selectedMulti: false
  599. },
  600. data: {
  601. simpleData: {
  602. idKey: 'id',
  603. pIdKey: 'tree_pid',
  604. rootPId: '-1',
  605. enable: true,
  606. }
  607. },
  608. edit: {
  609. enable: false,
  610. },
  611. callback: {
  612. onClick: async function (e, key, node) {
  613. if (this.curTender && this.curTender.id === node.id) return;
  614. self.setCurTender(node);
  615. },
  616. }
  617. };
  618. $('body').on('click', '[name=rf-check]', function () {
  619. self.selectFile(this.getAttribute('rfid'), this.checked);
  620. });
  621. $('#tf-type').change(function() {
  622. self.selectTfType(this.value);
  623. });
  624. $('#tf-sub-type').change(function() {
  625. self.selectTfSubType(this.value);
  626. });
  627. $('#tf-stage').change(function() {
  628. self.selectTfStage(this.value);
  629. });
  630. $('#rela-file-ok').click(function() {
  631. const selectFiles = self.getSelectRelaFile();
  632. filingObj.relaFiles(selectFiles, function() {
  633. $('#rela-file').modal('hide');
  634. });
  635. });
  636. }
  637. clearFileSelect() {
  638. if (!this.tenderTree) return;
  639. const nodes = this.tenderTree.getNodes();
  640. nodes.forEach(node => {
  641. const x = node.source_node;
  642. x.selectFiles = [];
  643. if (x.att) x.att.forEach(la => { la.checked = false });
  644. if (x.advance) {
  645. x.advance.forEach(a => {
  646. if (a.files) a.files.forEach(aa => { aa.checked = false });
  647. });
  648. }
  649. if (x.stage) {
  650. x.stage.forEach(s => {
  651. if (s.att) s.att.forEach(sa => { sa.checked = false });
  652. })
  653. }
  654. });
  655. }
  656. refreshSelectHint(){
  657. if (this.curTender) {
  658. $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
  659. } else {
  660. $('#cur-tender-hint').html('');
  661. }
  662. const nodes = this.tenderTree.getNodes();
  663. const selectTenders = nodes.filter(x => { return x.source_node.selectFiles.length > 0; });
  664. if (selectTenders.length > 0) {
  665. const count = selectTenders.reduce((rst, x) => { return rst + x.source_node.selectFiles.length; }, 0);
  666. $('#rela-file-hint').html(`已选择${selectTenders.length}个标段,共${count}个文件`);
  667. } else {
  668. $('#rela-file-hint').html('未选择标段、文件');
  669. }
  670. }
  671. selectFile(fileId, isSelect) {
  672. const file = this.curFiles.find(x => { return x.rf_id == fileId });
  673. if (file) {
  674. file.checked = isSelect;
  675. if (isSelect) {
  676. this.curTender.source_node.selectFiles.push(file);
  677. } else {
  678. const index = this.curTender.source_node.selectFiles.findIndex(x => { return x.rf_id === file.rf_id });
  679. this.curTender.source_node.selectFiles.splice(index, 1);
  680. }
  681. this.refreshSelectHint();
  682. }
  683. }
  684. async showRelaFile(){
  685. $('#rela-filing-hint').html(`当前目录:${filingObj.getCurFilingFullPath()}`);
  686. if (!this.tenderTree) {
  687. const tenders = await postDataAsync('file/rela/tender', {});
  688. const sortNodes = tenders.map(x => {
  689. return { id: x.id, tree_pid: -1, name: x.name, source_node: x };
  690. });
  691. this.tenderTree = this.filingTree = $.fn.zTree.init($('#rela-tender'), this.treeSetting, sortNodes);
  692. }
  693. this.clearFileSelect();
  694. this.refreshSelectHint();
  695. const firstNode = this.filingTree.getNodes()[0];
  696. if (firstNode) {
  697. this.filingTree.selectNode(firstNode);
  698. await this.setCurTender(firstNode);
  699. }
  700. }
  701. refreshTenderFileStage() {
  702. if (this.rfType.sub_type) {
  703. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
  704. const subType = type.subType ? type.subType.find(x => { return x.value === this.rfType.sub_type; }) : null;
  705. if (subType) {
  706. this.rfType.stage = subType.stage[0].value;
  707. const html= [];
  708. for (const stage of subType.stage) {
  709. html.push(`<option value="${stage.value}">${stage.text}</option>`);
  710. }
  711. $('#tf-stage').html(html.join('')).show();
  712. } else {
  713. $('#tf-stage').html('').hide();
  714. }
  715. } else {
  716. $('#tf-stage').html('').hide();
  717. }
  718. }
  719. refreshTenderFileSubType() {
  720. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
  721. if (type.subType && type.subType.length > 0) {
  722. this.rfType.sub_type = type.subType[0].value;
  723. const html= [];
  724. for (const tfst of type.subType) {
  725. html.push(`<option value="${tfst.value}">${tfst.text}</option>`);
  726. }
  727. $('#tf-sub-type').html(html.join('')).show();
  728. } else {
  729. $('#tf-sub-type').html('').hide();
  730. }
  731. }
  732. refreshTenderFileType() {
  733. const html= [];
  734. for (const tft of this.tenderFileType) {
  735. html.push(`<option value="${tft.value}">${tft.text}</option>`);
  736. }
  737. $('#tf-type').html(html.join(''));
  738. }
  739. refreshSelects(tender) {
  740. this.tenderFileType = [];
  741. this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
  742. if (tender.stage && tender.stage.length > 0) {
  743. const stages = tender.stage.map(x => { return {value: x.id, text: `第${x.order}期`}; });
  744. this.tenderFileType.push({
  745. value: 'stage', text: '计量期',
  746. subType: [
  747. { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
  748. ],
  749. });
  750. }
  751. if (tender.advance && tender.advance.length > 0) {
  752. const advanceType = [];
  753. tender.advance.forEach(x => {
  754. let at = advanceType.find(y => { return y.value === x.type + '' });
  755. if (!at) {
  756. at = { value: x.type + '', text: x.type_str, stage: [] };
  757. advanceType.push(at);
  758. }
  759. at.stage.push({ value: x.id, text: `第${x.order}期`});
  760. });
  761. this.tenderFileType.push({
  762. value: 'advance', text: '预付款', subType: advanceType
  763. });
  764. }
  765. this.rfType = { type: this.tenderFileType[0].value };
  766. this.refreshTenderFileType();
  767. this.refreshTenderFileSubType();
  768. this.refreshTenderFileStage();
  769. }
  770. async selectTfStage(stage){
  771. this.rfType.stage = stage;
  772. await this.loadFiles();
  773. this.refreshFileTable();
  774. }
  775. async selectTfSubType(sub_type){
  776. this.rfType.sub_type = sub_type;
  777. this.refreshTenderFileStage();
  778. await this.loadFiles();
  779. this.refreshFileTable();
  780. }
  781. async selectTfType(type){
  782. this.rfType.type = type;
  783. this.refreshTenderFileSubType();
  784. this.refreshTenderFileStage();
  785. await this.loadFiles();
  786. this.refreshFileTable();
  787. }
  788. refreshFileTable() {
  789. const html = [];
  790. const typeStr = [];
  791. const selectOption = $('option:selected');
  792. selectOption.each((i, x) => {
  793. typeStr.push(x.innerText);
  794. });
  795. for (const f of this.curFiles) {
  796. html.push('<tr>');
  797. const checked = f.checked ? "checked" : '';
  798. html.push(`<td><input type="checkbox" name="rf-check" rfid="${f.rf_id}" ${checked}></td>`);
  799. html.push(`<td>${f.filename}${f.fileext}</td>`);
  800. html.push(`<td>${typeStr.join(' - ')}</td>`);
  801. html.push('</tr>');
  802. }
  803. $('#rf-files').html(html.join(''));
  804. };
  805. initFilesId(files){
  806. const tender_id = this.curTender.id;
  807. const rfType = this.rfType;
  808. files.forEach((f, i) => {
  809. f.rf_id = `${tender_id}-${rfType.type}-${rfType.sub_type}-${rfType.stage}-${i}`;
  810. f.rf_key = {
  811. tender_id, ...rfType, id: f.id,
  812. };
  813. });
  814. }
  815. async _loadRelaFiles(rfType) {
  816. return await postDataAsync('file/rela/files', { tender_id: this.curTender.id, ...rfType });
  817. }
  818. async _loadLedgerFile() {
  819. if (!this.curTender.source_node.att) this.curTender.source_node.att = await this._loadRelaFiles(this.rfType);
  820. this.curFiles = this.curTender.source_node.att;
  821. }
  822. async _loadStageFile() {
  823. const rfType = this.rfType;
  824. const stage = this.curTender.source_node.stage.find(x => {
  825. return x.id == rfType.stage;
  826. });
  827. if (!stage) {
  828. this.curFiles = [];
  829. return;
  830. }
  831. if (!stage[this.rfType.sub_type]) stage[this.rfType.sub_type] = await this._loadRelaFiles(rfType);
  832. this.curFiles = stage[this.rfType.sub_type];
  833. }
  834. async _loadAdvanceFile() {
  835. const rfType = this.rfType;
  836. const advance = this.curTender.source_node.advance.find(x => {
  837. return x.id == rfType.stage;
  838. });
  839. if (!advance) {
  840. this.curFiles = [];
  841. return;
  842. }
  843. if (!advance.files) advance.files = await this._loadRelaFiles(rfType);
  844. this.curFiles = advance.files;
  845. }
  846. async loadFiles() {
  847. switch (this.rfType.type) {
  848. case 'ledger': await this._loadLedgerFile(); break;
  849. case 'stage': await this._loadStageFile(); break;
  850. case 'advance': await this._loadAdvanceFile(); break;
  851. }
  852. this.initFilesId(this.curFiles);
  853. }
  854. async setCurTender(node) {
  855. this.curTender = node;
  856. this.refreshSelects(node.source_node);
  857. await this.loadFiles();
  858. this.refreshSelectHint();
  859. this.refreshFileTable();
  860. }
  861. getSelectRelaFile() {
  862. const data = [];
  863. const nodes = this.tenderTree.getNodes();
  864. nodes.forEach(node => {
  865. if (node.source_node.selectFiles.length === 0) return;
  866. node.source_node.selectFiles.forEach(x => {
  867. data.push({
  868. filename: x.filename, fileext: x.fileext, filepath: x.filepath, filesize: x.filesize,
  869. rela_info: x.rf_key,
  870. })
  871. });
  872. });
  873. return data;
  874. }
  875. }
  876. const relaFileLoader = new RelaFileLoader();
  877. $('#rela-file').on('show.bs.modal', function() {
  878. relaFileLoader.showRelaFile(this.getAttribute('content'));
  879. });
  880. // 授权相关
  881. class FilingPermission {
  882. constructor (setting) {
  883. this.setting = setting;
  884. const self = this;
  885. $(setting.modal).on('show.bs.modal', () => {
  886. self.loadPermission();
  887. });
  888. $(`${setting.modal}-ok`).click(() => {
  889. self.savePermission();
  890. });
  891. $('[name=ftName]').click(function () {
  892. const filingId = this.getAttribute('ftid');
  893. self.setCurFiling(filingId);
  894. });
  895. $('.book-list').on('click', 'dt', function () {
  896. const idx = $(this).find('.acc-btn').attr('data-groupid');
  897. const type = $(this).find('.acc-btn').attr('data-type');
  898. if (type === 'hide') {
  899. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  900. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  901. $(this).find('.acc-btn').attr('data-type', 'show')
  902. })
  903. } else {
  904. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  905. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  906. $(this).find('.acc-btn').attr('data-type', 'hide')
  907. })
  908. }
  909. return false;
  910. });
  911. $('dl').on('click', 'dd', function () {
  912. const type = $(this).data('type');
  913. if (type === 'all') {
  914. const cid = parseInt($(this).data('id'));
  915. const company = self.company.find(x => { return x.id === cid });
  916. for (const u of company.users) {
  917. if (u.filing_type.indexOf(self.curFiling) < 0) u.filing_type.push(self.curFiling);
  918. }
  919. } else {
  920. const uid = $(this).data('id');
  921. const pu = self.permissionUser.find(x => { return x.id === uid });
  922. if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
  923. }
  924. self.loadCurFiling();
  925. });
  926. $('#sync-filing').click(function() {
  927. const selectFiling = $('[name=cbft]:checked');
  928. if (selectFiling.length === 0) {
  929. toastr.warning('请先选择文档类别');
  930. return;
  931. }
  932. const selectFilingId = [];
  933. selectFiling.each((i, x) => { selectFilingId.push(x.value); });
  934. self.syncFiling(self.curFiling, selectFilingId);
  935. toastr.success('同步成功');
  936. $('[name=cbft]').each((i, x) => { x.checked = false; });
  937. });
  938. $('#batch-del-filing').click(() => {
  939. const selectUser = $('[name=ftu-check]:checked');
  940. if (selectUser.length === 0) {
  941. toastr.warning('请先选择用户');
  942. return;
  943. }
  944. const userId = [];
  945. selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
  946. self.delFiling(self.curFiling, userId);
  947. self.loadCurFiling();
  948. });
  949. $('body').on('click', '[name=del-filing]', function() {
  950. const id = this.getAttribute('uid');
  951. self.delFiling(self.curFiling, id);
  952. self.loadCurFiling();
  953. })
  954. }
  955. analysisFiling(data) {
  956. this.permissionUser = data;
  957. this.permissionUser.forEach(x => { x.filing_type = x.filing_type ? x.filing_type.split(',') : []; });
  958. this.company = [];
  959. for (const pu of this.permissionUser) {
  960. let c = this.company.find(x => { return x.company === pu.company });
  961. if (!c) {
  962. c = { id: this.company.length + 1, company: pu.company, users: [] };
  963. this.company.push(c);
  964. }
  965. c.users.push(pu);
  966. }
  967. }
  968. loadCurFiling() {
  969. const html = [];
  970. for (const f of this.permissionUser) {
  971. if (f.filing_type.indexOf(this.curFiling) < 0) continue;
  972. html.push('<tr>');
  973. html.push(`<td><input uid="${f.id}" type="checkbox" name="ftu-check"></td>`);
  974. html.push(`<td>${f.name}</td>`);
  975. html.push(`<td>${moment(f.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  976. html.push(`<td>${f.file_permission}</td>`);
  977. html.push(`<td><button class="btn btn-sm btn-outline-danger" uid="${f.id}" name="del-filing">移除</button></td>`);
  978. html.push('</tr>');
  979. }
  980. $(this.setting.list).html(html.join(''));
  981. }
  982. setCurFiling(filingType) {
  983. this.curFiling = filingType;
  984. $('[name=ftName]').removeClass('bg-warning-50');
  985. $(`[ftid=${filingType}]`).addClass('bg-warning-50');
  986. this.loadCurFiling();
  987. }
  988. loadPermissionUser() {
  989. const html = [];
  990. for (const c of this.company) {
  991. 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>`);
  992. html.push(`<div class="dd-content" data-toggleid="${c.id}">`);
  993. 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>`);
  994. for (const u of c.users) {
  995. html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${u.id}" >`);
  996. html.push(`<p class="mb-0 d-flex"><span class="text-primary">${u.name}</span><span class="ml-auto">${u.mobile}</span></p>`);
  997. html.push(`<span class="text-muted">${u.role}</span>`);
  998. html.push(`</dd>`);
  999. }
  1000. html.push('</div>');
  1001. }
  1002. $('#puList').html(html.join(''));
  1003. }
  1004. loadPermission() {
  1005. const self = this;
  1006. postData('permission', {}, function(result) {
  1007. self.analysisFiling(result);
  1008. if (!self.curFiling) {
  1009. self.setCurFiling($('[name=ftName]').attr('ftid'));
  1010. } else {
  1011. self.loadCurFiling();
  1012. }
  1013. self.loadPermissionUser();
  1014. });
  1015. }
  1016. syncFiling(sourceId, targetIds) {
  1017. for (const pu of this.permissionUser) {
  1018. if (pu.filing_type.indexOf(sourceId) >= 0) {
  1019. targetIds.forEach(id => {
  1020. if (pu.filing_type.indexOf(id) < 0) pu.filing_type.push(id);
  1021. });
  1022. } else {
  1023. targetIds.forEach(id => {
  1024. if (pu.filing_type.indexOf(id) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(id), 1);
  1025. })
  1026. }
  1027. }
  1028. }
  1029. delFiling(filingId, userId) {
  1030. const userIds = userId instanceof Array ? userId : [userId];
  1031. for (const id of userIds) {
  1032. const pu = this.permissionUser.find(x => { return x.id === id });
  1033. if (!pu) continue;
  1034. if (pu.filing_type.indexOf(filingId) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(filingId), 1);
  1035. }
  1036. }
  1037. savePermission() {
  1038. const self = this;
  1039. const data = this.permissionUser.map(x => {
  1040. return { id: x.id, filing_type: x.filing_type.join(',') };
  1041. });
  1042. postData('permission/save', data, function(result) {
  1043. $(self.setting.modal).modal('hide');
  1044. });
  1045. }
  1046. }
  1047. const filingPermission = new FilingPermission({
  1048. modal: '#filing-permission',
  1049. list: '#filing-valid',
  1050. });
  1051. // 显示层次
  1052. (function (select) {
  1053. $(select).click(function () {
  1054. const tag = $(this).attr('tag');
  1055. setTimeout(() => {
  1056. showWaitingView();
  1057. switch (tag) {
  1058. case "1":
  1059. case "2":
  1060. case "3":
  1061. case "4":
  1062. filingObj.expandByLevel(parseInt(tag));
  1063. break;
  1064. case "last":
  1065. filingObj.expandByCustom(() => { return true; });
  1066. break;
  1067. }
  1068. closeWaitingView();
  1069. }, 100);
  1070. });
  1071. })('a[name=showLevel]');
  1072. });