file_detail.js 48 KB

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