file_detail.js 36 KB

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