file_detail.js 65 KB

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