file_detail.js 84 KB

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