change_information.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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. } 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. // 清单汇总信息获取
  407. let hzSpread = null;
  408. const hzSpreadSetting = {
  409. cols: [
  410. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80},
  411. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  412. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60},
  413. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
  414. {title: '申报变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
  415. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
  416. {title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'amount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.amount', visible: auditStatus === 7},
  417. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'a_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.a_tp', visible: auditStatus === 7},
  418. {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},
  419. {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},
  420. {title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', hAlign: 2, width: 60, type: 'Number', getValue: '', visible: [1,2,9].indexOf(auditStatus) !== -1},
  421. {title: '|金额', colSpan: '|1', rowSpan: '|1', hAlign: 2, width: 80, type: 'Number', getValue: '', visible: [1,2,9].indexOf(auditStatus) !== -1},
  422. ],
  423. emptyRows: 0,
  424. headRows: 2,
  425. headRowHeight: [25, 25],
  426. defaultRowHeight: 21,
  427. headerFont: '12px 微软雅黑',
  428. font: '12px 微软雅黑',
  429. readOnly: true,
  430. localCache: {
  431. key: 'changes-hz',
  432. colWidth: true,
  433. }
  434. };
  435. const hzCol = {
  436. getValue: {
  437. unit_price: function(data) {
  438. return ZhCalc.round(data.unit_price, unitPriceUnit);
  439. },
  440. camount: function (data) {
  441. return ZhCalc.round(data.camount, findDecimal(data.unit));
  442. },
  443. ca_tp: function (data) {
  444. return ZhCalc.round(data.ca_tp, totalPriceUnit);
  445. },
  446. amount: function (data) {
  447. return ZhCalc.round(data.amount, findDecimal(data.unit));
  448. },
  449. a_tp: function (data) {
  450. return ZhCalc.round(data.a_tp, totalPriceUnit);
  451. },
  452. spamount: function (data) {
  453. return ZhCalc.round(data.spamount, findDecimal(data.unit));
  454. },
  455. spa_tp: function (data) {
  456. return ZhCalc.round(data.spa_tp, totalPriceUnit);
  457. },
  458. }
  459. };
  460. const hzSpreadObj = {
  461. makeBackColor: function () {
  462. const rowCount = hzSpread.getActiveSheet().getRowCount();
  463. for (let i = 0; i < rowCount; i++) {
  464. if ([3,4,5,6,8].indexOf(auditStatus) !== -1 && hzSpread.getActiveSheet().zh_data[i].camount != hzSpread.getActiveSheet().zh_data[i].spamount) {
  465. hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
  466. } else if (auditStatus === 7 && hzSpread.getActiveSheet().zh_data[i].camount != hzSpread.getActiveSheet().zh_data[i].amount) {
  467. hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
  468. } 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)) {
  469. hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
  470. }
  471. }
  472. },
  473. makeSjsFooter: function () {
  474. // 增加汇总行并设为锁定禁止编辑状态
  475. hzSpread.getActiveSheet().addRows(hzSpread.getActiveSheet().getRowCount(), 1);
  476. hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 0, '合计');
  477. hzSpread.getActiveSheet().setStyle(hzSpread.getActiveSheet().getRowCount() - 1, -1, style1);
  478. hzSpreadObj.countSum();
  479. },
  480. countSum: function () {
  481. const rowCount = hzSpread.getActiveSheet().getRowCount();
  482. let cSum = 0,
  483. sSum = 0,
  484. spSum = 0;
  485. for (let i = 0; i < rowCount - 1; i++) {
  486. cSum = ZhCalc.add(cSum, hzSpread.getActiveSheet().getValue(i, 5));
  487. sSum = ZhCalc.add(sSum, hzSpread.getActiveSheet().getValue(i, 7));
  488. spSum = ZhCalc.add(spSum, hzSpread.getActiveSheet().getValue(i, 9));
  489. }
  490. hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 5, cSum !== 0 ? cSum : null);
  491. hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 7, sSum !== 0 ? sSum : null);
  492. hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 9, spSum !== 0 ? spSum : null);
  493. },
  494. };
  495. $('#qdgather').on('shown.bs.modal', function () {
  496. if (!hzSpread) {
  497. hzSpread = SpreadJsObj.createNewSpread($('#hz-spread')[0]);
  498. SpreadJsObj.initSpreadSettingEvents(hzSpreadSetting, hzCol);
  499. SpreadJsObj.initSheet(hzSpread.getActiveSheet(), hzSpreadSetting);
  500. }
  501. const hzList = [];
  502. const newChangeList = _.cloneDeep(changeList);
  503. for (const cl of newChangeList) {
  504. const hzIndex = _.findIndex(hzList, { code: cl.code, name: cl.name, unit: cl.unit, unit_price: cl.unit_price});
  505. const audit_amount = cl.audit_amount ? cl.audit_amount.split(',') : '';
  506. const amount = audit_amount ? parseFloat(audit_amount[audit_amount.length - 1]) : 0;
  507. cl.ca_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.camount, findDecimal(cl.unit))), totalPriceUnit);
  508. cl.spa_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.spamount, findDecimal(cl.unit))), totalPriceUnit);
  509. cl.amount = amount;
  510. cl.a_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.amount, findDecimal(cl.unit))), totalPriceUnit);
  511. if (hzIndex !== -1) {
  512. hzList[hzIndex].camount = ZhCalc.add(hzList[hzIndex].camount, cl.camount);
  513. hzList[hzIndex].ca_tp = ZhCalc.add(hzList[hzIndex].ca_tp, cl.ca_tp);
  514. hzList[hzIndex].spamount = ZhCalc.add(hzList[hzIndex].spamount, cl.spamount);
  515. hzList[hzIndex].spa_tp = ZhCalc.add(hzList[hzIndex].spa_tp, cl.spa_tp);
  516. hzList[hzIndex].amount = ZhCalc.add(hzList[hzIndex].amount, amount);
  517. hzList[hzIndex].a_tp = ZhCalc.add(hzList[hzIndex].a_tp, cl.a_tp);
  518. } else {
  519. hzList.push(cl);
  520. }
  521. }
  522. if (hzList.length > 0) {
  523. // 按清单编号排序
  524. hzList.sort(sortByCode);
  525. }
  526. console.log(hzList);
  527. // // sjs设置
  528. SpreadJsObj.loadSheetData(hzSpread.getActiveSheet(), SpreadJsObj.DataType.Data, hzList);
  529. hzSpreadObj.makeBackColor();
  530. hzSpreadObj.makeSjsFooter();
  531. });
  532. $.subMenu({
  533. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  534. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  535. key: 'menu.1.0.0',
  536. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  537. callback: function (info) {
  538. if (info.mini) {
  539. $('.panel-title').addClass('fluid');
  540. $('#sub-menu').removeClass('panel-sidebar');
  541. } else {
  542. $('.panel-title').removeClass('fluid');
  543. $('#sub-menu').addClass('panel-sidebar');
  544. }
  545. autoFlashHeight();
  546. changeSpread.refresh();
  547. }
  548. });
  549. // 切换页数
  550. $('.page-select').on('click', function () {
  551. const totalPageNum = parseInt($('#totalPage').text());
  552. const lastPageNum = parseInt($('#currentPage').text());
  553. const status = $(this).attr('content');
  554. if (status === 'pre' && lastPageNum > 1) {
  555. getAllList(lastPageNum-1);
  556. $('#showAttachment').hide();
  557. $('#syfujian .check-all-file').prop('checked', false)
  558. } else if (status === 'next' && lastPageNum < totalPageNum) {
  559. getAllList(lastPageNum+1);
  560. $('#showAttachment').hide();
  561. $('#syfujian .check-all-file').prop('checked', false)
  562. }
  563. });
  564. // 项目节信息获取
  565. const xmjSpreadSetting = {
  566. cols: [
  567. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'xmj_code', hAlign: 0, width: 80},
  568. // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  569. {title: '细目', colSpan: '1', rowSpan: '2', field: 'xmj_jldy', hAlign: 0, width: 100},
  570. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'xmj_dwgc', hAlign: 0, width: 100},
  571. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'xmj_fbgc', hAlign: 0, width: 100},
  572. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'xmj_fxgc', hAlign: 0, width: 100},
  573. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 100},
  574. {title: '数量', colSpan: '1', rowSpan: '2', field: 'oamount', hAlign: 2, width: 80},
  575. ],
  576. emptyRows: 0,
  577. headRows: 1,
  578. headRowHeight: [25, 25],
  579. defaultRowHeight: 21,
  580. headerFont: '12px 微软雅黑',
  581. font: '12px 微软雅黑',
  582. readOnly: true,
  583. localCache: {
  584. key: 'changes-xmj',
  585. colWidth: true,
  586. }
  587. };
  588. SpreadJsObj.initSheet(xmjSpread.getActiveSheet(), xmjSpreadSetting);
  589. $.divResizer({
  590. select: '#right-spr',
  591. callback: function () {
  592. changeSpread.refresh();
  593. xmjSpread.refresh();
  594. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  595. setLocalCache('change_information_width', width);
  596. $('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  597. }
  598. });
  599. // 根据浏览器记录展开收起
  600. if (getLocalCache('change_information_width')) {
  601. $('#left-view').css('width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  602. $('#right-view').css('width', getLocalCache('change_information_width') + '%');
  603. $('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  604. changeSpread.refresh();
  605. xmjSpread.refresh();
  606. } else {
  607. $('#left-header').css('min-width', '33.33%');
  608. }
  609. });
  610. function calcChangePrice() {
  611. let positive_tp = 0;
  612. let negative_tp = 0;
  613. let new_tp = 0;
  614. for (const c of changeList) {
  615. if (c.spamount) {
  616. const price = ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
  617. new_tp = ZhCalc.add(new_tp, price);
  618. if (price >= 0) {
  619. positive_tp = ZhCalc.add(positive_tp, price);
  620. } else {
  621. negative_tp = ZhCalc.add(negative_tp, price);
  622. }
  623. }
  624. }
  625. const updateTpList = {};
  626. let updateFlag = false;
  627. if (changeTp !== new_tp) {
  628. updateTpList.total_price = new_tp;
  629. updateFlag = true;
  630. }
  631. if (positive_tp !== changePp) {
  632. updateTpList.positive_tp = positive_tp;
  633. updateFlag = true;
  634. }
  635. if (negative_tp !== changeNp) {
  636. updateTpList.negative_tp = negative_tp;
  637. updateFlag = true;
  638. }
  639. if (updateFlag) {
  640. console.log(updateTpList);
  641. postData(window.location.pathname + '/save', { type:'update_tp', updateData: updateTpList }, function () {
  642. changePp = positive_tp;
  643. changeNp = negative_tp;
  644. changeTp = new_tp;
  645. });
  646. }
  647. }
  648. function findDecimal(unit) {
  649. let value = precision.other.value;
  650. const changeUnits = precision;
  651. for (const d in changeUnits) {
  652. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  653. value = changeUnits[d].value;
  654. break;
  655. }
  656. }
  657. return value;
  658. }
  659. // 生成附件列表
  660. function getAllList(currPageNum = 1) {
  661. // 每页最多几个附件
  662. const pageCount = 20;
  663. // 附件总数
  664. const total = attData.length;
  665. // 总页数
  666. const pageNum = Math.ceil(total/pageCount);
  667. $('#totalPage').text(pageNum);
  668. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  669. // 当前页附件内容
  670. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  671. currPageFileData = currPageAttData;
  672. let html = '';
  673. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  674. for(const [index,att] of currPageAttData.entries()) {
  675. html += `<tr>
  676. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  677. <td>${((currPageNum-1)*pageCount)+index+1}</td>
  678. <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>
  679. <td>${moment(att.in_time * 1000).format('YYYY-MM-DD')}<br>${bytesToSize(att.filesize)}</td>
  680. <td>
  681. <a href="/change/download/file/${att.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  682. html += (att.uid === accountId && (auditStatus === 4 ? Boolean(att.extra_upload) : true)) ?
  683. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  684. html += `</td>`;
  685. }
  686. $('#attList').html(html);
  687. $('#attList').on('click', 'tr', function() {
  688. $('#attList tr').removeClass('bg-light');
  689. $(this).addClass('bg-light');
  690. })
  691. }
  692. function bytesToSize(bytes) {
  693. if (parseInt(bytes) === 0) return '0 B';
  694. const k = 1024;
  695. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  696. const i = Math.floor(Math.log(bytes) / Math.log(k));
  697. // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
  698. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  699. }