file_detail.js 54 KB

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