change_information_approval.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. function getPasteHint (str, row = '') {
  10. let returnObj = str;
  11. if (row) {
  12. returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
  13. }
  14. return returnObj;
  15. }
  16. $(document).ready(() => {
  17. const changeSpreadSetting = {
  18. cols: [
  19. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  20. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  21. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  22. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  23. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  24. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price', readOnly: true},
  25. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount', readOnly: true},
  26. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.oa_tp', readOnly: true},
  27. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount', readOnly: true},
  28. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp', readOnly: true},
  29. ],
  30. emptyRows: 0,
  31. headRows: 2,
  32. headRowHeight: [25, 25],
  33. defaultRowHeight: 21,
  34. headerFont: '12px 微软雅黑',
  35. font: '12px 微软雅黑',
  36. // readOnly: true,
  37. rowHeader:[
  38. {
  39. rowHeaderType: 'circle',
  40. setting: {
  41. size: 5,
  42. indent: 16,
  43. getColor: function (index, data) {
  44. if (!data) return;
  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 newColcount = {
  59. title: userinfo.name + ' 审批|数量',
  60. colSpan: '2|1', rowSpan: '1|1',
  61. field: 'audit_amount_' + aid,
  62. hAlign: 2, width: 60, type: 'Number',
  63. readOnly: aid !== parseInt(accountId)
  64. };
  65. const newColTp = {
  66. title: '|金额',
  67. colSpan: '|1', rowSpan: '|1',
  68. field: 'sa_tp',
  69. hAlign: 2, width: 80, type: 'Number',
  70. readOnly: true
  71. };
  72. changeSpreadSetting.cols.push(newColcount);
  73. changeSpreadSetting.cols.push(newColTp);
  74. }
  75. const changeCol = {
  76. getValue: {
  77. unit_price: function(data) {
  78. return ZhCalc.round(data.unit_price, unitPriceUnit);
  79. },
  80. oa_tp: function (data) {
  81. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  82. },
  83. ca_tp: function (data) {
  84. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  85. },
  86. oamount: function (data) {
  87. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  88. },
  89. camount: function (data) {
  90. return ZhCalc.round(data.camount, findDecimal(data.unit));
  91. },
  92. },
  93. };
  94. const changeSpreadObj = {
  95. makeSjsFooter: function () {
  96. // 增加汇总行并设为锁定禁止编辑状态
  97. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  98. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  99. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  100. changeSpreadObj.countSum();
  101. },
  102. setAuditValue: function () {
  103. const rowCount = changeSpreadSheet.getRowCount();
  104. // 用户的数据合计
  105. for (const j in aidList) {
  106. for(let i = 0; i <= rowCount - 1; i++){
  107. const data = {
  108. unit_price: changeSpreadSheet.getValue(i, 5),
  109. amount: parseFloat(changeSpreadSheet.getValue(i, 10 + parseInt(j)*2)),
  110. };
  111. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);
  112. changeSpreadSheet.setValue(i, 11 + j*2, sum !== 0 ? sum : null);
  113. }
  114. }
  115. },
  116. resetXmjSpread: function(data = null) {
  117. const xmj = [];
  118. if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
  119. if (data.bwmx === data.xmj_jldy) {
  120. data.bwmx = '';
  121. }
  122. xmj.push(data);
  123. }
  124. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  125. },
  126. selectionChanged: function (e, info) {
  127. const data = SpreadJsObj.getSelectObject(info.sheet);
  128. changeSpreadObj.resetXmjSpread(data);
  129. },
  130. setRowValueAndSum: function (data, row, col) {
  131. for (const j in aidList) {
  132. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, parseFloat(changeSpreadSheet.getValue(row, 10 + parseInt(j)*2))), totalPriceUnit);
  133. changeSpreadSheet.setValue(row, 11 + j*2, sum !== 0 ? sum : null);
  134. }
  135. // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.spamount), totalPriceUnit);
  136. // changeSpreadSheet.setValue(row, col+1, sum !== 0 ? sum : null);
  137. const rowCount = changeSpreadSheet.getRowCount();
  138. // 用户的数据合计
  139. let audit_sum = 0;
  140. for(let i = 0; i < rowCount - 1; i++){
  141. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, col+1));
  142. }
  143. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, col+1, audit_sum !== 0 ? audit_sum : null);
  144. },
  145. countSum: function() {
  146. const rowCount = changeSpreadSheet.getRowCount();
  147. let oSum = 0,
  148. cSum = 0;
  149. for(let i = 0; i < rowCount - 1; i++){
  150. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  151. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  152. }
  153. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  154. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  155. // 用户的数据合计
  156. for (const j in aidList) {
  157. let audit_sum = 0;
  158. for(let i = 0; i < rowCount - 1; i++){
  159. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 11 + j*2));
  160. }
  161. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11 + j*2, audit_sum !== 0 ? audit_sum : null);
  162. }
  163. },
  164. deletePress: function (sheet) {
  165. return;
  166. },
  167. editEnded: function (e, info) {
  168. if (info.sheet.zh_setting) {
  169. const select = SpreadJsObj.getSelectObject(info.sheet);
  170. const col = info.sheet.zh_setting.cols[info.col];
  171. // 未改变值则不提交
  172. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  173. const orgValue = select[col.field];
  174. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  175. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  176. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  177. return;
  178. }
  179. // 判断部分值是否输入的是数字判断和数据计算
  180. if (col.type === 'Number') {
  181. if (isNaN(validText)) {
  182. toastr.error('不能输入其它非数字类型字符');
  183. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  184. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  185. return;
  186. }
  187. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  188. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  189. const usedInfo = _.find(changeUsedData, { id: select.id });
  190. if (usedInfo && validText >= 0 && validText < usedInfo.used_qty) {
  191. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  192. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  193. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  194. return;
  195. } else if (usedInfo && validText < 0 && validText > usedInfo.used_qty) {
  196. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  197. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  198. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  199. return;
  200. }
  201. }
  202. select[col.field] = validText;
  203. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  204. const data = {
  205. id: select.id,
  206. spamount: select.spamount,
  207. };
  208. console.log(data);
  209. // 更新至服务器
  210. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  211. changeList.splice(info.row, 1, select);
  212. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  213. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  214. }, function () {
  215. select[col.field] = orgValue;
  216. select.spamount = orgValue;
  217. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  218. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  219. });
  220. }
  221. },
  222. clipboardPasted(e, info) {
  223. const hint = {
  224. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  225. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  226. qtyError: {type: 'error', msg: '变更数值必须大于等于已调用值'},
  227. };
  228. const range = info.cellRange;
  229. const sortData = info.sheet.zh_data || [];
  230. // console.log(info, range);
  231. // if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  232. // toastMessageUniq(hint.cellError);
  233. // // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  234. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  235. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  236. // changeSpreadObj.setAuditValue();
  237. // changeSpreadObj.makeSjsFooter();
  238. // return;
  239. // }
  240. // if (sortData.length > 0 && range.col + range.colCount > 10) {
  241. // toastMessageUniq(hint.cellError);
  242. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  243. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  244. // changeSpreadObj.setAuditValue();
  245. // changeSpreadObj.makeSjsFooter();
  246. // return;
  247. // }
  248. const data = [];
  249. // const rowData = [];
  250. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  251. let bPaste = true;
  252. const curRow = range.row + iRow;
  253. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  254. const cLData = { id: sortData[curRow].id };
  255. const hintRow = range.rowCount > 1 ? curRow : '';
  256. let sameCol = 0;
  257. for (let iCol = 0; iCol < range.colCount; iCol++) {
  258. const curCol = range.col + iCol;
  259. const colSetting = info.sheet.zh_setting.cols[curCol];
  260. if (!colSetting) continue;
  261. let validText = info.sheet.getText(curRow, curCol);
  262. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  263. const orgValue = sortData[curRow][colSetting.field];
  264. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  265. sameCol++;
  266. if (range.colCount === sameCol) {
  267. bPaste = false;
  268. }
  269. continue;
  270. }
  271. if (colSetting.type === 'Number') {
  272. if (isNaN(validText)) {
  273. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  274. bPaste = false;
  275. continue;
  276. }
  277. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  278. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  279. const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id });
  280. if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
  281. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  282. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  283. changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
  284. bPaste = false;
  285. continue;
  286. } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
  287. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  288. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  289. changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
  290. bPaste = false;
  291. continue;
  292. }
  293. }
  294. // cLData[colSetting.field] = validText;
  295. sortData[curRow][colSetting.field] = validText;
  296. cLData.spamount = validText;
  297. }
  298. if (bPaste) {
  299. data.push(cLData);
  300. // rowData.push(curRow);
  301. } else {
  302. // SpreadJsObj.reLoadRowData(info.sheet, curRow);
  303. }
  304. }
  305. if (data.length === 0) {
  306. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  307. return;
  308. }
  309. console.log(data);
  310. // 更新至服务器
  311. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  312. changeList = result;
  313. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  314. changeSpreadObj.setAuditValue();
  315. changeSpreadObj.makeSjsFooter();
  316. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  317. }, function () {
  318. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  319. changeSpreadObj.setAuditValue();
  320. return;
  321. });
  322. },
  323. };
  324. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  325. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  326. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  327. changeSpreadObj.setAuditValue();
  328. changeSpreadObj.makeSjsFooter();
  329. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  330. const userIndex = aidList.indexOf(parseInt(accountId));
  331. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  332. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  333. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  334. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  335. // 审批提交与判断
  336. $('.approval-btn').on('click', function () {
  337. // 判断审批状态
  338. let returnflag = true;
  339. if ($(this).hasClass('btn-success')) {
  340. const sdesc = $('#success-approval').find('textarea').val();
  341. if (sdesc === '') {
  342. toastr.error('审批意见不能为空!');
  343. returnflag = false;
  344. }
  345. if ($('input[name="p_code"]').val() === '') {
  346. toastr.error('变更令号(批复编号)不能为空!');
  347. returnflag = false;
  348. } else if ($('input[name="p_code"]').val() !== undefined) {
  349. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  350. const postData = {
  351. p_code: $('input[name="p_code"]').val(),
  352. };
  353. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) {
  354. }, function (data) {
  355. returnflag = false;
  356. });
  357. }
  358. // 判断并提交变更清单表格数据到表单中
  359. const clist = [];
  360. for(const [i,cl] of changeList.entries()) {
  361. if (cl['audit_amount_' + accountId] === null || cl['audit_amount_' + accountId] === '') {
  362. toastr.error('清单第' + (i+1) + '行审批变更数量不能为空');
  363. returnflag = false;
  364. } else {
  365. clist.push(cl.id + '_' + cl['audit_amount_' + accountId]);
  366. }
  367. }
  368. $('#change-list-approval').val(clist.join(','));
  369. if(returnflag) {
  370. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  371. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  372. if ($('#warning-text').length) $('#warning-text').remove()
  373. $('#success-approval').submit();
  374. }
  375. } else {
  376. const sdesc = $('#fail-approval').find('textarea').val();
  377. if (sdesc === '') {
  378. toastr.error('审批意见不能为空!');
  379. returnflag = false;
  380. }
  381. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  382. if (type === undefined) {
  383. // toastr.error('请选择退回类型!');
  384. if (!$('#warning-text').length) {
  385. $('#change-back-content').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  386. }
  387. returnflag = false;
  388. }
  389. if(returnflag) {
  390. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  391. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  392. $('#fail-approval').submit();
  393. }
  394. }
  395. })
  396. });
  397. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  398. if (showWaiting) showWaitingView();
  399. $.ajax({
  400. type:"POST",
  401. url: url,
  402. data: {'data': JSON.stringify(data)},
  403. dataType: 'json',
  404. cache: false,
  405. async: false,
  406. timeout: 60000,
  407. beforeSend: function(xhr) {
  408. let csrfToken = Cookies.get('csrfToken_j');
  409. xhr.setRequestHeader('x-csrf-token', csrfToken);
  410. },
  411. success: function(result){
  412. if (result.err === 0) {
  413. if (successCallback) {
  414. successCallback(result.data);
  415. }
  416. } else {
  417. toastr.error(result.msg);
  418. if (errorCallBack) {
  419. errorCallBack(result.msg);
  420. }
  421. }
  422. if (showWaiting) closeWaitingView();
  423. },
  424. error: function(jqXHR, textStatus, errorThrown){
  425. toastr.error('error: ' + textStatus + " " + errorThrown);
  426. if (errorCallBack) {
  427. errorCallBack();
  428. }
  429. if (showWaiting) closeWaitingView();
  430. }
  431. });
  432. };
  433. function auditCheck(i) {
  434. const inlineRadio1 = $('#change-back:checked').val()
  435. const inlineRadio2 = $('#chagne-backnew:checked').val()
  436. const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  437. $('textarea[name="sdesc"]').eq(i).val(opinion);
  438. if (i === 1) {
  439. if (!inlineRadio1 && !inlineRadio2) {
  440. if (!$('#warning-text').length) {
  441. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  442. }
  443. return false;
  444. }
  445. if ($('#warning-text').length) $('#warning-text').remove()
  446. }
  447. return true;
  448. }