change_information_show.js 13 KB

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