change_information_show.js 11 KB

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