change_information_show.js 13 KB

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