file_detail.js 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  1. $(document).ready(function() {
  2. let fileSearch;
  3. autoFlashHeight();
  4. $('#filing').height($(".sjs-height-0").height() - $('#add-slibing').parent().parent().height() - 10);
  5. class FilingObj {
  6. constructor(setting) {
  7. // 原始数据整理后的树结构,用来整理zTree显示
  8. this.dragTree = createDragTree({
  9. id: 'id',
  10. pid: 'tree_pid',
  11. level: 'tree_level',
  12. order: 'tree_order',
  13. rootId: '-1'
  14. });
  15. // 界面显示的zTree
  16. this.setting = setting;
  17. this.filingTree = null;
  18. this.pageCount = 15;
  19. this.expandKey = 'filing-' + window.location.pathname.split('/')[2];
  20. const cache = getLocalCache(this.expandKey);
  21. this.expandCache = cache ? _.uniq(cache.split(',')) : [];
  22. this.curFilingKey = 'cur-filing-' + window.location.pathname.split('/')[2];
  23. $('#filing').height($(".sjs-height-0").height()-$('.d-flex',".sjs-height-0").height() - 10);
  24. this.fileOrderKey = 'fileOrder';
  25. this.fileOrder = getLocalCache(this.fileOrderKey) || 'create_time|desc';
  26. }
  27. refreshFileOrderButton() {
  28. const orderBy = this.fileOrder.split('|');
  29. const field = orderBy[0], sort = orderBy[1];
  30. const buttons = $('[name=file-sort]');
  31. for (const b of buttons) {
  32. const curField = b.getAttribute('field');
  33. if (curField === field) {
  34. $(b).html(`<i class="fa fa-sort-amount-${sort}" aria-hidden="true"></i>`).attr('tag', `${curField}|${sort === 'asc' ? 'desc' : 'asc'}`);
  35. } else {
  36. $(b).html('<i class="fa fa-sort" aria-hidden="true">').attr('tag', `${curField}|desc`);
  37. }
  38. }
  39. }
  40. calcTotalFileCount() {
  41. this.dragTree.recursiveFun(this.dragTree.children, x => {
  42. if (x.children && x.children.length > 0) {
  43. x.total_file_count = x.children.reduce((pre, c) => {
  44. if (x.filing_type === 1) console.log('reduce', c.name, c.total_file_count);
  45. return pre + c.total_file_count
  46. }, 0);
  47. } else {
  48. x.total_file_count = x.file_count || 0;
  49. }
  50. if (x.filing_type === 1) console.log(x.name, x.total_file_count);
  51. });
  52. }
  53. _loadFilingSourceNode() {
  54. const self = this;
  55. const loadChildren = function(children) {
  56. for (const child of children) {
  57. if (child.children && child.children.length > 0) loadChildren(child.children);
  58. child.source_node = self.dragTree.getItems(child.id);
  59. }
  60. };
  61. const nodes = this.filingTree.getNodes();
  62. loadChildren(nodes);
  63. }
  64. loadFiling() {
  65. const self = this;
  66. if (this.filingTree) $.fn.zTree.destroy(this.setting.treeId);
  67. const sortNodes = this.dragTree.nodes.map(x => {
  68. const result = {
  69. id: x.id,
  70. tree_pid: x.tree_pid,
  71. name: x.name + (x.total_file_count > 0 ? `(${x.total_file_count})` : ''),
  72. spid: x.spid,
  73. tips: x.tips || '',
  74. };
  75. if (x.is_fixed) result.isParent = true;
  76. if (x.is_folder || x.is_fixed) result.open = self.expandCache.indexOf(result.id) >= 0;
  77. return result;
  78. });
  79. this.filingTree = $.fn.zTree.init($('#filing'), this.setting, sortNodes);
  80. this._loadFilingSourceNode();
  81. const curCache = getLocalCache(this.curFilingKey);
  82. const curNode = curCache ? this.filingTree.getNodeByParam('id', curCache) : null;
  83. if (curNode){
  84. this.filingTree.selectNode(curNode);
  85. filingObj.setCurFiling(curNode);
  86. }
  87. }
  88. analysisFiling(data) {
  89. this.dragTree.loadDatas(data);
  90. this.calcTotalFileCount();
  91. this.loadFiling();
  92. }
  93. _getFileNameHtml(file) {
  94. const moveHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="move-file" fid="${file.id}"><i class="fa fa-exchange fa-fw"></i></a>` : '';
  95. const editHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="edit-file" fid="${file.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
  96. const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
  97. 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>`;
  98. const delHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1 text-danger" name="del-file" fid="${file.id}"><i class="fa fa-trash-o fa-fw"></i></a>` : '';
  99. return `<div class="d-flex justify-content-between align-items-center table-file"><div name="filename" fid="${file.id}">${file.filename}${file.fileext}</div><div class="btn-group-table" style="display: none;">${moveHtml}${editHtml}${viewHtml}${downHtml}${delHtml}</div></div>`;
  100. }
  101. _getEditFileNameHtml(file) {
  102. const inputHtml = `<input type="text" class="form-control form-control-sm form-control-width" maxlength="100" value="${file.filename + file.fileext}" fid="${file.id}">`;
  103. const btnHtml = `<div class="btn-group-table" style="display: none;"><a href="javascript: void(0)" class="mr-1" name="edit-file-ok"><i class="fa fa-check fa-fw"></i></a><a href="javascript: void(0)" class="mr-1" name="edit-file-cancel"><i class="fa fa-remove fa-fw"></i></a></div>`;
  104. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  105. }
  106. _getFileHtml(file) {
  107. const html = [];
  108. html.push(`<tr fid="${file.id}">`);
  109. html.push(`<td class="text-center"><input type="checkbox" name="bd-check" fid="${file.id}"></td>`);
  110. html.push(`<td fid="${file.id}">${this._getFileNameHtml(file)}</td>`);
  111. html.push(`<td class="text-center">${file.user_name}</td>`);
  112. html.push(`<td class="text-center">${moment(file.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  113. html.push(`<td class="text-center">${file.fileext_str}</td>`);
  114. html.push('</tr>');
  115. return html.join('');
  116. }
  117. refreshFilesTable() {
  118. const html = [];
  119. const files = this.curFiling.source_node.files;
  120. if (!files || files.length === 0) {
  121. $('#file-list').html('');
  122. return;
  123. }
  124. const startIndex = (this.curPage - 1)*this.pageCount;
  125. const endIndex = this.curPage*this.pageCount;
  126. for (const [i, f] of files.entries()) {
  127. if (i < startIndex || i >= endIndex) continue;
  128. html.push(this._getFileHtml(f));
  129. }
  130. $('#file-list').html(html.join(''));
  131. }
  132. refreshPages() {
  133. if (!filingObj.curFiling) return;
  134. filingObj.curTotalPage = Math.ceil(filingObj.curFiling.source_node.file_count / this.pageCount);
  135. filingObj.curPage = Math.min(filingObj.curTotalPage, Math.max(filingObj.curPage, 1));
  136. $('#curPage').html(filingObj.curPage);
  137. $('#curTotalPage').html(filingObj.curTotalPage);
  138. if (filingObj.curTotalPage > 1) {
  139. $('#showPage').show();
  140. } else {
  141. $('#showPage').hide();
  142. }
  143. }
  144. async loadFiles(node, page) {
  145. if (node.source_node.children && node.source_node.children.length > 0) return;
  146. if (!node.source_node.files) node.source_node.files = [];
  147. if (!node.source_node.file_count) return;
  148. if (node.source_node.files && node.source_node.files.length === node.source_node.file_count) return;
  149. const needFiles = Math.min(page*this.pageCount, node.source_node.file_count);
  150. if (node.source_node.files && needFiles <= node.source_node.files.length) return;
  151. const files = await postDataAsync('file/load', { filing_id: node.id, page, count: this.pageCount, order: this.fileOrder });
  152. files.forEach(x => {
  153. const file = node.source_node.files.find(f => {return x.id === f.id; });
  154. if (file) {
  155. Object.assign(file, x);
  156. } else {
  157. node.source_node.files.push(x);
  158. }
  159. });
  160. // node.source_node.files.sort((x, y) => {
  161. // return x.create_time - y.create_time;
  162. // });
  163. }
  164. addSiblingFiling(node) {
  165. const self = this;
  166. postData('filing/add', { tree_pid: node.tree_pid, tree_pre_id: node.id }, function(result) {
  167. const refreshData = self.dragTree.loadPostData(result);
  168. const newNode = refreshData.create[0];
  169. const nodes = self.filingTree.addNodes(node.getParentNode(), node.getIndex() + 1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid }]);
  170. nodes[0].source_node = newNode;
  171. });
  172. }
  173. addChildFiling(node) {
  174. const self = this;
  175. postData('filing/add', { tree_pid: node.id }, function(result) {
  176. const refreshData = self.dragTree.loadPostData(result);
  177. const newNode = refreshData.create[0];
  178. const nodes = self.filingTree.addNodes(node, -1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid}]);
  179. nodes[0].source_node = newNode;
  180. });
  181. }
  182. delFiling(node, callback) {
  183. const parent = node.getParentNode();
  184. const self = this;
  185. postData('filing/del', { id: node.id }, function(result) {
  186. self.updateFilingFileCount(node, 0);
  187. self.dragTree.loadPostData(result);
  188. self.filingTree.removeNode(node);
  189. self.calcTotalFileCount();
  190. if (parent) {
  191. const path = parent.getPath();
  192. for (const p of path) {
  193. p.name = p.source_node.name + (p.source_node.total_file_count > 0 ? `(${p.source_node.total_file_count})` : '');
  194. if (p.source_node.is_fixed) p.isParent = true;
  195. filingObj.filingTree.updateNode(p);
  196. }
  197. }
  198. if (callback) callback();
  199. });
  200. }
  201. async renameFiling(node, newName) {
  202. const result = await postDataAsync('filing/save', { id: node.id, name: newName });
  203. node.source_node.name = newName;
  204. node.name = node.source_node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
  205. return result;
  206. }
  207. updateFilingFileCount(filing, count) {
  208. let differ = count - (filing.source_node.file_count || 0);
  209. filing.source_node.file_count = count;
  210. filing.source_node.total_file_count = count;
  211. filing.name = filing.source_node.name + (filing.source_node.total_file_count > 0 ? `(${filing.source_node.total_file_count})` : '');
  212. filingObj.filingTree.updateNode(filing);
  213. let parent = filing.getParentNode();
  214. while (!!parent) {
  215. parent.source_node.total_file_count = parent.source_node.total_file_count ? parent.source_node.total_file_count + differ : differ;
  216. parent.name = parent.source_node.name + (parent.source_node.total_file_count > 0 ? `(${parent.source_node.total_file_count})` : '');
  217. filingObj.filingTree.updateNode(parent);
  218. parent = parent.getParentNode();
  219. }
  220. }
  221. checkFilesExist(files, callback) {
  222. const data = [];
  223. for (const file of files) {
  224. if (file === undefined) return [];
  225. data.push(file.name);
  226. }
  227. postData('file/check', { filing_id: filingObj.curFiling.id, files: data }, function(result) {
  228. callback(result);
  229. });
  230. }
  231. uploadFiles(files, filterFiles, callback) {
  232. const formData = new FormData();
  233. formData.append('filing_id', filingObj.curFiling.id);
  234. let count = 0;
  235. for (const file of files) {
  236. if (filterFiles.indexOf(file.name) >= 0) continue;
  237. if (file === undefined) {
  238. toastr.error('未选择上传文件。');
  239. return false;
  240. }
  241. if (file.size > 50 * 1024 * 1024) {
  242. toastr.error('上传文件大小超过50MB。');
  243. return false;
  244. }
  245. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  246. if (whiteList.indexOf(fileext) === -1) {
  247. toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
  248. return false;
  249. }
  250. formData.append('size', file.size);
  251. formData.append('file[]', file);
  252. count++;
  253. }
  254. if (count === 0) {
  255. toastr.warning('没有可上传的文件');
  256. return false;
  257. }
  258. postDataWithFile('file/upload', formData, function (data) {
  259. filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
  260. filingObj.curFiling.source_node.files.unshift(...data.files);
  261. filingObj.refreshPages();
  262. filingObj.refreshFilesTable();
  263. if (callback) callback();
  264. });
  265. }
  266. uploadBigFile(file, callback) {
  267. if (file.size > 500 * 1024 * 1024) {
  268. toastr.error('上传文件大小超过500MB。');
  269. return false;
  270. }
  271. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  272. if (whiteList.indexOf(fileext) === -1) {
  273. toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
  274. return false;
  275. }
  276. AliOss.uploadBigFile(file, 'file/upload/big', { filing_id: filingObj.curFiling.id },
  277. { progressObj: $('#upload-big-file-progress'), resumeObj: $('#add-big-file-resume'), stopObj: $('#add-big-file-stop') },
  278. function(result) {
  279. filingObj.curFiling.source_node.files.unshift(...result.files);
  280. filingObj.updateFilingFileCount(filingObj.curFiling, result.filing.file_count);
  281. filingObj.refreshPages();
  282. filingObj.refreshFilesTable();
  283. if (callback) callback();
  284. });
  285. }
  286. delFiles(files, callback) {
  287. postData('file/del', { del: files }, async function(data) {
  288. const relaFiling = data.filing.id === filingObj.curFiling.source_node.id
  289. ? filingObj.curFiling : filingObj.findFiling(data.filing.id);
  290. for (const id of data.del) {
  291. const fIndex = relaFiling.source_node.files.findIndex(x => { return x.id === id });
  292. if (fIndex >= 0) relaFiling.source_node.files.splice(fIndex, 1);
  293. fileSearch.removeSearchFile(id);
  294. }
  295. filingObj.updateFilingFileCount(relaFiling, data.filing.file_count);
  296. await filingObj.loadFiles(relaFiling, filingObj.curPage);
  297. if (data.filing.id === filingObj.curFiling.source_node.id) {
  298. filingObj.refreshPages();
  299. filingObj.refreshFilesTable();
  300. }
  301. if (callback) callback();
  302. });
  303. }
  304. renameFile(file, filename) {
  305. const self = this;
  306. const td = $(`td[fid=${file.id}]`);
  307. postData('file/save', { id: file.id, filename }, function(data) {
  308. const relaFiling = filingObj.findFiling(file.filing_id);
  309. const relaFile = relaFiling.source_node.files.find(x => { return x.id === file.id });
  310. relaFile.filename = data.filename;
  311. relaFile.fileext = data.fileext;
  312. td.html(self._getFileNameHtml(relaFile));
  313. fileSearch.renameSearchFile(file.id, data);
  314. }, function() {
  315. td.html(self._getFileNameHtml(file));
  316. fileSearch.renameSearchFile(file.id);
  317. });
  318. }
  319. relaFiles(files, callback) {
  320. postData('file/rela', { filing_id: this.curFiling.id, files: files }, async function(data) {
  321. filingObj.curFiling.source_node.files.unshift(...data.files);
  322. filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
  323. filingObj.refreshFilesTable();
  324. filingObj.refreshPages();
  325. if (callback) callback();
  326. });
  327. }
  328. moveFile(file, filingId, callback) {
  329. if (file.filing_id === filingId) {
  330. callback();
  331. return;
  332. }
  333. postData('file/move', { id: file.id, filingId: filingId }, function(data) {
  334. const orgFiling = filingObj.findFiling(file.filing_id);
  335. filingObj.updateFilingFileCount(orgFiling, orgFiling.source_node.file_count - 1);
  336. const fIndex = orgFiling.source_node.files.findIndex(x => { return x.id === file.id });
  337. if (fIndex >= 0) orgFiling.source_node.files.splice(fIndex, 1);
  338. const targetFiling = filingObj.findFiling(filingId);
  339. filingObj.updateFilingFileCount(targetFiling, targetFiling.source_node.file_count + 1);
  340. if (file.filing_id === filingObj.curFiling.source_node.id) {
  341. filingObj.refreshPages();
  342. filingObj.refreshFilesTable();
  343. }
  344. fileSearch.refreshSearchFile(data.file);
  345. callback();
  346. });
  347. }
  348. async setCurFiling(node) {
  349. filingObj.curFiling = node;
  350. filingObj.curPage = 1;
  351. filingObj.refreshPages();
  352. if (filingObj.curFiling.source_node.children && filingObj.curFiling.source_node.children.length > 0) {
  353. $('#file-view').hide();
  354. } else {
  355. $('#file-view').show();
  356. await filingObj.loadFiles(node, 1);
  357. filingObj.refreshFilesTable();
  358. }
  359. if (filingObj.curFiling.source_node.filing_type === 5) {
  360. $('#rela-file-btn').show();
  361. } else {
  362. $('#rela-file-btn').hide();
  363. }
  364. setLocalCache(this.curFilingKey, filingObj.curFiling.id);
  365. }
  366. findFiling(id) {
  367. return filingObj.filingTree.getNodeByParam('id', id);
  368. }
  369. prePage() {
  370. if (this.curPage === 1) return;
  371. this.curPage = this.curPage - 1;
  372. this.refreshPages();
  373. this.refreshFilesTable();
  374. }
  375. async nextPage() {
  376. if (this.curPage === this.curTotalPage) return;
  377. await filingObj.loadFiles(this.curFiling, this.curPage + 1);
  378. this.curPage = this.curPage + 1;
  379. this.refreshPages();
  380. this.refreshFilesTable();
  381. }
  382. getCurFilingFullPath(){
  383. let cur = filingObj.curFiling;
  384. const result = [];
  385. while (cur) {
  386. result.unshift(cur.source_node.name);
  387. cur = cur.getParentNode();
  388. }
  389. return result.join('/');
  390. }
  391. expandFiling(node, expand) {
  392. if (expand) {
  393. this.expandCache.push(node.id);
  394. } else{
  395. this.expandCache = this.expandCache.filter(x => { return x !== node.id });
  396. }
  397. setLocalCache(this.expandKey, this.expandCache.join(','));
  398. }
  399. expandByLevel(level) {
  400. this.expandByCustom(x => {
  401. return x.level + 1 < level;
  402. })
  403. }
  404. expandByCustom(fun) {
  405. const self = this;
  406. const expandCache = [];
  407. const expandChildren = function(children) {
  408. for (const child of children) {
  409. if (!child.children || child.children.length === 0) continue;
  410. const expand = fun(child);
  411. if (expand) expandCache.push(child.id);
  412. self.filingTree.expandNode(child, expand, false, false);
  413. expandChildren(child.children);
  414. }
  415. };
  416. const nodes = this.filingTree.getNodes();
  417. expandChildren(nodes);
  418. this.expandCache = expandCache;
  419. setLocalCache(this.expandKey, this.expandCache.join(','));
  420. }
  421. moveFiling(node, tree_pid, tree_order) {
  422. if (tree_pid === node.source_node.tree_pid && tree_order === node.source_node.tree_order) return;
  423. const self = this;
  424. postData('filing/move', { id: node.id, tree_pid, tree_order }, function(result) {
  425. const refresh = self.dragTree.loadPostData(result);
  426. self.calcTotalFileCount();
  427. const updated = [];
  428. for (const u of refresh.update) {
  429. const node = self.filingTree.getNodeByParam('id', u.id);
  430. if (node) {
  431. const path = node.getPath();
  432. for (const p of path) {
  433. if (updated.indexOf(p.id) >= 0) continue;
  434. p.name = p.source_node.name + (p.source_node.total_file_count > 0 ? `(${p.source_node.total_file_count})` : '');
  435. filingObj.filingTree.updateNode(p);
  436. updated.push(p.id);
  437. }
  438. }
  439. }
  440. });
  441. }
  442. _clearAllFileCache() {
  443. const nodes = this.filingTree.getNodes();
  444. for (const node of nodes) {
  445. if (node.children && node.children.length > 0) continue;
  446. if (node.source_node.files) node.source_node.files.length = 0;
  447. }
  448. }
  449. changeFileOrder(fileOrder) {
  450. this.fileOrder = fileOrder;
  451. setLocalCache(this.fileOrderKey, fileOrder);
  452. this.refreshFileOrderButton();
  453. this._clearAllFileCache();
  454. this.setCurFiling(this.curFiling);
  455. }
  456. getNodeFilingType(node) {
  457. if (!node.is_fixed) return [];
  458. const types = [];
  459. if (node.children && node.children.length > 0) {
  460. for (const child of node.children) {
  461. const childTypes = this.getNodeFilingType(child);
  462. if (childTypes.length > 0) types.push(...childTypes);
  463. }
  464. }
  465. if (types.length === 0) types.push(node.filing_type);
  466. return types;
  467. }
  468. getParentFilingType(node) {
  469. const parent = this.dragTree.getParent(node);
  470. if (!parent) return [];
  471. if (parent.is_fixed) return [parent.filing_type];
  472. return this.getParentFilingType(parent);
  473. }
  474. getAllFilingType() {
  475. const types = [];
  476. for (const node of this.dragTree.children) {
  477. types.push(...this.getNodeFilingType(node))
  478. }
  479. return types;
  480. }
  481. getCurFilingType() {
  482. const cur = filingObj.curFiling;
  483. const node = this.dragTree.nodes.find(x => { return x.id === cur.source_node.id; });
  484. return node.is_fixed ? this.getNodeFilingType(node) : this.getParentFilingType(node);
  485. }
  486. }
  487. const levelTreeSetting = {
  488. treeId: 'filing',
  489. view: {
  490. selectedMulti: false,
  491. showTitle: true,
  492. },
  493. data: {
  494. simpleData: {
  495. idKey: 'id',
  496. pIdKey: 'tree_pid',
  497. rootPId: '-1',
  498. enable: true,
  499. },
  500. key: { title: 'tips' },
  501. },
  502. edit: {
  503. enable: true,
  504. showRemoveBtn: function(treeId, treeNode) {
  505. if (!canFiling) return false;
  506. return !treeNode.source_node.is_fixed;
  507. },
  508. showRenameBtn: function(treeId, treeNode) {
  509. if (!canFiling) return false;
  510. return !treeNode.source_node.is_fixed;
  511. },
  512. renameTitle: '编辑',
  513. removeTitle: '删除',
  514. drag: {
  515. isCopy: false,
  516. isMove: true,
  517. pre: true,
  518. next: true,
  519. inner: false,
  520. },
  521. editNameSelectAll: true,
  522. },
  523. callback: {
  524. onClick: async function (e, key, node) {
  525. if (filingObj.curFiling && filingObj.curFiling.id === node.id) return;
  526. filingObj.setCurFiling(node);
  527. },
  528. beforeEditName: function(key, node) {
  529. node.name = node.source_node.name;
  530. },
  531. beforeRename: async function(key, node, newName, isCancel) {
  532. if (!isCancel) await filingObj.renameFiling(node, newName);
  533. return true;
  534. },
  535. onRename: function(e, key, node, isCancel) {
  536. node.name = node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
  537. filingObj.filingTree.updateNode(node);
  538. },
  539. beforeRemove: function(key, node, isCancel) {
  540. $('#del-filing').modal('show');
  541. return false;
  542. },
  543. onExpand(e, key, node) {
  544. filingObj.expandFiling(node, true);
  545. },
  546. onCollapse: function(e, key, node) {
  547. filingObj.expandFiling(node, false);
  548. },
  549. beforeDrop: function(key, nodes, target, moveType, isCopy) {
  550. if (!canFiling) return false;
  551. if (!target) return false;
  552. if (nodes[0].level < 1) {
  553. toastr.error('顶层节点请勿移动');
  554. return false;
  555. }
  556. if (nodes[0].is_fixed) {
  557. toastr.error('固定分类请勿移动');
  558. return false;
  559. }
  560. if (nodes[0].source_node.filing_type !== target.source_node.filing_type) {
  561. toastr.error('请勿跨越最顶层节点移动');
  562. return false;
  563. }
  564. if (target.source_node.file_count > 0 && moveType === 'inner') {
  565. toastr.error(`节点[${target.source_node.name}]下存在文件,不可添加子级`);
  566. return false;
  567. }
  568. const order = nodes[0].getIndex() + 1;
  569. const targetOrder = target.getIndex() + 1;
  570. const targetMax = target.getParentNode().children.length;
  571. if (moveType === 'prev') {
  572. if (target.tree_pid === nodes[0].tree_pid) {
  573. if (targetOrder > order) {
  574. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder - 1);
  575. } else {
  576. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
  577. }
  578. } else {
  579. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
  580. }
  581. } else if (moveType === 'next') {
  582. if (target.tree_pid === nodes[0].tree_pid) {
  583. if (targetOrder < order) {
  584. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder + 1);
  585. } else {
  586. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder);
  587. }
  588. } else {
  589. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder + 1);
  590. }
  591. } else if (moveType === 'inner') {
  592. filingObj.moveFiling(nodes[0], target.tree_id, targetMax + 1);
  593. }
  594. }
  595. }
  596. };
  597. const filingObj = new FilingObj(levelTreeSetting);
  598. filingObj.analysisFiling(filing);
  599. $('#add-slibing').click(() => {
  600. if (!filingObj.curFiling) return;
  601. if (filingObj.curFiling.source_node.is_fixed) {
  602. toastr.error('固定分类不可添加同级');
  603. return;
  604. }
  605. filingObj.addSiblingFiling(filingObj.curFiling);
  606. });
  607. $('#add-child').click(() => {
  608. if (!filingObj.curFiling) return;
  609. const fixedChild = filingObj.curFiling.source_node.children.find(x => { return x.is_fixed; });
  610. if (fixedChild) {
  611. toastr.error('该分类下存在固定分类,不可添加子级');
  612. return;
  613. }
  614. if (filingObj.curFiling.source_node.file_count > 0) {
  615. toastr.error('该分类下已导入文件,不可添加子级');
  616. return;
  617. }
  618. filingObj.addChildFiling(filingObj.curFiling);
  619. });
  620. $('[name=file-sort]').click(function() {
  621. const tag = this.getAttribute('tag');
  622. filingObj.changeFileOrder(tag);
  623. });
  624. // $('#del-filing-btn').click(() => {
  625. // if (!filingObj.curFiling) return;
  626. // if (filingObj.curFiling.source_node.is_fixed) {
  627. // toastr.error('固定分类不可删除');
  628. // return;
  629. // }
  630. //
  631. // $('#del-filing').modal('show');
  632. // });
  633. $('#del-filing-ok').click(() => {
  634. filingObj.delFiling(filingObj.curFiling, function() {
  635. $('#del-filing').modal('hide');
  636. });
  637. });
  638. $('#add-file').on('show.bs.modal', function() {
  639. $('#filter-same')[0].checked = false;
  640. $('#filter-same').parent().hide();
  641. $('#upload-file-hint').hide();
  642. $('#upload-file')[0].value = '';
  643. if ($('#add-file-ok').hasClass('btn-warning')) $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary');
  644. });
  645. $('#upload-file').change(() => {
  646. $('#add-file-ok').attr('disabled', true);
  647. const input = $('#upload-file');
  648. filingObj.checkFilesExist(input[0].files, function(result) {
  649. if (result.length === 0) {
  650. $('#upload-file-hint').hide();
  651. $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
  652. $('#filter-same').parent().hide();
  653. } else {
  654. const msg = result[0] + (result.length > 1 ? `(等${result.length}个文件)`: '') + '</br>存在同名文件,请确认是否上传重复';
  655. $('#upload-file-hint').html(msg).show();
  656. $('#add-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
  657. $('#filter-same').parent().show();
  658. $('#filter-same').attr('filterFiles', result.join('$;$'));
  659. }
  660. });
  661. });
  662. $('#add-file-ok').click(() => {
  663. const input = $('#upload-file');
  664. const filter = $('#filter-same')[0].checked;
  665. const filterFiles = filter ? $('#filter-same').attr('filterFiles').split('$;$') : [];
  666. filingObj.uploadFiles(input[0].files, filterFiles, function() {
  667. $(input).val('');
  668. $('#add-file').modal('hide');
  669. });
  670. });
  671. $('#add-big-file').on('show.bs.modal', function() {
  672. $('#upload-big-file-hint').hide();
  673. $('#upload-big-file')[0].value = '';
  674. if ($('#add-big-file-ok').hasClass('btn-warning')) $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary');
  675. });
  676. $('#upload-big-file').change(() => {
  677. $('#add-big-file-ok').attr('disabled', true);
  678. const input = $('#upload-big-file');
  679. filingObj.checkFilesExist(input[0].files, function(result) {
  680. if (result.length === 0) {
  681. $('#upload-big-file-hint').hide();
  682. $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
  683. } else {
  684. $('#upload-big-file-hint').html('存在同名文件,请确认是否上传重复').show();
  685. $('#add-big-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
  686. }
  687. });
  688. });
  689. $('#add-big-file-ok').click(() => {
  690. const input = $('#upload-big-file');
  691. filingObj.uploadBigFile(input[0].files[0], function () {
  692. $('#upload-big-file').val('');
  693. $('#add-big-file').modal('hide');
  694. });
  695. });
  696. $('body').on('mouseenter', ".table-file", function(){
  697. $(this).children(".btn-group-table").css("display","block");
  698. });
  699. $('body').on('mouseleave', ".table-file", function(){
  700. $(this).children(".btn-group-table").css("display","none");
  701. });
  702. $('body').on('click', "a[name=del-file]", function() {
  703. const del = [this.getAttribute('fid')];
  704. filingObj.delFiles(del);
  705. });
  706. $('body').on('click', "a[name=edit-file]", function() {
  707. const check = $('[name=filename] input[fid]');
  708. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  709. const id = this.getAttribute('fid');
  710. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === id });
  711. $(`td[fid=${id}]`).html(filingObj._getEditFileNameHtml(file));
  712. });
  713. $('body').on('click', "a[name=edit-file-ok]", function() {
  714. const td = $(this).parent().parent().parent();
  715. const fid = td.attr('fid');
  716. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  717. if (!file) return;
  718. const filename = $('input', td).val();
  719. if (filename === file.filename + file.fileext) {
  720. td.html(this._getFileNameHtml(file));
  721. return;
  722. }
  723. filingObj.renameFile(file, filename);
  724. });
  725. $('body').on('click', "a[name=edit-file-cancel]", function() {
  726. const td = $(this).parent().parent().parent();
  727. const fid = td.attr('fid');
  728. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  729. if (!file) return;
  730. td.html(filingObj._getFileNameHtml(file));
  731. });
  732. class MoveFileObj {
  733. constructor() {
  734. const self = this;
  735. this.setting = {
  736. treeId: 'moveTree',
  737. view: {
  738. selectedMulti: false,
  739. showTitle: true,
  740. },
  741. data: {
  742. simpleData: {
  743. idKey: 'id',
  744. pIdKey: 'tree_pid',
  745. rootPId: '-1',
  746. enable: true,
  747. },
  748. key: { title: 'tips' },
  749. },
  750. edit: {
  751. enable: false,
  752. },
  753. };
  754. this.moveTree = null;
  755. $('#move-file2-ok').click(function() {
  756. const targetFiling = self.moveTree.getSelectedNodes()[0];
  757. if (!targetFiling) {
  758. toastr.warning('请选择目标分类');
  759. return;
  760. }
  761. if (targetFiling.children && targetFiling.children.length > 0) {
  762. toastr.warning('请选择最底层目标分类');
  763. return;
  764. }
  765. filingObj.moveFile(self.file, targetFiling.id, function() {
  766. $('#move-file2').modal('hide');
  767. });
  768. });
  769. // 显示层次
  770. (function (select) {
  771. $(select).click(function () {
  772. const tag = $(this).attr('tag');
  773. setTimeout(() => {
  774. showWaitingView();
  775. switch (tag) {
  776. case "1":
  777. case "2":
  778. case "3":
  779. case "4":
  780. self.expandByLevel(parseInt(tag));
  781. break;
  782. case "last":
  783. self.expandByCustom(() => { return true; });
  784. break;
  785. }
  786. closeWaitingView();
  787. }, 100);
  788. });
  789. })('a[name=mf2-showLevel]');
  790. }
  791. expandByLevel(level) {
  792. this.expandByCustom(x => {
  793. return x.level + 1 < level;
  794. })
  795. }
  796. expandByCustom(fun) {
  797. const self = this;
  798. const expandChildren = function(children) {
  799. for (const child of children) {
  800. if (!child.children || child.children.length === 0) continue;
  801. const expand = fun(child);
  802. self.moveTree.expandNode(child, expand, false, false);
  803. expandChildren(child.children);
  804. }
  805. };
  806. const nodes = this.moveTree.getNodes();
  807. expandChildren(nodes);
  808. }
  809. initMoveTree() {
  810. if (this.moveTree) $.fn.zTree.destroy(this.setting.treeId);
  811. const sortNodes = filingObj.dragTree.nodes.map(x => {
  812. const result = {
  813. id: x.id,
  814. tree_pid: x.tree_pid,
  815. name: x.name,
  816. spid: x.spid,
  817. tips: x.tips || '',
  818. };
  819. if (x.is_fixed) result.isParent = true;
  820. return result;
  821. });
  822. this.moveTree = $.fn.zTree.init($('#moveFile'), this.setting, sortNodes);
  823. }
  824. show (file) {
  825. this.file = file;
  826. this.initMoveTree();
  827. $('#move-file2').modal('show');
  828. }
  829. }
  830. const moveFileObj = new MoveFileObj();
  831. $('body').on('click', "a[name=move-file]", function() {
  832. const id = this.getAttribute('fid');
  833. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === id });
  834. moveFileObj.show(file);
  835. });
  836. // $('body').on('blur', "[name=filename] input[fid]", function() {
  837. // filingObj.renameFile(this.getAttribute('fid'), this.value);
  838. // });
  839. // $('body').on('keypress', "[name=filename] input[fid]", function(e) {
  840. // if (e.keyCode == 13) {
  841. // filingObj.renameFile(this.getAttribute('fid'), this.value);
  842. // }
  843. // });
  844. $('.page-select').click(function() {
  845. const content = this.getAttribute('content');
  846. switch(content) {
  847. case 'pre': filingObj.prePage(); break;
  848. case 'next': filingObj.nextPage(); break;
  849. default: return;
  850. }
  851. });
  852. $('#batch-download').click(function () {
  853. const self = this;
  854. const files = [];
  855. const checkes = $('[name=bd-check]:checked');
  856. checkes.each(function() {
  857. const fid = this.getAttribute('fid');
  858. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid; });
  859. file && files.push(file);
  860. });
  861. if (files.length === 0) return;
  862. $(self).attr('disabled', 'true');
  863. AliOss.zipFiles(files, filingObj.curFiling.source_node.name + '.zip', (fails) => {
  864. $(self).removeAttr('disabled');
  865. if (fails.length === 0) {
  866. toastr.success('下载成功');
  867. } else {
  868. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  869. }
  870. }, () => {
  871. $(self).removeAttr('disabled');
  872. toastr.error('批量下载失败');
  873. });
  874. });
  875. $('#batch-del-file-btn').click(() => {
  876. const checkes = $('[name=bd-check]:checked');
  877. if (checkes.length === 0) {
  878. return;
  879. } else {
  880. for (const c of checkes) {
  881. const fid = c.getAttribute('fid');
  882. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  883. if (!file) continue;
  884. if (file.user_id !== userID) {
  885. toastr.error(`文件【${file.filename + file.fileext}】不是您上传的文件,请勿删除`);
  886. return;
  887. }
  888. }
  889. }
  890. $('#batch-del-file').modal('show');
  891. });
  892. $('#batch-del-file-ok').click(function() {
  893. const del = [];
  894. const checkes = $('[name=bd-check]:checked');
  895. checkes.each(function() {
  896. del.push(this.getAttribute('fid'));
  897. });
  898. filingObj.delFiles(del, function() {
  899. $('#batch-del-file').modal('hide');
  900. });
  901. });
  902. class RelaFileLoader {
  903. constructor() {
  904. const self = this;
  905. // 可导入的标段
  906. this.treeSetting = {
  907. view: {
  908. selectedMulti: false
  909. },
  910. data: {
  911. simpleData: {
  912. idKey: 'id',
  913. pIdKey: 'tree_pid',
  914. rootPId: '-1',
  915. enable: true,
  916. }
  917. },
  918. edit: {
  919. enable: false,
  920. },
  921. callback: {
  922. onClick: async function (e, key, node) {
  923. if (this.curTender && this.curTender.id === node.id) return;
  924. self.setCurTender(node);
  925. },
  926. }
  927. };
  928. $('body').on('click', '[name=rf-check]', function () {
  929. self.selectFile(this.getAttribute('rfid'), this.checked);
  930. });
  931. $('#tf-type').change(function() {
  932. self.selectTfType(this.value);
  933. });
  934. $('#tf-sub-type').change(function() {
  935. self.selectTfSubType(this.value);
  936. });
  937. $('#tf-stage').change(function() {
  938. self.selectTfStage(this.value);
  939. });
  940. $('#rela-file-ok').click(function() {
  941. const selectFiles = self.getSelectRelaFile();
  942. filingObj.relaFiles(selectFiles, function() {
  943. $('#rela-file').modal('hide');
  944. });
  945. });
  946. }
  947. clearFileSelect() {
  948. if (!this.tenderTree) return;
  949. const nodes = this.tenderTree.getNodes();
  950. nodes.forEach(node => {
  951. const x = node.source_node;
  952. x.selectFiles = [];
  953. if (x.att) x.att.forEach(la => { la.checked = false });
  954. if (x.advance) {
  955. x.advance.forEach(a => {
  956. if (a.files) a.files.forEach(aa => { aa.checked = false });
  957. });
  958. }
  959. if (x.stage) {
  960. x.stage.forEach(s => {
  961. if (s.att) s.att.forEach(sa => { sa.checked = false });
  962. })
  963. }
  964. });
  965. }
  966. refreshSelectHint(){
  967. if (this.curTender) {
  968. $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
  969. } else {
  970. $('#cur-tender-hint').html('');
  971. }
  972. const nodes = this.tenderTree.getNodes();
  973. const selectTenders = nodes.filter(x => { return x.source_node.selectFiles.length > 0; });
  974. if (selectTenders.length > 0) {
  975. const count = selectTenders.reduce((rst, x) => { return rst + x.source_node.selectFiles.length; }, 0);
  976. $('#rela-file-hint').html(`已选择${selectTenders.length}个标段,共${count}个文件`);
  977. } else {
  978. $('#rela-file-hint').html('未选择标段、文件');
  979. }
  980. }
  981. selectFile(fileId, isSelect) {
  982. const file = this.curFiles.find(x => { return x.rf_id == fileId });
  983. if (file) {
  984. file.checked = isSelect;
  985. if (isSelect) {
  986. this.curTender.source_node.selectFiles.push(file);
  987. } else {
  988. const index = this.curTender.source_node.selectFiles.findIndex(x => { return x.rf_id === file.rf_id });
  989. this.curTender.source_node.selectFiles.splice(index, 1);
  990. }
  991. this.refreshSelectHint();
  992. }
  993. }
  994. async showRelaFile(){
  995. $('#rela-filing-hint').html(`当前目录:${filingObj.getCurFilingFullPath()}`);
  996. if (!this.tenderTree) {
  997. const tenders = await postDataAsync('file/rela/tender', {});
  998. const sortNodes = tenders.map(x => {
  999. return { id: x.id, tree_pid: -1, name: x.name, source_node: x };
  1000. });
  1001. this.tenderTree = this.filingTree = $.fn.zTree.init($('#rela-tender'), this.treeSetting, sortNodes);
  1002. }
  1003. this.clearFileSelect();
  1004. this.refreshSelectHint();
  1005. const firstNode = this.filingTree.getNodes()[0];
  1006. if (firstNode) {
  1007. this.filingTree.selectNode(firstNode);
  1008. await this.setCurTender(firstNode);
  1009. }
  1010. }
  1011. refreshTenderFileStage() {
  1012. if (this.rfType.sub_type) {
  1013. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
  1014. const subType = type.subType ? type.subType.find(x => { return x.value === this.rfType.sub_type; }) : null;
  1015. if (subType) {
  1016. this.rfType.stage = subType.stage[0].value;
  1017. const html= [];
  1018. for (const stage of subType.stage) {
  1019. html.push(`<option value="${stage.value}">${stage.text}</option>`);
  1020. }
  1021. $('#tf-stage').html(html.join('')).show();
  1022. } else {
  1023. $('#tf-stage').html('').hide();
  1024. }
  1025. } else {
  1026. $('#tf-stage').html('').hide();
  1027. }
  1028. }
  1029. refreshTenderFileSubType() {
  1030. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
  1031. if (type.subType && type.subType.length > 0) {
  1032. this.rfType.sub_type = type.subType[0].value;
  1033. const html= [];
  1034. for (const tfst of type.subType) {
  1035. html.push(`<option value="${tfst.value}">${tfst.text}</option>`);
  1036. }
  1037. $('#tf-sub-type').html(html.join('')).show();
  1038. } else {
  1039. $('#tf-sub-type').html('').hide();
  1040. }
  1041. }
  1042. refreshTenderFileType() {
  1043. const html= [];
  1044. for (const tft of this.tenderFileType) {
  1045. html.push(`<option value="${tft.value}">${tft.text}</option>`);
  1046. }
  1047. $('#tf-type').html(html.join(''));
  1048. }
  1049. refreshSelects(tender) {
  1050. this.tenderFileType = [];
  1051. this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
  1052. if (tender.stage && tender.stage.length > 0) {
  1053. const stages = tender.stage.map(x => { return {value: x.id, text: `第${x.order}期`}; });
  1054. this.tenderFileType.push({
  1055. value: 'stage', text: '计量期',
  1056. subType: [
  1057. { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
  1058. ],
  1059. });
  1060. }
  1061. if (tender.advance && tender.advance.length > 0) {
  1062. const advanceType = [];
  1063. tender.advance.forEach(x => {
  1064. let at = advanceType.find(y => { return y.value === x.type + '' });
  1065. if (!at) {
  1066. at = { value: x.type + '', text: x.type_str, stage: [] };
  1067. advanceType.push(at);
  1068. }
  1069. at.stage.push({ value: x.id, text: `第${x.order}期`});
  1070. });
  1071. this.tenderFileType.push({
  1072. value: 'advance', text: '预付款', subType: advanceType
  1073. });
  1074. }
  1075. this.rfType = { type: this.tenderFileType[0].value };
  1076. this.refreshTenderFileType();
  1077. this.refreshTenderFileSubType();
  1078. this.refreshTenderFileStage();
  1079. }
  1080. async selectTfStage(stage){
  1081. this.rfType.stage = stage;
  1082. await this.loadFiles();
  1083. this.refreshFileTable();
  1084. }
  1085. async selectTfSubType(sub_type){
  1086. this.rfType.sub_type = sub_type;
  1087. this.refreshTenderFileStage();
  1088. await this.loadFiles();
  1089. this.refreshFileTable();
  1090. }
  1091. async selectTfType(type){
  1092. this.rfType.type = type;
  1093. this.refreshTenderFileSubType();
  1094. this.refreshTenderFileStage();
  1095. await this.loadFiles();
  1096. this.refreshFileTable();
  1097. }
  1098. refreshFileTable() {
  1099. const html = [];
  1100. const typeStr = [];
  1101. const selectOption = $('option:selected');
  1102. selectOption.each((i, x) => {
  1103. typeStr.push(x.innerText);
  1104. });
  1105. for (const f of this.curFiles) {
  1106. html.push('<tr>');
  1107. const checked = f.checked ? "checked" : '';
  1108. html.push(`<td><input type="checkbox" name="rf-check" rfid="${f.rf_id}" ${checked}></td>`);
  1109. html.push(`<td>${f.filename}${f.fileext}</td>`);
  1110. html.push(`<td>${typeStr.join(' - ')}</td>`);
  1111. html.push('</tr>');
  1112. }
  1113. $('#rf-files').html(html.join(''));
  1114. };
  1115. initFilesId(files){
  1116. const tender_id = this.curTender.id;
  1117. const rfType = this.rfType;
  1118. files.forEach((f, i) => {
  1119. f.rf_id = `${tender_id}-${rfType.type}-${rfType.sub_type}-${rfType.stage}-${i}`;
  1120. f.rf_key = {
  1121. tender_id, ...rfType, id: f.id,
  1122. };
  1123. });
  1124. }
  1125. async _loadRelaFiles(rfType) {
  1126. return await postDataAsync('file/rela/files', { tender_id: this.curTender.id, ...rfType });
  1127. }
  1128. async _loadLedgerFile() {
  1129. if (!this.curTender.source_node.att) this.curTender.source_node.att = await this._loadRelaFiles(this.rfType);
  1130. this.curFiles = this.curTender.source_node.att;
  1131. }
  1132. async _loadStageFile() {
  1133. const rfType = this.rfType;
  1134. const stage = this.curTender.source_node.stage.find(x => {
  1135. return x.id == rfType.stage;
  1136. });
  1137. if (!stage) {
  1138. this.curFiles = [];
  1139. return;
  1140. }
  1141. if (!stage[this.rfType.sub_type]) stage[this.rfType.sub_type] = await this._loadRelaFiles(rfType);
  1142. this.curFiles = stage[this.rfType.sub_type];
  1143. }
  1144. async _loadAdvanceFile() {
  1145. const rfType = this.rfType;
  1146. const advance = this.curTender.source_node.advance.find(x => {
  1147. return x.id == rfType.stage;
  1148. });
  1149. if (!advance) {
  1150. this.curFiles = [];
  1151. return;
  1152. }
  1153. if (!advance.files) advance.files = await this._loadRelaFiles(rfType);
  1154. this.curFiles = advance.files;
  1155. }
  1156. async loadFiles() {
  1157. switch (this.rfType.type) {
  1158. case 'ledger': await this._loadLedgerFile(); break;
  1159. case 'stage': await this._loadStageFile(); break;
  1160. case 'advance': await this._loadAdvanceFile(); break;
  1161. }
  1162. this.initFilesId(this.curFiles);
  1163. }
  1164. async setCurTender(node) {
  1165. this.curTender = node;
  1166. this.refreshSelects(node.source_node);
  1167. await this.loadFiles();
  1168. this.refreshSelectHint();
  1169. this.refreshFileTable();
  1170. }
  1171. getSelectRelaFile() {
  1172. const data = [];
  1173. const nodes = this.tenderTree.getNodes();
  1174. nodes.forEach(node => {
  1175. if (node.source_node.selectFiles.length === 0) return;
  1176. node.source_node.selectFiles.forEach(x => {
  1177. data.push({
  1178. filename: x.filename, fileext: x.fileext, filepath: x.filepath, filesize: x.filesize,
  1179. rela_info: x.rf_key,
  1180. })
  1181. });
  1182. });
  1183. return data;
  1184. }
  1185. }
  1186. const relaFileLoader = new RelaFileLoader();
  1187. $('#rela-file').on('show.bs.modal', function() {
  1188. relaFileLoader.showRelaFile(this.getAttribute('content'));
  1189. });
  1190. // 授权相关
  1191. class FilingPermission {
  1192. constructor (setting) {
  1193. this.setting = setting;
  1194. const self = this;
  1195. $(setting.modal).on('show.bs.modal', () => {
  1196. self.loadPermission();
  1197. });
  1198. $(`${setting.modal}-ok`).click(() => {
  1199. self.savePermission();
  1200. });
  1201. $('[name=ftName]').click(function () {
  1202. const filingId = this.getAttribute('ftid');
  1203. self.setCurFiling(filingId);
  1204. });
  1205. $('.book-list').on('click', 'dt', function () {
  1206. const idx = $(this).find('.acc-btn').attr('data-groupid');
  1207. const type = $(this).find('.acc-btn').attr('data-type');
  1208. if (type === 'hide') {
  1209. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  1210. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  1211. $(this).find('.acc-btn').attr('data-type', 'show')
  1212. })
  1213. } else {
  1214. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  1215. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  1216. $(this).find('.acc-btn').attr('data-type', 'hide')
  1217. })
  1218. }
  1219. return false;
  1220. });
  1221. $('dl').on('click', 'dd', function () {
  1222. const type = $(this).data('type');
  1223. if (type === 'all') {
  1224. const cid = parseInt($(this).data('id'));
  1225. const company = self.company.find(x => { return x.id === cid });
  1226. for (const u of company.users) {
  1227. if (u.filing_type.indexOf(self.curFiling) < 0) u.filing_type.push(self.curFiling);
  1228. }
  1229. } else {
  1230. const uid = $(this).data('id');
  1231. const pu = self.permissionUser.find(x => { return x.id === uid });
  1232. if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
  1233. }
  1234. self.loadCurFiling();
  1235. });
  1236. $('#sync-filing').click(function() {
  1237. const selectFiling = $('[name=cbft]:checked');
  1238. if (selectFiling.length === 0) {
  1239. toastr.warning('请先选择文档类别');
  1240. return;
  1241. }
  1242. const selectFilingId = [];
  1243. selectFiling.each((i, x) => { selectFilingId.push(x.value); });
  1244. self.syncFiling(self.curFiling, selectFilingId);
  1245. toastr.success('同步成功');
  1246. $('[name=cbft]').removeAttr('checked');
  1247. $('#filing-select-all')[0].checked = false;
  1248. });
  1249. $('#batch-del-filing').click(() => {
  1250. const selectUser = $('[name=ftu-check]:checked');
  1251. if (selectUser.length === 0) {
  1252. toastr.warning('请先选择用户');
  1253. return;
  1254. }
  1255. const userId = [];
  1256. selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
  1257. self.delFiling(self.curFiling, userId);
  1258. self.loadCurFiling();
  1259. });
  1260. $('body').on('click', '[name=del-filing]', function() {
  1261. const id = this.getAttribute('uid');
  1262. self.delFiling(self.curFiling, id);
  1263. self.loadCurFiling();
  1264. });
  1265. $('#user-select-all').click(function(){
  1266. $('input[uid]').attr('checked', this.checked);
  1267. });
  1268. $('#filing-select-all').click(function(){
  1269. $('input[name=cbft]').attr('checked', this.checked);
  1270. });
  1271. }
  1272. analysisFiling(data) {
  1273. this.permissionUser = data;
  1274. this.permissionUser.forEach(x => { x.filing_type = x.filing_type ? x.filing_type.split(',') : []; });
  1275. this.company = [];
  1276. for (const pu of this.permissionUser) {
  1277. let c = this.company.find(x => { return x.company === pu.company });
  1278. if (!c) {
  1279. c = { id: this.company.length + 1, company: pu.company, users: [] };
  1280. this.company.push(c);
  1281. }
  1282. c.users.push(pu);
  1283. }
  1284. }
  1285. loadCurFiling() {
  1286. const html = [];
  1287. for (const f of this.permissionUser) {
  1288. if (f.filing_type.indexOf(this.curFiling) < 0) continue;
  1289. html.push('<tr>');
  1290. html.push(`<td><input uid="${f.id}" type="checkbox" name="ftu-check"></td>`);
  1291. html.push(`<td>${f.name}</td>`);
  1292. html.push(`<td>${moment(f.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  1293. html.push(`<td>${f.file_permission}</td>`);
  1294. html.push(`<td><button class="btn btn-sm btn-outline-danger" uid="${f.id}" name="del-filing">移除</button></td>`);
  1295. html.push('</tr>');
  1296. }
  1297. $(this.setting.list).html(html.join(''));
  1298. $('#user-select-all')[0].checked = false;
  1299. }
  1300. setCurFiling(filingType) {
  1301. this.curFiling = filingType;
  1302. $('[name=ftName]').removeClass('bg-warning-50');
  1303. $(`[ftid=${filingType}]`).addClass('bg-warning-50');
  1304. this.loadCurFiling();
  1305. }
  1306. loadPermissionUser() {
  1307. const html = [];
  1308. for (const c of this.company) {
  1309. 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>`);
  1310. html.push(`<div class="dd-content" data-toggleid="${c.id}">`);
  1311. 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>`);
  1312. for (const u of c.users) {
  1313. html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${u.id}" >`);
  1314. html.push(`<p class="mb-0 d-flex"><span class="text-primary">${u.name}</span><span class="ml-auto">${u.mobile}</span></p>`);
  1315. html.push(`<span class="text-muted">${u.role}</span>`);
  1316. html.push(`</dd>`);
  1317. }
  1318. html.push('</div>');
  1319. }
  1320. $('#puList').html(html.join(''));
  1321. }
  1322. loadPermission() {
  1323. const self = this;
  1324. postData('permission', {}, function(result) {
  1325. self.analysisFiling(result);
  1326. if (!self.curFiling) {
  1327. self.setCurFiling($('[name=ftName]').attr('ftid'));
  1328. } else {
  1329. self.loadCurFiling();
  1330. }
  1331. self.loadPermissionUser();
  1332. });
  1333. }
  1334. syncFiling(sourceId, targetIds) {
  1335. for (const pu of this.permissionUser) {
  1336. if (pu.filing_type.indexOf(sourceId) >= 0) {
  1337. targetIds.forEach(id => {
  1338. if (pu.filing_type.indexOf(id) < 0) pu.filing_type.push(id);
  1339. });
  1340. } else {
  1341. targetIds.forEach(id => {
  1342. if (pu.filing_type.indexOf(id) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(id), 1);
  1343. })
  1344. }
  1345. }
  1346. }
  1347. delFiling(filingId, userId) {
  1348. const userIds = userId instanceof Array ? userId : [userId];
  1349. for (const id of userIds) {
  1350. const pu = this.permissionUser.find(x => { return x.id === id });
  1351. if (!pu) continue;
  1352. if (pu.filing_type.indexOf(filingId) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(filingId), 1);
  1353. }
  1354. }
  1355. savePermission() {
  1356. const self = this;
  1357. const data = this.permissionUser.map(x => {
  1358. return { id: x.id, filing_type: x.filing_type.join(',') };
  1359. });
  1360. postData('permission/save', data, function(result) {
  1361. $(self.setting.modal).modal('hide');
  1362. });
  1363. }
  1364. }
  1365. const filingPermission = new FilingPermission({
  1366. modal: '#filing-permission',
  1367. list: '#filing-valid',
  1368. });
  1369. class FileSearch {
  1370. constructor() {
  1371. this.searchResult = [];
  1372. this.initSearch();
  1373. }
  1374. getOperateHtml(file) {
  1375. const locateHtml = `<a href="javascript: void(0);" class="mr-1" name="locate-search-file" fid="${file.id}"><i class="fa fa-crosshairs"></i></a>`;
  1376. const editHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="edit-search-file" fid="${file.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
  1377. const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
  1378. 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>`;
  1379. const delHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1 text-danger" name="del-search-file" fid="${file.id}"><i class="fa fa-trash-o fa-fw"></i></a>` : '';
  1380. return `<div class="d-flex justify-content-between align-items-center table-file">${locateHtml}${editHtml}${viewHtml}${downHtml}${delHtml}</div>`
  1381. }
  1382. getFileHtml(file) {
  1383. const html = [];
  1384. html.push(`<tr fid="search_${file.id}">`);
  1385. html.push(`<td fid="search_${file.id}">${file.filename}${file.fileext}</td>`);
  1386. html.push(`<td class="text-center">${file.user_name}</td>`);
  1387. html.push(`<td class="text-center">${this.getOperateHtml(file)}</td>`);
  1388. html.push('</tr>');
  1389. return html.join('');
  1390. }
  1391. getResultHtml (result) {
  1392. this.searchResult = result;
  1393. const html = [];
  1394. for (const r of result) {
  1395. html.push(this.getFileHtml(r));
  1396. }
  1397. return html.join('');
  1398. }
  1399. getSearchFilter() {
  1400. const filter = $('#search-filter').val();
  1401. const filing_type = filter === 'all' ? filingObj.getAllFilingType() : filingObj.getCurFilingType();
  1402. return { filing_type };
  1403. }
  1404. getEditFileNameHtml(file) {
  1405. const inputHtml = `<input type="text" class="form-control form-control-sm form-control-s-width" maxlength="100" value="${file.filename + file.fileext}" fid="${file.id}">`;
  1406. const btnHtml = `<div class="btn-group-table" style="display: none;"><a href="javascript: void(0)" class="mr-1" name="edit-search-file-ok"><i class="fa fa-check fa-fw"></i></a><a href="javascript: void(0)" class="mr-1" name="edit-search-file-cancel"><i class="fa fa-remove fa-fw"></i></a></div>`;
  1407. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  1408. }
  1409. search() {
  1410. const searchData = this.getSearchFilter();
  1411. searchData.keyword = $('#search-keyword', '#search').val();
  1412. if (!searchData.keyword) {
  1413. toastr.warning('请输入查询的文件名称');
  1414. this.getResultHtml([]);
  1415. return;
  1416. }
  1417. postData(window.location.pathname + '/search', searchData, function(result) {
  1418. if (result.list.length === result.limit) toastr.warning(`最多查询${result.limit}个结果,请给出更准确的文件名称`);
  1419. $('#search-list').html(fileSearch.getResultHtml(result.list));
  1420. });
  1421. }
  1422. refreshSearchFile(file) {
  1423. const sfile = this.searchResult.find(x => { return x.id === file.id; });
  1424. if (sfile) {
  1425. for (const prop in file) {
  1426. if (prop === 'id') continue;
  1427. sfile[prop] = file[prop];
  1428. }
  1429. }
  1430. }
  1431. removeSearchFile(fid){
  1432. $(`tr[fid=search_${fid}]`, '#search').remove();
  1433. const index = this.searchResult.findIndex(x => { return x.id === fid; });
  1434. this.searchResult.splice(index, 1);
  1435. }
  1436. renameSearchFile(fid, data) {
  1437. const file = this.searchResult.find(x => { return x.id === fid; });
  1438. if (file) {
  1439. file.filename = data.filename;
  1440. file.fileext = data.fileext;
  1441. const td = $(`td[fid=search_${file.id}]`);
  1442. td.html(`${file.filename}${file.fileext}`);
  1443. }
  1444. }
  1445. initSearch() {
  1446. const self = this;
  1447. $.divResizer({
  1448. select: '#right-spr',
  1449. callback: function() {},
  1450. });
  1451. $('input', '#search').bind('keydown', function (e) {
  1452. if (e.keyCode == 13) self.search();
  1453. });
  1454. $('button', '#search').bind('click', () => { self.search(); });
  1455. $('body').on('click', "a[name=del-search-file]", function() {
  1456. const del = [this.getAttribute('fid')];
  1457. filingObj.delFiles(del);
  1458. });
  1459. $('body').on('click', "a[name=locate-search-file]", function() {
  1460. const fid = this.getAttribute('fid');
  1461. const file = self.searchResult.find(x => { return x.id === fid});
  1462. const filing = filingObj.findFiling(file.filing_id);
  1463. filingObj.filingTree.selectNode(filing);
  1464. filingObj.setCurFiling(filing);
  1465. });
  1466. $('body').on('click', "a[name=edit-search-file]", function() {
  1467. const check = $('[name=search-filename] input[fid]');
  1468. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  1469. const id = this.getAttribute('fid');
  1470. const file = self.searchResult.find(x => { return x.id === id });
  1471. $(`td[fid=search_${id}]`).html(self.getEditFileNameHtml(file));
  1472. });
  1473. $('body').on('click', "a[name=edit-search-file-ok]", function() {
  1474. const td = $(this).parent().parent().parent();
  1475. const fid = td.attr('fid').split('_')[1];
  1476. const file = self.searchResult.find(x => { return x.id === fid });
  1477. if (!file) return;
  1478. filingObj.renameFile(file, $('input', td).val());
  1479. });
  1480. $('body').on('click', "a[name=edit-search-file-cancel]", function() {
  1481. const td = $(this).parent().parent().parent();
  1482. const fid = td.attr('fid').split('_')[1];
  1483. const file = self.searchResult.find(x => { return x.id === fid });
  1484. if (!file) return;
  1485. td.html(`${file.filename}${file.fileext}`);
  1486. });
  1487. }
  1488. }
  1489. fileSearch = new FileSearch();
  1490. const showSideTools = function (show) {
  1491. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1492. if (show) {
  1493. right.show();
  1494. autoFlashHeight();
  1495. /**
  1496. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1497. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1498. * 故需要通过最终的parent.width再计算一次left.width
  1499. *
  1500. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1501. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1502. *
  1503. */
  1504. //left.css('width', parent.width() - right.outerWidth());
  1505. //left.css('width', parent.width() - right.outerWidth());
  1506. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1507. left.css('width', percent + '%');
  1508. } else {
  1509. left.width(parent.width());
  1510. right.hide();
  1511. }
  1512. };
  1513. // 展开收起标准清单
  1514. $('a', '#side-menu').bind('click', function (e) {
  1515. e.preventDefault();
  1516. const tab = $(this), tabPanel = $(tab.attr('content'));
  1517. // 展开工具栏、切换标签
  1518. if (!tab.hasClass('active')) {
  1519. // const close = $('.active', '#side-menu').length === 0;
  1520. $('a', '#side-menu').removeClass('active');
  1521. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  1522. tab.addClass('active');
  1523. tabPanel.addClass('active');
  1524. // $('.tab-content .tab-pane').removeClass('active');
  1525. showSideTools(tab.hasClass('active'));
  1526. } else { // 收起工具栏
  1527. tab.removeClass('active');
  1528. tabPanel.removeClass('active');
  1529. showSideTools(tab.hasClass('active'));
  1530. }
  1531. });
  1532. // 显示层次
  1533. (function (select) {
  1534. $(select).click(function () {
  1535. const tag = $(this).attr('tag');
  1536. setTimeout(() => {
  1537. showWaitingView();
  1538. switch (tag) {
  1539. case "1":
  1540. case "2":
  1541. case "3":
  1542. case "4":
  1543. filingObj.expandByLevel(parseInt(tag));
  1544. break;
  1545. case "last":
  1546. filingObj.expandByCustom(() => { return true; });
  1547. break;
  1548. }
  1549. closeWaitingView();
  1550. }, 100);
  1551. });
  1552. })('a[name=showLevel]');
  1553. });