change_information_approval.js 25 KB

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