file_detail.js 86 KB

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