file_detail.js 37 KB

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