change_information_approval.js 26 KB

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