file_detail.js 51 KB

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