file_detail.js 65 KB

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