file_detail.js 86 KB

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