change_information_show.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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: 'code', hAlign: 0, width: 80, formatter: '@'},
  13. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  14. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@'},
  15. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@'},
  16. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  17. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
  18. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount'},
  19. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, formatter: '@', type: 'Number', getValue: 'getValue.oa_tp'},
  20. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
  21. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, formatter: '@', type: 'Number', getValue: 'getValue.ca_tp'},
  22. {title: '审批后变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.samount'},
  23. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, formatter: '@', type: 'Number', getValue: 'getValue.sa_tp'},
  24. ],
  25. emptyRows: 0,
  26. headRows: 2,
  27. headRowHeight: [25, 25],
  28. defaultRowHeight: 21,
  29. headerFont: '12px 微软雅黑',
  30. font: '12px 微软雅黑',
  31. readOnly: true,
  32. };
  33. for (const aid of aidList) {
  34. const userinfo = _.find(auditList2, { 'uid': aid });
  35. const newColcount = {
  36. title: userinfo.name + ' 审批|数量',
  37. colSpan: '2|1', rowSpan: '1|1',
  38. field: 'audit_amount_' + aid,
  39. hAlign: 2, width: 60, type: 'Number',
  40. };
  41. const newColTp = {
  42. title: '|金额',
  43. colSpan: '|1', rowSpan: '|1',
  44. field: 'sa_tp',
  45. hAlign: 2, width: 80, formatter: '@', type: 'Number',
  46. };
  47. changeSpreadSetting.cols.push(newColcount);
  48. changeSpreadSetting.cols.push(newColTp);
  49. }
  50. const changeCol = {
  51. getValue: {
  52. unit_price: function(data) {
  53. return ZhCalc.round(data.unit_price, unitPriceUnit);
  54. },
  55. oa_tp: function (data) {
  56. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  57. },
  58. ca_tp: function (data) {
  59. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  60. },
  61. oamount: function (data) {
  62. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  63. },
  64. camount: function (data) {
  65. return ZhCalc.round(data.camount, findDecimal(data.unit));
  66. },
  67. samount: function (data) {
  68. return ZhCalc.round(data.samount, findDecimal(data.unit));
  69. },
  70. sa_tp: function (data) {
  71. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.samount), totalPriceUnit);
  72. },
  73. },
  74. };
  75. const changeSpreadObj = {
  76. makeSjsFooter: function () {
  77. // 增加汇总行并设为锁定禁止编辑状态
  78. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  79. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  80. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  81. changeSpreadObj.countSum();
  82. },
  83. setAuditValue: function () {
  84. const rowCount = changeSpreadSheet.getRowCount();
  85. // 用户的数据合计
  86. for (const j in aidList) {
  87. for(let i = 0; i <= rowCount - 1; i++){
  88. const data = {
  89. unit_price: changeSpreadSheet.getValue(i, 5),
  90. amount: parseFloat(changeSpreadSheet.getValue(i, 12 + parseInt(j)*2)),
  91. };
  92. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);
  93. changeSpreadSheet.setValue(i, 13 + j*2, sum !== 0 ? sum : null);
  94. }
  95. }
  96. },
  97. countSum: function() {
  98. const rowCount = changeSpreadSheet.getRowCount();
  99. let oSum = 0,
  100. cSum = 0,
  101. sSum = 0;
  102. for(let i = 0; i < rowCount - 1; i++){
  103. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  104. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  105. sSum = ZhCalc.add(sSum, changeSpreadSheet.getValue(i, 11));
  106. }
  107. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  108. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  109. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11, sSum !== 0 ? sSum : null);
  110. // 用户的数据合计
  111. for (const j in aidList) {
  112. let audit_sum = 0;
  113. for(let i = 0; i < rowCount - 1; i++){
  114. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 13 + j*2));
  115. }
  116. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 13 + j*2, audit_sum !== 0 ? audit_sum : null);
  117. }
  118. },
  119. showHideAudit: function (show = false) {
  120. const count = changeSpreadSetting.cols.length;
  121. for (let i = 12; i < count; i++) {
  122. changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  123. }
  124. changeSpreadSheet.setColumnVisible(10, !show, GC.Spread.Sheets.SheetArea.viewport);
  125. changeSpreadSheet.setColumnVisible(11, !show, GC.Spread.Sheets.SheetArea.viewport);
  126. }
  127. };
  128. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  129. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  130. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  131. changeSpreadObj.setAuditValue();
  132. changeSpreadObj.makeSjsFooter();
  133. changeSpreadObj.showHideAudit();
  134. // 审批流程展示与隐藏
  135. $('#show-table-detail').on('click', function (e) {
  136. if($(e.target).is('label')){
  137. return;
  138. }
  139. changeSpreadObj.showHideAudit($(this).is(':checked'));
  140. });
  141. // 重新审批获取手机验证码
  142. // 获取验证码
  143. let isPosting = false;
  144. $("#get-code").click(function() {
  145. if (isPosting) {
  146. return false;
  147. }
  148. const btn = $(this);
  149. $.ajax({
  150. url: '/profile/code?_csrf=' + csrf,
  151. type: 'post',
  152. data: { mobile: authMobile, type: 'shenpi' },
  153. dataTye: 'json',
  154. error: function() {
  155. isPosting = false;
  156. },
  157. beforeSend: function() {
  158. isPosting = true;
  159. },
  160. success: function(response) {
  161. isPosting = false;
  162. if (response.err === 0) {
  163. codeSuccess(btn);
  164. $("input[name='code']").removeAttr('readonly');
  165. $("#re-shenpi-btn").removeAttr('disabled');
  166. } else {
  167. toast(response.msg, 'error');
  168. }
  169. }
  170. });
  171. });
  172. });
  173. /**
  174. * 获取成功后的操作
  175. *
  176. * @param {Object} btn - 点击的按钮
  177. * @return {void}
  178. */
  179. function codeSuccess(btn) {
  180. let counter = 60;
  181. btn.addClass('disabled').text('重新获取 ' + counter + 'S');
  182. btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
  183. const bindBtn = $("#bind-btn");
  184. bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
  185. const countDown = setInterval(function() {
  186. const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
  187. // 倒数结束后
  188. if (countString === '') {
  189. clearInterval(countDown);
  190. btn.removeClass('disabled');
  191. }
  192. const text = '重新获取' + countString;
  193. btn.text(text);
  194. counter -= 1;
  195. }, 1000);
  196. }