file_detail.js 54 KB

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