file_detail.js 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  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. $('#rela-file-ok').click(function() {
  950. const selectFiles = self.getSelectRelaFile();
  951. filingObj.relaFiles(selectFiles, function() {
  952. $('#rela-file').modal('hide');
  953. });
  954. });
  955. }
  956. clearFileSelect() {
  957. if (!this.tenderTree) return;
  958. const nodes = this.tenderTree.getNodes();
  959. nodes.forEach(node => {
  960. const x = node.source_node;
  961. x.selectFiles = [];
  962. if (x.att) x.att.forEach(la => { la.checked = false });
  963. if (x.advance) {
  964. x.advance.forEach(a => {
  965. if (a.files) a.files.forEach(aa => { aa.checked = false });
  966. });
  967. }
  968. if (x.stage) {
  969. x.stage.forEach(s => {
  970. if (s.att) s.att.forEach(sa => { sa.checked = false });
  971. })
  972. }
  973. });
  974. }
  975. refreshSelectHint(){
  976. if (this.curTender) {
  977. $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
  978. } else {
  979. $('#cur-tender-hint').html('');
  980. }
  981. const nodes = this.tenderTree.getNodes();
  982. const selectTenders = nodes.filter(x => { return x.source_node.selectFiles.length > 0; });
  983. if (selectTenders.length > 0) {
  984. const count = selectTenders.reduce((rst, x) => { return rst + x.source_node.selectFiles.length; }, 0);
  985. $('#rela-file-hint').html(`已选择${selectTenders.length}个标段,共${count}个文件`);
  986. } else {
  987. $('#rela-file-hint').html('未选择标段、文件');
  988. }
  989. }
  990. selectFile(fileId, isSelect) {
  991. const file = this.curFiles.find(x => { return x.rf_id == fileId });
  992. if (file) {
  993. file.checked = isSelect;
  994. if (isSelect) {
  995. this.curTender.source_node.selectFiles.push(file);
  996. } else {
  997. const index = this.curTender.source_node.selectFiles.findIndex(x => { return x.rf_id === file.rf_id });
  998. this.curTender.source_node.selectFiles.splice(index, 1);
  999. }
  1000. this.refreshSelectHint();
  1001. }
  1002. }
  1003. async showRelaFile(){
  1004. $('#rela-filing-hint').html(`当前目录:${filingObj.getCurFilingFullPath()}`);
  1005. if (!this.tenderTree) {
  1006. const tenders = await postDataAsync('file/rela/tender', {});
  1007. const sortNodes = tenders.map(x => {
  1008. return { id: x.id, tree_pid: -1, name: x.name, source_node: x };
  1009. });
  1010. this.tenderTree = this.filingTree = $.fn.zTree.init($('#rela-tender'), this.treeSetting, sortNodes);
  1011. }
  1012. this.clearFileSelect();
  1013. this.refreshSelectHint();
  1014. const firstNode = this.filingTree.getNodes()[0];
  1015. if (firstNode) {
  1016. this.filingTree.selectNode(firstNode);
  1017. await this.setCurTender(firstNode);
  1018. }
  1019. }
  1020. refreshTenderFileStage() {
  1021. if (this.rfType.sub_type) {
  1022. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
  1023. const subType = type.subType ? type.subType.find(x => { return x.value === this.rfType.sub_type; }) : null;
  1024. if (subType) {
  1025. this.rfType.stage = subType.stage[0].value;
  1026. const html= [];
  1027. for (const stage of subType.stage) {
  1028. html.push(`<option value="${stage.value}">${stage.text}</option>`);
  1029. }
  1030. $('#tf-stage').html(html.join('')).show();
  1031. } else {
  1032. $('#tf-stage').html('').hide();
  1033. }
  1034. } else {
  1035. $('#tf-stage').html('').hide();
  1036. }
  1037. }
  1038. refreshTenderFileSubType() {
  1039. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
  1040. if (type.subType && type.subType.length > 0) {
  1041. this.rfType.sub_type = type.subType[0].value;
  1042. const html= [];
  1043. for (const tfst of type.subType) {
  1044. html.push(`<option value="${tfst.value}">${tfst.text}</option>`);
  1045. }
  1046. $('#tf-sub-type').html(html.join('')).show();
  1047. } else {
  1048. $('#tf-sub-type').html('').hide();
  1049. }
  1050. }
  1051. refreshTenderFileType() {
  1052. const html= [];
  1053. for (const tft of this.tenderFileType) {
  1054. html.push(`<option value="${tft.value}">${tft.text}</option>`);
  1055. }
  1056. $('#tf-type').html(html.join(''));
  1057. }
  1058. refreshSelects(tender) {
  1059. this.tenderFileType = [];
  1060. this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
  1061. if (tender.stage && tender.stage.length > 0) {
  1062. const stages = tender.stage.map(x => { return {value: x.id, text: `第${x.order}期`}; });
  1063. this.tenderFileType.push({
  1064. value: 'stage', text: '计量期',
  1065. subType: [
  1066. { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
  1067. ],
  1068. });
  1069. }
  1070. if (tender.advance && tender.advance.length > 0) {
  1071. const advanceType = [];
  1072. tender.advance.forEach(x => {
  1073. let at = advanceType.find(y => { return y.value === x.type + '' });
  1074. if (!at) {
  1075. at = { value: x.type + '', text: x.type_str, stage: [] };
  1076. advanceType.push(at);
  1077. }
  1078. at.stage.push({ value: x.id, text: `第${x.order}期`});
  1079. });
  1080. this.tenderFileType.push({
  1081. value: 'advance', text: '预付款', subType: advanceType
  1082. });
  1083. }
  1084. this.rfType = { type: this.tenderFileType[0].value };
  1085. this.refreshTenderFileType();
  1086. this.refreshTenderFileSubType();
  1087. this.refreshTenderFileStage();
  1088. }
  1089. async selectTfStage(stage){
  1090. this.rfType.stage = stage;
  1091. await this.loadFiles();
  1092. this.refreshFileTable();
  1093. }
  1094. async selectTfSubType(sub_type){
  1095. this.rfType.sub_type = sub_type;
  1096. this.refreshTenderFileStage();
  1097. await this.loadFiles();
  1098. this.refreshFileTable();
  1099. }
  1100. async selectTfType(type){
  1101. this.rfType.type = type;
  1102. this.refreshTenderFileSubType();
  1103. this.refreshTenderFileStage();
  1104. await this.loadFiles();
  1105. this.refreshFileTable();
  1106. }
  1107. refreshFileTable() {
  1108. const html = [];
  1109. const typeStr = [];
  1110. const selectOption = $('option:selected');
  1111. selectOption.each((i, x) => {
  1112. typeStr.push(x.innerText);
  1113. });
  1114. for (const f of this.curFiles) {
  1115. html.push('<tr>');
  1116. const checked = f.checked ? "checked" : '';
  1117. html.push(`<td><input type="checkbox" name="rf-check" rfid="${f.rf_id}" ${checked}></td>`);
  1118. html.push(`<td>${f.filename}${f.fileext}</td>`);
  1119. html.push(`<td>${typeStr.join(' - ')}</td>`);
  1120. html.push('</tr>');
  1121. }
  1122. $('#rf-files').html(html.join(''));
  1123. };
  1124. initFilesId(files){
  1125. const tender_id = this.curTender.id;
  1126. const rfType = this.rfType;
  1127. files.forEach((f, i) => {
  1128. f.rf_id = `${tender_id}-${rfType.type}-${rfType.sub_type}-${rfType.stage}-${i}`;
  1129. f.rf_key = {
  1130. tender_id, ...rfType, id: f.id,
  1131. };
  1132. });
  1133. }
  1134. async _loadRelaFiles(rfType) {
  1135. return await postDataAsync('file/rela/files', { tender_id: this.curTender.id, ...rfType });
  1136. }
  1137. async _loadLedgerFile() {
  1138. if (!this.curTender.source_node.att) this.curTender.source_node.att = await this._loadRelaFiles(this.rfType);
  1139. this.curFiles = this.curTender.source_node.att;
  1140. }
  1141. async _loadStageFile() {
  1142. const rfType = this.rfType;
  1143. const stage = this.curTender.source_node.stage.find(x => {
  1144. return x.id == rfType.stage;
  1145. });
  1146. if (!stage) {
  1147. this.curFiles = [];
  1148. return;
  1149. }
  1150. if (!stage[this.rfType.sub_type]) stage[this.rfType.sub_type] = await this._loadRelaFiles(rfType);
  1151. this.curFiles = stage[this.rfType.sub_type];
  1152. }
  1153. async _loadAdvanceFile() {
  1154. const rfType = this.rfType;
  1155. const advance = this.curTender.source_node.advance.find(x => {
  1156. return x.id == rfType.stage;
  1157. });
  1158. if (!advance) {
  1159. this.curFiles = [];
  1160. return;
  1161. }
  1162. if (!advance.files) advance.files = await this._loadRelaFiles(rfType);
  1163. this.curFiles = advance.files;
  1164. }
  1165. async loadFiles() {
  1166. switch (this.rfType.type) {
  1167. case 'ledger': await this._loadLedgerFile(); break;
  1168. case 'stage': await this._loadStageFile(); break;
  1169. case 'advance': await this._loadAdvanceFile(); break;
  1170. }
  1171. this.initFilesId(this.curFiles);
  1172. }
  1173. async setCurTender(node) {
  1174. this.curTender = node;
  1175. this.refreshSelects(node.source_node);
  1176. await this.loadFiles();
  1177. this.refreshSelectHint();
  1178. this.refreshFileTable();
  1179. }
  1180. getSelectRelaFile() {
  1181. const data = [];
  1182. const nodes = this.tenderTree.getNodes();
  1183. nodes.forEach(node => {
  1184. if (node.source_node.selectFiles.length === 0) return;
  1185. node.source_node.selectFiles.forEach(x => {
  1186. data.push({
  1187. filename: x.filename, fileext: x.fileext, filepath: x.filepath, filesize: x.filesize,
  1188. rela_info: x.rf_key,
  1189. })
  1190. });
  1191. });
  1192. return data;
  1193. }
  1194. }
  1195. const relaFileLoader = new RelaFileLoader();
  1196. $('#rela-file').on('show.bs.modal', function() {
  1197. relaFileLoader.showRelaFile(this.getAttribute('content'));
  1198. });
  1199. // 授权相关
  1200. class FilingPermission {
  1201. constructor (setting) {
  1202. this.setting = setting;
  1203. const self = this;
  1204. this.spread = SpreadJsObj.createNewSpread($(`${setting.spread}`)[0]);
  1205. this.sheet = this.spread.getActiveSheet();
  1206. this.spreadSetting = {
  1207. cols: [
  1208. { title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 200, formatter: '@', cellType: 'tree'},
  1209. { title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 45, cellType: 'checkbox' },
  1210. ],
  1211. emptyRows: 0,
  1212. headRows: 1,
  1213. headRowHeight: [32],
  1214. defaultRowHeight: 21,
  1215. headColWidth: [25],
  1216. headerFont: '12px 微软雅黑',
  1217. font: '12px 微软雅黑',
  1218. readOnly: true,
  1219. selectedBackColor: '#fffacd',
  1220. };
  1221. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1222. this.permissionTree = createNewPathTree('base', {
  1223. id: 'tree_id',
  1224. pid: 'tree_pid',
  1225. order: 'order',
  1226. level: 'level',
  1227. isLeaf: 'is_leaf',
  1228. fullPath: 'full_path',
  1229. rootId: -1,
  1230. });
  1231. this.spread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
  1232. if (!info.sheet.zh_setting) return;
  1233. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  1234. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  1235. if (sheet.isEditing()) sheet.endEdit(true);
  1236. }
  1237. const col = info.sheet.zh_setting.cols[info.col];
  1238. if (col.field !== 'check') return;
  1239. const tree = self.permissionTree;
  1240. const node = tree.nodes[info.row];
  1241. const row = [info.row];
  1242. node.check = !node.check;
  1243. if (node.children && node.children.length > 0) {
  1244. const posterity = tree.getPosterity(node);
  1245. for (const p of posterity) {
  1246. p.check = node.check;
  1247. row.push(tree.nodes.indexOf(p));
  1248. }
  1249. }
  1250. if (!node.check) {
  1251. const parent = tree.getAllParents(node);
  1252. for (const p of parent) {
  1253. p.check = node.check;
  1254. row.push(tree.nodes.indexOf(p));
  1255. }
  1256. }
  1257. SpreadJsObj.reLoadRowsData(info.sheet, row);
  1258. });
  1259. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1260. if (info.newSelections[0].col === 1) {
  1261. info.sheet.setSelection(info.oldSelections[0].row, info.oldSelections[0].col, info.oldSelections[0].rowCount, info.oldSelections[0].colCount);
  1262. SpreadJsObj.reloadRowsBackColor(info.sheet, [info.newSelections[0].row, info.oldSelections[0].row]);
  1263. } else {
  1264. const node = SpreadJsObj.getSelectObject(info.sheet);
  1265. self.setCurFiling(node.filing_type);
  1266. }
  1267. });
  1268. $(setting.modal).on('show.bs.modal', () => {
  1269. self.loadPermission();
  1270. });
  1271. $(setting.modal).on('shown.bs.modal', () => {
  1272. self.spread.refresh();
  1273. });
  1274. $(`${setting.modal}-ok`).click(() => {
  1275. self.savePermission();
  1276. });
  1277. $('.book-list').on('click', 'dt', function () {
  1278. const idx = $(this).find('.acc-btn').attr('data-groupid');
  1279. const type = $(this).find('.acc-btn').attr('data-type');
  1280. if (type === 'hide') {
  1281. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  1282. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  1283. $(this).find('.acc-btn').attr('data-type', 'show')
  1284. })
  1285. } else {
  1286. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  1287. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  1288. $(this).find('.acc-btn').attr('data-type', 'hide')
  1289. })
  1290. }
  1291. return false;
  1292. });
  1293. $('dl').on('click', 'dd', function () {
  1294. const type = $(this).data('type');
  1295. if (type === 'all') {
  1296. const cid = parseInt($(this).data('id'));
  1297. const company = self.company.find(x => { return x.id === cid });
  1298. for (const u of company.users) {
  1299. if (u.filing_type.indexOf(self.curFiling) < 0) u.filing_type.push(self.curFiling);
  1300. }
  1301. } else {
  1302. const uid = $(this).data('id');
  1303. const pu = self.permissionUser.find(x => { return x.id === uid });
  1304. if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
  1305. }
  1306. self.loadCurFiling();
  1307. });
  1308. $('#sync-filing').click(function() {
  1309. const selectFilingId = [];
  1310. self.permissionTree.nodes.forEach(x => { if (x.check && (!x.children || x.children.length === 0)) selectFilingId.push(x.filing_type); });
  1311. if (selectFilingId.length === 0) {
  1312. toastr.warning('请先选择文档类别');
  1313. return;
  1314. }
  1315. self.syncFiling(self.curFiling, selectFilingId);
  1316. toastr.success('同步成功');
  1317. self.permissionTree.nodes.forEach(x => { x.check = false; });
  1318. SpreadJsObj.reloadColData(self.sheet, 1);
  1319. $('#filing-select-all')[0].checked = false;
  1320. });
  1321. $('#batch-del-filing').click(() => {
  1322. const selectUser = $('[name=ftu-check]:checked');
  1323. if (selectUser.length === 0) {
  1324. toastr.warning('请先选择用户');
  1325. return;
  1326. }
  1327. const userId = [];
  1328. selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
  1329. self.delFiling(self.curFiling, userId);
  1330. self.loadCurFiling();
  1331. });
  1332. $('#batch-add-filing').click(() => {
  1333. const selectFilingId = [];
  1334. self.permissionTree.nodes.forEach(x => { if (x.check && (!x.children || x.children.length === 0)) selectFilingId.push(x.filing_type); });
  1335. if (selectFilingId.length === 0) {
  1336. toastr.warning('请先选择文档类别');
  1337. return;
  1338. }
  1339. const selectUser = $('[name=ftu-check]:checked');
  1340. if (selectUser.length === 0) {
  1341. toastr.warning('请先选择用户');
  1342. return;
  1343. }
  1344. const userId = [];
  1345. selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
  1346. self.batchAddFiling(selectFilingId, userId);
  1347. self.loadCurFiling();
  1348. toastr.success('批量添加成功');
  1349. self.permissionTree.nodes.forEach(x => { x.check = false; });
  1350. SpreadJsObj.reloadColData(self.sheet, 1);
  1351. $('#filing-select-all')[0].checked = false;
  1352. });
  1353. $('body').on('click', '[name=del-filing]', function() {
  1354. const id = this.getAttribute('uid');
  1355. self.delFiling(self.curFiling, id);
  1356. self.loadCurFiling();
  1357. });
  1358. $('#user-select-all').click(function(){
  1359. $('input[uid]').attr('checked', this.checked);
  1360. });
  1361. $('#filing-select-all').click(function(){
  1362. self.permissionTree.nodes.forEach(x => {
  1363. x.check = this.checked;
  1364. });
  1365. SpreadJsObj.reloadColData(self.sheet, 1);
  1366. });
  1367. }
  1368. analysisFiling(data) {
  1369. this.permissionUser = data;
  1370. this.permissionUser.forEach(x => { x.filing_type = x.filing_type ? x.filing_type.split(',') : []; });
  1371. this.company = [];
  1372. for (const pu of this.permissionUser) {
  1373. let c = this.company.find(x => { return x.company === pu.company });
  1374. if (!c) {
  1375. c = { id: this.company.length + 1, company: pu.company, users: [] };
  1376. this.company.push(c);
  1377. }
  1378. c.users.push(pu);
  1379. }
  1380. }
  1381. loadCurFiling() {
  1382. const html = [];
  1383. for (const f of this.permissionUser) {
  1384. if (f.filing_type.indexOf(this.curFiling) < 0) continue;
  1385. html.push('<tr>');
  1386. html.push(`<td><input uid="${f.id}" type="checkbox" name="ftu-check"></td>`);
  1387. html.push(`<td>${f.name}</td>`);
  1388. html.push(`<td>${moment(f.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  1389. html.push(`<td>${f.file_permission}</td>`);
  1390. html.push(`<td><button class="btn btn-sm btn-outline-danger" uid="${f.id}" name="del-filing">移除</button></td>`);
  1391. html.push('</tr>');
  1392. }
  1393. $(this.setting.list).html(html.join(''));
  1394. $('#user-select-all')[0].checked = false;
  1395. }
  1396. refreshBtn() {
  1397. const self = this;
  1398. const filing = this.permissionTree.nodes.find(x => { return x.filing_type === self.curFiling; });
  1399. if (!filing || (filing.children && filing.children.length > 0)) {
  1400. $('#filing-add-user').hide();
  1401. $('#batch-del-filing').hide();
  1402. $('#batch-add-filing').hide();
  1403. $('#sync-filing').hide();
  1404. } else {
  1405. $('#filing-add-user').show();
  1406. $('#batch-del-filing').show();
  1407. $('#batch-add-filing').show();
  1408. $('#sync-filing').show();
  1409. }
  1410. }
  1411. setCurFiling(filingType) {
  1412. this.curFiling = filingType;
  1413. this.loadCurFiling();
  1414. this.refreshBtn();
  1415. }
  1416. loadPermissionUser() {
  1417. const html = [];
  1418. for (const c of this.company) {
  1419. 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>`);
  1420. html.push(`<div class="dd-content" data-toggleid="${c.id}">`);
  1421. 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>`);
  1422. for (const u of c.users) {
  1423. html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${u.id}" >`);
  1424. html.push(`<p class="mb-0 d-flex"><span class="text-primary">${u.name}</span><span class="ml-auto">${u.mobile}</span></p>`);
  1425. html.push(`<span class="text-muted">${u.role}</span>`);
  1426. html.push(`</dd>`);
  1427. }
  1428. html.push('</div>');
  1429. }
  1430. $('#puList').html(html.join(''));
  1431. }
  1432. _convertData(sourceTree) {
  1433. const data = [];
  1434. for (const node of sourceTree.nodes) {
  1435. if (!node.is_fixed) continue;
  1436. const parent = node.tree_pid === '-1' ? undefined : data.find(x => { return x.id === node.tree_pid; });
  1437. const child = sourceTree.nodes.find(x => { return x.tree_pid === node.id; });
  1438. data.push({
  1439. id: node.id,
  1440. tree_id: data.length + 1,
  1441. tree_pid: parent ? parent.tree_id : -1,
  1442. order: node.tree_order + 1,
  1443. level: node.tree_level,
  1444. is_leaf: !child || !child.is_fixed,
  1445. full_path: '',
  1446. name: node.name,
  1447. is_fixed: node.is_fixed,
  1448. filing_type: node.filing_type + '',
  1449. tips: node.tips,
  1450. file_count: node.file_count,
  1451. });
  1452. }
  1453. return data;
  1454. }
  1455. loadPermission() {
  1456. this.permissionTree.loadDatas(this._convertData(filingObj.dragTree));
  1457. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.permissionTree);
  1458. const self = this;
  1459. postData('permission', {}, function(result) {
  1460. self.analysisFiling(result);
  1461. if (!self.curFiling) {
  1462. const node = SpreadJsObj.getSelectObject(self.sheet);
  1463. self.setCurFiling(node.filing_type);
  1464. } else {
  1465. self.loadCurFiling();
  1466. }
  1467. self.loadPermissionUser();
  1468. });
  1469. }
  1470. syncFiling(sourceId, targetIds) {
  1471. for (const pu of this.permissionUser) {
  1472. if (pu.filing_type.indexOf(sourceId) >= 0) {
  1473. targetIds.forEach(id => {
  1474. if (pu.filing_type.indexOf(id) < 0) pu.filing_type.push(id);
  1475. });
  1476. } else {
  1477. targetIds.forEach(id => {
  1478. if (pu.filing_type.indexOf(id) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(id), 1);
  1479. })
  1480. }
  1481. }
  1482. }
  1483. delFiling(filingId, userId) {
  1484. const userIds = userId instanceof Array ? userId : [userId];
  1485. for (const id of userIds) {
  1486. const pu = this.permissionUser.find(x => { return x.id === id });
  1487. if (!pu) continue;
  1488. if (pu.filing_type.indexOf(filingId) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(filingId), 1);
  1489. }
  1490. }
  1491. batchAddFiling(filingIds, userId) {
  1492. for (const pu of this.permissionUser) {
  1493. if (userId.indexOf(pu.id) < 0) continue;
  1494. filingIds.forEach(fid => {
  1495. if (pu.filing_type.indexOf(fid) < 0) pu.filing_type.push(fid);
  1496. });
  1497. }
  1498. }
  1499. savePermission() {
  1500. const self = this;
  1501. const data = this.permissionUser.map(x => {
  1502. return { id: x.id, filing_type: x.filing_type.join(',') };
  1503. });
  1504. postData('permission/save', data, function(result) {
  1505. $(self.setting.modal).modal('hide');
  1506. });
  1507. }
  1508. }
  1509. const filingPermission = new FilingPermission({
  1510. modal: '#filing-permission',
  1511. list: '#filing-valid',
  1512. spread: '#permission-spread',
  1513. });
  1514. class FileSearch {
  1515. constructor() {
  1516. this.searchResult = [];
  1517. this.initSearch();
  1518. }
  1519. getOperateHtml(file) {
  1520. const locateHtml = `<a href="javascript: void(0);" class="mr-1" name="locate-search-file" fid="${file.id}"><i class="fa fa-crosshairs"></i></a>`;
  1521. 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>` : '';
  1522. const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
  1523. 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>`;
  1524. 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>` : '';
  1525. return `<div class="d-flex justify-content-between align-items-center table-file">${locateHtml}${editHtml}${viewHtml}${downHtml}${delHtml}</div>`
  1526. }
  1527. getFileHtml(file) {
  1528. const html = [];
  1529. html.push(`<tr fid="search_${file.id}">`);
  1530. html.push(`<td fid="search_${file.id}">${file.filename}${file.fileext}</td>`);
  1531. html.push(`<td class="text-center">${file.user_name}</td>`);
  1532. html.push(`<td class="text-center">${this.getOperateHtml(file)}</td>`);
  1533. html.push('</tr>');
  1534. return html.join('');
  1535. }
  1536. getResultHtml (result) {
  1537. this.searchResult = result;
  1538. const html = [];
  1539. for (const r of result) {
  1540. html.push(this.getFileHtml(r));
  1541. }
  1542. return html.join('');
  1543. }
  1544. getSearchFilter() {
  1545. const filter = $('#search-filter').val();
  1546. const filing_type = filter === 'all' ? filingObj.getAllFilingType() : filingObj.getCurFilingType();
  1547. return { filing_type };
  1548. }
  1549. getEditFileNameHtml(file) {
  1550. 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}">`;
  1551. 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>`;
  1552. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  1553. }
  1554. search() {
  1555. const searchData = this.getSearchFilter();
  1556. searchData.keyword = $('#search-keyword', '#search').val();
  1557. if (!searchData.keyword) {
  1558. toastr.warning('请输入查询的文件名称');
  1559. this.getResultHtml([]);
  1560. return;
  1561. }
  1562. postData(window.location.pathname + '/search', searchData, function(result) {
  1563. if (result.list.length === result.limit) toastr.warning(`最多查询${result.limit}个结果,请给出更准确的文件名称`);
  1564. $('#search-list').html(fileSearch.getResultHtml(result.list));
  1565. });
  1566. }
  1567. refreshSearchFile(file) {
  1568. const sfile = this.searchResult.find(x => { return x.id === file.id; });
  1569. if (sfile) {
  1570. for (const prop in file) {
  1571. if (prop === 'id') continue;
  1572. sfile[prop] = file[prop];
  1573. }
  1574. }
  1575. }
  1576. removeSearchFile(fid){
  1577. $(`tr[fid=search_${fid}]`, '#search').remove();
  1578. const index = this.searchResult.findIndex(x => { return x.id === fid; });
  1579. this.searchResult.splice(index, 1);
  1580. }
  1581. renameSearchFile(fid, data) {
  1582. const file = this.searchResult.find(x => { return x.id === fid; });
  1583. if (file) {
  1584. file.filename = data.filename;
  1585. file.fileext = data.fileext;
  1586. const td = $(`td[fid=search_${file.id}]`);
  1587. td.html(`${file.filename}${file.fileext}`);
  1588. }
  1589. }
  1590. initSearch() {
  1591. const self = this;
  1592. $.divResizer({
  1593. select: '#right-spr',
  1594. callback: function() {
  1595. if (fileReference) fileReference.spread.refresh();
  1596. },
  1597. });
  1598. $('input', '#search').bind('keydown', function (e) {
  1599. if (e.keyCode == 13) self.search();
  1600. });
  1601. $('button', '#search').bind('click', () => { self.search(); });
  1602. $('body').on('click', "a[name=del-search-file]", function() {
  1603. const del = [this.getAttribute('fid')];
  1604. filingObj.delFiles(del);
  1605. });
  1606. $('body').on('click', "a[name=locate-search-file]", function() {
  1607. const fid = this.getAttribute('fid');
  1608. const file = self.searchResult.find(x => { return x.id === fid});
  1609. const filing = filingObj.findFiling(file.filing_id);
  1610. filingObj.filingTree.selectNode(filing);
  1611. filingObj.setCurFiling(filing);
  1612. });
  1613. $('body').on('click', "a[name=edit-search-file]", function() {
  1614. const check = $('[name=search-filename] input[fid]');
  1615. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  1616. const id = this.getAttribute('fid');
  1617. const file = self.searchResult.find(x => { return x.id === id });
  1618. $(`td[fid=search_${id}]`).html(self.getEditFileNameHtml(file));
  1619. });
  1620. $('body').on('click', "a[name=edit-search-file-ok]", function() {
  1621. const td = $(this).parent().parent().parent();
  1622. const fid = td.attr('fid').split('_')[1];
  1623. const file = self.searchResult.find(x => { return x.id === fid });
  1624. if (!file) return;
  1625. filingObj.renameFile(file, $('input', td).val());
  1626. });
  1627. $('body').on('click', "a[name=edit-search-file-cancel]", function() {
  1628. const td = $(this).parent().parent().parent();
  1629. const fid = td.attr('fid').split('_')[1];
  1630. const file = self.searchResult.find(x => { return x.id === fid });
  1631. if (!file) return;
  1632. td.html(`${file.filename}${file.fileext}`);
  1633. });
  1634. }
  1635. }
  1636. fileSearch = new FileSearch();
  1637. const showSideTools = function (show) {
  1638. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1639. if (show) {
  1640. right.show();
  1641. autoFlashHeight();
  1642. /**
  1643. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1644. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1645. * 故需要通过最终的parent.width再计算一次left.width
  1646. *
  1647. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1648. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1649. *
  1650. */
  1651. //left.css('width', parent.width() - right.outerWidth());
  1652. //left.css('width', parent.width() - right.outerWidth());
  1653. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1654. left.css('width', percent + '%');
  1655. } else {
  1656. left.width(parent.width());
  1657. right.hide();
  1658. }
  1659. };
  1660. // 展开收起标准清单
  1661. $('a', '#side-menu').bind('click', function (e) {
  1662. e.preventDefault();
  1663. const tab = $(this), tabPanel = $(tab.attr('content'));
  1664. // 展开工具栏、切换标签
  1665. if (!tab.hasClass('active')) {
  1666. // const close = $('.active', '#side-menu').length === 0;
  1667. $('a', '#side-menu').removeClass('active');
  1668. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  1669. tab.addClass('active');
  1670. tabPanel.addClass('active');
  1671. // $('.tab-content .tab-pane').removeClass('active');
  1672. showSideTools(tab.hasClass('active'));
  1673. if (tab.attr('content') === '#reference') {
  1674. if (!fileReference) {
  1675. fileReference = $.stdLib({
  1676. selector: '#reference',
  1677. stdType: 'reference',
  1678. libs: fileReferenceList,
  1679. treeSetting: {
  1680. id: 'template_id',
  1681. pid: 'pid',
  1682. order: 'order',
  1683. level: 'level',
  1684. rootId: -1,
  1685. keys: ['id', 'list_id', 'template_id'],
  1686. },
  1687. spreadSetting: {
  1688. cols: [
  1689. {title: '名称', field: 'name', hAlign: 0, width: 420, formatter: '@', cellType: 'tree', wordWrap: true},
  1690. {title: '备注', field: 'remark', hAlign: 1, width: 150, formatter: '@'}
  1691. ],
  1692. emptyRows: 0,
  1693. headRows: 1,
  1694. headRowHeight: [32],
  1695. defaultRowHeight: 21,
  1696. headerFont: '12px 微软雅黑',
  1697. font: '12px 微软雅黑',
  1698. headColWidth: [30],
  1699. selectedBackColor: '#fffacd',
  1700. readOnly: true,
  1701. localCache: {
  1702. key: 'file_detail_reference',
  1703. colWidth: true,
  1704. },
  1705. },
  1706. page: 'file',
  1707. });
  1708. }
  1709. fileReference.spread.refresh();
  1710. }
  1711. } else { // 收起工具栏
  1712. tab.removeClass('active');
  1713. tabPanel.removeClass('active');
  1714. showSideTools(tab.hasClass('active'));
  1715. }
  1716. });
  1717. // 显示层次
  1718. (function (select) {
  1719. $(select).click(function () {
  1720. const tag = $(this).attr('tag');
  1721. setTimeout(() => {
  1722. showWaitingView();
  1723. switch (tag) {
  1724. case "1":
  1725. case "2":
  1726. case "3":
  1727. case "4":
  1728. filingObj.expandByLevel(parseInt(tag));
  1729. break;
  1730. case "last":
  1731. filingObj.expandByCustom(() => { return true; });
  1732. break;
  1733. }
  1734. closeWaitingView();
  1735. }, 100);
  1736. });
  1737. })('a[name=showLevel]');
  1738. });