file_detail.js 79 KB

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