change_information.js 26 KB

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