change_information.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. const is_numeric = (value) => {
  10. if (typeof(value) === 'object') {
  11. return false;
  12. } else {
  13. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  14. }
  15. };
  16. function sortByCode(a, b) {
  17. let code1 = a.code.split('-');
  18. let code2 = b.code.split('-');
  19. let code1length = code1.length;
  20. let code2length = code2.length;
  21. for (let i = 0; i < code1length; i ++) {
  22. if (i+1 <= code2length) {
  23. if (code1[i] != code2[i]) {
  24. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  25. return parseInt(code1[i]) - parseInt(code2[i]);
  26. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  27. return 1;
  28. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  29. return -1;
  30. } else {
  31. const str1length = code1[i].length;
  32. const str2length = code2[i].length;
  33. for (let j = 0; j < str1length; j++) {
  34. if (j+1 <= str2length) {
  35. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  36. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  37. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  38. if (str1length == str2length) {
  39. return 0;
  40. } else {
  41. return str1length - str2length;
  42. }
  43. }
  44. } else {
  45. if (j+1 >= str1length) {
  46. return 1;
  47. } else {
  48. return -1;
  49. }
  50. }
  51. }
  52. }
  53. } else if (i+1 == code1length && code1[i] == code2[i]) {
  54. if (code1length == code2length) {
  55. return 0;
  56. } else {
  57. return code1length - code2length;
  58. }
  59. }
  60. } else {
  61. if (i+1 >= code1length) {
  62. return 1;
  63. } else {
  64. return -1;
  65. }
  66. }
  67. }
  68. }
  69. $(document).ready(() => {
  70. //初始化所有附件列表
  71. getAllList();
  72. const cca = getLocalCache('change-checkbox-account-' + accountId);
  73. if (cca !== null && cca !== undefined) {
  74. $('#customCheck1').prop('checked', cca !== 'false');
  75. }
  76. changeSpreadSheet.setColumnVisible(5,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  77. // 变更详情展示和隐藏
  78. $('.change-detail-checkbox').on('click', function (e) {
  79. if($(e.target).is('label')){
  80. return;
  81. }
  82. // // 设置用户项目本地记录展示和隐藏情况
  83. setLocalCache('change-checkbox-account-'+ accountId, $(this).is(':checked'));
  84. changeSpreadSheet.setColumnVisible(5,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  85. });
  86. // 计算最新的变更总额和change的total_price是否一致,不一致则更新
  87. if (changeStatus !== auditConst.status.checked) {
  88. let new_tp = 0;
  89. for (const c of changeList) {
  90. new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
  91. }
  92. console.log(changeTp, new_tp);
  93. if (changeTp !== new_tp) {
  94. postData(window.location.pathname + '/save', { type:'update_tp', updateData: new_tp }, function (result) {
  95. });
  96. }
  97. }
  98. //tab change
  99. $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
  100. const tab = $(this).data('tab');
  101. if (tab === 'bgfujian') {
  102. $('#fujian_btn').show();
  103. } else {
  104. $('#fujian_btn').hide();
  105. }
  106. });
  107. $('#add-bj').on('click', 'input[type="checkbox"]', function () {
  108. const isCheck = $(this).prop('checked');
  109. if (isCheck) {
  110. $('#add-bj input[type="checkbox"]').each(function () {
  111. $(this).prop('checked', false)
  112. });
  113. $(this).prop('checked', true)
  114. }
  115. });
  116. $('#bg-copy').click(function() {
  117. const cid = $('#add-bj input:checked').data('id');
  118. postData(window.location.pathname + '/copy', cid, function () {
  119. window.location.reload();
  120. })
  121. });
  122. // 上传附件
  123. $('#upload-file-btn').click(function () {
  124. const files = $('#upload-file')[0].files;
  125. const formData = new FormData();
  126. formData.append('cid', $('#changeId').val());
  127. formData.append('tid', $('#tenderId').val());
  128. for (const file of files) {
  129. if (file === undefined) {
  130. toastr.error('未选择上传文件!');
  131. return false;
  132. }
  133. const filesize = file.size;
  134. if (filesize > 30 * 1024 * 1024) {
  135. toastr.error('文件大小过大!');
  136. return false;
  137. }
  138. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  139. if (whiteList.indexOf(fileext) === -1) {
  140. toastr.error('只能上传指定格式的附件!');
  141. return false;
  142. }
  143. formData.append('size', filesize);
  144. formData.append('file[]', file);
  145. }
  146. if (auditList.findIndex(item => item.uid === parseInt(accountId)) === -1 && !touristPermission) {
  147. return toastr.error('暂无权限上传!');
  148. }
  149. postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
  150. attData = data.concat(attData);
  151. // 重新生成List
  152. getAllList();
  153. $('#addfujian').modal('hide');
  154. // let html = '';
  155. // let index = $('#attList tr').length + 1;
  156. // for (const fileInfo of data) {
  157. // html += '<tr> ' +
  158. // `<td width="20"><input type="checkbox" class="check-file" file-id=${fileInfo.id}></td>` +
  159. // '<td>' + index + '</td> ' +
  160. // `<td><a href="javascript: void(0);" class="file-atn" f-id="${fileInfo.id}">${fileInfo.filename}${fileInfo.fileext}</a></td>`+
  161. // '<td>' + fileInfo.in_time + '<br>' + fileInfo.filesize + '</td> ' +
  162. // `<td><a href="/change/download/file/${fileInfo.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`+
  163. // ( auditStatus === 4 ?
  164. // fileInfo.extra_upload ? `<a class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : ''
  165. // : ` <a href="javascript:void(0);" class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>`)+
  166. // `</td>`+
  167. // // '<td> <a class="btn btn-light btn-sm delete-file" data-attid="' + fileInfo.id + '" title="删除附件"><span class="fa fa-trash text-danger"></span></a> </td> ' +
  168. // '</tr>';
  169. // ++index;
  170. // }
  171. // $('#attList').append(html);
  172. }, function () {
  173. });
  174. $('#upload-file').val('');
  175. });
  176. // 删除附件
  177. $('body').on('click', '.delete-file', function () {
  178. let attid = $(this).data('attid');
  179. let self = $(this);
  180. const data = {id: attid};
  181. postData(window.location.pathname + '/file/delete', data, function (result) {
  182. // self.parents('tr').remove();
  183. // // 重新排序
  184. // let newsort = 1;
  185. // $('#attList tr').each(function(){
  186. // $(this).children('td').eq(1).text(newsort);
  187. // newsort++;
  188. // });
  189. // 删除到attData中
  190. const att_index = attData.findIndex(function (item) {
  191. return item.id === parseInt(attid);
  192. });
  193. attData.splice(att_index, 1);
  194. // 重新生成List
  195. if ($('#attList tr').length === 1) {
  196. getAllList(parseInt($('#currentPage').text()) - 1);
  197. } else {
  198. getAllList(parseInt($('#currentPage').text()));
  199. }
  200. });
  201. });
  202. // /change/download/file/
  203. $('#attList').on('click', '.file-atn', function() {
  204. const id = $(this).attr('f-id');
  205. postData(`/change/download/file/${id}`, {}, (data) => {
  206. const { filepath } = data;
  207. $('#file-upload').attr('href', filepath);
  208. $('#file-upload')[0].click();
  209. })
  210. });
  211. $('#attList').on('click', '.check-file', function() {
  212. const checkedList = $('#attList').find('input:checked');
  213. const childs = $('#attList').children().length;
  214. const checkBox = $('#check-all-file');
  215. if (checkedList.length === childs) {
  216. checkBox.prop("checked", true);
  217. } else {
  218. checkBox.prop("checked", false);
  219. }
  220. });
  221. $('#check-all-file').click(function() {
  222. const isCheck = $(this).is(':checked');
  223. $('#attList').children().each(function() {
  224. $(this).find('input:checkbox').prop("checked", isCheck);
  225. })
  226. });
  227. $('#bach-download').click(function() {
  228. const fileIds = [];
  229. $( '#attList .check-file:checked').each(function() {
  230. const fileId = $(this).attr('file-id');
  231. fileId && fileIds.push(fileId);
  232. });
  233. if (fileIds.length) {
  234. // const tid = $('#tenderId').val();
  235. // const cid = $('#changeId').val();
  236. // $('#downloadZip').attr('href', `/tender/${tid}/change/${cid}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`);
  237. // $('#downloadZip')[0].click();
  238. if (fileIds.length > 20) {
  239. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`);
  240. }
  241. const tid = $('#tenderId').val();
  242. const cid = $('#changeId').val();
  243. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
  244. $(this).attr('disabled', "true");
  245. const btn = $(this);
  246. const fileArr = [];
  247. for (const id of fileIds) {
  248. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  249. fileArr.push({
  250. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  251. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  252. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  253. });
  254. }
  255. const packageName = `${tenderName}-工程变更-${changeName}-附件.zip`;
  256. try {
  257. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  258. } catch (e) {
  259. btn.removeAttr('disabled');
  260. toastr.clear();
  261. toastr.error('批量下载失败');
  262. }
  263. // postCompressFile(`/tender/${tid}/change/${cid}/download/compresse-file`, {fileIds}, function(result) {
  264. // toastr.clear();
  265. // toastr.success('压缩文件成功');
  266. // btn.removeAttr('disabled');
  267. // const href = window.URL.createObjectURL(result);
  268. // $('#zipDown').attr('href', href);
  269. // $('#zipDown').attr('download', `${tenderName}-工程变更-${changeName}-附件.zip`);
  270. // $("#zipDown")[0].click();
  271. // }, () => {
  272. // btn.removeAttr('disabled');
  273. // toastr.clear();
  274. // toastr.error('批量下载失败');
  275. // });
  276. }
  277. });
  278. // 差值对比信息获取
  279. let czSpread = null;
  280. const czSpreadSetting = {
  281. cols: [
  282. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80},
  283. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  284. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60},
  285. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
  286. {title: '变更方案|数量', colSpan: '2|1', rowSpan: '1|1', field: 'pamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.pamount'},
  287. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'pa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.pa_tp'},
  288. {title: '变更令|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
  289. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
  290. {title: '差值对比|数量', colSpan: '2|1', rowSpan: '1|1', field: 'czamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.czamount'},
  291. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'cz_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.cz_tp'},
  292. ],
  293. emptyRows: 0,
  294. headRows: 2,
  295. headRowHeight: [25, 25],
  296. defaultRowHeight: 21,
  297. headerFont: '12px 微软雅黑',
  298. font: '12px 微软雅黑',
  299. readOnly: true,
  300. localCache: {
  301. key: 'changes-cz',
  302. colWidth: true,
  303. }
  304. };
  305. const czCol = {
  306. getValue: {
  307. unit_price: function(data) {
  308. return ZhCalc.round(data.unit_price, unitPriceUnit);
  309. },
  310. pa_tp: function (data) {
  311. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.pamount, findDecimal(data.unit))), totalPriceUnit);
  312. },
  313. ca_tp: function (data) {
  314. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  315. },
  316. pamount: function (data) {
  317. return ZhCalc.round(data.pamount, findDecimal(data.unit));
  318. },
  319. camount: function (data) {
  320. return ZhCalc.round(data.camount, findDecimal(data.unit));
  321. },
  322. czamount: function (data) {
  323. return ZhCalc.sub(ZhCalc.round(data.camount, findDecimal(data.unit)), ZhCalc.round(data.pamount, findDecimal(data.unit)));
  324. },
  325. cz_tp: function (data) {
  326. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(ZhCalc.sub(ZhCalc.round(data.camount, findDecimal(data.unit)), ZhCalc.round(data.pamount, findDecimal(data.unit))), findDecimal(data.unit))), totalPriceUnit);
  327. },
  328. }
  329. };
  330. const czSpreadObj = {
  331. makeBackColor: function () {
  332. const rowCount = czSpread.getActiveSheet().getRowCount();
  333. for (let i = 0; i < rowCount; i++) {
  334. if (czSpread.getActiveSheet().zh_data[i].color) czSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#f5c6cb');
  335. }
  336. },
  337. makeSjsFooter: function () {
  338. // 增加汇总行并设为锁定禁止编辑状态
  339. czSpread.getActiveSheet().addRows(czSpread.getActiveSheet().getRowCount(), 1);
  340. czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 0, '合计');
  341. czSpread.getActiveSheet().setStyle(czSpread.getActiveSheet().getRowCount() - 1, -1, style1);
  342. czSpreadObj.countSum();
  343. },
  344. countSum: function () {
  345. const rowCount = czSpread.getActiveSheet().getRowCount();
  346. let pSum = 0,
  347. cSum = 0,
  348. czSum = 0;
  349. for (let i = 0; i < rowCount - 1; i++) {
  350. pSum = ZhCalc.add(pSum, czSpread.getActiveSheet().getValue(i, 5));
  351. cSum = ZhCalc.add(cSum, czSpread.getActiveSheet().getValue(i, 7));
  352. czSum = ZhCalc.add(czSum, czSpread.getActiveSheet().getValue(i, 9));
  353. }
  354. czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 5, pSum !== 0 ? pSum : null);
  355. czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 7, cSum !== 0 ? cSum : null);
  356. czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 9, czSum !== 0 ? czSum : null);
  357. },
  358. };
  359. $('#bgfadb').on('shown.bs.modal', function () {
  360. if (!czSpread) {
  361. czSpread = SpreadJsObj.createNewSpread($('#cz-spread')[0]);
  362. SpreadJsObj.initSpreadSettingEvents(czSpreadSetting, czCol);
  363. SpreadJsObj.initSheet(czSpread.getActiveSheet(), czSpreadSetting);
  364. }
  365. const cList = [];
  366. const newChangeList = _.cloneDeep(changeList);
  367. for (const cl of newChangeList) {
  368. const cIndex = _.findIndex(cList, { code: cl.code, name: cl.name, unit: cl.unit, unit_price: cl.unit_price});
  369. if (cIndex !== -1) {
  370. cList[cIndex].spamount = ZhCalc.add(cList[cIndex].spamount, cl.spamount);
  371. } else {
  372. cList.push(cl);
  373. }
  374. }
  375. // 生成差值对比数据列表
  376. const czList = [];
  377. const newPlanList = _.cloneDeep(planList);
  378. for (const c of cList) {
  379. const planInfo = _.find(newPlanList, { code: c.code, name: c.name, unit: c.unit, unit_price: c.unit_price });
  380. const pamount = planInfo ? planInfo.spamount : null;
  381. let color = true;
  382. if (planInfo) {
  383. _.remove(newPlanList, (item) => item === planInfo);
  384. if ((pamount ? pamount : 0) === (c.spamount ? c.spamount : 0)) {
  385. color = false;
  386. }
  387. }
  388. czList.push({ code: c.code, name: c.name, unit: c.unit, unit_price: c.unit_price, camount: c.spamount, pamount, color });
  389. }
  390. if (newPlanList.length > 0) {
  391. for (const np of newPlanList) {
  392. czList.push({ code: np.code, name: np.name, unit: np.unit, unit_price: np.unit_price, camount: null, pamount: np.spamount, color: true });
  393. }
  394. }
  395. if (czList.length > 0) {
  396. // 按清单编号排序
  397. czList.sort(sortByCode);
  398. }
  399. console.log(czList);
  400. // sjs设置
  401. SpreadJsObj.loadSheetData(czSpread.getActiveSheet(), SpreadJsObj.DataType.Data, czList);
  402. czSpreadObj.makeBackColor();
  403. czSpreadObj.makeSjsFooter();
  404. });
  405. $.subMenu({
  406. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  407. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  408. key: 'menu.1.0.0',
  409. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  410. callback: function (info) {
  411. if (info.mini) {
  412. $('.panel-title').addClass('fluid');
  413. $('#sub-menu').removeClass('panel-sidebar');
  414. } else {
  415. $('.panel-title').removeClass('fluid');
  416. $('#sub-menu').addClass('panel-sidebar');
  417. }
  418. autoFlashHeight();
  419. changeSpread.refresh();
  420. }
  421. });
  422. // 切换页数
  423. $('.page-select').on('click', function () {
  424. const totalPageNum = parseInt($('#totalPage').text());
  425. const lastPageNum = parseInt($('#currentPage').text());
  426. const status = $(this).attr('content');
  427. if (status === 'pre' && lastPageNum > 1) {
  428. getAllList(lastPageNum-1);
  429. $('#showAttachment').hide();
  430. $('#syfujian .check-all-file').prop('checked', false)
  431. } else if (status === 'next' && lastPageNum < totalPageNum) {
  432. getAllList(lastPageNum+1);
  433. $('#showAttachment').hide();
  434. $('#syfujian .check-all-file').prop('checked', false)
  435. }
  436. });
  437. // 项目节信息获取
  438. const xmjSpreadSetting = {
  439. cols: [
  440. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'xmj_code', hAlign: 0, width: 80},
  441. // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  442. {title: '细目', colSpan: '1', rowSpan: '2', field: 'xmj_jldy', hAlign: 0, width: 100},
  443. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'xmj_dwgc', hAlign: 0, width: 100},
  444. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'xmj_fbgc', hAlign: 0, width: 100},
  445. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'xmj_fxgc', hAlign: 0, width: 100},
  446. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 100},
  447. {title: '数量', colSpan: '1', rowSpan: '2', field: 'oamount', hAlign: 2, width: 80},
  448. ],
  449. emptyRows: 0,
  450. headRows: 1,
  451. headRowHeight: [25, 25],
  452. defaultRowHeight: 21,
  453. headerFont: '12px 微软雅黑',
  454. font: '12px 微软雅黑',
  455. readOnly: true,
  456. localCache: {
  457. key: 'changes-xmj',
  458. colWidth: true,
  459. }
  460. };
  461. SpreadJsObj.initSheet(xmjSpread.getActiveSheet(), xmjSpreadSetting);
  462. $.divResizer({
  463. select: '#right-spr',
  464. callback: function () {
  465. changeSpread.refresh();
  466. xmjSpread.refresh();
  467. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  468. setLocalCache('change_information_width', width);
  469. }
  470. });
  471. // 根据浏览器记录展开收起
  472. if (getLocalCache('change_information_width')) {
  473. $('#left-view').css('width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  474. $('#right-view').css('width', getLocalCache('change_information_width') + '%');
  475. changeSpread.refresh();
  476. xmjSpread.refresh();
  477. }
  478. });
  479. function findDecimal(unit) {
  480. let value = precision.other.value;
  481. const changeUnits = precision;
  482. for (const d in changeUnits) {
  483. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  484. value = changeUnits[d].value;
  485. break;
  486. }
  487. }
  488. return value;
  489. }
  490. // 生成附件列表
  491. function getAllList(currPageNum = 1) {
  492. // 每页最多几个附件
  493. const pageCount = 20;
  494. // 附件总数
  495. const total = attData.length;
  496. // 总页数
  497. const pageNum = Math.ceil(total/pageCount);
  498. $('#totalPage').text(pageNum);
  499. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  500. // 当前页附件内容
  501. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  502. currPageFileData = currPageAttData;
  503. let html = '';
  504. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  505. for(const [index,att] of currPageAttData.entries()) {
  506. html += `<tr>
  507. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  508. <td>${((currPageNum-1)*pageCount)+index+1}</td>
  509. <td><a href="${att.filepath}" target="_blank" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a></td>
  510. <td>${moment(att.in_time * 1000).format('YYYY-MM-DD')}<br>${bytesToSize(att.filesize)}</td>
  511. <td>
  512. <a href="/change/download/file/${att.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  513. html += (att.uid === accountId && (auditStatus === 4 ? Boolean(att.extra_upload) : true)) ?
  514. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  515. html += `</td>`;
  516. }
  517. $('#attList').html(html);
  518. $('#attList').on('click', 'tr', function() {
  519. $('#attList tr').removeClass('bg-light');
  520. $(this).addClass('bg-light');
  521. })
  522. }
  523. function bytesToSize(bytes) {
  524. if (parseInt(bytes) === 0) return '0 B';
  525. const k = 1024;
  526. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  527. const i = Math.floor(Math.log(bytes) / Math.log(k));
  528. // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
  529. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  530. }