file_detail.js 85 KB

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