change_information_approval.js 25 KB

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