file_detail.js 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  1. $(document).ready(function() {
  2. let fileSearch, fileReference;
  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. refreshFileCountHint() {
  41. const sum = _.sum(this.dragTree.children.map(x => { return x.total_file_count}));
  42. $('#file-count').html(`文件总数:${sum}`);
  43. }
  44. calcTotalFileCount() {
  45. this.dragTree.recursiveFun(this.dragTree.children, x => {
  46. if (x.children && x.children.length > 0) {
  47. x.total_file_count = x.children.reduce((pre, c) => {
  48. return pre + c.total_file_count
  49. }, 0);
  50. } else {
  51. x.total_file_count = x.file_count || 0;
  52. }
  53. });
  54. }
  55. _loadFilingSourceNode() {
  56. const self = this;
  57. const loadChildren = function(children) {
  58. for (const child of children) {
  59. if (child.children && child.children.length > 0) loadChildren(child.children);
  60. child.source_node = self.dragTree.getItems(child.id);
  61. }
  62. };
  63. const nodes = this.filingTree.getNodes();
  64. loadChildren(nodes);
  65. }
  66. loadFiling() {
  67. const self = this;
  68. if (this.filingTree) $.fn.zTree.destroy(this.setting.treeId);
  69. const sortNodes = this.dragTree.nodes.map(x => {
  70. const result = {
  71. id: x.id,
  72. tree_pid: x.tree_pid,
  73. name: x.name + (x.total_file_count > 0 ? `(${x.total_file_count})` : ''),
  74. spid: x.spid,
  75. tips: x.tips || '',
  76. };
  77. if (x.is_fixed) result.isParent = true;
  78. if (x.is_folder || x.is_fixed) result.open = self.expandCache.indexOf(result.id) >= 0;
  79. return result;
  80. });
  81. this.filingTree = $.fn.zTree.init($('#filing'), this.setting, sortNodes);
  82. this._loadFilingSourceNode();
  83. const curCache = getLocalCache(this.curFilingKey);
  84. const curNode = curCache ? this.filingTree.getNodeByParam('id', curCache) : null;
  85. if (curNode){
  86. this.filingTree.selectNode(curNode);
  87. filingObj.setCurFiling(curNode);
  88. }
  89. }
  90. analysisFiling(data) {
  91. this.dragTree.loadDatas(data);
  92. this.calcTotalFileCount();
  93. this.loadFiling();
  94. this.refreshFileCountHint();
  95. }
  96. _getFileNameHtml(file) {
  97. const moveHtml = file.canEdit || canEdit ? `<a href="javascript: void(0);" class="mr-1" name="move-file" fid="${file.id}"><i class="fa fa-exchange fa-fw"></i></a>` : '';
  98. const editHtml = file.canEdit || canEdit ? `<a href="javascript: void(0);" class="mr-1" name="edit-file" fid="${file.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
  99. const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
  100. 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>`;
  101. const delHtml = file.canEdit || 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>` : '';
  102. 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;">${moveHtml}${editHtml}${viewHtml}${downHtml}${delHtml}</div></div>`;
  103. }
  104. _getEditFileNameHtml(file) {
  105. const inputHtml = `<input type="text" class="form-control form-control-sm form-control-width" maxlength="100" value="${file.filename + file.fileext}" fid="${file.id}">`;
  106. 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>`;
  107. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  108. }
  109. _getFileHtml(file) {
  110. const html = [];
  111. html.push(`<tr fid="${file.id}">`);
  112. html.push(`<td class="text-center"><input type="checkbox" name="bd-check" fid="${file.id}"></td>`);
  113. html.push(`<td fid="${file.id}">${this._getFileNameHtml(file)}</td>`);
  114. html.push(`<td class="text-center">${file.user_name}</td>`);
  115. html.push(`<td class="text-center">${moment(file.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  116. html.push(`<td class="text-center">${file.fileext_str}</td>`);
  117. html.push('</tr>');
  118. return html.join('');
  119. }
  120. refreshFilesTable() {
  121. const html = [];
  122. const files = this.curFiling.source_node.files;
  123. if (!files || files.length === 0) {
  124. $('#file-list').html('');
  125. return;
  126. }
  127. const startIndex = (this.curPage - 1)*this.pageCount;
  128. const endIndex = this.curPage*this.pageCount;
  129. for (const [i, f] of files.entries()) {
  130. if (i < startIndex || i >= endIndex) continue;
  131. html.push(this._getFileHtml(f));
  132. }
  133. $('#file-list').html(html.join(''));
  134. }
  135. refreshPages() {
  136. if (!filingObj.curFiling) return;
  137. filingObj.curTotalPage = Math.ceil(filingObj.curFiling.source_node.file_count / this.pageCount);
  138. filingObj.curPage = Math.min(filingObj.curTotalPage, Math.max(filingObj.curPage, 1));
  139. $('#curPage').html(filingObj.curPage);
  140. $('#curTotalPage').html(filingObj.curTotalPage);
  141. if (filingObj.curTotalPage > 1) {
  142. $('#showPage').show();
  143. } else {
  144. $('#showPage').hide();
  145. }
  146. }
  147. async loadFiles(node, page) {
  148. if (node.source_node.children && node.source_node.children.length > 0) return;
  149. if (!node.source_node.files) node.source_node.files = [];
  150. if (!node.source_node.file_count) return;
  151. if (node.source_node.files && node.source_node.files.length === node.source_node.file_count) return;
  152. const needFiles = Math.min(page*this.pageCount, node.source_node.file_count);
  153. if (node.source_node.files && needFiles <= node.source_node.files.length) return;
  154. const files = await postDataAsync('file/load', { filing_id: node.id, page, count: this.pageCount, order: this.fileOrder });
  155. files.forEach(x => {
  156. const file = node.source_node.files.find(f => {return x.id === f.id; });
  157. if (file) {
  158. Object.assign(file, x);
  159. } else {
  160. node.source_node.files.push(x);
  161. }
  162. });
  163. // node.source_node.files.sort((x, y) => {
  164. // return x.create_time - y.create_time;
  165. // });
  166. }
  167. addSiblingFiling(node) {
  168. const self = this;
  169. postData('filing/add', { tree_pid: node.tree_pid, tree_pre_id: node.id }, function(result) {
  170. const refreshData = self.dragTree.loadPostData(result);
  171. const newNode = refreshData.create[0];
  172. const nodes = self.filingTree.addNodes(node.getParentNode(), node.getIndex() + 1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid }]);
  173. nodes[0].source_node = newNode;
  174. });
  175. }
  176. addChildFiling(node) {
  177. const self = this;
  178. postData('filing/add', { tree_pid: node.id }, function(result) {
  179. const refreshData = self.dragTree.loadPostData(result);
  180. const newNode = refreshData.create[0];
  181. const nodes = self.filingTree.addNodes(node, -1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid}]);
  182. nodes[0].source_node = newNode;
  183. });
  184. }
  185. delFiling(node, callback) {
  186. const parent = node.getParentNode();
  187. const self = this;
  188. postData('filing/del', { id: node.id }, function(result) {
  189. self.updateFilingFileCount(node, 0);
  190. self.dragTree.loadPostData(result);
  191. self.filingTree.removeNode(node);
  192. self.calcTotalFileCount();
  193. self.refreshFileCountHint();
  194. if (parent) {
  195. const path = parent.getPath();
  196. for (const p of path) {
  197. p.name = p.source_node.name + (p.source_node.total_file_count > 0 ? `(${p.source_node.total_file_count})` : '');
  198. if (p.source_node.is_fixed) p.isParent = true;
  199. filingObj.filingTree.updateNode(p);
  200. }
  201. }
  202. if (callback) callback();
  203. });
  204. }
  205. async renameFiling(node, newName) {
  206. const result = await postDataAsync('filing/save', { id: node.id, name: newName });
  207. node.source_node.name = newName;
  208. node.name = node.source_node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
  209. return result;
  210. }
  211. updateFilingFileCount(filing, count) {
  212. let differ = count - (filing.source_node.file_count || 0);
  213. filing.source_node.file_count = count;
  214. filing.source_node.total_file_count = count;
  215. filing.name = filing.source_node.name + (filing.source_node.total_file_count > 0 ? `(${filing.source_node.total_file_count})` : '');
  216. filingObj.filingTree.updateNode(filing);
  217. let parent = filing.getParentNode();
  218. while (!!parent) {
  219. parent.source_node.total_file_count = parent.source_node.total_file_count ? parent.source_node.total_file_count + differ : differ;
  220. parent.name = parent.source_node.name + (parent.source_node.total_file_count > 0 ? `(${parent.source_node.total_file_count})` : '');
  221. filingObj.filingTree.updateNode(parent);
  222. parent = parent.getParentNode();
  223. }
  224. }
  225. checkFilesExist(files, callback) {
  226. const data = [];
  227. for (const file of files) {
  228. if (file === undefined) return [];
  229. data.push(file.name);
  230. }
  231. postData('file/check', { filing_id: filingObj.curFiling.id, files: data }, function(result) {
  232. callback(result);
  233. });
  234. }
  235. uploadFiles(files, filterFiles, callback) {
  236. const formData = new FormData();
  237. formData.append('filing_id', filingObj.curFiling.id);
  238. let count = 0;
  239. for (const file of files) {
  240. if (filterFiles.indexOf(file.name) >= 0) continue;
  241. if (file === undefined) {
  242. toastr.error('未选择上传文件。');
  243. return false;
  244. }
  245. if (file.size > 50 * 1024 * 1024) {
  246. toastr.error('上传文件大小超过50MB。');
  247. return false;
  248. }
  249. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  250. if (whiteList.indexOf(fileext) === -1) {
  251. toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
  252. return false;
  253. }
  254. formData.append('size', file.size);
  255. formData.append('file[]', file);
  256. count++;
  257. }
  258. if (count === 0) {
  259. toastr.warning('没有可上传的文件');
  260. return false;
  261. }
  262. postDataWithFile('file/upload', formData, function (data) {
  263. filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
  264. filingObj.curFiling.source_node.files.unshift(...data.files);
  265. filingObj.refreshPages();
  266. filingObj.refreshFilesTable();
  267. filingObj.refreshFileCountHint();
  268. if (callback) callback();
  269. });
  270. }
  271. uploadBigFile(file, callback) {
  272. if (file.size > 500 * 1024 * 1024) {
  273. toastr.error('上传文件大小超过500MB。');
  274. return false;
  275. }
  276. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  277. if (whiteList.indexOf(fileext) === -1) {
  278. toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
  279. return false;
  280. }
  281. AliOss.uploadBigFile(file, 'file/upload/big', { filing_id: filingObj.curFiling.id },
  282. { progressObj: $('#upload-big-file-progress'), resumeObj: $('#add-big-file-resume'), stopObj: $('#add-big-file-stop') },
  283. function(result) {
  284. filingObj.curFiling.source_node.files.unshift(...result.files);
  285. filingObj.updateFilingFileCount(filingObj.curFiling, result.filing.file_count);
  286. filingObj.refreshPages();
  287. filingObj.refreshFilesTable();
  288. filingObj.refreshFileCountHint();
  289. if (callback) callback();
  290. });
  291. }
  292. delFiles(files, callback, hint = '') {
  293. const del = function() {
  294. postData('file/del', { del: files }, async function(data) {
  295. const relaFiling = data.filing.id === filingObj.curFiling.source_node.id
  296. ? filingObj.curFiling : filingObj.findFiling(data.filing.id);
  297. for (const id of data.del) {
  298. const fIndex = relaFiling.source_node.files.findIndex(x => { return x.id === id });
  299. if (fIndex >= 0) relaFiling.source_node.files.splice(fIndex, 1);
  300. fileSearch.removeSearchFile(id);
  301. }
  302. filingObj.updateFilingFileCount(relaFiling, data.filing.file_count);
  303. await filingObj.loadFiles(relaFiling, filingObj.curPage);
  304. if (data.filing.id === filingObj.curFiling.source_node.id) {
  305. filingObj.refreshPages();
  306. filingObj.refreshFilesTable();
  307. filingObj.refreshFileCountHint();
  308. }
  309. if (callback) callback();
  310. });
  311. };
  312. if (hint) {
  313. deleteAfterHint(del, hint);
  314. } else {
  315. del();
  316. }
  317. }
  318. renameFile(file, filename) {
  319. const self = this;
  320. const td = $(`td[fid=${file.id}]`);
  321. postData('file/save', { id: file.id, filename }, function(data) {
  322. const relaFiling = filingObj.findFiling(file.filing_id);
  323. const relaFile = relaFiling.source_node.files.find(x => { return x.id === file.id });
  324. relaFile.filename = data.filename;
  325. relaFile.fileext = data.fileext;
  326. td.html(self._getFileNameHtml(relaFile));
  327. fileSearch.renameSearchFile(file.id, data);
  328. }, function() {
  329. td.html(self._getFileNameHtml(file));
  330. fileSearch.renameSearchFile(file.id);
  331. });
  332. }
  333. relaFiles(files, callback) {
  334. postData('file/rela', { filing_id: this.curFiling.id, files: files }, async function(data) {
  335. filingObj.curFiling.source_node.files.unshift(...data.files);
  336. filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
  337. filingObj.refreshFilesTable();
  338. filingObj.refreshFileCountHint();
  339. filingObj.refreshPages();
  340. if (callback) callback();
  341. });
  342. }
  343. moveFile(file, filingId, callback) {
  344. if (file.filing_id === filingId) {
  345. callback();
  346. return;
  347. }
  348. postData('file/move', { id: file.id, filingId: filingId }, function(data) {
  349. const orgFiling = filingObj.findFiling(file.filing_id);
  350. filingObj.updateFilingFileCount(orgFiling, orgFiling.source_node.file_count - 1);
  351. const fIndex = orgFiling.source_node.files.findIndex(x => { return x.id === file.id });
  352. if (fIndex >= 0) orgFiling.source_node.files.splice(fIndex, 1);
  353. const targetFiling = filingObj.findFiling(filingId);
  354. filingObj.updateFilingFileCount(targetFiling, targetFiling.source_node.file_count + 1);
  355. if (file.filing_id === filingObj.curFiling.source_node.id) {
  356. filingObj.refreshPages();
  357. filingObj.refreshFilesTable();
  358. }
  359. fileSearch.refreshSearchFile(data.file);
  360. callback();
  361. });
  362. }
  363. async setCurFiling(node) {
  364. filingObj.curFiling = node;
  365. filingObj.curPage = 1;
  366. filingObj.refreshPages();
  367. if (filingObj.curFiling.source_node.children && filingObj.curFiling.source_node.children.length > 0) {
  368. $('#file-view').hide();
  369. } else {
  370. $('#file-view').show();
  371. await filingObj.loadFiles(node, 1);
  372. filingObj.refreshFilesTable();
  373. }
  374. // if (filingObj.curFiling.source_node.filing_type === 5) {
  375. // $('#rela-file-btn').show();
  376. // } else {
  377. // $('#rela-file-btn').hide();
  378. // }
  379. setLocalCache(this.curFilingKey, filingObj.curFiling.id);
  380. }
  381. findFiling(id) {
  382. return filingObj.filingTree.getNodeByParam('id', id);
  383. }
  384. prePage() {
  385. if (this.curPage === 1) return;
  386. this.curPage = this.curPage - 1;
  387. this.refreshPages();
  388. this.refreshFilesTable();
  389. }
  390. async nextPage() {
  391. if (this.curPage === this.curTotalPage) return;
  392. await filingObj.loadFiles(this.curFiling, this.curPage + 1);
  393. this.curPage = this.curPage + 1;
  394. this.refreshPages();
  395. this.refreshFilesTable();
  396. }
  397. getCurFilingFullPath(){
  398. let cur = filingObj.curFiling;
  399. const result = [];
  400. while (cur) {
  401. result.unshift(cur.source_node.name);
  402. cur = cur.getParentNode();
  403. }
  404. return result.join('/');
  405. }
  406. expandFiling(node, expand) {
  407. if (expand) {
  408. this.expandCache.push(node.id);
  409. } else{
  410. this.expandCache = this.expandCache.filter(x => { return x !== node.id });
  411. }
  412. setLocalCache(this.expandKey, this.expandCache.join(','));
  413. }
  414. expandByLevel(level) {
  415. this.expandByCustom(x => {
  416. return x.level + 1 < level;
  417. })
  418. }
  419. expandByCustom(fun) {
  420. const self = this;
  421. const expandCache = [];
  422. const expandChildren = function(children) {
  423. for (const child of children) {
  424. if (!child.children || child.children.length === 0) continue;
  425. const expand = fun(child);
  426. if (expand) expandCache.push(child.id);
  427. self.filingTree.expandNode(child, expand, false, false);
  428. expandChildren(child.children);
  429. }
  430. };
  431. const nodes = this.filingTree.getNodes();
  432. expandChildren(nodes);
  433. this.expandCache = expandCache;
  434. setLocalCache(this.expandKey, this.expandCache.join(','));
  435. }
  436. moveFiling(node, tree_pid, tree_order) {
  437. if (tree_pid === node.source_node.tree_pid && tree_order === node.source_node.tree_order) return;
  438. const self = this;
  439. postData('filing/move', { id: node.id, tree_pid, tree_order }, function(result) {
  440. const refresh = self.dragTree.loadPostData(result);
  441. self.calcTotalFileCount();
  442. const updated = [];
  443. for (const u of refresh.update) {
  444. const node = self.filingTree.getNodeByParam('id', u.id);
  445. if (node) {
  446. const path = node.getPath();
  447. for (const p of path) {
  448. if (updated.indexOf(p.id) >= 0) continue;
  449. p.name = p.source_node.name + (p.source_node.total_file_count > 0 ? `(${p.source_node.total_file_count})` : '');
  450. filingObj.filingTree.updateNode(p);
  451. updated.push(p.id);
  452. }
  453. }
  454. }
  455. });
  456. }
  457. _clearAllFileCache() {
  458. const nodes = this.filingTree.getNodes();
  459. for (const node of nodes) {
  460. if (node.children && node.children.length > 0) continue;
  461. if (node.source_node.files) node.source_node.files.length = 0;
  462. }
  463. }
  464. changeFileOrder(fileOrder) {
  465. this.fileOrder = fileOrder;
  466. setLocalCache(this.fileOrderKey, fileOrder);
  467. this.refreshFileOrderButton();
  468. this._clearAllFileCache();
  469. this.setCurFiling(this.curFiling);
  470. }
  471. getNodeFilingType(node) {
  472. if (!node.is_fixed) return [];
  473. const types = [];
  474. if (node.children && node.children.length > 0) {
  475. for (const child of node.children) {
  476. const childTypes = this.getNodeFilingType(child);
  477. if (childTypes.length > 0) types.push(...childTypes);
  478. }
  479. }
  480. if (types.length === 0) types.push(node.filing_type);
  481. return types;
  482. }
  483. getParentFilingType(node) {
  484. const parent = this.dragTree.getParent(node);
  485. if (!parent) return [];
  486. if (parent.is_fixed) return [parent.filing_type];
  487. return this.getParentFilingType(parent);
  488. }
  489. getAllFilingType() {
  490. const types = [];
  491. for (const node of this.dragTree.children) {
  492. types.push(...this.getNodeFilingType(node))
  493. }
  494. return types;
  495. }
  496. getCurFilingType() {
  497. const cur = filingObj.curFiling;
  498. const node = this.dragTree.nodes.find(x => { return x.id === cur.source_node.id; });
  499. return node.is_fixed ? this.getNodeFilingType(node) : this.getParentFilingType(node);
  500. }
  501. }
  502. const levelTreeSetting = {
  503. treeId: 'filing',
  504. view: {
  505. selectedMulti: false,
  506. showTitle: true,
  507. },
  508. data: {
  509. simpleData: {
  510. idKey: 'id',
  511. pIdKey: 'tree_pid',
  512. rootPId: '-1',
  513. enable: true,
  514. },
  515. key: { title: 'tips' },
  516. },
  517. edit: {
  518. enable: true,
  519. showRemoveBtn: function(treeId, treeNode) {
  520. if (!canFiling) return false;
  521. return !treeNode.source_node.is_fixed;
  522. },
  523. showRenameBtn: function(treeId, treeNode) {
  524. if (!canFiling) return false;
  525. return !treeNode.source_node.is_fixed;
  526. },
  527. renameTitle: '编辑',
  528. removeTitle: '删除',
  529. drag: {
  530. isCopy: false,
  531. isMove: true,
  532. pre: true,
  533. next: true,
  534. inner: false,
  535. },
  536. editNameSelectAll: true,
  537. },
  538. callback: {
  539. onClick: async function (e, key, node) {
  540. if (filingObj.curFiling && filingObj.curFiling.id === node.id) return;
  541. filingObj.setCurFiling(node);
  542. },
  543. beforeEditName: function(key, node) {
  544. node.name = node.source_node.name;
  545. },
  546. beforeRename: async function(key, node, newName, isCancel) {
  547. if (!isCancel) await filingObj.renameFiling(node, newName);
  548. return true;
  549. },
  550. onRename: function(e, key, node, isCancel) {
  551. node.name = node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
  552. filingObj.filingTree.updateNode(node);
  553. },
  554. beforeRemove: function(key, node, isCancel) {
  555. filingObj.selectRemoveNode = node;
  556. $('#del-filing').modal('show');
  557. return false;
  558. },
  559. onExpand(e, key, node) {
  560. filingObj.expandFiling(node, true);
  561. },
  562. onCollapse: function(e, key, node) {
  563. filingObj.expandFiling(node, false);
  564. },
  565. beforeDrop: function(key, nodes, target, moveType, isCopy) {
  566. if (!canFiling) return false;
  567. if (!target) return false;
  568. if (nodes[0].level < 1) {
  569. toastr.error('顶层节点请勿移动');
  570. return false;
  571. }
  572. if (nodes[0].is_fixed) {
  573. toastr.error('固定分类请勿移动');
  574. return false;
  575. }
  576. if (nodes[0].source_node.filing_type !== target.source_node.filing_type) {
  577. toastr.error('请勿跨越最顶层节点移动');
  578. return false;
  579. }
  580. if (target.source_node.file_count > 0 && moveType === 'inner') {
  581. toastr.error(`节点[${target.source_node.name}]下存在文件,不可添加子级`);
  582. return false;
  583. }
  584. const order = nodes[0].getIndex() + 1;
  585. const targetOrder = target.getIndex() + 1;
  586. const targetMax = target.getParentNode().children.length;
  587. if (moveType === 'prev') {
  588. if (target.tree_pid === nodes[0].tree_pid) {
  589. if (targetOrder > order) {
  590. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder - 1);
  591. } else {
  592. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
  593. }
  594. } else {
  595. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
  596. }
  597. } else if (moveType === 'next') {
  598. if (target.tree_pid === nodes[0].tree_pid) {
  599. if (targetOrder < order) {
  600. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder + 1);
  601. } else {
  602. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder);
  603. }
  604. } else {
  605. filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder + 1);
  606. }
  607. } else if (moveType === 'inner') {
  608. filingObj.moveFiling(nodes[0], target.tree_id, targetMax + 1);
  609. }
  610. }
  611. }
  612. };
  613. const filingObj = new FilingObj(levelTreeSetting);
  614. filingObj.analysisFiling(filing);
  615. $('#add-slibing').click(() => {
  616. if (!filingObj.curFiling) return;
  617. if (filingObj.curFiling.source_node.is_fixed) {
  618. toastr.error('固定分类不可添加同级');
  619. return;
  620. }
  621. filingObj.addSiblingFiling(filingObj.curFiling);
  622. });
  623. $('#add-child').click(() => {
  624. if (!filingObj.curFiling) return;
  625. const fixedChild = filingObj.curFiling.source_node.children.find(x => { return x.is_fixed; });
  626. if (fixedChild) {
  627. toastr.error('该分类下存在固定分类,不可添加子级');
  628. return;
  629. }
  630. if (filingObj.curFiling.source_node.file_count > 0) {
  631. toastr.error('该分类下已导入文件,不可添加子级');
  632. return;
  633. }
  634. filingObj.addChildFiling(filingObj.curFiling);
  635. });
  636. $('[name=file-sort]').click(function() {
  637. const tag = this.getAttribute('tag');
  638. filingObj.changeFileOrder(tag);
  639. });
  640. // $('#del-filing-btn').click(() => {
  641. // if (!filingObj.curFiling) return;
  642. // if (filingObj.curFiling.source_node.is_fixed) {
  643. // toastr.error('固定分类不可删除');
  644. // return;
  645. // }
  646. //
  647. // $('#del-filing').modal('show');
  648. // });
  649. $('#del-filing-ok').click(() => {
  650. filingObj.delFiling(filingObj.selectRemoveNode, function() {
  651. $('#del-filing').modal('hide');
  652. });
  653. });
  654. $('#add-file').on('show.bs.modal', function() {
  655. $('#filter-same')[0].checked = false;
  656. $('#filter-same').parent().hide();
  657. $('#upload-file-hint').hide();
  658. $('#upload-file')[0].value = '';
  659. if ($('#add-file-ok').hasClass('btn-warning')) $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary');
  660. });
  661. $('#upload-file').change(() => {
  662. $('#add-file-ok').attr('disabled', true);
  663. const input = $('#upload-file');
  664. filingObj.checkFilesExist(input[0].files, function(result) {
  665. if (result.length === 0) {
  666. $('#upload-file-hint').hide();
  667. $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
  668. $('#filter-same').parent().hide();
  669. } else {
  670. const msg = result[0] + (result.length > 1 ? `(等${result.length}个文件)`: '') + '</br>存在同名文件,请确认是否上传重复';
  671. $('#upload-file-hint').html(msg).show();
  672. $('#add-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
  673. $('#filter-same').parent().show();
  674. $('#filter-same').attr('filterFiles', result.join('$;$'));
  675. }
  676. });
  677. });
  678. $('#add-file-ok').click(() => {
  679. const input = $('#upload-file');
  680. const filter = $('#filter-same')[0].checked;
  681. const filterFiles = filter ? $('#filter-same').attr('filterFiles').split('$;$') : [];
  682. filingObj.uploadFiles(input[0].files, filterFiles, function() {
  683. $(input).val('');
  684. $('#add-file').modal('hide');
  685. });
  686. });
  687. $('#add-big-file').on('show.bs.modal', function() {
  688. $('#upload-big-file-hint').hide();
  689. $('#upload-big-file')[0].value = '';
  690. if ($('#add-big-file-ok').hasClass('btn-warning')) $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary');
  691. });
  692. $('#upload-big-file').change(() => {
  693. $('#add-big-file-ok').attr('disabled', true);
  694. const input = $('#upload-big-file');
  695. filingObj.checkFilesExist(input[0].files, function(result) {
  696. if (result.length === 0) {
  697. $('#upload-big-file-hint').hide();
  698. $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
  699. } else {
  700. $('#upload-big-file-hint').html('存在同名文件,请确认是否上传重复').show();
  701. $('#add-big-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
  702. }
  703. });
  704. });
  705. $('#add-big-file-ok').click(() => {
  706. const input = $('#upload-big-file');
  707. filingObj.uploadBigFile(input[0].files[0], function () {
  708. $('#upload-big-file').val('');
  709. $('#add-big-file').modal('hide');
  710. });
  711. });
  712. $('body').on('mouseenter', ".table-file", function(){
  713. $(this).children(".btn-group-table").css("display","block");
  714. });
  715. $('body').on('mouseleave', ".table-file", function(){
  716. $(this).children(".btn-group-table").css("display","none");
  717. });
  718. $('body').on('click', "a[name=del-file]", function() {
  719. const del = [this.getAttribute('fid')];
  720. const filename = $('[name=filename]', $(this).closest('td'))[0].innerHTML;
  721. filingObj.delFiles(del, null, `确认删除「${filename}」?`);
  722. });
  723. $('body').on('click', "a[name=edit-file]", function() {
  724. const check = $('[name=filename] input[fid]');
  725. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  726. const id = this.getAttribute('fid');
  727. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === id });
  728. $(`td[fid=${id}]`).html(filingObj._getEditFileNameHtml(file));
  729. });
  730. $('body').on('click', "a[name=edit-file-ok]", function() {
  731. const td = $(this).parent().parent().parent();
  732. const fid = td.attr('fid');
  733. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  734. if (!file) return;
  735. const filename = $('input', td).val();
  736. if (filename === file.filename + file.fileext) {
  737. td.html(this._getFileNameHtml(file));
  738. return;
  739. }
  740. filingObj.renameFile(file, filename);
  741. });
  742. $('body').on('click', "a[name=edit-file-cancel]", function() {
  743. const td = $(this).parent().parent().parent();
  744. const fid = td.attr('fid');
  745. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  746. if (!file) return;
  747. td.html(filingObj._getFileNameHtml(file));
  748. });
  749. class MoveFileObj {
  750. constructor() {
  751. const self = this;
  752. this.setting = {
  753. treeId: 'moveTree',
  754. view: {
  755. selectedMulti: false,
  756. showTitle: true,
  757. },
  758. data: {
  759. simpleData: {
  760. idKey: 'id',
  761. pIdKey: 'tree_pid',
  762. rootPId: '-1',
  763. enable: true,
  764. },
  765. key: { title: 'tips' },
  766. },
  767. edit: {
  768. enable: false,
  769. },
  770. };
  771. this.moveTree = null;
  772. $('#move-file2-ok').click(function() {
  773. const targetFiling = self.moveTree.getSelectedNodes()[0];
  774. if (!targetFiling) {
  775. toastr.warning('请选择目标分类');
  776. return;
  777. }
  778. if (targetFiling.children && targetFiling.children.length > 0) {
  779. toastr.warning('请选择最底层目标分类');
  780. return;
  781. }
  782. filingObj.moveFile(self.file, targetFiling.id, function() {
  783. $('#move-file2').modal('hide');
  784. });
  785. });
  786. // 显示层次
  787. (function (select) {
  788. $(select).click(function () {
  789. const tag = $(this).attr('tag');
  790. setTimeout(() => {
  791. showWaitingView();
  792. switch (tag) {
  793. case "1":
  794. case "2":
  795. case "3":
  796. case "4":
  797. self.expandByLevel(parseInt(tag));
  798. break;
  799. case "last":
  800. self.expandByCustom(() => { return true; });
  801. break;
  802. }
  803. closeWaitingView();
  804. }, 100);
  805. });
  806. })('a[name=mf2-showLevel]');
  807. }
  808. expandByLevel(level) {
  809. this.expandByCustom(x => {
  810. return x.level + 1 < level;
  811. })
  812. }
  813. expandByCustom(fun) {
  814. const self = this;
  815. const expandChildren = function(children) {
  816. for (const child of children) {
  817. if (!child.children || child.children.length === 0) continue;
  818. const expand = fun(child);
  819. self.moveTree.expandNode(child, expand, false, false);
  820. expandChildren(child.children);
  821. }
  822. };
  823. const nodes = this.moveTree.getNodes();
  824. expandChildren(nodes);
  825. }
  826. initMoveTree() {
  827. if (this.moveTree) $.fn.zTree.destroy(this.setting.treeId);
  828. const sortNodes = filingObj.dragTree.nodes.map(x => {
  829. const result = {
  830. id: x.id,
  831. tree_pid: x.tree_pid,
  832. name: x.name,
  833. spid: x.spid,
  834. tips: x.tips || '',
  835. };
  836. if (x.is_fixed) result.isParent = true;
  837. return result;
  838. });
  839. this.moveTree = $.fn.zTree.init($('#moveFile'), this.setting, sortNodes);
  840. }
  841. show (file) {
  842. this.file = file;
  843. this.initMoveTree();
  844. $('#move-file2').modal('show');
  845. }
  846. }
  847. const moveFileObj = new MoveFileObj();
  848. $('body').on('click', "a[name=move-file]", function() {
  849. const id = this.getAttribute('fid');
  850. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === id });
  851. moveFileObj.show(file);
  852. });
  853. // $('body').on('blur', "[name=filename] input[fid]", function() {
  854. // filingObj.renameFile(this.getAttribute('fid'), this.value);
  855. // });
  856. // $('body').on('keypress', "[name=filename] input[fid]", function(e) {
  857. // if (e.keyCode == 13) {
  858. // filingObj.renameFile(this.getAttribute('fid'), this.value);
  859. // }
  860. // });
  861. $('.page-select').click(function() {
  862. const content = this.getAttribute('content');
  863. switch(content) {
  864. case 'pre': filingObj.prePage(); break;
  865. case 'next': filingObj.nextPage(); break;
  866. default: return;
  867. }
  868. });
  869. $('#batch-download').click(function () {
  870. const self = this;
  871. const files = [];
  872. const checkes = $('[name=bd-check]:checked');
  873. checkes.each(function() {
  874. const fid = this.getAttribute('fid');
  875. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid; });
  876. file && files.push(file);
  877. });
  878. if (files.length === 0) return;
  879. $(self).attr('disabled', 'true');
  880. AliOss.zipFiles(files, filingObj.curFiling.source_node.name + '.zip', (fails) => {
  881. $(self).removeAttr('disabled');
  882. if (fails.length === 0) {
  883. toastr.success('下载成功');
  884. } else {
  885. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  886. }
  887. }, () => {
  888. $(self).removeAttr('disabled');
  889. toastr.error('批量下载失败');
  890. });
  891. });
  892. $('#batch-del-file-btn').click(() => {
  893. const checkes = $('[name=bd-check]:checked');
  894. if (checkes.length === 0) {
  895. return;
  896. } else {
  897. for (const c of checkes) {
  898. const fid = c.getAttribute('fid');
  899. const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
  900. if (!file) continue;
  901. if (file.user_id !== userID && !canEdit) {
  902. toastr.error(`文件【${file.filename + file.fileext}】不是您上传的文件,请勿删除`);
  903. return;
  904. }
  905. }
  906. }
  907. $('#batch-del-file').modal('show');
  908. });
  909. $('#batch-del-file-ok').click(function() {
  910. const del = [];
  911. const checkes = $('[name=bd-check]:checked');
  912. checkes.each(function() {
  913. del.push(this.getAttribute('fid'));
  914. });
  915. filingObj.delFiles(del, function() {
  916. $('#batch-del-file').modal('hide');
  917. });
  918. });
  919. class RelaFileLoader {
  920. constructor() {
  921. const self = this;
  922. // 可导入的标段
  923. this.treeSetting = {
  924. view: {
  925. selectedMulti: false
  926. },
  927. data: {
  928. simpleData: {
  929. idKey: 'id',
  930. pIdKey: 'tree_pid',
  931. rootPId: '-1',
  932. enable: true,
  933. }
  934. },
  935. edit: {
  936. enable: false,
  937. },
  938. callback: {
  939. onClick: async function (e, key, node) {
  940. if (this.curTender && this.curTender.id === node.id) return;
  941. self.setCurTender(node);
  942. },
  943. }
  944. };
  945. $('body').on('click', '[name=rf-check]', function () {
  946. self.selectFile(this.getAttribute('rfid'), this.checked);
  947. });
  948. $('#tf-type').change(function() {
  949. self.selectTfType(this.value);
  950. });
  951. $('#tf-sub-type').change(function() {
  952. self.selectTfSubType(this.value);
  953. });
  954. $('#tf-stage').change(function() {
  955. self.selectTfStage(this.value);
  956. });
  957. $('#tf-select').change(function() {
  958. self.selectTfId(this.value);
  959. });
  960. $('#rela-file-ok').click(function() {
  961. const selectFiles = self.getSelectRelaFile();
  962. filingObj.relaFiles(selectFiles, function() {
  963. $('#rela-file').modal('hide');
  964. });
  965. });
  966. }
  967. clearFileSelect() {
  968. if (!this.tenderTree) return;
  969. const nodes = this.tenderTree.getNodes();
  970. nodes.forEach(node => {
  971. const x = node.source_node;
  972. x.selectFiles = [];
  973. if (x.att) x.att.forEach(la => { la.checked = false });
  974. if (x.advance) {
  975. x.advance.forEach(a => {
  976. if (a.files) a.files.forEach(aa => { aa.checked = false });
  977. });
  978. }
  979. if (x.stage) {
  980. x.stage.forEach(s => {
  981. if (s.att) s.att.forEach(sa => { sa.checked = false });
  982. })
  983. }
  984. });
  985. }
  986. refreshSelectHint(){
  987. if (this.curTender) {
  988. $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
  989. } else {
  990. $('#cur-tender-hint').html('');
  991. }
  992. const nodes = this.tenderTree.getNodes();
  993. const selectTenders = nodes.filter(x => { return x.source_node.selectFiles.length > 0; });
  994. if (selectTenders.length > 0) {
  995. const count = selectTenders.reduce((rst, x) => { return rst + x.source_node.selectFiles.length; }, 0);
  996. $('#rela-file-hint').html(`已选择${selectTenders.length}个标段,共${count}个文件`);
  997. } else {
  998. $('#rela-file-hint').html('未选择标段、文件');
  999. }
  1000. }
  1001. selectFile(fileId, isSelect) {
  1002. const file = this.curFiles.find(x => { return x.rf_id == fileId });
  1003. if (file) {
  1004. file.checked = isSelect;
  1005. if (isSelect) {
  1006. this.curTender.source_node.selectFiles.push(file);
  1007. } else {
  1008. const index = this.curTender.source_node.selectFiles.findIndex(x => { return x.rf_id === file.rf_id });
  1009. this.curTender.source_node.selectFiles.splice(index, 1);
  1010. }
  1011. this.refreshSelectHint();
  1012. }
  1013. }
  1014. async showRelaFile(){
  1015. $('#rela-filing-hint').html(`当前目录:${filingObj.getCurFilingFullPath()}`);
  1016. if (!this.tenderTree) {
  1017. const tenders = await postDataAsync('file/rela/tender', {});
  1018. const sortNodes = tenders.map(x => {
  1019. return { id: x.id, tree_pid: -1, name: x.name, source_node: x };
  1020. });
  1021. this.tenderTree = this.filingTree = $.fn.zTree.init($('#rela-tender'), this.treeSetting, sortNodes);
  1022. }
  1023. this.clearFileSelect();
  1024. this.refreshSelectHint();
  1025. const firstNode = this.filingTree.getNodes()[0];
  1026. if (firstNode) {
  1027. this.filingTree.selectNode(firstNode);
  1028. await this.setCurTender(firstNode);
  1029. }
  1030. }
  1031. refreshTenderFileSelectId() {
  1032. if (['change', 'change_apply', 'change_plan', 'change_project'].indexOf(this.rfType.type) >= 0) {
  1033. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type; });
  1034. const html = type.select.map(x => { return `<option value="${x.value}">${x.text}</option>`});
  1035. $('#tf-select').html(html.join('')).show();
  1036. this.rfType.selectId = type.select[0].value;
  1037. } else {
  1038. $('#tf-select').html('').hide();
  1039. }
  1040. }
  1041. refreshTenderFileStage() {
  1042. if (this.rfType.sub_type) {
  1043. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type; });
  1044. const subType = type.subType ? type.subType.find(x => { return x.value === this.rfType.sub_type; }) : null;
  1045. if (subType) {
  1046. this.rfType.stage = subType.stage[0].value;
  1047. const html= [];
  1048. for (const stage of subType.stage) {
  1049. html.push(`<option value="${stage.value}">${stage.text}</option>`);
  1050. }
  1051. $('#tf-stage').html(html.join('')).show();
  1052. } else {
  1053. $('#tf-stage').html('').hide();
  1054. }
  1055. } else {
  1056. $('#tf-stage').html('').hide();
  1057. }
  1058. }
  1059. refreshTenderFileSubType() {
  1060. const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
  1061. if (type.subType && type.subType.length > 0) {
  1062. this.rfType.sub_type = type.subType[0].value;
  1063. const html= [];
  1064. for (const tfst of type.subType) {
  1065. html.push(`<option value="${tfst.value}">${tfst.text}</option>`);
  1066. }
  1067. $('#tf-sub-type').html(html.join('')).show();
  1068. } else {
  1069. $('#tf-sub-type').html('').hide();
  1070. }
  1071. }
  1072. refreshTenderFileType() {
  1073. const html= [];
  1074. for (const tft of this.tenderFileType) {
  1075. html.push(`<option value="${tft.value}">${tft.text}</option>`);
  1076. }
  1077. $('#tf-type').html(html.join(''));
  1078. }
  1079. refreshSelects(tender) {
  1080. this.tenderFileType = [];
  1081. this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
  1082. if (tender.stage && tender.stage.length > 0) {
  1083. const stages = tender.stage.map(x => { return {value: x.id, text: `第${x.order}期`}; });
  1084. this.tenderFileType.push({
  1085. value: 'stage', text: '计量期',
  1086. subType: [
  1087. { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
  1088. { value: 'dealPay', text: '合同支付', stage: JSON.parse(JSON.stringify(stages)) },
  1089. { value: 'stageIm', text: '中间计量', stage: JSON.parse(JSON.stringify(stages)) },
  1090. ],
  1091. });
  1092. }
  1093. if (tender.advance && tender.advance.length > 0) {
  1094. const advanceType = [];
  1095. tender.advance.forEach(x => {
  1096. let at = advanceType.find(y => { return y.value === x.type + '' });
  1097. if (!at) {
  1098. at = { value: x.type + '', text: x.type_str, stage: [] };
  1099. advanceType.push(at);
  1100. }
  1101. at.stage.push({ value: x.id, text: `第${x.order}期`});
  1102. });
  1103. this.tenderFileType.push({
  1104. value: 'advance', text: '预付款', subType: advanceType
  1105. });
  1106. }
  1107. if (tender.change && tender.change.length > 0) {
  1108. const selects = [];
  1109. tender.change.forEach(x => {
  1110. selects.push({ value: x.cid, text: x.code })
  1111. });
  1112. this.tenderFileType.push({ value: 'change', text: '变更令', select: selects });
  1113. }
  1114. if (tender.change_plan && tender.change_plan.length > 0) {
  1115. const selects = [];
  1116. tender.change_plan.forEach(x => {
  1117. selects.push({ value: x.cpid, text: x.code })
  1118. });
  1119. this.tenderFileType.push({ value: 'change_plan', text: '变更方案', select: selects });
  1120. }
  1121. if (tender.change_project && tender.change_project.length > 0) {
  1122. const selects = [];
  1123. tender.change_project.forEach(x => {
  1124. selects.push({ value: x.cid, text: x.code })
  1125. });
  1126. this.tenderFileType.push({ value: 'change_project', text: '变更立项', select: selects });
  1127. }
  1128. if (tender.change_apply && tender.change_apply.length > 0) {
  1129. const selects = [];
  1130. tender.change_apply.forEach(x => {
  1131. selects.push({ value: x.cid, text: x.code })
  1132. });
  1133. this.tenderFileType.push({ value: 'change_apply', text: '变更申请', select: selects });
  1134. }
  1135. this.rfType = { type: this.tenderFileType[0].value };
  1136. this.refreshTenderFileType();
  1137. this.refreshTenderFileSubType();
  1138. this.refreshTenderFileStage();
  1139. this.refreshTenderFileSelectId();
  1140. }
  1141. async selectTfId(id) {
  1142. this.rfType.selectId = id;
  1143. await this.loadFiles();
  1144. this.refreshFileTable();
  1145. }
  1146. async selectTfStage(stage){
  1147. this.rfType.stage = stage;
  1148. await this.loadFiles();
  1149. this.refreshFileTable();
  1150. }
  1151. async selectTfSubType(sub_type){
  1152. this.rfType.sub_type = sub_type;
  1153. this.refreshTenderFileStage();
  1154. await this.loadFiles();
  1155. this.refreshFileTable();
  1156. }
  1157. async selectTfType(type){
  1158. this.rfType.type = type;
  1159. this.refreshTenderFileSubType();
  1160. this.refreshTenderFileStage();
  1161. this.refreshTenderFileSelectId();
  1162. await this.loadFiles();
  1163. this.refreshFileTable();
  1164. }
  1165. refreshFileTable() {
  1166. const html = [];
  1167. const typeStr = [];
  1168. const selectOption = $('option:selected', '#rela-file');
  1169. selectOption.each((i, x) => {
  1170. typeStr.push(x.innerText);
  1171. });
  1172. for (const f of this.curFiles) {
  1173. html.push('<tr>');
  1174. const checked = f.checked ? "checked" : '';
  1175. html.push(`<td><input type="checkbox" name="rf-check" rfid="${f.rf_id}" ${checked}></td>`);
  1176. html.push(`<td>${f.filename}${f.fileext}</td>`);
  1177. html.push(`<td>${typeStr.join(' - ')}</td>`);
  1178. html.push('</tr>');
  1179. }
  1180. $('#rf-files').html(html.join(''));
  1181. };
  1182. initFilesId(files){
  1183. const tender_id = this.curTender.id;
  1184. const rfType = this.rfType;
  1185. files.forEach((f, i) => {
  1186. f.rf_id = `${tender_id}-${rfType.type}-${rfType.sub_type}-${rfType.stage}-${i}`;
  1187. f.rf_key = {
  1188. tender_id, ...rfType, id: f.id,
  1189. };
  1190. });
  1191. }
  1192. async _loadRelaFiles(rfType) {
  1193. return await postDataAsync('file/rela/files', { tender_id: this.curTender.id, ...rfType });
  1194. }
  1195. async _loadLedgerFile() {
  1196. if (!this.curTender.source_node.att) this.curTender.source_node.att = await this._loadRelaFiles(this.rfType);
  1197. this.curFiles = this.curTender.source_node.att;
  1198. }
  1199. async _loadStageFile() {
  1200. const rfType = this.rfType;
  1201. const stage = this.curTender.source_node.stage.find(x => {
  1202. return x.id == rfType.stage;
  1203. });
  1204. if (!stage) {
  1205. this.curFiles = [];
  1206. return;
  1207. }
  1208. if (!stage[this.rfType.sub_type]) stage[this.rfType.sub_type] = await this._loadRelaFiles(rfType);
  1209. this.curFiles = stage[this.rfType.sub_type];
  1210. }
  1211. async _loadAdvanceFile() {
  1212. const rfType = this.rfType;
  1213. const advance = this.curTender.source_node.advance.find(x => {
  1214. return x.id == rfType.stage;
  1215. });
  1216. if (!advance) {
  1217. this.curFiles = [];
  1218. return;
  1219. }
  1220. if (!advance.files) advance.files = await this._loadRelaFiles(rfType);
  1221. this.curFiles = advance.files;
  1222. }
  1223. async _loadChangeFile() {
  1224. const rfType = this.rfType;
  1225. const change = this.curTender.source_node.change.find(x => {
  1226. return x.cid === rfType.selectId;
  1227. });
  1228. if (!change) {
  1229. this.curFiles = [];
  1230. return;
  1231. }
  1232. if (!change.files) change.files = await this._loadRelaFiles(rfType);
  1233. this.curFiles = change.files;
  1234. }
  1235. async _loadChangePlanFile() {
  1236. const rfType = this.rfType;
  1237. const change = this.curTender.source_node.change_plan.find(x => {
  1238. return x.id === rfType.selectId;
  1239. });
  1240. if (!change) {
  1241. this.curFiles = [];
  1242. return;
  1243. }
  1244. if (!change.files) change.files = await this._loadRelaFiles(rfType);
  1245. this.curFiles = change.files;
  1246. }
  1247. async _loadChangeProjectFile() {
  1248. const rfType = this.rfType;
  1249. const change = this.curTender.source_node.change_project.find(x => {
  1250. return x.id === rfType.selectId;
  1251. });
  1252. if (!change) {
  1253. this.curFiles = [];
  1254. return;
  1255. }
  1256. if (!change.files) change.files = await this._loadRelaFiles(rfType);
  1257. this.curFiles = change.files;
  1258. }
  1259. async _loadChangeApplyFile() {
  1260. const rfType = this.rfType;
  1261. const change = this.curTender.source_node.change_apply.find(x => {
  1262. return x.id === rfType.selectId;
  1263. });
  1264. if (!change) {
  1265. this.curFiles = [];
  1266. return;
  1267. }
  1268. if (!change.files) change.files = await this._loadRelaFiles(rfType);
  1269. this.curFiles = change.files;
  1270. }
  1271. async loadFiles() {
  1272. switch (this.rfType.type) {
  1273. case 'ledger': await this._loadLedgerFile(); break;
  1274. case 'stage': await this._loadStageFile(); break;
  1275. case 'advance': await this._loadAdvanceFile(); break;
  1276. case 'change': await this._loadChangeFile(); break;
  1277. case 'change_plan': await this._loadChangePlanFile(); break;
  1278. case 'change_project': await this._loadChangeProjectFile(); break;
  1279. case 'change_apply': await this._loadChangeApplyFile(); break;
  1280. }
  1281. this.initFilesId(this.curFiles);
  1282. }
  1283. async setCurTender(node) {
  1284. this.curTender = node;
  1285. this.refreshSelects(node.source_node);
  1286. await this.loadFiles();
  1287. this.refreshSelectHint();
  1288. this.refreshFileTable();
  1289. }
  1290. getSelectRelaFile() {
  1291. const data = [];
  1292. const nodes = this.tenderTree.getNodes();
  1293. nodes.forEach(node => {
  1294. if (node.source_node.selectFiles.length === 0) return;
  1295. node.source_node.selectFiles.forEach(x => {
  1296. data.push({
  1297. filename: x.filename, fileext: x.fileext, filepath: x.filepath, filesize: x.filesize,
  1298. rela_info: x.rf_key,
  1299. })
  1300. });
  1301. });
  1302. return data;
  1303. }
  1304. }
  1305. const relaFileLoader = new RelaFileLoader();
  1306. $('#rela-file').on('show.bs.modal', function() {
  1307. relaFileLoader.showRelaFile(this.getAttribute('content'));
  1308. });
  1309. // 授权相关
  1310. class FilingPermission {
  1311. constructor (setting) {
  1312. this.setting = setting;
  1313. const self = this;
  1314. this.spread = SpreadJsObj.createNewSpread($(`${setting.spread}`)[0]);
  1315. this.sheet = this.spread.getActiveSheet();
  1316. this.spreadSetting = {
  1317. cols: [
  1318. { title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 200, formatter: '@', cellType: 'tree'},
  1319. { title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 45, cellType: 'checkbox' },
  1320. { title: '归档单位', colSpan: '1', rowSpan: '1', field: 'file_company', hAlign: 0, width: 80, formatter: '@' },
  1321. ],
  1322. emptyRows: 0,
  1323. headRows: 1,
  1324. headRowHeight: [32],
  1325. defaultRowHeight: 21,
  1326. headColWidth: [25],
  1327. headerFont: '12px 微软雅黑',
  1328. font: '12px 微软雅黑',
  1329. readOnly: true,
  1330. selectedBackColor: '#fffacd',
  1331. };
  1332. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1333. this.permissionTree = createNewPathTree('base', {
  1334. id: 'tree_id',
  1335. pid: 'tree_pid',
  1336. order: 'order',
  1337. level: 'level',
  1338. isLeaf: 'is_leaf',
  1339. fullPath: 'full_path',
  1340. rootId: -1,
  1341. });
  1342. this.spread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
  1343. if (!info.sheet.zh_setting) return;
  1344. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  1345. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  1346. if (sheet.isEditing()) sheet.endEdit(true);
  1347. }
  1348. const col = info.sheet.zh_setting.cols[info.col];
  1349. if (col.field !== 'check') return;
  1350. const tree = self.permissionTree;
  1351. const node = tree.nodes[info.row];
  1352. const row = [info.row];
  1353. node.check = !node.check;
  1354. if (node.children && node.children.length > 0) {
  1355. const posterity = tree.getPosterity(node);
  1356. for (const p of posterity) {
  1357. p.check = node.check;
  1358. row.push(tree.nodes.indexOf(p));
  1359. }
  1360. }
  1361. if (!node.check) {
  1362. const parent = tree.getAllParents(node);
  1363. for (const p of parent) {
  1364. p.check = node.check;
  1365. row.push(tree.nodes.indexOf(p));
  1366. }
  1367. }
  1368. SpreadJsObj.reLoadRowsData(info.sheet, row);
  1369. });
  1370. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1371. if (info.newSelections[0].col === 1) {
  1372. info.sheet.setSelection(info.oldSelections[0].row, info.oldSelections[0].col, info.oldSelections[0].rowCount, info.oldSelections[0].colCount);
  1373. SpreadJsObj.reloadRowsBackColor(info.sheet, [info.newSelections[0].row, info.oldSelections[0].row]);
  1374. } else {
  1375. const node = SpreadJsObj.getSelectObject(info.sheet);
  1376. self.setCurFiling(node.filing_type);
  1377. }
  1378. });
  1379. $(setting.modal).on('show.bs.modal', () => {
  1380. self.loadPermission();
  1381. });
  1382. $(setting.modal).on('shown.bs.modal', () => {
  1383. self.spread.refresh();
  1384. });
  1385. $(`${setting.modal}-ok`).click(() => {
  1386. self.savePermission();
  1387. });
  1388. $('.book-list').on('click', 'dt', function () {
  1389. const idx = $(this).find('.acc-btn').attr('data-groupid');
  1390. const type = $(this).find('.acc-btn').attr('data-type');
  1391. if (type === 'hide') {
  1392. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  1393. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  1394. $(this).find('.acc-btn').attr('data-type', 'show')
  1395. })
  1396. } else {
  1397. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  1398. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  1399. $(this).find('.acc-btn').attr('data-type', 'hide')
  1400. })
  1401. }
  1402. return false;
  1403. });
  1404. $('dl').on('click', 'dd', function () {
  1405. const type = $(this).data('type');
  1406. if (type === 'all') {
  1407. const cid = parseInt($(this).data('id'));
  1408. const company = self.company.find(x => { return x.id === cid });
  1409. for (const u of company.users) {
  1410. if (u.filing_type.indexOf(self.curFiling) < 0) u.filing_type.push(self.curFiling);
  1411. }
  1412. } else {
  1413. const uid = $(this).data('id');
  1414. const pu = self.permissionUser.find(x => { return x.id === uid });
  1415. if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
  1416. }
  1417. self.loadCurFiling();
  1418. });
  1419. $('#sync-filing').click(function() {
  1420. const selectFilingId = [];
  1421. self.permissionTree.nodes.forEach(x => { if (x.check && (!x.children || x.children.length === 0)) selectFilingId.push(x.filing_type); });
  1422. if (selectFilingId.length === 0) {
  1423. toastr.warning('请先选择文档类别');
  1424. return;
  1425. }
  1426. self.syncFiling(self.curFiling, selectFilingId);
  1427. toastr.success('同步成功');
  1428. self.permissionTree.nodes.forEach(x => { x.check = false; });
  1429. SpreadJsObj.reloadColData(self.sheet, 1);
  1430. $('#filing-select-all')[0].checked = false;
  1431. });
  1432. $('#batch-del-filing').click(() => {
  1433. const selectUser = $('[name=ftu-check]:checked');
  1434. if (selectUser.length === 0) {
  1435. toastr.warning('请先选择用户');
  1436. return;
  1437. }
  1438. const userId = [];
  1439. selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
  1440. self.delFiling(self.curFiling, userId);
  1441. self.loadCurFiling();
  1442. });
  1443. $('#batch-add-filing').click(() => {
  1444. const selectFilingId = [];
  1445. self.permissionTree.nodes.forEach(x => { if (x.check && (!x.children || x.children.length === 0)) selectFilingId.push(x.filing_type); });
  1446. if (selectFilingId.length === 0) {
  1447. toastr.warning('请先选择文档类别');
  1448. return;
  1449. }
  1450. const selectUser = $('[name=ftu-check]:checked');
  1451. if (selectUser.length === 0) {
  1452. toastr.warning('请先选择用户');
  1453. return;
  1454. }
  1455. const userId = [];
  1456. selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
  1457. self.batchAddFiling(selectFilingId, userId);
  1458. self.loadCurFiling();
  1459. toastr.success('批量添加成功');
  1460. self.permissionTree.nodes.forEach(x => { x.check = false; });
  1461. SpreadJsObj.reloadColData(self.sheet, 1);
  1462. $('#filing-select-all')[0].checked = false;
  1463. });
  1464. $('body').on('click', '[name=del-filing]', function() {
  1465. const id = this.getAttribute('uid');
  1466. self.delFiling(self.curFiling, id);
  1467. self.loadCurFiling();
  1468. });
  1469. $('#user-select-all').click(function(){
  1470. $('input[uid]').attr('checked', this.checked);
  1471. });
  1472. $('#filing-select-all').click(function(){
  1473. self.permissionTree.nodes.forEach(x => {
  1474. x.check = this.checked;
  1475. });
  1476. SpreadJsObj.reloadColData(self.sheet, 1);
  1477. });
  1478. }
  1479. analysisFiling(data) {
  1480. this.permissionUser = data;
  1481. this.permissionUser.forEach(x => { x.filing_type = x.filing_type ? x.filing_type.split(',') : []; });
  1482. this.company = [];
  1483. for (const pu of this.permissionUser) {
  1484. let c = this.company.find(x => { return x.company === pu.company });
  1485. if (!c) {
  1486. c = { id: this.company.length + 1, company: pu.company, users: [] };
  1487. this.company.push(c);
  1488. }
  1489. c.users.push(pu);
  1490. }
  1491. }
  1492. loadCurFiling() {
  1493. const html = [];
  1494. for (const f of this.permissionUser) {
  1495. if (f.filing_type.indexOf(this.curFiling) < 0) continue;
  1496. html.push('<tr>');
  1497. html.push(`<td><input uid="${f.id}" type="checkbox" name="ftu-check"></td>`);
  1498. html.push(`<td>${f.name}</td>`);
  1499. html.push(`<td>${moment(f.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  1500. html.push(`<td>${f.file_permission}</td>`);
  1501. html.push(`<td><button class="btn btn-sm btn-outline-danger" uid="${f.id}" name="del-filing">移除</button></td>`);
  1502. html.push('</tr>');
  1503. }
  1504. $(this.setting.list).html(html.join(''));
  1505. $('#user-select-all')[0].checked = false;
  1506. }
  1507. refreshBtn() {
  1508. const self = this;
  1509. const filing = this.permissionTree.nodes.find(x => { return x.filing_type === self.curFiling; });
  1510. if (!filing || (filing.children && filing.children.length > 0)) {
  1511. $('#filing-add-user').hide();
  1512. $('#batch-del-filing').hide();
  1513. $('#batch-add-filing').hide();
  1514. $('#sync-filing').hide();
  1515. } else {
  1516. $('#filing-add-user').show();
  1517. $('#batch-del-filing').show();
  1518. $('#batch-add-filing').show();
  1519. $('#sync-filing').show();
  1520. }
  1521. }
  1522. setCurFiling(filingType) {
  1523. this.curFiling = filingType;
  1524. this.loadCurFiling();
  1525. this.refreshBtn();
  1526. }
  1527. loadPermissionUser() {
  1528. const html = [];
  1529. for (const c of this.company) {
  1530. 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>`);
  1531. html.push(`<div class="dd-content" data-toggleid="${c.id}">`);
  1532. 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>`);
  1533. for (const u of c.users) {
  1534. html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${u.id}" >`);
  1535. html.push(`<p class="mb-0 d-flex"><span class="text-primary">${u.name}</span><span class="ml-auto">${u.mobile}</span></p>`);
  1536. html.push(`<span class="text-muted">${u.role}</span>`);
  1537. html.push(`</dd>`);
  1538. }
  1539. html.push('</div>');
  1540. }
  1541. $('#puList').html(html.join(''));
  1542. }
  1543. _convertData(sourceTree) {
  1544. const data = [];
  1545. for (const node of sourceTree.nodes) {
  1546. if (!node.is_fixed) continue;
  1547. const parent = node.tree_pid === '-1' ? undefined : data.find(x => { return x.id === node.tree_pid; });
  1548. const child = sourceTree.nodes.find(x => { return x.tree_pid === node.id; });
  1549. data.push({
  1550. id: node.id,
  1551. tree_id: data.length + 1,
  1552. tree_pid: parent ? parent.tree_id : -1,
  1553. order: node.tree_order + 1,
  1554. level: node.tree_level,
  1555. is_leaf: !child || !child.is_fixed,
  1556. full_path: '',
  1557. name: node.name,
  1558. is_fixed: node.is_fixed,
  1559. filing_type: node.filing_type + '',
  1560. tips: node.tips,
  1561. file_company: node.file_company,
  1562. file_count: node.file_count,
  1563. });
  1564. }
  1565. return data;
  1566. }
  1567. loadPermission() {
  1568. this.permissionTree.loadDatas(this._convertData(filingObj.dragTree));
  1569. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.permissionTree);
  1570. const self = this;
  1571. postData('permission', {}, function(result) {
  1572. self.analysisFiling(result);
  1573. if (!self.curFiling) {
  1574. const node = SpreadJsObj.getSelectObject(self.sheet);
  1575. self.setCurFiling(node.filing_type);
  1576. } else {
  1577. self.loadCurFiling();
  1578. }
  1579. self.loadPermissionUser();
  1580. });
  1581. }
  1582. syncFiling(sourceId, targetIds) {
  1583. for (const pu of this.permissionUser) {
  1584. if (pu.filing_type.indexOf(sourceId) >= 0) {
  1585. targetIds.forEach(id => {
  1586. if (pu.filing_type.indexOf(id) < 0) pu.filing_type.push(id);
  1587. });
  1588. } else {
  1589. targetIds.forEach(id => {
  1590. if (pu.filing_type.indexOf(id) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(id), 1);
  1591. })
  1592. }
  1593. }
  1594. }
  1595. delFiling(filingId, userId) {
  1596. const userIds = userId instanceof Array ? userId : [userId];
  1597. for (const id of userIds) {
  1598. const pu = this.permissionUser.find(x => { return x.id === id });
  1599. if (!pu) continue;
  1600. if (pu.filing_type.indexOf(filingId) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(filingId), 1);
  1601. }
  1602. }
  1603. batchAddFiling(filingIds, userId) {
  1604. for (const pu of this.permissionUser) {
  1605. if (userId.indexOf(pu.id) < 0) continue;
  1606. filingIds.forEach(fid => {
  1607. if (pu.filing_type.indexOf(fid) < 0) pu.filing_type.push(fid);
  1608. });
  1609. }
  1610. }
  1611. savePermission() {
  1612. const self = this;
  1613. const data = this.permissionUser.map(x => {
  1614. return { id: x.id, filing_type: x.filing_type.join(',') };
  1615. });
  1616. postData('permission/save', data, function(result) {
  1617. $(self.setting.modal).modal('hide');
  1618. });
  1619. }
  1620. }
  1621. const filingPermission = new FilingPermission({
  1622. modal: '#filing-permission',
  1623. list: '#filing-valid',
  1624. spread: '#permission-spread',
  1625. });
  1626. class FileSearch {
  1627. constructor() {
  1628. this.searchResult = [];
  1629. this.initSearch();
  1630. }
  1631. getOperateHtml(file) {
  1632. const locateHtml = `<a href="javascript: void(0);" class="mr-1" name="locate-search-file" fid="${file.id}"><i class="fa fa-crosshairs"></i></a>`;
  1633. const editHtml = file.canEdit || 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>` : '';
  1634. const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
  1635. 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>`;
  1636. const delHtml = file.canEdit || 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>` : '';
  1637. return `<div class="d-flex justify-content-between align-items-center table-file">${locateHtml}${editHtml}${viewHtml}${downHtml}${delHtml}</div>`
  1638. }
  1639. getFileHtml(file) {
  1640. const html = [];
  1641. html.push(`<tr fid="search_${file.id}">`);
  1642. html.push(`<td name="filename" fid="search_${file.id}">${file.filename}${file.fileext}</td>`);
  1643. html.push(`<td class="text-center">${file.user_name}</td>`);
  1644. html.push(`<td class="text-center">${this.getOperateHtml(file)}</td>`);
  1645. html.push('</tr>');
  1646. return html.join('');
  1647. }
  1648. getResultHtml (result) {
  1649. this.searchResult = result;
  1650. const html = [];
  1651. for (const r of result) {
  1652. html.push(this.getFileHtml(r));
  1653. }
  1654. return html.join('');
  1655. }
  1656. getSearchFilter() {
  1657. const filter = $('#search-filter').val();
  1658. const filing_type = filter === 'all' ? filingObj.getAllFilingType() : filingObj.getCurFilingType();
  1659. return { filing_type };
  1660. }
  1661. getEditFileNameHtml(file) {
  1662. 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}">`;
  1663. 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>`;
  1664. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  1665. }
  1666. search() {
  1667. const searchData = this.getSearchFilter();
  1668. searchData.keyword = $('#search-keyword', '#search').val();
  1669. if (!searchData.keyword) {
  1670. toastr.warning('请输入查询的文件名称');
  1671. this.getResultHtml([]);
  1672. return;
  1673. }
  1674. postData(window.location.pathname + '/search', searchData, function(result) {
  1675. if (result.list.length === result.limit) toastr.warning(`最多查询${result.limit}个结果,请给出更准确的文件名称`);
  1676. $('#search-list').html(fileSearch.getResultHtml(result.list));
  1677. });
  1678. }
  1679. refreshSearchFile(file) {
  1680. const sfile = this.searchResult.find(x => { return x.id === file.id; });
  1681. if (sfile) {
  1682. for (const prop in file) {
  1683. if (prop === 'id') continue;
  1684. sfile[prop] = file[prop];
  1685. }
  1686. }
  1687. }
  1688. removeSearchFile(fid){
  1689. $(`tr[fid=search_${fid}]`, '#search').remove();
  1690. const index = this.searchResult.findIndex(x => { return x.id === fid; });
  1691. this.searchResult.splice(index, 1);
  1692. }
  1693. renameSearchFile(fid, data) {
  1694. const file = this.searchResult.find(x => { return x.id === fid; });
  1695. if (file) {
  1696. file.filename = data.filename;
  1697. file.fileext = data.fileext;
  1698. const td = $(`td[fid=search_${file.id}]`);
  1699. td.html(`${file.filename}${file.fileext}`);
  1700. }
  1701. }
  1702. initSearch() {
  1703. const self = this;
  1704. $.divResizer({
  1705. select: '#right-spr',
  1706. callback: function() {
  1707. if (fileReference) fileReference.spread.refresh();
  1708. },
  1709. });
  1710. $('input', '#search').bind('keydown', function (e) {
  1711. if (e.keyCode == 13) self.search();
  1712. });
  1713. $('button', '#search').bind('click', () => { self.search(); });
  1714. $('body').on('click', "a[name=del-search-file]", function() {
  1715. const del = [this.getAttribute('fid')];
  1716. const filename = $('[name=filename]', $(this).closest('tr'))[0].innerHTML;
  1717. filingObj.delFiles(del, null, `确认删除「${filename}」?`);
  1718. });
  1719. $('body').on('click', "a[name=locate-search-file]", function() {
  1720. const fid = this.getAttribute('fid');
  1721. const file = self.searchResult.find(x => { return x.id === fid});
  1722. const filing = filingObj.findFiling(file.filing_id);
  1723. filingObj.filingTree.selectNode(filing);
  1724. filingObj.setCurFiling(filing);
  1725. });
  1726. $('body').on('click', "a[name=edit-search-file]", function() {
  1727. const check = $('[name=search-filename] input[fid]');
  1728. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  1729. const id = this.getAttribute('fid');
  1730. const file = self.searchResult.find(x => { return x.id === id });
  1731. $(`td[fid=search_${id}]`).html(self.getEditFileNameHtml(file));
  1732. });
  1733. $('body').on('click', "a[name=edit-search-file-ok]", function() {
  1734. const td = $(this).parent().parent().parent();
  1735. const fid = td.attr('fid').split('_')[1];
  1736. const file = self.searchResult.find(x => { return x.id === fid });
  1737. if (!file) return;
  1738. filingObj.renameFile(file, $('input', td).val());
  1739. });
  1740. $('body').on('click', "a[name=edit-search-file-cancel]", function() {
  1741. const td = $(this).parent().parent().parent();
  1742. const fid = td.attr('fid').split('_')[1];
  1743. const file = self.searchResult.find(x => { return x.id === fid });
  1744. if (!file) return;
  1745. td.html(`${file.filename}${file.fileext}`);
  1746. });
  1747. }
  1748. }
  1749. fileSearch = new FileSearch();
  1750. const showSideTools = function (show) {
  1751. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1752. if (show) {
  1753. right.show();
  1754. autoFlashHeight();
  1755. /**
  1756. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1757. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1758. * 故需要通过最终的parent.width再计算一次left.width
  1759. *
  1760. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1761. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1762. *
  1763. */
  1764. //left.css('width', parent.width() - right.outerWidth());
  1765. //left.css('width', parent.width() - right.outerWidth());
  1766. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1767. left.css('width', percent + '%');
  1768. } else {
  1769. left.width(parent.width());
  1770. right.hide();
  1771. }
  1772. };
  1773. // 展开收起标准清单
  1774. $('a', '#side-menu').bind('click', function (e) {
  1775. e.preventDefault();
  1776. const tab = $(this), tabPanel = $(tab.attr('content'));
  1777. // 展开工具栏、切换标签
  1778. if (!tab.hasClass('active')) {
  1779. // const close = $('.active', '#side-menu').length === 0;
  1780. $('a', '#side-menu').removeClass('active');
  1781. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  1782. tab.addClass('active');
  1783. tabPanel.addClass('active');
  1784. // $('.tab-content .tab-pane').removeClass('active');
  1785. showSideTools(tab.hasClass('active'));
  1786. if (tab.attr('content') === '#reference') {
  1787. if (!fileReference) {
  1788. fileReference = $.stdLib({
  1789. selector: '#reference',
  1790. stdType: 'reference',
  1791. libs: fileReferenceList,
  1792. treeSetting: {
  1793. id: 'template_id',
  1794. pid: 'pid',
  1795. order: 'order',
  1796. level: 'level',
  1797. rootId: -1,
  1798. keys: ['id', 'list_id', 'template_id'],
  1799. },
  1800. spreadSetting: {
  1801. cols: [
  1802. {title: '名称', field: 'name', hAlign: 0, width: 420, formatter: '@', cellType: 'tree', wordWrap: true},
  1803. {title: '备注', field: 'remark', hAlign: 1, width: 150, formatter: '@'}
  1804. ],
  1805. emptyRows: 0,
  1806. headRows: 1,
  1807. headRowHeight: [32],
  1808. defaultRowHeight: 21,
  1809. headerFont: '12px 微软雅黑',
  1810. font: '12px 微软雅黑',
  1811. headColWidth: [30],
  1812. selectedBackColor: '#fffacd',
  1813. readOnly: true,
  1814. localCache: {
  1815. key: 'file_detail_reference',
  1816. colWidth: true,
  1817. },
  1818. },
  1819. page: 'file',
  1820. });
  1821. }
  1822. fileReference.spread.refresh();
  1823. }
  1824. } else { // 收起工具栏
  1825. tab.removeClass('active');
  1826. tabPanel.removeClass('active');
  1827. showSideTools(tab.hasClass('active'));
  1828. }
  1829. });
  1830. // 显示层次
  1831. (function (select) {
  1832. $(select).click(function () {
  1833. const tag = $(this).attr('tag');
  1834. setTimeout(() => {
  1835. showWaitingView();
  1836. switch (tag) {
  1837. case "1":
  1838. case "2":
  1839. case "3":
  1840. case "4":
  1841. filingObj.expandByLevel(parseInt(tag));
  1842. break;
  1843. case "last":
  1844. filingObj.expandByCustom(() => { return true; });
  1845. break;
  1846. }
  1847. closeWaitingView();
  1848. }, 100);
  1849. });
  1850. })('a[name=showLevel]');
  1851. $.divResizer({
  1852. select: '#file-right-spr',
  1853. callback: function() {
  1854. if (fileReference) fileReference.spread.refresh();
  1855. },
  1856. });
  1857. });