change_information_show.js 9.1 KB

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