change_information.js 35 KB

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