change_information_show.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. resetXmjSpread: function(data = null) {
  98. const xmj = [];
  99. if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
  100. if (data.bwmx === data.xmj_jldy) {
  101. data.bwmx = '';
  102. }
  103. xmj.push(data);
  104. }
  105. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  106. },
  107. selectionChanged: function (e, info) {
  108. const data = SpreadJsObj.getSelectObject(info.sheet);
  109. changeSpreadObj.resetXmjSpread(data);
  110. },
  111. setAuditValue: function () {
  112. const rowCount = changeSpreadSheet.getRowCount();
  113. // 用户的数据合计
  114. for (const j in aidList) {
  115. for(let i = 0; i <= rowCount - 1; i++){
  116. const data = {
  117. unit_price: changeSpreadSheet.getValue(i, 5),
  118. amount: parseFloat(changeSpreadSheet.getValue(i, 12 + parseInt(j)*2)),
  119. };
  120. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);
  121. changeSpreadSheet.setValue(i, 13 + j*2, sum !== 0 ? sum : null);
  122. }
  123. }
  124. },
  125. countSum: function() {
  126. const rowCount = changeSpreadSheet.getRowCount();
  127. let oSum = 0,
  128. cSum = 0,
  129. sSum = 0;
  130. for(let i = 0; i < rowCount - 1; i++){
  131. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  132. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  133. sSum = ZhCalc.add(sSum, changeSpreadSheet.getValue(i, 11));
  134. }
  135. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  136. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  137. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11, sSum !== 0 ? sSum : null);
  138. // 用户的数据合计
  139. for (const j in aidList) {
  140. let audit_sum = 0;
  141. for(let i = 0; i < rowCount - 1; i++){
  142. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 13 + j*2));
  143. }
  144. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 13 + j*2, audit_sum !== 0 ? audit_sum : null);
  145. }
  146. },
  147. showHideAudit: function (show = false) {
  148. const count = changeSpreadSetting.cols.length;
  149. for (let i = 12; i < count; i++) {
  150. changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  151. }
  152. changeSpreadSheet.setColumnVisible(10, !show, GC.Spread.Sheets.SheetArea.viewport);
  153. changeSpreadSheet.setColumnVisible(11, !show, GC.Spread.Sheets.SheetArea.viewport);
  154. }
  155. };
  156. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  157. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  158. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  159. changeSpreadObj.setAuditValue();
  160. changeSpreadObj.makeSjsFooter();
  161. changeSpreadObj.showHideAudit();
  162. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  163. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  164. // 审批流程展示与隐藏
  165. $('#show-table-detail').on('click', function (e) {
  166. if($(e.target).is('label')){
  167. return;
  168. }
  169. changeSpreadObj.showHideAudit($(this).is(':checked'));
  170. });
  171. // 重新审批获取手机验证码
  172. // 获取验证码
  173. let isPosting = false;
  174. $("#get-code").click(function() {
  175. if (isPosting) {
  176. return false;
  177. }
  178. const btn = $(this);
  179. $.ajax({
  180. url: '/profile/code?_csrf=' + csrf,
  181. type: 'post',
  182. data: { mobile: authMobile, type: 'shenpi' },
  183. dataTye: 'json',
  184. error: function() {
  185. isPosting = false;
  186. },
  187. beforeSend: function() {
  188. isPosting = true;
  189. },
  190. success: function(response) {
  191. isPosting = false;
  192. if (response.err === 0) {
  193. codeSuccess(btn);
  194. $("input[name='code']").removeAttr('readonly');
  195. $("#re-shenpi-btn").removeAttr('disabled');
  196. } else {
  197. toast(response.msg, 'error');
  198. }
  199. }
  200. });
  201. });
  202. });
  203. /**
  204. * 获取成功后的操作
  205. *
  206. * @param {Object} btn - 点击的按钮
  207. * @return {void}
  208. */
  209. function codeSuccess(btn) {
  210. let counter = 60;
  211. btn.addClass('disabled').text('重新获取 ' + counter + 'S');
  212. btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
  213. const bindBtn = $("#bind-btn");
  214. bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
  215. const countDown = setInterval(function() {
  216. const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
  217. // 倒数结束后
  218. if (countString === '') {
  219. clearInterval(countDown);
  220. btn.removeClass('disabled');
  221. }
  222. const text = '重新获取' + countString;
  223. btn.text(text);
  224. counter -= 1;
  225. }, 1000);
  226. }