change_information_show.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. const changeSpreadSetting = {
  11. cols: [
  12. {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: true},
  13. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  14. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  15. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  16. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
  17. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@'},
  18. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@'},
  19. {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, formatter: '@', visible: openChangeState},
  20. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount'},
  21. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.oa_tp'},
  22. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
  23. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
  24. {title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.samount'},
  25. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.sa_tp'},
  26. ],
  27. emptyRows: 0,
  28. headRows: 2,
  29. headRowHeight: [25, 25],
  30. defaultRowHeight: 21,
  31. headerFont: '12px 微软雅黑',
  32. font: '12px 微软雅黑',
  33. readOnly: true,
  34. rowHeader:[
  35. {
  36. rowHeaderType: 'circle',
  37. setting: {
  38. size: 5,
  39. indent: 16,
  40. getColor: function (index, data) {
  41. if (!data) return;
  42. if(data.lid != 0) return;
  43. return '#007bff';
  44. }
  45. },
  46. },
  47. ],
  48. localCache: {
  49. key: 'changes-spread',
  50. colWidth: true,
  51. }
  52. };
  53. for (const aid of aidList) {
  54. // const userinfo = _.find(auditList2, { 'uid': aid });
  55. const newColcount = {
  56. title: (auditors2[aid - 1] && auditors2[aid - 1].length > 1 ? (aid + '审') : auditors2[aid - 1][0].name) + ' 审批|数量',
  57. colSpan: '2|1', rowSpan: '1|1',
  58. field: 'audit_amount_' + aid,
  59. hAlign: 2, width: 60, type: 'Number',
  60. };
  61. const newColTp = {
  62. title: '|金额',
  63. colSpan: '|1', rowSpan: '|1',
  64. field: 'sa_tp_' + aid,
  65. hAlign: 2, width: 80, type: 'Number',
  66. };
  67. changeSpreadSetting.cols.push(newColcount);
  68. changeSpreadSetting.cols.push(newColTp);
  69. }
  70. changeSpreadSetting.cols.push({title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.changed_amount'});
  71. changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.changed_tp'});
  72. changeSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  73. return checkIsSettle(data) ? spreadColor.stage.settle : defaultColor;
  74. }
  75. const changeCol = {
  76. getValue: {
  77. unit_price: function(data) {
  78. return ZhCalc.round(data.unit_price, unitPriceUnit);
  79. },
  80. oa_tp: function (data) {
  81. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit);
  82. },
  83. ca_tp: function (data) {
  84. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  85. },
  86. oamount: function (data) {
  87. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  88. },
  89. camount: function (data) {
  90. return ZhCalc.round(data.camount, findDecimal(data.unit));
  91. },
  92. samount: function (data) {
  93. return ZhCalc.round(data.samount, findDecimal(data.unit));
  94. },
  95. sa_tp: function (data) {
  96. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.samount, findDecimal(data.unit))), totalPriceUnit);
  97. },
  98. changed_amount: function (data) {
  99. // return ZhCalc.round(ZhCalc.add(data.oamount, data.spamount), findDecimal(data.unit));
  100. return ZhCalc.round(ZhCalc.add(data.oamount, data.checked_amount), findDecimal(data.unit));
  101. },
  102. changed_tp: function (data) {
  103. // return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit),
  104. // ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.spamount, findDecimal(data.unit))), totalPriceUnit));
  105. return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit),
  106. ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.checked_amount, findDecimal(data.unit))), totalPriceUnit));
  107. },
  108. },
  109. };
  110. const changeSpreadObj = {
  111. makeSjsFooter: function () {
  112. // 增加汇总行并设为锁定禁止编辑状态
  113. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  114. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  115. const cellType1 = new GC.Spread.Sheets.CellTypes.Text();
  116. changeSpreadSheet.getCell(changeSpreadSheet.getRowCount() - 1, 0).cellType(cellType1);
  117. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  118. changeSpreadObj.countSum();
  119. },
  120. resetXmjSpread: function(data = null) {
  121. const xmj = [];
  122. if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
  123. if (data.bwmx === data.xmj_jldy) {
  124. data.bwmx = '';
  125. }
  126. xmj.push(data);
  127. }
  128. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  129. },
  130. selectionChanged: function (e, info) {
  131. const sel = info.sheet.getSelections()[0];
  132. const col = info.sheet.zh_setting.cols[sel.col];
  133. const data = SpreadJsObj.getSelectObject(info.sheet);
  134. if (col && col.field === 'camount' && data) {
  135. $('#camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
  136. } else {
  137. $('#camount-expr').val('');
  138. }
  139. changeSpreadObj.resetXmjSpread(data);
  140. },
  141. setAuditValue: function () {
  142. const rowCount = changeSpreadSheet.getRowCount();
  143. // 用户的数据合计
  144. for (const j in aidList) {
  145. for(let i = 0; i <= rowCount - 1; i++){
  146. const data = {
  147. unit_price: changeSpreadSheet.getValue(i, 4),
  148. amount: parseFloat(changeSpreadSheet.getValue(i, startLimit + 5 + parseInt(j)*2)),
  149. };
  150. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);
  151. changeSpreadSheet.setValue(i, startLimit + 6 + j*2, sum !== 0 ? sum : null);
  152. }
  153. }
  154. },
  155. countSum: function() {
  156. const rowCount = changeSpreadSheet.getRowCount();
  157. let oSum = 0,
  158. cSum = 0,
  159. sSum = 0,
  160. cdSum = 0;
  161. for(let i = 0; i < rowCount - 1; i++){
  162. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, startLimit));
  163. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, startLimit + 2));
  164. sSum = ZhCalc.add(sSum, changeSpreadSheet.getValue(i, startLimit + 4));
  165. cdSum = ZhCalc.add(cdSum, changeSpreadSheet.getValue(i, (startLimit + 6 + aidList.length*2)));
  166. }
  167. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit, oSum !== 0 ? oSum : null);
  168. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 2, cSum !== 0 ? cSum : null);
  169. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 4, sSum !== 0 ? sSum : null);
  170. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, (startLimit + 6 + aidList.length*2), cdSum !== 0 ? cdSum : null);
  171. // 用户的数据合计
  172. for (const j in aidList) {
  173. let audit_sum = 0;
  174. for(let i = 0; i < rowCount - 1; i++){
  175. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, startLimit + 6 + j*2));
  176. }
  177. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 6 + j*2, audit_sum !== 0 ? audit_sum : null);
  178. }
  179. },
  180. showHideAudit: function (show = false) {
  181. const count = changeSpreadSetting.cols.length;
  182. for (let i = startLimit + 5; i < count - 2; i++) {
  183. changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  184. }
  185. changeSpreadSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);
  186. changeSpreadSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);
  187. }
  188. };
  189. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  190. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  191. for (const c of changeList) {
  192. for (const j of aidList) {
  193. c['sa_tp_' + j] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + j], c.unit_price), totalPriceUnit);
  194. }
  195. }
  196. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  197. // changeSpreadObj.setAuditValue();
  198. changeSpreadObj.makeSjsFooter();
  199. changeSpreadObj.showHideAudit();
  200. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  201. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  202. // 审批流程展示与隐藏
  203. $('#show-table-detail').on('click', function (e) {
  204. if($(e.target).is('label')){
  205. return;
  206. }
  207. changeSpreadObj.showHideAudit($(this).is(':checked'));
  208. });
  209. // 重新审批获取手机验证码
  210. // 获取验证码
  211. let isPosting = false;
  212. $("#get-code").click(function() {
  213. if (isPosting) {
  214. return false;
  215. }
  216. const btn = $(this);
  217. $.ajax({
  218. url: '/profile/code?_csrf_j=' + csrf,
  219. type: 'post',
  220. data: { mobile: authMobile, type: 'shenpi' },
  221. dataTye: 'json',
  222. error: function() {
  223. isPosting = false;
  224. },
  225. beforeSend: function() {
  226. isPosting = true;
  227. },
  228. success: function(response) {
  229. isPosting = false;
  230. if (response.err === 0) {
  231. codeSuccess(btn);
  232. $("input[name='code']").removeAttr('readonly');
  233. $("#re-shenpi-btn").removeAttr('disabled');
  234. $("#re-shenpi-btn2").removeAttr('disabled');
  235. } else {
  236. toast(response.msg, 'error');
  237. }
  238. }
  239. });
  240. });
  241. });
  242. /**
  243. * 获取成功后的操作
  244. *
  245. * @param {Object} btn - 点击的按钮
  246. * @return {void}
  247. */
  248. function codeSuccess(btn) {
  249. let counter = 60;
  250. btn.addClass('disabled').text('重新获取 ' + counter + 'S');
  251. btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
  252. const bindBtn = $("#bind-btn");
  253. bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
  254. const countDown = setInterval(function() {
  255. const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
  256. // 倒数结束后
  257. if (countString === '') {
  258. clearInterval(countDown);
  259. btn.removeClass('disabled');
  260. }
  261. const text = '重新获取' + countString;
  262. btn.text(text);
  263. counter -= 1;
  264. }, 1000);
  265. }