change_information_approval.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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 < usedInfo.used_qty) {
  191. toastr.error('清单变更数值必须大于等于已调用值');
  192. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  193. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  194. return;
  195. }
  196. }
  197. select[col.field] = validText;
  198. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  199. const data = {
  200. id: select.id,
  201. spamount: select.spamount,
  202. };
  203. console.log(data);
  204. // 更新至服务器
  205. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  206. changeList.splice(info.row, 1, select);
  207. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  208. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  209. }, function () {
  210. select[col.field] = orgValue;
  211. select.spamount = orgValue;
  212. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  213. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  214. });
  215. }
  216. },
  217. clipboardPasted(e, info) {
  218. const hint = {
  219. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  220. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  221. qtyError: {type: 'error', msg: '变更数值必须大于等于已调用值'},
  222. };
  223. const range = info.cellRange;
  224. const sortData = info.sheet.zh_data || [];
  225. // console.log(info, range);
  226. // if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  227. // toastMessageUniq(hint.cellError);
  228. // // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  229. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  230. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  231. // changeSpreadObj.setAuditValue();
  232. // changeSpreadObj.makeSjsFooter();
  233. // return;
  234. // }
  235. // if (sortData.length > 0 && range.col + range.colCount > 10) {
  236. // toastMessageUniq(hint.cellError);
  237. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  238. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  239. // changeSpreadObj.setAuditValue();
  240. // changeSpreadObj.makeSjsFooter();
  241. // return;
  242. // }
  243. const data = [];
  244. // const rowData = [];
  245. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  246. let bPaste = true;
  247. const curRow = range.row + iRow;
  248. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  249. const cLData = { id: sortData[curRow].id };
  250. const hintRow = range.rowCount > 1 ? curRow : '';
  251. let sameCol = 0;
  252. for (let iCol = 0; iCol < range.colCount; iCol++) {
  253. const curCol = range.col + iCol;
  254. const colSetting = info.sheet.zh_setting.cols[curCol];
  255. if (!colSetting) continue;
  256. let validText = info.sheet.getText(curRow, curCol);
  257. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  258. const orgValue = sortData[curRow][colSetting.field];
  259. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  260. sameCol++;
  261. if (range.colCount === sameCol) {
  262. bPaste = false;
  263. }
  264. continue;
  265. }
  266. if (colSetting.type === 'Number') {
  267. if (isNaN(validText)) {
  268. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  269. bPaste = false;
  270. continue;
  271. }
  272. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  273. // 判断是否大于等于限制值,否则无法更改
  274. const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id });
  275. if (usedInfo && validText < usedInfo.used_qty) {
  276. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  277. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  278. changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
  279. bPaste = false;
  280. continue;
  281. }
  282. }
  283. // cLData[colSetting.field] = validText;
  284. sortData[curRow][colSetting.field] = validText;
  285. cLData.spamount = validText;
  286. }
  287. if (bPaste) {
  288. data.push(cLData);
  289. // rowData.push(curRow);
  290. } else {
  291. // SpreadJsObj.reLoadRowData(info.sheet, curRow);
  292. }
  293. }
  294. if (data.length === 0) {
  295. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  296. return;
  297. }
  298. console.log(data);
  299. // 更新至服务器
  300. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  301. changeList = result;
  302. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  303. changeSpreadObj.setAuditValue();
  304. changeSpreadObj.makeSjsFooter();
  305. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  306. }, function () {
  307. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  308. changeSpreadObj.setAuditValue();
  309. return;
  310. });
  311. },
  312. };
  313. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  314. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  315. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  316. changeSpreadObj.setAuditValue();
  317. changeSpreadObj.makeSjsFooter();
  318. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  319. const userIndex = aidList.indexOf(parseInt(accountId));
  320. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  321. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  322. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  323. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  324. // 审批提交与判断
  325. $('.approval-btn').on('click', function () {
  326. // 判断审批状态
  327. let returnflag = true;
  328. if ($(this).hasClass('btn-success')) {
  329. const sdesc = $('#success-approval').find('textarea').val();
  330. if (sdesc === '') {
  331. toastr.error('审批意见不能为空!');
  332. returnflag = false;
  333. }
  334. if ($('input[name="p_code"]').val() === '') {
  335. toastr.error('变更令号(批复编号)不能为空!');
  336. returnflag = false;
  337. } else if ($('input[name="p_code"]').val() !== undefined) {
  338. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  339. const postData = {
  340. p_code: $('input[name="p_code"]').val(),
  341. };
  342. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) {
  343. }, function (data) {
  344. returnflag = false;
  345. });
  346. }
  347. // 判断并提交变更清单表格数据到表单中
  348. const clist = [];
  349. for(const [i,cl] of changeList.entries()) {
  350. if (cl['audit_amount_' + accountId] === null || cl['audit_amount_' + accountId] === '') {
  351. toastr.error('清单第' + (i+1) + '行审批变更数量不能为空');
  352. returnflag = false;
  353. } else {
  354. clist.push(cl.id + '_' + cl['audit_amount_' + accountId]);
  355. }
  356. }
  357. $('#change-list-approval').val(clist.join(','));
  358. if(returnflag) {
  359. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  360. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  361. if ($('#warning-text').length) $('#warning-text').remove()
  362. $('#success-approval').submit();
  363. }
  364. } else {
  365. const sdesc = $('#fail-approval').find('textarea').val();
  366. if (sdesc === '') {
  367. toastr.error('审批意见不能为空!');
  368. returnflag = false;
  369. }
  370. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  371. if (type === undefined) {
  372. // toastr.error('请选择退回类型!');
  373. if (!$('#warning-text').length) {
  374. $('#change-back-content').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  375. }
  376. returnflag = false;
  377. }
  378. if(returnflag) {
  379. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  380. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  381. $('#fail-approval').submit();
  382. }
  383. }
  384. })
  385. });
  386. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  387. if (showWaiting) showWaitingView();
  388. $.ajax({
  389. type:"POST",
  390. url: url,
  391. data: {'data': JSON.stringify(data)},
  392. dataType: 'json',
  393. cache: false,
  394. async: false,
  395. timeout: 60000,
  396. beforeSend: function(xhr) {
  397. let csrfToken = Cookies.get('csrfToken_j');
  398. xhr.setRequestHeader('x-csrf-token', csrfToken);
  399. },
  400. success: function(result){
  401. if (result.err === 0) {
  402. if (successCallback) {
  403. successCallback(result.data);
  404. }
  405. } else {
  406. toastr.error(result.msg);
  407. if (errorCallBack) {
  408. errorCallBack(result.msg);
  409. }
  410. }
  411. if (showWaiting) closeWaitingView();
  412. },
  413. error: function(jqXHR, textStatus, errorThrown){
  414. toastr.error('error: ' + textStatus + " " + errorThrown);
  415. if (errorCallBack) {
  416. errorCallBack();
  417. }
  418. if (showWaiting) closeWaitingView();
  419. }
  420. });
  421. };
  422. function auditCheck(i) {
  423. const inlineRadio1 = $('#change-back:checked').val()
  424. const inlineRadio2 = $('#chagne-backnew:checked').val()
  425. const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  426. $('textarea[name="sdesc"]').eq(i).val(opinion);
  427. if (i === 1) {
  428. if (!inlineRadio1 && !inlineRadio2) {
  429. if (!$('#warning-text').length) {
  430. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  431. }
  432. return false;
  433. }
  434. if ($('#warning-text').length) $('#warning-text').remove()
  435. }
  436. return true;
  437. }