change_information_show.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. $.event.special.valuechange = {
  10. teardown: function (namespaces) {
  11. $(this).unbind('.valuechange');
  12. },
  13. handler: function (e) {
  14. $.event.special.valuechange.triggerChanged($(this));
  15. },
  16. add: function (obj) {
  17. $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
  18. },
  19. triggerChanged: function (element) {
  20. var current = element[0].contentEditable === 'true' ? element.html() : element.val()
  21. , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
  22. if (current !== previous) {
  23. element.trigger('valuechange', [element.data('previous')]);
  24. element.data('previous', current);
  25. }
  26. }
  27. };
  28. $(document).ready(() => {
  29. const changeSpreadSetting = {
  30. cols: [
  31. {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: true},
  32. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  33. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  34. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  35. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
  36. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@'},
  37. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@'},
  38. {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, formatter: '@', visible: openChangeState},
  39. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount2'},
  40. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.oa_tp'},
  41. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
  42. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
  43. {title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.samount'},
  44. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.sa_tp'},
  45. ],
  46. emptyRows: 0,
  47. headRows: 2,
  48. headRowHeight: [25, 25],
  49. defaultRowHeight: 21,
  50. headerFont: '12px 微软雅黑',
  51. font: '12px 微软雅黑',
  52. readOnly: true,
  53. rowHeader:[
  54. {
  55. rowHeaderType: 'circle',
  56. setting: {
  57. size: 5,
  58. indent: 16,
  59. getColor: function (index, data) {
  60. if (!data) return;
  61. if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
  62. return '#dc3545';
  63. }
  64. if(data.lid != 0) return;
  65. return '#007bff';
  66. }
  67. },
  68. },
  69. ],
  70. localCache: {
  71. key: 'changes-spread',
  72. colWidth: true,
  73. }
  74. };
  75. for (const aid of aidList) {
  76. // const userinfo = _.find(auditList2, { 'uid': aid });
  77. const audit = _.find(auditors2, function(item){
  78. return _.findIndex(item, { audit_order: aid }) !== -1;
  79. });
  80. const newColcount = {
  81. title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
  82. colSpan: '2|1', rowSpan: '1|1',
  83. field: 'audit_amount_' + aid,
  84. hAlign: 2, width: 60, type: 'Number',
  85. };
  86. const newColTp = {
  87. title: '|金额',
  88. colSpan: '|1', rowSpan: '|1',
  89. field: 'sa_tp_' + aid,
  90. hAlign: 2, width: 80, type: 'Number',
  91. };
  92. changeSpreadSetting.cols.push(newColcount);
  93. changeSpreadSetting.cols.push(newColTp);
  94. }
  95. changeSpreadSetting.cols.push({title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.changed_amount'});
  96. changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.changed_tp'});
  97. changeSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  98. return checkIsSettle(data) ? spreadColor.stage.settle : defaultColor;
  99. }
  100. const changeCol = {
  101. getValue: {
  102. unit_price: function(data) {
  103. return ZhCalc.round(data.unit_price, unitPriceUnit);
  104. },
  105. oa_tp: function (data) {
  106. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit);
  107. },
  108. ca_tp: function (data) {
  109. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  110. },
  111. oamount2: function (data) {
  112. return ZhCalc.round(data.oamount2, findDecimal(data.unit));
  113. },
  114. camount: function (data) {
  115. return ZhCalc.round(data.camount, findDecimal(data.unit));
  116. },
  117. samount: function (data) {
  118. return ZhCalc.round(data.samount, findDecimal(data.unit));
  119. },
  120. sa_tp: function (data) {
  121. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.samount, findDecimal(data.unit))), totalPriceUnit);
  122. },
  123. changed_amount: function (data) {
  124. // return ZhCalc.round(ZhCalc.add(data.oamount, data.spamount), findDecimal(data.unit));
  125. return ZhCalc.round(ZhCalc.add(data.oamount2, data.checked_amount), findDecimal(data.unit));
  126. },
  127. changed_tp: function (data) {
  128. // return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit),
  129. // ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.spamount, findDecimal(data.unit))), totalPriceUnit));
  130. return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit),
  131. ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.checked_amount, findDecimal(data.unit))), totalPriceUnit));
  132. },
  133. },
  134. };
  135. const changeSpreadObj = {
  136. makeSjsFooter: function () {
  137. // 增加汇总行并设为锁定禁止编辑状态
  138. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  139. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  140. const cellType1 = new GC.Spread.Sheets.CellTypes.Text();
  141. changeSpreadSheet.getCell(changeSpreadSheet.getRowCount() - 1, 0).cellType(cellType1);
  142. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  143. changeSpreadObj.countSum();
  144. },
  145. resetXmjSpread: function(data = null) {
  146. const xmj = [];
  147. if (data && data.lid != 0) {
  148. if (data.bwmx === data.xmj_jldy) {
  149. data.bwmx = '';
  150. }
  151. xmj.push(data);
  152. }
  153. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  154. },
  155. selectionChanged: function (e, info) {
  156. const sel = info.sheet.getSelections()[0];
  157. const col = info.sheet.zh_setting.cols[sel.col];
  158. const data = SpreadJsObj.getSelectObject(info.sheet);
  159. if (col && col.field === 'camount' && data) {
  160. $('#camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
  161. } else {
  162. $('#camount-expr').val('');
  163. }
  164. changeSpreadObj.resetXmjSpread(data);
  165. },
  166. setAuditValue: function () {
  167. const rowCount = changeSpreadSheet.getRowCount();
  168. // 用户的数据合计
  169. for (const j in aidList) {
  170. for(let i = 0; i <= rowCount - 1; i++){
  171. const data = {
  172. unit_price: changeSpreadSheet.getValue(i, 4),
  173. amount: parseFloat(changeSpreadSheet.getValue(i, startLimit + 5 + parseInt(j)*2)),
  174. };
  175. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);
  176. changeSpreadSheet.setValue(i, startLimit + 6 + j*2, sum !== 0 ? sum : null);
  177. }
  178. }
  179. },
  180. countSum: function() {
  181. const rowCount = changeSpreadSheet.getRowCount();
  182. let oSum = 0,
  183. cSum = 0,
  184. sSum = 0,
  185. cdSum = 0;
  186. for(let i = 0; i < rowCount - 1; i++){
  187. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, startLimit));
  188. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, startLimit + 2));
  189. sSum = ZhCalc.add(sSum, changeSpreadSheet.getValue(i, startLimit + 4));
  190. cdSum = ZhCalc.add(cdSum, changeSpreadSheet.getValue(i, (startLimit + 6 + aidList.length*2)));
  191. }
  192. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit, oSum !== 0 ? oSum : null);
  193. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 2, cSum !== 0 ? cSum : null);
  194. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 4, sSum !== 0 ? sSum : null);
  195. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, (startLimit + 6 + aidList.length*2), cdSum !== 0 ? cdSum : null);
  196. // 用户的数据合计
  197. for (const j in aidList) {
  198. let audit_sum = 0;
  199. for(let i = 0; i < rowCount - 1; i++){
  200. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, startLimit + 6 + j*2));
  201. }
  202. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 6 + j*2, audit_sum !== 0 ? audit_sum : null);
  203. }
  204. },
  205. showHideAudit: function (show = false) {
  206. const count = changeSpreadSetting.cols.length;
  207. for (let i = startLimit + 5; i < count - 2; i++) {
  208. changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  209. }
  210. changeSpreadSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);
  211. changeSpreadSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);
  212. }
  213. };
  214. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  215. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  216. for (const c of changeList) {
  217. for (const j of aidList) {
  218. c['sa_tp_' + j] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + j], c.unit_price), totalPriceUnit);
  219. }
  220. }
  221. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  222. // changeSpreadObj.setAuditValue();
  223. changeSpreadObj.makeSjsFooter();
  224. changeSpreadObj.showHideAudit();
  225. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  226. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  227. // 审批流程展示与隐藏
  228. $('#show-table-detail').on('click', function (e) {
  229. if($(e.target).is('label')){
  230. return;
  231. }
  232. changeSpreadObj.showHideAudit($(this).is(':checked'));
  233. });
  234. // 重新审批获取手机验证码
  235. // 获取验证码
  236. let isPosting = false;
  237. $(".get-code").on('click', function() {
  238. if (isPosting) {
  239. return false;
  240. }
  241. const btn = $(this);
  242. $.ajax({
  243. url: '/profile/code?_csrf_j=' + csrf,
  244. type: 'post',
  245. data: { mobile: authMobile, type: 'shenpi' },
  246. dataTye: 'json',
  247. error: function() {
  248. isPosting = false;
  249. },
  250. beforeSend: function() {
  251. isPosting = true;
  252. },
  253. success: function(response) {
  254. isPosting = false;
  255. if (response.err === 0) {
  256. codeSuccess(btn);
  257. $("input[name='code']").removeAttr('readonly');
  258. $("#re-shenpi-btn").removeAttr('disabled');
  259. $("#re-shenpi-btn2").removeAttr('disabled');
  260. } else {
  261. toast(response.msg, 'error');
  262. }
  263. }
  264. });
  265. });
  266. // 记录变更信息操作
  267. $('body').on('valuechange', '#w_code', function (e, previous) {
  268. const new_w_code = $(this).val();
  269. if (new_w_code !== w_code) {
  270. $('#show-save-btn').show();
  271. $('#sp-btn').hide();
  272. $('.title-main').addClass('bg-warning');
  273. } else {
  274. $('#show-save-btn').hide();
  275. $('#sp-btn').show();
  276. $('.title-main').removeClass('bg-warning');
  277. }
  278. });
  279. // 保存修改ajax提交(不刷新页面)
  280. $('.save_change_btn').on('click', function () {
  281. const new_w_code = $('#w_code').val();
  282. // 后改为br
  283. // 更新至服务器
  284. postData(window.location.pathname + '/save', { type:'info', updateData: { w_code: new_w_code } }, function (result) {
  285. toastr.success(result ? result.msg : '');
  286. $('#show-save-btn').hide();
  287. $('#sp-btn').show();
  288. $('.title-main').removeClass('bg-warning');
  289. w_code = new_w_code;
  290. });
  291. return false;
  292. });
  293. $('#cancel_change').on('click', function () {
  294. $('#show-save-btn').hide();
  295. $('#sp-btn').show();
  296. $('.title-main').removeClass('bg-warning');
  297. $('#w_code').val(w_code);
  298. // toastr.success('已还原到上次保存状态');
  299. });
  300. });
  301. /**
  302. * 获取成功后的操作
  303. *
  304. * @param {Object} btn - 点击的按钮
  305. * @return {void}
  306. */
  307. function codeSuccess(btn) {
  308. let counter = 60;
  309. btn.addClass('disabled').text('重新获取 ' + counter + 'S');
  310. btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
  311. const bindBtn = $("#bind-btn");
  312. bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
  313. const countDown = setInterval(function() {
  314. const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
  315. // 倒数结束后
  316. if (countString === '') {
  317. clearInterval(countDown);
  318. btn.removeClass('disabled');
  319. }
  320. const text = '重新获取' + countString;
  321. btn.text(text);
  322. counter -= 1;
  323. }, 1000);
  324. }