file_detail.js 41 KB

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