file_detail.js 37 KB

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