file_detail.js 78 KB

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