change_information.js 34 KB

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