file_detail.js 36 KB

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