file_detail.js 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  1. $(document).ready(function() {
  2. let fileSearch;
  3. autoFlashHeight();
  4. $('#filing').height($(".sjs-height-0").height() - $('#add-slibing').parent().parent().height() - 10);
  5. class FilingObj {
  6. constructor(setting) {
  7. // 原始数据整理后的树结构,用来整理zTree显示
  8. this.dragTree = createDragTree({
  9. id: 'id',
  10. pid: 'tree_pid',
  11. level: 'tree_level',
  12. order: 'tree_order',
  13. rootId: '-1'
  14. });
  15. // 界面显示的zTree
  16. this.setting = setting;
  17. this.filingTree = null;
  18. this.pageCount = 15;
  19. this.expandKey = 'filing-' + window.location.pathname.split('/')[2];
  20. const cache = getLocalCache(this.expandKey);
  21. this.expandCache = cache ? _.uniq(cache.split(',')) : [];
  22. this.curFilingKey = 'cur-filing-' + window.location.pathname.split('/')[2];
  23. $('#filing').height($(".sjs-height-0").height()-$('.d-flex',".sjs-height-0").height() - 10);
  24. this.fileOrderKey = 'fileOrder';
  25. this.fileOrder = getLocalCache(this.fileOrderKey) || 'create_time|desc';
  26. }
  27. refreshFileOrderButton() {
  28. const orderBy = this.fileOrder.split('|');
  29. const field = orderBy[0], sort = orderBy[1];
  30. const buttons = $('[name=file-sort]');
  31. for (const b of buttons) {
  32. const curField = b.getAttribute('field');
  33. if (curField === field) {
  34. $(b).html(`<i class="fa fa-sort-amount-${sort}" aria-hidden="true"></i>`).attr('tag', `${curField}|${sort === 'asc' ? 'desc' : 'asc'}`);
  35. } else {
  36. $(b).html('<i class="fa fa-sort" aria-hidden="true">').attr('tag', `${curField}|desc`);
  37. }
  38. }
  39. }
  40. calcTotalFileCount() {
  41. this.dragTree.recursiveFun(this.dragTree.children, x => {
  42. if (x.children && x.children.length > 0) {
  43. x.total_file_count = x.children.reduce((pre, c) => {
  44. if (x.filing_type === 1) console.log('reduce', c.name, c.total_file_count);
  45. return pre + c.total_file_count
  46. }, 0);
  47. } else {
  48. x.total_file_count = x.file_count || 0;
  49. }
  50. if (x.filing_type === 1) console.log(x.name, x.total_file_count);
  51. });
  52. }
  53. _loadFilingSourceNode() {
  54. const self = this;
  55. const loadChildren = function(children) {
  56. for (const child of children) {
  57. if (child.children && child.children.length > 0) loadChildren(child.children);
  58. child.source_node = self.dragTree.getItems(child.id);
  59. }
  60. };
  61. const nodes = this.filingTree.getNodes();
  62. loadChildren(nodes);
  63. }
  64. loadFiling() {
  65. const self = this;
  66. if (this.filingTree) $.fn.zTree.destroy(this.setting.treeId);
  67. const sortNodes = this.dragTree.nodes.map(x => {
  68. const result = {
  69. id: x.id,
  70. tree_pid: x.tree_pid,
  71. name: x.name + (x.total_file_count > 0 ? `(${x.total_file_count})` : ''),
  72. spid: x.spid,
  73. tips: x.tips || '',
  74. };
  75. if (x.is_fixed) result.isParent = true;
  76. if (x.is_folder || x.is_fixed) result.open = self.expandCache.indexOf(result.id) >= 0;
  77. return result;
  78. });
  79. this.filingTree = $.fn.zTree.init($('#filing'), this.setting, sortNodes);
  80. this._loadFilingSourceNode();
  81. const curCache = getLocalCache(this.curFilingKey);
  82. const curNode = curCache ? this.filingTree.getNodeByParam('id', curCache) : null;
  83. if (curNode){
  84. this.filingTree.selectNode(curNode);
  85. filingObj.setCurFiling(curNode);
  86. }
  87. }
  88. analysisFiling(data) {
  89. this.dragTree.loadDatas(data);
  90. this.calcTotalFileCount();
  91. this.loadFiling();
  92. }
  93. _getFileNameHtml(file) {
  94. const editHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="edit-file" fid="${file.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
  95. const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
  96. 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>`;
  97. const delHtml = file.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>` : '';
  98. 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;">${editHtml}${viewHtml}${downHtml}${delHtml}</div></div>`;
  99. }
  100. _getEditFileNameHtml(file) {
  101. const inputHtml = `<input type="text" class="form-control form-control-sm form-control-width" maxlength="100" value="${file.filename + file.fileext}" fid="${file.id}">`;
  102. 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>`;
  103. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  104. }
  105. _getFileHtml(file) {
  106. const html = [];
  107. html.push(`<tr fid="${file.id}">`);
  108. html.push(`<td class="text-center"><input type="checkbox" name="bd-check" fid="${file.id}"></td>`);
  109. html.push(`<td fid="${file.id}">${this._getFileNameHtml(file)}</td>`);
  110. html.push(`<td class="text-center">${file.user_name}</td>`);
  111. html.push(`<td class="text-center">${moment(file.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  112. html.push(`<td class="text-center">${file.fileext_str}</td>`);
  113. html.push('</tr>');
  114. return html.join('');
  115. }
  116. refreshFilesTable() {
  117. const html = [];
  118. const files = this.curFiling.source_node.files;
  119. if (!files || files.length === 0) {
  120. $('#file-list').html('');
  121. return;
  122. }
  123. const startIndex = (this.curPage - 1)*this.pageCount;
  124. const endIndex = this.curPage*this.pageCount;
  125. for (const [i, f] of files.entries()) {
  126. if (i < startIndex || i >= endIndex) continue;
  127. html.push(this._getFileHtml(f));
  128. }
  129. $('#file-list').html(html.join(''));
  130. }
  131. refreshPages() {
  132. if (!filingObj.curFiling) return;
  133. filingObj.curTotalPage = Math.ceil(filingObj.curFiling.source_node.file_count / this.pageCount);
  134. filingObj.curPage = Math.min(filingObj.curTotalPage, Math.max(filingObj.curPage, 1));
  135. $('#curPage').html(filingObj.curPage);
  136. $('#curTotalPage').html(filingObj.curTotalPage);
  137. if (filingObj.curTotalPage > 1) {
  138. $('#showPage').show();
  139. } else {
  140. $('#showPage').hide();
  141. }
  142. }
  143. async loadFiles(node, page) {
  144. if (node.source_node.children && node.source_node.children.length > 0) return;
  145. if (!node.source_node.files) node.source_node.files = [];
  146. if (!node.source_node.file_count) return;
  147. if (node.source_node.files && node.source_node.files.length === node.source_node.file_count) return;
  148. const needFiles = Math.min(page*this.pageCount, node.source_node.file_count);
  149. if (node.source_node.files && needFiles <= node.source_node.files.length) return;
  150. const files = await postDataAsync('file/load', { filing_id: node.id, page, count: this.pageCount, order: this.fileOrder });
  151. files.forEach(x => {
  152. const file = node.source_node.files.find(f => {return x.id === f.id; });
  153. if (file) {
  154. Object.assign(file, x);
  155. } else {
  156. node.source_node.files.push(x);
  157. }
  158. });
  159. // node.source_node.files.sort((x, y) => {
  160. // return x.create_time - y.create_time;
  161. // });
  162. }
  163. addSiblingFiling(node) {
  164. const self = this;
  165. postData('filing/add', { tree_pid: node.tree_pid, tree_pre_id: node.id }, function(result) {
  166. const refreshData = self.dragTree.loadPostData(result);
  167. const newNode = refreshData.create[0];
  168. const nodes = self.filingTree.addNodes(node.getParentNode(), node.getIndex() + 1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid }]);
  169. nodes[0].source_node = newNode;
  170. });
  171. }
  172. addChildFiling(node) {
  173. const self = this;
  174. postData('filing/add', { tree_pid: node.id }, function(result) {
  175. const refreshData = self.dragTree.loadPostData(result);
  176. const newNode = refreshData.create[0];
  177. const nodes = self.filingTree.addNodes(node, -1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid}]);
  178. nodes[0].source_node = newNode;
  179. });
  180. }
  181. delFiling(node, callback) {
  182. const parent = node.getParentNode();
  183. const self = this;
  184. postData('filing/del', { id: node.id }, function(result) {
  185. self.updateFilingFileCount(node, 0);
  186. self.dragTree.loadPostData(result);
  187. self.filingTree.removeNode(node);
  188. self.calcTotalFileCount();
  189. if (parent) {
  190. const path = parent.getPath();
  191. for (const p of path) {
  192. p.name = p.source_node.name + (p.source_node.total_file_count > 0 ? `(${p.source_node.total_file_count})` : '');
  193. if (p.source_node.is_fixed) p.isParent = true;
  194. filingObj.filingTree.updateNode(p);
  195. }
  196. }
  197. if (callback) callback();
  198. });
  199. }
  200. async renameFiling(node, newName) {
  201. const result = await postDataAsync('filing/save', { id: node.id, name: newName });
  202. node.source_node.name = newName;
  203. node.name = node.source_node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
  204. return result;
  205. }
  206. updateFilingFileCount(filing, count) {
  207. let differ = count - (filing.source_node.file_count || 0);
  208. filing.source_node.file_count = count;
  209. filing.source_node.total_file_count = count;
  210. filing.name = filing.source_node.name + (filing.source_node.total_file_count > 0 ? `(${filing.source_node.total_file_count})` : '');
  211. filingObj.filingTree.updateNode(filing);
  212. let parent = filing.getParentNode();
  213. while (!!parent) {
  214. parent.source_node.total_file_count = parent.source_node.total_file_count ? parent.source_node.total_file_count + differ : differ;
  215. parent.name = parent.source_node.name + (parent.source_node.total_file_count > 0 ? `(${parent.source_node.total_file_count})` : '');
  216. filingObj.filingTree.updateNode(parent);
  217. parent = parent.getParentNode();
  218. }
  219. }
  220. checkFilesExist(files, callback) {
  221. const data = [];
  222. for (const file of files) {
  223. if (file === undefined) return [];
  224. data.push(file.name);
  225. }
  226. postData('file/check', { filing_id: filingObj.curFiling.id, files: data }, function(result) {
  227. callback(result);
  228. });
  229. }
  230. uploadFiles(files, filterFiles, callback) {
  231. const formData = new FormData();
  232. formData.append('filing_id', filingObj.curFiling.id);
  233. let count = 0;
  234. for (const file of files) {
  235. if (filterFiles.indexOf(file.name) >= 0) continue;
  236. if (file === undefined) {
  237. toastr.error('未选择上传文件。');
  238. return false;
  239. }
  240. if (file.size > 50 * 1024 * 1024) {
  241. toastr.error('上传文件大小超过50MB。');
  242. return false;
  243. }
  244. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  245. if (whiteList.indexOf(fileext) === -1) {
  246. toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
  247. return false;
  248. }
  249. formData.append('size', file.size);
  250. formData.append('file[]', file);
  251. count++;
  252. }
  253. if (count === 0) {
  254. toastr.warning('没有可上传的文件');
  255. return false;
  256. }
  257. postDataWithFile('file/upload', formData, function (data) {
  258. filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
  259. filingObj.curFiling.source_node.files.unshift(...data.files);
  260. filingObj.refreshPages();
  261. filingObj.refreshFilesTable();
  262. if (callback) callback();
  263. });
  264. }
  265. uploadBigFile(file, callback) {
  266. if (file.size > 500 * 1024 * 1024) {
  267. toastr.error('上传文件大小超过500MB。');
  268. return false;
  269. }
  270. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  271. if (whiteList.indexOf(fileext) === -1) {
  272. toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
  273. return false;
  274. }
  275. AliOss.uploadBigFile(file, 'file/upload/big', { filing_id: filingObj.curFiling.id },
  276. { progressObj: $('#upload-big-file-progress'), resumeObj: $('#add-big-file-resume'), stopObj: $('#add-big-file-stop') },
  277. function(result) {
  278. filingObj.curFiling.source_node.files.unshift(...result.files);
  279. filingObj.updateFilingFileCount(filingObj.curFiling, result.filing.file_count);
  280. filingObj.refreshPages();
  281. filingObj.refreshFilesTable();
  282. if (callback) callback();
  283. });
  284. }
  285. delFiles(files, callback) {
  286. postData('file/del', { del: files }, async function(data) {
  287. const relaFiling = data.filing.id === filingObj.curFiling.source_node.id
  288. ? filingObj.curFiling : filingObj.findFiling(data.filing.id);
  289. for (const id of data.del) {
  290. const fIndex = relaFiling.source_node.files.findIndex(x => { return x.id === id });
  291. if (fIndex >= 0) relaFiling.source_node.files.splice(fIndex, 1);
  292. fileSearch.removeSearchFile(id);
  293. }
  294. filingObj.updateFilingFileCount(relaFiling, data.filing.file_count);
  295. await filingObj.loadFiles(relaFiling, filingObj.curPage);
  296. if (data.filing.id === filingObj.curFiling.source_node.id) {
  297. filingObj.refreshPages();
  298. filingObj.refreshFilesTable();
  299. }
  300. if (callback) callback();
  301. });
  302. }
  303. renameFile(file, filename) {
  304. const self = this;
  305. const td = $(`td[fid=${file.id}]`);
  306. postData('file/save', { id: file.id, filename }, function(data) {
  307. const relaFiling = filingObj.findFiling(file.filing_id);
  308. const relaFile = relaFiling.source_node.files.find(x => { return x.id === file.id });
  309. relaFile.filename = data.filename;
  310. relaFile.fileext = data.fileext;
  311. td.html(self._getFileNameHtml(relaFile));
  312. fileSearch.renameSearchFile(file.id, data);
  313. }, function() {
  314. td.html(self._getFileNameHtml(file));
  315. fileSearch.renameSearchFile(file.id);
  316. });
  317. }
  318. relaFiles(files, callback) {
  319. postData('file/rela', { filing_id: this.curFiling.id, files: files }, async function(data) {
  320. filingObj.curFiling.source_node.files.unshift(...data.files);
  321. filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
  322. filingObj.refreshFilesTable();
  323. filingObj.refreshPages();
  324. if (callback) callback();
  325. });
  326. }
  327. async setCurFiling(node) {
  328. filingObj.curFiling = node;
  329. filingObj.curPage = 1;
  330. filingObj.refreshPages();
  331. if (filingObj.curFiling.source_node.children && filingObj.curFiling.source_node.children.length > 0) {
  332. $('#file-view').hide();
  333. } else {
  334. $('#file-view').show();
  335. await filingObj.loadFiles(node, 1);
  336. filingObj.refreshFilesTable();
  337. }
  338. if (filingObj.curFiling.source_node.filing_type === 5) {
  339. $('#rela-file-btn').show();
  340. } else {
  341. $('#rela-file-btn').hide();
  342. }
  343. setLocalCache(this.curFilingKey, filingObj.curFiling.id);
  344. }
  345. findFiling(id) {
  346. return filingObj.filingTree.getNodeByParam('id', id);
  347. }
  348. prePage() {
  349. if (this.curPage === 1) return;
  350. this.curPage = this.curPage - 1;
  351. this.refreshPages();
  352. this.refreshFilesTable();
  353. }
  354. async nextPage() {
  355. if (this.curPage === this.curTotalPage) return;
  356. await filingObj.loadFiles(this.curFiling, this.curPage + 1);
  357. this.curPage = this.curPage + 1;
  358. this.refreshPages();
  359. this.refreshFilesTable();
  360. }
  361. getCurFilingFullPath(){
  362. let cur = filingObj.curFiling;
  363. const result = [];
  364. while (cur) {
  365. result.unshift(cur.source_node.name);
  366. cur = cur.getParentNode();
  367. }
  368. return result.join('/');
  369. }
  370. expandFiling(node, expand) {
  371. if (expand) {
  372. this.expandCache.push(node.id);
  373. } else{
  374. this.expandCache = this.expandCache.filter(x => { return x !== node.id });
  375. }
  376. setLocalCache(this.expandKey, this.expandCache.join(','));
  377. }
  378. expandByLevel(level) {
  379. this.expandByCustom(x => {
  380. return x.level + 1 < level;
  381. })
  382. }
  383. expandByCustom(fun) {
  384. const self = this;
  385. const expandCache = [];
  386. const expandChildren = function(children) {
  387. for (const child of children) {
  388. if (!child.children || child.children.length === 0) continue;
  389. const expand = fun(child);
  390. if (expand) expandCache.push(child.id);
  391. self.filingTree.expandNode(child, expand, false, false);
  392. expandChildren(child.children);
  393. }
  394. };
  395. const nodes = this.filingTree.getNodes();
  396. expandChildren(nodes);
  397. this.expandCache = expandCache;
  398. setLocalCache(this.expandKey, this.expandCache.join(','));
  399. }
  400. moveFiling(node, tree_pid, tree_order) {
  401. if (tree_pid === node.source_node.tree_pid && tree_order === node.source_node.tree_order) return;
  402. const self = this;
  403. postData('filing/move', { id: node.id, tree_pid, tree_order }, function(result) {
  404. const refresh = self.dragTree.loadPostData(result);
  405. self.calcTotalFileCount();
  406. const updated = [];
  407. for (const u of refresh.update) {
  408. const node = self.filingTree.getNodeByParam('id', u.id);
  409. if (node) {
  410. const path = node.getPath();
  411. for (const p of path) {
  412. if (updated.indexOf(p.id) >= 0) continue;
  413. p.name = p.source_node.name + (p.source_node.total_file_count > 0 ? `(${p.source_node.total_file_count})` : '');
  414. filingObj.filingTree.updateNode(p);
  415. updated.push(p.id);
  416. }
  417. }
  418. }
  419. });
  420. }
  421. _clearAllFileCache() {
  422. const nodes = this.filingTree.getNodes();
  423. for (const node of nodes) {
  424. if (node.children && node.children.length > 0) continue;
  425. if (node.source_node.files) node.source_node.files.length = 0;
  426. }
  427. }
  428. changeFileOrder(fileOrder) {
  429. this.fileOrder = fileOrder;
  430. setLocalCache(this.fileOrderKey, fileOrder);
  431. this.refreshFileOrderButton();
  432. this._clearAllFileCache();
  433. this.setCurFiling(this.curFiling);
  434. }
  435. getNodeFilingType(node) {
  436. if (!node.is_fixed) return [];
  437. const types = [];
  438. if (node.children && node.children.length > 0) {
  439. for (const child of node.children) {
  440. const childTypes = this.getNodeFilingType(child);
  441. if (childTypes.length > 0) types.push(...childTypes);
  442. }
  443. }
  444. if (types.length === 0) types.push(node.filing_type);
  445. return types;
  446. }
  447. getParentFilingType(node) {
  448. const parent = this.dragTree.getParent(node);
  449. if (!parent) return [];
  450. if (parent.is_fixed) return [parent.filing_type];
  451. return this.getParentFilingType(parent);
  452. }
  453. getAllFilingType() {
  454. const types = [];
  455. for (const node of this.dragTree.children) {
  456. types.push(...this.getNodeFilingType(node))
  457. }
  458. return types;
  459. }
  460. getCurFilingType() {
  461. const cur = filingObj.curFiling;
  462. const node = this.dragTree.nodes.find(x => { return x.id === cur.source_node.id; });
  463. return node.is_fixed ? this.getNodeFilingType(node) : this.getParentFilingType(node);
  464. }
  465. }
  466. const levelTreeSetting = {
  467. treeId: 'filing',
  468. view: {
  469. selectedMulti: false,
  470. showTitle: true,
  471. },
  472. data: {
  473. simpleData: {
  474. idKey: 'id',
  475. pIdKey: 'tree_pid',
  476. rootPId: '-1',
  477. enable: true,
  478. },
  479. key: { title: 'tips' },
  480. },
  481. edit: {
  482. enable: true,
  483. showRemoveBtn: function(treeId, treeNode) {
  484. if (!canFiling) return false;
  485. return !treeNode.source_node.is_fixed;
  486. },
  487. showRenameBtn: function(treeId, treeNode) {
  488. if (!canFiling) return false;
  489. return !treeNode.source_node.is_fixed;
  490. },
  491. renameTitle: '编辑',
  492. removeTitle: '删除',
  493. drag: {
  494. isCopy: false,
  495. isMove: true,
  496. pre: true,
  497. next: true,
  498. inner: false,
  499. },
  500. editNameSelectAll: true,
  501. },
  502. callback: {
  503. onClick: async function (e, key, node) {
  504. if (filingObj.curFiling && filingObj.curFiling.id === node.id) return;
  505. filingObj.setCurFiling(node);
  506. },
  507. beforeEditName: function(key, node) {
  508. node.name = node.source_node.name;
  509. },
  510. beforeRename: async function(key, node, newName, isCancel) {
  511. if (!isCancel) await filingObj.renameFiling(node, newName);
  512. return true;
  513. },
  514. onRename: function(e, key, node, isCancel) {
  515. node.name = node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
  516. filingObj.filingTree.updateNode(node);
  517. },
  518. beforeRemove: function(key, node, isCancel) {
  519. $('#del-filing').modal('show');
  520. return false;
  521. },
  522. onExpand(e, key, node) {
  523. filingObj.expandFiling(node, true);
  524. },
  525. onCollapse: function(e, key, node) {
  526. filingObj.expandFiling(node, false);
  527. },
  528. beforeDrop: function(key, nodes, target, moveType, isCopy) {
  529. if (!canFiling) return false;
  530. if (!target) return false;
  531. if (nodes[0].level < 1) {
  532. toastr.error('顶层节点请勿移动');
  533. return false;
  534. }
  535. if (nodes[0].is_fixed) {
  536. toastr.error('固定分类请勿移动');
  537. return false;
  538. }
  539. if (nodes[0].source_node.filing_type !== target.source_node.filing_type) {
  540. toastr.error('请勿跨越最顶层节点移动');
  541. return false;
  542. }
  543. if (target.source_node.file_count > 0 && moveType === 'inner') {
  544. toastr.error(`节点[${target.source_node.name}]下存在文件,不可添加子级`);
  545. return false;
  546. }
  547. const order = nodes[0].getIndex() + 1;
  548. const targetOrder = target.getIndex() + 1;
  549. const targetMax = target.getParentNode().children.length;
  550. if (moveType === 'prev') {
  551. if (target.tree_pid === nodes[0].tree_pid) {
  552. if (targetOrder > order) {
  553. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder - 1);
  554. } else {
  555. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
  556. }
  557. } else {
  558. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
  559. }
  560. } else if (moveType === 'next') {
  561. if (target.tree_pid === nodes[0].tree_pid) {
  562. if (targetOrder < order) {
  563. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder + 1);
  564. } else {
  565. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder);
  566. }
  567. } else {
  568. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder + 1);
  569. }
  570. } else if (moveType === 'inner') {
  571. filingObj.moveFiling(nodes[0], target.tree_id, targetMax + 1);
  572. }
  573. }
  574. }
  575. };
  576. const filingObj = new FilingObj(levelTreeSetting);
  577. filingObj.analysisFiling(filing);
  578. $('#add-slibing').click(() => {
  579. if (!filingObj.curFiling) return;
  580. if (filingObj.curFiling.source_node.is_fixed) {
  581. toastr.error('固定分类不可添加同级');
  582. return;
  583. }
  584. filingObj.addSiblingFiling(filingObj.curFiling);
  585. });
  586. $('#add-child').click(() => {
  587. if (!filingObj.curFiling) return;
  588. const fixedChild = filingObj.curFiling.source_node.children.find(x => { return x.is_fixed; });
  589. if (fixedChild) {
  590. toastr.error('该分类下存在固定分类,不可添加子级');
  591. return;
  592. }
  593. if (filingObj.curFiling.source_node.file_count > 0) {
  594. toastr.error('该分类下已导入文件,不可添加子级');
  595. return;
  596. }
  597. filingObj.addChildFiling(filingObj.curFiling);
  598. });
  599. $('[name=file-sort]').click(function() {
  600. const tag = this.getAttribute('tag');
  601. filingObj.changeFileOrder(tag);
  602. });
  603. // $('#del-filing-btn').click(() => {
  604. // if (!filingObj.curFiling) return;
  605. // if (filingObj.curFiling.source_node.is_fixed) {
  606. // toastr.error('固定分类不可删除');
  607. // return;
  608. // }
  609. //
  610. // $('#del-filing').modal('show');
  611. // });
  612. $('#del-filing-ok').click(() => {
  613. filingObj.delFiling(filingObj.curFiling, function() {
  614. $('#del-filing').modal('hide');
  615. });
  616. });
  617. $('#add-file').on('show.bs.modal', function() {
  618. $('#filter-same')[0].checked = false;
  619. $('#filter-same').parent().hide();
  620. $('#upload-file-hint').hide();
  621. $('#upload-file')[0].value = '';
  622. if ($('#add-file-ok').hasClass('btn-warning')) $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary');
  623. });
  624. $('#upload-file').change(() => {
  625. $('#add-file-ok').attr('disabled', true);
  626. const input = $('#upload-file');
  627. filingObj.checkFilesExist(input[0].files, function(result) {
  628. if (result.length === 0) {
  629. $('#upload-file-hint').hide();
  630. $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
  631. $('#filter-same').parent().hide();
  632. } else {
  633. const msg = result[0] + (result.length > 1 ? `(等${result.length}个文件)`: '') + '</br>存在同名文件,请确认是否上传重复';
  634. $('#upload-file-hint').html(msg).show();
  635. $('#add-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
  636. $('#filter-same').parent().show();
  637. $('#filter-same').attr('filterFiles', result.join('$;$'));
  638. }
  639. });
  640. });
  641. $('#add-file-ok').click(() => {
  642. const input = $('#upload-file');
  643. const filter = $('#filter-same')[0].checked;
  644. const filterFiles = filter ? $('#filter-same').attr('filterFiles').split('$;$') : [];
  645. filingObj.uploadFiles(input[0].files, filterFiles, function() {
  646. $(input).val('');
  647. $('#add-file').modal('hide');
  648. });
  649. });
  650. $('#add-big-file').on('show.bs.modal', function() {
  651. $('#upload-big-file-hint').hide();
  652. $('#upload-big-file')[0].value = '';
  653. if ($('#add-big-file-ok').hasClass('btn-warning')) $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary');
  654. });
  655. $('#upload-big-file').change(() => {
  656. $('#add-big-file-ok').attr('disabled', true);
  657. const input = $('#upload-big-file');
  658. filingObj.checkFilesExist(input[0].files, function(result) {
  659. if (result.length === 0) {
  660. $('#upload-big-file-hint').hide();
  661. $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
  662. } else {
  663. $('#upload-big-file-hint').html('存在同名文件,请确认是否上传重复').show();
  664. $('#add-big-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
  665. }
  666. });
  667. });
  668. $('#add-big-file-ok').click(() => {
  669. const input = $('#upload-big-file');
  670. filingObj.uploadBigFile(input[0].files[0], function () {
  671. $('#upload-big-file').val('');
  672. $('#add-big-file').modal('hide');
  673. });
  674. });
  675. $('body').on('mouseenter', ".table-file", function(){
  676. $(this).children(".btn-group-table").css("display","block");
  677. });
  678. $('body').on('mouseleave', ".table-file", function(){
  679. $(this).children(".btn-group-table").css("display","none");
  680. });
  681. $('body').on('click', "a[name=del-file]", function() {
  682. const del = [this.getAttribute('fid')];
  683. filingObj.delFiles(del);
  684. });
  685. $('body').on('click', "a[name=edit-file]", function() {
  686. const check = $('[name=filename] input[fid]');
  687. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  688. const id = this.getAttribute('fid');
  689. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === id });
  690. $(`td[fid=${id}]`).html(filingObj._getEditFileNameHtml(file));
  691. });
  692. $('body').on('click', "a[name=edit-file-ok]", function() {
  693. const td = $(this).parent().parent().parent();
  694. const fid = td.attr('fid');
  695. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  696. if (!file) return;
  697. const filename = $('input', td).val();
  698. if (filename === file.filename + file.fileext) {
  699. td.html(this._getFileNameHtml(file));
  700. return;
  701. }
  702. filingObj.renameFile(file, filename);
  703. });
  704. $('body').on('click', "a[name=edit-file-cancel]", function() {
  705. const td = $(this).parent().parent().parent();
  706. const fid = td.attr('fid');
  707. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  708. if (!file) return;
  709. td.html(filingObj._getFileNameHtml(file));
  710. });
  711. // $('body').on('blur', "[name=filename] input[fid]", function() {
  712. // filingObj.renameFile(this.getAttribute('fid'), this.value);
  713. // });
  714. // $('body').on('keypress', "[name=filename] input[fid]", function(e) {
  715. // if (e.keyCode == 13) {
  716. // filingObj.renameFile(this.getAttribute('fid'), this.value);
  717. // }
  718. // });
  719. $('.page-select').click(function() {
  720. const content = this.getAttribute('content');
  721. switch(content) {
  722. case 'pre': filingObj.prePage(); break;
  723. case 'next': filingObj.nextPage(); break;
  724. default: return;
  725. }
  726. });
  727. $('#batch-download').click(function () {
  728. const self = this;
  729. const files = [];
  730. const checkes = $('[name=bd-check]:checked');
  731. checkes.each(function() {
  732. const fid = this.getAttribute('fid');
  733. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid; });
  734. file && files.push(file);
  735. });
  736. if (files.length === 0) return;
  737. $(self).attr('disabled', 'true');
  738. AliOss.zipFiles(files, filingObj.curFiling.source_node.name + '.zip', (fails) => {
  739. $(self).removeAttr('disabled');
  740. if (fails.length === 0) {
  741. toastr.success('下载成功');
  742. } else {
  743. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  744. }
  745. }, () => {
  746. $(self).removeAttr('disabled');
  747. toastr.error('批量下载失败');
  748. });
  749. });
  750. $('#batch-del-file-btn').click(() => {
  751. const checkes = $('[name=bd-check]:checked');
  752. if (checkes.length === 0) {
  753. return;
  754. } else {
  755. for (const c of checkes) {
  756. const fid = c.getAttribute('fid');
  757. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  758. if (!file) continue;
  759. if (file.user_id !== userID) {
  760. toastr.error(`文件【${file.filename + file.fileext}】不是您上传的文件,请勿删除`);
  761. return;
  762. }
  763. }
  764. }
  765. $('#batch-del-file').modal('show');
  766. });
  767. $('#batch-del-file-ok').click(function() {
  768. const del = [];
  769. const checkes = $('[name=bd-check]:checked');
  770. checkes.each(function() {
  771. del.push(this.getAttribute('fid'));
  772. });
  773. filingObj.delFiles(del, function() {
  774. $('#batch-del-file').modal('hide');
  775. });
  776. });
  777. class RelaFileLoader {
  778. constructor() {
  779. const self = this;
  780. // 可导入的标段
  781. this.treeSetting = {
  782. view: {
  783. selectedMulti: false
  784. },
  785. data: {
  786. simpleData: {
  787. idKey: 'id',
  788. pIdKey: 'tree_pid',
  789. rootPId: '-1',
  790. enable: true,
  791. }
  792. },
  793. edit: {
  794. enable: false,
  795. },
  796. callback: {
  797. onClick: async function (e, key, node) {
  798. if (this.curTender && this.curTender.id === node.id) return;
  799. self.setCurTender(node);
  800. },
  801. }
  802. };
  803. $('body').on('click', '[name=rf-check]', function () {
  804. self.selectFile(this.getAttribute('rfid'), this.checked);
  805. });
  806. $('#tf-type').change(function() {
  807. self.selectTfType(this.value);
  808. });
  809. $('#tf-sub-type').change(function() {
  810. self.selectTfSubType(this.value);
  811. });
  812. $('#tf-stage').change(function() {
  813. self.selectTfStage(this.value);
  814. });
  815. $('#rela-file-ok').click(function() {
  816. const selectFiles = self.getSelectRelaFile();
  817. filingObj.relaFiles(selectFiles, function() {
  818. $('#rela-file').modal('hide');
  819. });
  820. });
  821. }
  822. clearFileSelect() {
  823. if (!this.tenderTree) return;
  824. const nodes = this.tenderTree.getNodes();
  825. nodes.forEach(node => {
  826. const x = node.source_node;
  827. x.selectFiles = [];
  828. if (x.att) x.att.forEach(la => { la.checked = false });
  829. if (x.advance) {
  830. x.advance.forEach(a => {
  831. if (a.files) a.files.forEach(aa => { aa.checked = false });
  832. });
  833. }
  834. if (x.stage) {
  835. x.stage.forEach(s => {
  836. if (s.att) s.att.forEach(sa => { sa.checked = false });
  837. })
  838. }
  839. });
  840. }
  841. refreshSelectHint(){
  842. if (this.curTender) {
  843. $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
  844. } else {
  845. $('#cur-tender-hint').html('');
  846. }
  847. const nodes = this.tenderTree.getNodes();
  848. const selectTenders = nodes.filter(x => { return x.source_node.selectFiles.length > 0; });
  849. if (selectTenders.length > 0) {
  850. const count = selectTenders.reduce((rst, x) => { return rst + x.source_node.selectFiles.length; }, 0);
  851. $('#rela-file-hint').html(`已选择${selectTenders.length}个标段,共${count}个文件`);
  852. } else {
  853. $('#rela-file-hint').html('未选择标段、文件');
  854. }
  855. }
  856. selectFile(fileId, isSelect) {
  857. const file = this.curFiles.find(x => { return x.rf_id == fileId });
  858. if (file) {
  859. file.checked = isSelect;
  860. if (isSelect) {
  861. this.curTender.source_node.selectFiles.push(file);
  862. } else {
  863. const index = this.curTender.source_node.selectFiles.findIndex(x => { return x.rf_id === file.rf_id });
  864. this.curTender.source_node.selectFiles.splice(index, 1);
  865. }
  866. this.refreshSelectHint();
  867. }
  868. }
  869. async showRelaFile(){
  870. $('#rela-filing-hint').html(`当前目录:${filingObj.getCurFilingFullPath()}`);
  871. if (!this.tenderTree) {
  872. const tenders = await postDataAsync('file/rela/tender', {});
  873. const sortNodes = tenders.map(x => {
  874. return { id: x.id, tree_pid: -1, name: x.name, source_node: x };
  875. });
  876. this.tenderTree = this.filingTree = $.fn.zTree.init($('#rela-tender'), this.treeSetting, sortNodes);
  877. }
  878. this.clearFileSelect();
  879. this.refreshSelectHint();
  880. const firstNode = this.filingTree.getNodes()[0];
  881. if (firstNode) {
  882. this.filingTree.selectNode(firstNode);
  883. await this.setCurTender(firstNode);
  884. }
  885. }
  886. refreshTenderFileStage() {
  887. if (this.rfType.sub_type) {
  888. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
  889. const subType = type.subType ? type.subType.find(x => { return x.value === this.rfType.sub_type; }) : null;
  890. if (subType) {
  891. this.rfType.stage = subType.stage[0].value;
  892. const html= [];
  893. for (const stage of subType.stage) {
  894. html.push(`<option value="${stage.value}">${stage.text}</option>`);
  895. }
  896. $('#tf-stage').html(html.join('')).show();
  897. } else {
  898. $('#tf-stage').html('').hide();
  899. }
  900. } else {
  901. $('#tf-stage').html('').hide();
  902. }
  903. }
  904. refreshTenderFileSubType() {
  905. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
  906. if (type.subType && type.subType.length > 0) {
  907. this.rfType.sub_type = type.subType[0].value;
  908. const html= [];
  909. for (const tfst of type.subType) {
  910. html.push(`<option value="${tfst.value}">${tfst.text}</option>`);
  911. }
  912. $('#tf-sub-type').html(html.join('')).show();
  913. } else {
  914. $('#tf-sub-type').html('').hide();
  915. }
  916. }
  917. refreshTenderFileType() {
  918. const html= [];
  919. for (const tft of this.tenderFileType) {
  920. html.push(`<option value="${tft.value}">${tft.text}</option>`);
  921. }
  922. $('#tf-type').html(html.join(''));
  923. }
  924. refreshSelects(tender) {
  925. this.tenderFileType = [];
  926. this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
  927. if (tender.stage && tender.stage.length > 0) {
  928. const stages = tender.stage.map(x => { return {value: x.id, text: `第${x.order}期`}; });
  929. this.tenderFileType.push({
  930. value: 'stage', text: '计量期',
  931. subType: [
  932. { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
  933. ],
  934. });
  935. }
  936. if (tender.advance && tender.advance.length > 0) {
  937. const advanceType = [];
  938. tender.advance.forEach(x => {
  939. let at = advanceType.find(y => { return y.value === x.type + '' });
  940. if (!at) {
  941. at = { value: x.type + '', text: x.type_str, stage: [] };
  942. advanceType.push(at);
  943. }
  944. at.stage.push({ value: x.id, text: `第${x.order}期`});
  945. });
  946. this.tenderFileType.push({
  947. value: 'advance', text: '预付款', subType: advanceType
  948. });
  949. }
  950. this.rfType = { type: this.tenderFileType[0].value };
  951. this.refreshTenderFileType();
  952. this.refreshTenderFileSubType();
  953. this.refreshTenderFileStage();
  954. }
  955. async selectTfStage(stage){
  956. this.rfType.stage = stage;
  957. await this.loadFiles();
  958. this.refreshFileTable();
  959. }
  960. async selectTfSubType(sub_type){
  961. this.rfType.sub_type = sub_type;
  962. this.refreshTenderFileStage();
  963. await this.loadFiles();
  964. this.refreshFileTable();
  965. }
  966. async selectTfType(type){
  967. this.rfType.type = type;
  968. this.refreshTenderFileSubType();
  969. this.refreshTenderFileStage();
  970. await this.loadFiles();
  971. this.refreshFileTable();
  972. }
  973. refreshFileTable() {
  974. const html = [];
  975. const typeStr = [];
  976. const selectOption = $('option:selected');
  977. selectOption.each((i, x) => {
  978. typeStr.push(x.innerText);
  979. });
  980. for (const f of this.curFiles) {
  981. html.push('<tr>');
  982. const checked = f.checked ? "checked" : '';
  983. html.push(`<td><input type="checkbox" name="rf-check" rfid="${f.rf_id}" ${checked}></td>`);
  984. html.push(`<td>${f.filename}${f.fileext}</td>`);
  985. html.push(`<td>${typeStr.join(' - ')}</td>`);
  986. html.push('</tr>');
  987. }
  988. $('#rf-files').html(html.join(''));
  989. };
  990. initFilesId(files){
  991. const tender_id = this.curTender.id;
  992. const rfType = this.rfType;
  993. files.forEach((f, i) => {
  994. f.rf_id = `${tender_id}-${rfType.type}-${rfType.sub_type}-${rfType.stage}-${i}`;
  995. f.rf_key = {
  996. tender_id, ...rfType, id: f.id,
  997. };
  998. });
  999. }
  1000. async _loadRelaFiles(rfType) {
  1001. return await postDataAsync('file/rela/files', { tender_id: this.curTender.id, ...rfType });
  1002. }
  1003. async _loadLedgerFile() {
  1004. if (!this.curTender.source_node.att) this.curTender.source_node.att = await this._loadRelaFiles(this.rfType);
  1005. this.curFiles = this.curTender.source_node.att;
  1006. }
  1007. async _loadStageFile() {
  1008. const rfType = this.rfType;
  1009. const stage = this.curTender.source_node.stage.find(x => {
  1010. return x.id == rfType.stage;
  1011. });
  1012. if (!stage) {
  1013. this.curFiles = [];
  1014. return;
  1015. }
  1016. if (!stage[this.rfType.sub_type]) stage[this.rfType.sub_type] = await this._loadRelaFiles(rfType);
  1017. this.curFiles = stage[this.rfType.sub_type];
  1018. }
  1019. async _loadAdvanceFile() {
  1020. const rfType = this.rfType;
  1021. const advance = this.curTender.source_node.advance.find(x => {
  1022. return x.id == rfType.stage;
  1023. });
  1024. if (!advance) {
  1025. this.curFiles = [];
  1026. return;
  1027. }
  1028. if (!advance.files) advance.files = await this._loadRelaFiles(rfType);
  1029. this.curFiles = advance.files;
  1030. }
  1031. async loadFiles() {
  1032. switch (this.rfType.type) {
  1033. case 'ledger': await this._loadLedgerFile(); break;
  1034. case 'stage': await this._loadStageFile(); break;
  1035. case 'advance': await this._loadAdvanceFile(); break;
  1036. }
  1037. this.initFilesId(this.curFiles);
  1038. }
  1039. async setCurTender(node) {
  1040. this.curTender = node;
  1041. this.refreshSelects(node.source_node);
  1042. await this.loadFiles();
  1043. this.refreshSelectHint();
  1044. this.refreshFileTable();
  1045. }
  1046. getSelectRelaFile() {
  1047. const data = [];
  1048. const nodes = this.tenderTree.getNodes();
  1049. nodes.forEach(node => {
  1050. if (node.source_node.selectFiles.length === 0) return;
  1051. node.source_node.selectFiles.forEach(x => {
  1052. data.push({
  1053. filename: x.filename, fileext: x.fileext, filepath: x.filepath, filesize: x.filesize,
  1054. rela_info: x.rf_key,
  1055. })
  1056. });
  1057. });
  1058. return data;
  1059. }
  1060. }
  1061. const relaFileLoader = new RelaFileLoader();
  1062. $('#rela-file').on('show.bs.modal', function() {
  1063. relaFileLoader.showRelaFile(this.getAttribute('content'));
  1064. });
  1065. // 授权相关
  1066. class FilingPermission {
  1067. constructor (setting) {
  1068. this.setting = setting;
  1069. const self = this;
  1070. $(setting.modal).on('show.bs.modal', () => {
  1071. self.loadPermission();
  1072. });
  1073. $(`${setting.modal}-ok`).click(() => {
  1074. self.savePermission();
  1075. });
  1076. $('[name=ftName]').click(function () {
  1077. const filingId = this.getAttribute('ftid');
  1078. self.setCurFiling(filingId);
  1079. });
  1080. $('.book-list').on('click', 'dt', function () {
  1081. const idx = $(this).find('.acc-btn').attr('data-groupid');
  1082. const type = $(this).find('.acc-btn').attr('data-type');
  1083. if (type === 'hide') {
  1084. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  1085. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  1086. $(this).find('.acc-btn').attr('data-type', 'show')
  1087. })
  1088. } else {
  1089. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  1090. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  1091. $(this).find('.acc-btn').attr('data-type', 'hide')
  1092. })
  1093. }
  1094. return false;
  1095. });
  1096. $('dl').on('click', 'dd', function () {
  1097. const type = $(this).data('type');
  1098. if (type === 'all') {
  1099. const cid = parseInt($(this).data('id'));
  1100. const company = self.company.find(x => { return x.id === cid });
  1101. for (const u of company.users) {
  1102. if (u.filing_type.indexOf(self.curFiling) < 0) u.filing_type.push(self.curFiling);
  1103. }
  1104. } else {
  1105. const uid = $(this).data('id');
  1106. const pu = self.permissionUser.find(x => { return x.id === uid });
  1107. if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
  1108. }
  1109. self.loadCurFiling();
  1110. });
  1111. $('#sync-filing').click(function() {
  1112. const selectFiling = $('[name=cbft]:checked');
  1113. if (selectFiling.length === 0) {
  1114. toastr.warning('请先选择文档类别');
  1115. return;
  1116. }
  1117. const selectFilingId = [];
  1118. selectFiling.each((i, x) => { selectFilingId.push(x.value); });
  1119. self.syncFiling(self.curFiling, selectFilingId);
  1120. toastr.success('同步成功');
  1121. $('[name=cbft]').removeAttr('checked');
  1122. $('#filing-select-all')[0].checked = false;
  1123. });
  1124. $('#batch-del-filing').click(() => {
  1125. const selectUser = $('[name=ftu-check]:checked');
  1126. if (selectUser.length === 0) {
  1127. toastr.warning('请先选择用户');
  1128. return;
  1129. }
  1130. const userId = [];
  1131. selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
  1132. self.delFiling(self.curFiling, userId);
  1133. self.loadCurFiling();
  1134. });
  1135. $('body').on('click', '[name=del-filing]', function() {
  1136. const id = this.getAttribute('uid');
  1137. self.delFiling(self.curFiling, id);
  1138. self.loadCurFiling();
  1139. });
  1140. $('#user-select-all').click(function(){
  1141. $('input[uid]').attr('checked', this.checked);
  1142. });
  1143. $('#filing-select-all').click(function(){
  1144. $('input[name=cbft]').attr('checked', this.checked);
  1145. });
  1146. }
  1147. analysisFiling(data) {
  1148. this.permissionUser = data;
  1149. this.permissionUser.forEach(x => { x.filing_type = x.filing_type ? x.filing_type.split(',') : []; });
  1150. this.company = [];
  1151. for (const pu of this.permissionUser) {
  1152. let c = this.company.find(x => { return x.company === pu.company });
  1153. if (!c) {
  1154. c = { id: this.company.length + 1, company: pu.company, users: [] };
  1155. this.company.push(c);
  1156. }
  1157. c.users.push(pu);
  1158. }
  1159. }
  1160. loadCurFiling() {
  1161. const html = [];
  1162. for (const f of this.permissionUser) {
  1163. if (f.filing_type.indexOf(this.curFiling) < 0) continue;
  1164. html.push('<tr>');
  1165. html.push(`<td><input uid="${f.id}" type="checkbox" name="ftu-check"></td>`);
  1166. html.push(`<td>${f.name}</td>`);
  1167. html.push(`<td>${moment(f.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  1168. html.push(`<td>${f.file_permission}</td>`);
  1169. html.push(`<td><button class="btn btn-sm btn-outline-danger" uid="${f.id}" name="del-filing">移除</button></td>`);
  1170. html.push('</tr>');
  1171. }
  1172. $(this.setting.list).html(html.join(''));
  1173. $('#user-select-all')[0].checked = false;
  1174. }
  1175. setCurFiling(filingType) {
  1176. this.curFiling = filingType;
  1177. $('[name=ftName]').removeClass('bg-warning-50');
  1178. $(`[ftid=${filingType}]`).addClass('bg-warning-50');
  1179. this.loadCurFiling();
  1180. }
  1181. loadPermissionUser() {
  1182. const html = [];
  1183. for (const c of this.company) {
  1184. 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>`);
  1185. html.push(`<div class="dd-content" data-toggleid="${c.id}">`);
  1186. 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>`);
  1187. for (const u of c.users) {
  1188. html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${u.id}" >`);
  1189. html.push(`<p class="mb-0 d-flex"><span class="text-primary">${u.name}</span><span class="ml-auto">${u.mobile}</span></p>`);
  1190. html.push(`<span class="text-muted">${u.role}</span>`);
  1191. html.push(`</dd>`);
  1192. }
  1193. html.push('</div>');
  1194. }
  1195. $('#puList').html(html.join(''));
  1196. }
  1197. loadPermission() {
  1198. const self = this;
  1199. postData('permission', {}, function(result) {
  1200. self.analysisFiling(result);
  1201. if (!self.curFiling) {
  1202. self.setCurFiling($('[name=ftName]').attr('ftid'));
  1203. } else {
  1204. self.loadCurFiling();
  1205. }
  1206. self.loadPermissionUser();
  1207. });
  1208. }
  1209. syncFiling(sourceId, targetIds) {
  1210. for (const pu of this.permissionUser) {
  1211. if (pu.filing_type.indexOf(sourceId) >= 0) {
  1212. targetIds.forEach(id => {
  1213. if (pu.filing_type.indexOf(id) < 0) pu.filing_type.push(id);
  1214. });
  1215. } else {
  1216. targetIds.forEach(id => {
  1217. if (pu.filing_type.indexOf(id) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(id), 1);
  1218. })
  1219. }
  1220. }
  1221. }
  1222. delFiling(filingId, userId) {
  1223. const userIds = userId instanceof Array ? userId : [userId];
  1224. for (const id of userIds) {
  1225. const pu = this.permissionUser.find(x => { return x.id === id });
  1226. if (!pu) continue;
  1227. if (pu.filing_type.indexOf(filingId) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(filingId), 1);
  1228. }
  1229. }
  1230. savePermission() {
  1231. const self = this;
  1232. const data = this.permissionUser.map(x => {
  1233. return { id: x.id, filing_type: x.filing_type.join(',') };
  1234. });
  1235. postData('permission/save', data, function(result) {
  1236. $(self.setting.modal).modal('hide');
  1237. });
  1238. }
  1239. }
  1240. const filingPermission = new FilingPermission({
  1241. modal: '#filing-permission',
  1242. list: '#filing-valid',
  1243. });
  1244. class FileSearch {
  1245. constructor() {
  1246. this.searchResult = [];
  1247. this.initSearch();
  1248. }
  1249. getOperateHtml(file) {
  1250. const locateHtml = `<a href="javascript: void(0);" class="mr-1" name="locate-search-file" fid="${file.id}"><i class="fa fa-crosshairs"></i></a>`;
  1251. const editHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="edit-search-file" fid="${file.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
  1252. const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
  1253. 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>`;
  1254. const delHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1 text-danger" name="del-search-file" fid="${file.id}"><i class="fa fa-trash-o fa-fw"></i></a>` : '';
  1255. return `<div class="d-flex justify-content-between align-items-center table-file">${locateHtml}${editHtml}${viewHtml}${downHtml}${delHtml}</div>`
  1256. }
  1257. getFileHtml(file) {
  1258. const html = [];
  1259. html.push(`<tr fid="search_${file.id}">`);
  1260. html.push(`<td fid="search_${file.id}">${file.filename}${file.fileext}</td>`);
  1261. html.push(`<td class="text-center">${file.user_name}</td>`);
  1262. html.push(`<td class="text-center">${this.getOperateHtml(file)}</td>`);
  1263. html.push('</tr>');
  1264. return html.join('');
  1265. }
  1266. getResultHtml (result) {
  1267. this.searchResult = result;
  1268. const html = [];
  1269. for (const r of result) {
  1270. html.push(this.getFileHtml(r));
  1271. }
  1272. return html.join('');
  1273. }
  1274. getSearchFilter() {
  1275. const filter = $('#search-filter').val();
  1276. const filing_type = filter === 'all' ? filingObj.getAllFilingType() : filingObj.getCurFilingType();
  1277. return { filing_type };
  1278. }
  1279. getEditFileNameHtml(file) {
  1280. 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}">`;
  1281. 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>`;
  1282. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  1283. }
  1284. search() {
  1285. const searchData = this.getSearchFilter();
  1286. searchData.keyword = $('#search-keyword', '#search').val();
  1287. if (!searchData.keyword) {
  1288. toastr.warning('请输入查询的文件名称');
  1289. this.getResultHtml([]);
  1290. return;
  1291. }
  1292. postData(window.location.pathname + '/search', searchData, function(result) {
  1293. if (result.list.length === result.limit) toastr.warning(`最多查询${result.limit}个结果,请给出更准确的文件名称`);
  1294. $('#search-list').html(fileSearch.getResultHtml(result.list));
  1295. });
  1296. }
  1297. removeSearchFile(fid){
  1298. $(`tr[fid=search_${fid}]`, '#search').remove();
  1299. const index = this.searchResult.findIndex(x => { return x.id === fid; });
  1300. this.searchResult.splice(index, 1);
  1301. }
  1302. renameSearchFile(fid, data) {
  1303. const file = this.searchResult.find(x => { return x.id === fid; });
  1304. if (file) {
  1305. file.filename = data.filename;
  1306. file.fileext = data.fileext;
  1307. const td = $(`td[fid=search_${file.id}]`);
  1308. td.html(`${file.filename}${file.fileext}`);
  1309. }
  1310. }
  1311. initSearch() {
  1312. const self = this;
  1313. $.divResizer({
  1314. select: '#right-spr',
  1315. callback: function() {},
  1316. });
  1317. $('input', '#search').bind('keydown', function (e) {
  1318. if (e.keyCode == 13) self.search();
  1319. });
  1320. $('button', '#search').bind('click', () => { self.search(); });
  1321. $('body').on('click', "a[name=del-search-file]", function() {
  1322. const del = [this.getAttribute('fid')];
  1323. filingObj.delFiles(del);
  1324. });
  1325. $('body').on('click', "a[name=locate-search-file]", function() {
  1326. const fid = this.getAttribute('fid');
  1327. const file = self.searchResult.find(x => { return x.id === fid});
  1328. const filing = filingObj.findFiling(file.filing_id);
  1329. filingObj.filingTree.selectNode(filing);
  1330. filingObj.setCurFiling(filing);
  1331. });
  1332. $('body').on('click', "a[name=edit-search-file]", function() {
  1333. const check = $('[name=search-filename] input[fid]');
  1334. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  1335. const id = this.getAttribute('fid');
  1336. const file = self.searchResult.find(x => { return x.id === id });
  1337. $(`td[fid=search_${id}]`).html(self.getEditFileNameHtml(file));
  1338. });
  1339. $('body').on('click', "a[name=edit-search-file-ok]", function() {
  1340. const td = $(this).parent().parent().parent();
  1341. const fid = td.attr('fid').split('_')[1];
  1342. const file = self.searchResult.find(x => { return x.id === fid });
  1343. if (!file) return;
  1344. filingObj.renameFile(file, $('input', td).val());
  1345. });
  1346. $('body').on('click', "a[name=edit-search-file-cancel]", function() {
  1347. const td = $(this).parent().parent().parent();
  1348. const fid = td.attr('fid').split('_')[1];
  1349. const file = self.searchResult.find(x => { return x.id === fid });
  1350. if (!file) return;
  1351. td.html(`${file.filename}${file.fileext}`);
  1352. });
  1353. }
  1354. }
  1355. fileSearch = new FileSearch();
  1356. const showSideTools = function (show) {
  1357. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1358. if (show) {
  1359. right.show();
  1360. autoFlashHeight();
  1361. /**
  1362. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1363. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1364. * 故需要通过最终的parent.width再计算一次left.width
  1365. *
  1366. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1367. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1368. *
  1369. */
  1370. //left.css('width', parent.width() - right.outerWidth());
  1371. //left.css('width', parent.width() - right.outerWidth());
  1372. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1373. left.css('width', percent + '%');
  1374. } else {
  1375. left.width(parent.width());
  1376. right.hide();
  1377. }
  1378. };
  1379. // 展开收起标准清单
  1380. $('a', '#side-menu').bind('click', function (e) {
  1381. e.preventDefault();
  1382. const tab = $(this), tabPanel = $(tab.attr('content'));
  1383. // 展开工具栏、切换标签
  1384. if (!tab.hasClass('active')) {
  1385. // const close = $('.active', '#side-menu').length === 0;
  1386. $('a', '#side-menu').removeClass('active');
  1387. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  1388. tab.addClass('active');
  1389. tabPanel.addClass('active');
  1390. // $('.tab-content .tab-pane').removeClass('active');
  1391. showSideTools(tab.hasClass('active'));
  1392. } else { // 收起工具栏
  1393. tab.removeClass('active');
  1394. tabPanel.removeClass('active');
  1395. showSideTools(tab.hasClass('active'));
  1396. }
  1397. });
  1398. // 显示层次
  1399. (function (select) {
  1400. $(select).click(function () {
  1401. const tag = $(this).attr('tag');
  1402. setTimeout(() => {
  1403. showWaitingView();
  1404. switch (tag) {
  1405. case "1":
  1406. case "2":
  1407. case "3":
  1408. case "4":
  1409. filingObj.expandByLevel(parseInt(tag));
  1410. break;
  1411. case "last":
  1412. filingObj.expandByCustom(() => { return true; });
  1413. break;
  1414. }
  1415. closeWaitingView();
  1416. }, 100);
  1417. });
  1418. })('a[name=showLevel]');
  1419. });