file_detail.js 40 KB

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