file_detail.js 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  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. 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 || 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>` : '';
  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. if (fileReference) fileReference.spread.refresh();
  1451. },
  1452. });
  1453. $('input', '#search').bind('keydown', function (e) {
  1454. if (e.keyCode == 13) self.search();
  1455. });
  1456. $('button', '#search').bind('click', () => { self.search(); });
  1457. $('body').on('click', "a[name=del-search-file]", function() {
  1458. const del = [this.getAttribute('fid')];
  1459. filingObj.delFiles(del);
  1460. });
  1461. $('body').on('click', "a[name=locate-search-file]", function() {
  1462. const fid = this.getAttribute('fid');
  1463. const file = self.searchResult.find(x => { return x.id === fid});
  1464. const filing = filingObj.findFiling(file.filing_id);
  1465. filingObj.filingTree.selectNode(filing);
  1466. filingObj.setCurFiling(filing);
  1467. });
  1468. $('body').on('click', "a[name=edit-search-file]", function() {
  1469. const check = $('[name=search-filename] input[fid]');
  1470. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  1471. const id = this.getAttribute('fid');
  1472. const file = self.searchResult.find(x => { return x.id === id });
  1473. $(`td[fid=search_${id}]`).html(self.getEditFileNameHtml(file));
  1474. });
  1475. $('body').on('click', "a[name=edit-search-file-ok]", function() {
  1476. const td = $(this).parent().parent().parent();
  1477. const fid = td.attr('fid').split('_')[1];
  1478. const file = self.searchResult.find(x => { return x.id === fid });
  1479. if (!file) return;
  1480. filingObj.renameFile(file, $('input', td).val());
  1481. });
  1482. $('body').on('click', "a[name=edit-search-file-cancel]", function() {
  1483. const td = $(this).parent().parent().parent();
  1484. const fid = td.attr('fid').split('_')[1];
  1485. const file = self.searchResult.find(x => { return x.id === fid });
  1486. if (!file) return;
  1487. td.html(`${file.filename}${file.fileext}`);
  1488. });
  1489. }
  1490. }
  1491. fileSearch = new FileSearch();
  1492. const showSideTools = function (show) {
  1493. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1494. if (show) {
  1495. right.show();
  1496. autoFlashHeight();
  1497. /**
  1498. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1499. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1500. * 故需要通过最终的parent.width再计算一次left.width
  1501. *
  1502. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1503. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1504. *
  1505. */
  1506. //left.css('width', parent.width() - right.outerWidth());
  1507. //left.css('width', parent.width() - right.outerWidth());
  1508. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1509. left.css('width', percent + '%');
  1510. } else {
  1511. left.width(parent.width());
  1512. right.hide();
  1513. }
  1514. };
  1515. // 展开收起标准清单
  1516. $('a', '#side-menu').bind('click', function (e) {
  1517. e.preventDefault();
  1518. const tab = $(this), tabPanel = $(tab.attr('content'));
  1519. // 展开工具栏、切换标签
  1520. if (!tab.hasClass('active')) {
  1521. // const close = $('.active', '#side-menu').length === 0;
  1522. $('a', '#side-menu').removeClass('active');
  1523. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  1524. tab.addClass('active');
  1525. tabPanel.addClass('active');
  1526. // $('.tab-content .tab-pane').removeClass('active');
  1527. showSideTools(tab.hasClass('active'));
  1528. if (tab.attr('content') === '#reference') {
  1529. if (!fileReference) {
  1530. fileReference = $.stdLib({
  1531. selector: '#reference',
  1532. stdType: 'reference',
  1533. libs: fileReferenceList,
  1534. treeSetting: {
  1535. id: 'template_id',
  1536. pid: 'pid',
  1537. order: 'order',
  1538. level: 'level',
  1539. rootId: -1,
  1540. keys: ['id', 'list_id', 'template_id'],
  1541. },
  1542. spreadSetting: {
  1543. cols: [
  1544. {title: '名称', field: 'name', hAlign: 0, width: 300, formatter: '@', cellType: 'tree', wordWrap: true},
  1545. {title: '备注', field: 'remark', hAlign: 1, width: 150, formatter: '@', wordWrap: true}
  1546. ],
  1547. treeCol: 0,
  1548. emptyRows: 0,
  1549. headRows: 1,
  1550. headRowHeight: [32],
  1551. defaultRowHeight: 21,
  1552. headerFont: '12px 微软雅黑',
  1553. font: '12px 微软雅黑',
  1554. headColWidth: [30],
  1555. selectedBackColor: '#fffacd',
  1556. readOnly: true,
  1557. },
  1558. page: 'ledger',
  1559. });
  1560. }
  1561. fileReference.spread.refresh();
  1562. }
  1563. } else { // 收起工具栏
  1564. tab.removeClass('active');
  1565. tabPanel.removeClass('active');
  1566. showSideTools(tab.hasClass('active'));
  1567. }
  1568. });
  1569. // 显示层次
  1570. (function (select) {
  1571. $(select).click(function () {
  1572. const tag = $(this).attr('tag');
  1573. setTimeout(() => {
  1574. showWaitingView();
  1575. switch (tag) {
  1576. case "1":
  1577. case "2":
  1578. case "3":
  1579. case "4":
  1580. filingObj.expandByLevel(parseInt(tag));
  1581. break;
  1582. case "last":
  1583. filingObj.expandByCustom(() => { return true; });
  1584. break;
  1585. }
  1586. closeWaitingView();
  1587. }, 100);
  1588. });
  1589. })('a[name=showLevel]');
  1590. });