change_information_show.js 12 KB

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