change_information_show.js 10.0 KB

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