change_information_approval.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  373. let changeListData;
  374. let gclGatherData;
  375. postData(preUrl + '/defaultBills', {}, function (result) {
  376. gclGatherModel.loadLedgerData(result.bills);
  377. gclGatherModel.loadPosData(result.pos);
  378. gclGatherData = gclGatherModel.gatherGclData();
  379. gclGatherData = _.filter(gclGatherData, function (item) {
  380. return item.leafXmjs && item.leafXmjs.length !== 0;
  381. });
  382. for (const ggd in gclGatherData) {
  383. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  384. gclGatherData.splice(ggd, 1);
  385. }
  386. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  387. let hadcid = 0;
  388. for (const xmj of gclGatherData[ggd].leafXmjs) {
  389. const changeLedger = _.find(changeLedgerList, { id: xmj.gcl_id });
  390. const changePos = _.find(changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
  391. if (changeLedger || changePos) {
  392. xmj.cid = 1;
  393. xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
  394. hadcid = 1;
  395. }
  396. }
  397. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  398. }
  399. console.log(gclGatherData);
  400. // 数组去重
  401. const dealBillList = result.dealBills;
  402. for (const db of gclGatherData) {
  403. const exist_index = dealBillList.findIndex(function (item) {
  404. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  405. });
  406. if (exist_index !== -1) {
  407. dealBillList.splice(exist_index, 1);
  408. }
  409. }
  410. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  411. checkAndChange(changeListData);
  412. changeSpreadObj.setAuditValue();
  413. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  414. console.log(changeList);
  415. changeSpreadObj.makeSjsFooter();
  416. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  417. });
  418. const userIndex = aidList.indexOf(parseInt(accountId));
  419. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  420. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  421. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  422. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  423. // 审批提交与判断
  424. $('.approval-btn').on('click', function () {
  425. // 判断审批状态
  426. let returnflag = true;
  427. if ($(this).hasClass('btn-success')) {
  428. const sdesc = $('#success-approval').find('textarea').val();
  429. if (sdesc === '') {
  430. toastr.error('审批意见不能为空!');
  431. returnflag = false;
  432. }
  433. if ($('input[name="p_code"]').val() === '') {
  434. toastr.error('变更令号(批复编号)不能为空!');
  435. returnflag = false;
  436. } else if ($('input[name="p_code"]').val() !== undefined) {
  437. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  438. const postData = {
  439. p_code: $('input[name="p_code"]').val(),
  440. };
  441. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) {
  442. }, function (data) {
  443. returnflag = false;
  444. });
  445. }
  446. if(returnflag) {
  447. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  448. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  449. if ($('#warning-text').length) $('#warning-text').remove()
  450. $('#success-approval').submit();
  451. }
  452. } else {
  453. const sdesc = $('#fail-approval').find('textarea').val();
  454. if (sdesc === '') {
  455. toastr.error('审批意见不能为空!');
  456. returnflag = false;
  457. }
  458. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  459. if (type === undefined) {
  460. // toastr.error('请选择退回类型!');
  461. if (!$('#warning-text').length) {
  462. $('#change-back-content').append('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  463. }
  464. returnflag = false;
  465. }
  466. if(returnflag) {
  467. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  468. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  469. $('#fail-approval').submit();
  470. }
  471. }
  472. })
  473. });
  474. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  475. if (showWaiting) showWaitingView();
  476. $.ajax({
  477. type:"POST",
  478. url: url,
  479. data: {'data': JSON.stringify(data)},
  480. dataType: 'json',
  481. cache: false,
  482. async: false,
  483. timeout: 60000,
  484. beforeSend: function(xhr) {
  485. let csrfToken = Cookies.get('csrfToken_j');
  486. xhr.setRequestHeader('x-csrf-token', csrfToken);
  487. },
  488. success: function(result){
  489. if (result.err === 0) {
  490. if (successCallback) {
  491. successCallback(result.data);
  492. }
  493. } else {
  494. toastr.error(result.msg);
  495. if (errorCallBack) {
  496. errorCallBack(result.msg);
  497. }
  498. }
  499. if (showWaiting) closeWaitingView();
  500. },
  501. error: function(jqXHR, textStatus, errorThrown){
  502. toastr.error('error: ' + textStatus + " " + errorThrown);
  503. if (errorCallBack) {
  504. errorCallBack();
  505. }
  506. if (showWaiting) closeWaitingView();
  507. }
  508. });
  509. };
  510. function auditCheck(i) {
  511. const inlineRadio1 = $('#change-back:checked').val()
  512. const inlineRadio2 = $('#chagne-backnew:checked').val()
  513. const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  514. $('textarea[name="sdesc"]').eq(i).val(opinion);
  515. if (i === 1) {
  516. if (!inlineRadio1 && !inlineRadio2) {
  517. if (!$('#warning-text').length) {
  518. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  519. }
  520. return false;
  521. }
  522. if ($('#warning-text').length) $('#warning-text').remove()
  523. }
  524. return true;
  525. }
  526. function checkAndChange(changeListData) {
  527. // 根据已添加的清单显示
  528. if (changeList.length > 0 && changeList[0]) {
  529. const removeList = [];
  530. const updateList = [];
  531. const updateGclIdList = [];
  532. for (const [index,clinfo] of changeList.entries()) {
  533. if (clinfo.lid != 0) {
  534. let listinfo = changeListData.find(function (item) {
  535. return (item.id !== undefined && item.id == clinfo.lid) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && item.leafXmjs[0].gcl_id == clinfo.lid);
  536. });
  537. if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
  538. // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
  539. const newlistinfo = changeListData.find(function (item) {
  540. return (item.id !== undefined && item.id == clinfo.gcl_id) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && _.find(item.leafXmjs, {gcl_id: clinfo.gcl_id }));
  541. });
  542. if ((listinfo === undefined && newlistinfo) || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
  543. listinfo = newlistinfo;
  544. updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
  545. // 更新lid
  546. changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
  547. }
  548. }
  549. if (listinfo === undefined) {
  550. // 针对旧数据获取清单信息
  551. listinfo = changeListData[clinfo.lid - 1];
  552. if (listinfo === undefined) {
  553. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  554. if (changeStatus !== auditConst.status.revise) {
  555. removeList.push(clinfo);
  556. } else {
  557. updateList.push(makeWhiteList(clinfo));
  558. }
  559. continue;
  560. }
  561. }
  562. const info = makePushBwmx(clinfo, listinfo, removeList, updateList);
  563. if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
  564. // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
  565. const updateInfo = {};
  566. if (info.code !== clinfo.xmj_code) {
  567. updateInfo.xmj_code = info.code;
  568. changeList[index].xmj_code = info.code;
  569. }
  570. if (info.jldy !== clinfo.xmj_jldy) {
  571. updateInfo.xmj_jldy = info.jldy;
  572. changeList[index].xmj_jldy = info.jldy;
  573. }
  574. if (info.dwgc !== clinfo.xmj_dwgc) {
  575. updateInfo.xmj_dwgc = info.dwgc;
  576. changeList[index].xmj_dwgc = info.dwgc;
  577. }
  578. if (info.fbgc !== clinfo.xmj_fbgc) {
  579. updateInfo.xmj_fbgc = info.fbgc;
  580. changeList[index].xmj_fbgc = info.fbgc;
  581. }
  582. if (info.fxgc !== clinfo.xmj_fxgc) {
  583. updateInfo.xmj_fxgc = info.fxgc;
  584. changeList[index].xmj_fxgc = info.fxgc;
  585. }
  586. if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
  587. updateGclIdList.push(clinfo.gcl_id);
  588. // updateInfo.gcl_id = info.id;
  589. updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
  590. }
  591. }
  592. }
  593. }
  594. if(updateList.length > 0) {
  595. console.log(updateList);
  596. postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
  597. }, function () {
  598. });
  599. }
  600. if(removeList.length > 0) {
  601. _.pullAll(changeList, removeList);
  602. postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
  603. }, function () {
  604. });
  605. }
  606. }
  607. }
  608. function makePushBwmx(clinfo, listinfo, removeList, updateList) {
  609. let info = '';
  610. const checkKey = ['name', 'code', 'unit', 'unit_price'];
  611. const checkLeafKey = ['oamount', 'bwmx', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
  612. if (listinfo.leafXmjs !== undefined) {
  613. const leafInfo = listinfo.leafXmjs.find(function (item) {
  614. // const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id)) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  615. const flag = item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id));
  616. if (flag && item.code === clinfo.xmj_code) {
  617. return flag && item.code === clinfo.xmj_code;
  618. }
  619. return flag;
  620. });
  621. if (leafInfo) {
  622. const oneUpdate = { id: clinfo.id };
  623. let needUpdate = false;
  624. // 判断要不要更新名称,单位,原数量,单价
  625. checkKey.forEach(function (key) {
  626. if (listinfo[key] !== clinfo[key]) {
  627. oneUpdate[key] = listinfo[key];
  628. clinfo[key] = listinfo[key];
  629. if (key === 'unit') {
  630. const oamount = ZhCalc.round(clinfo.oamount, findDecimal(listinfo[key]));
  631. if (oamount !== clinfo.oamount) {
  632. oneUpdate.oamount = oamount;
  633. clinfo.oamount = oamount;
  634. }
  635. const camount = ZhCalc.round(clinfo.camount, findDecimal(listinfo[key]));
  636. if (camount !== clinfo.camount) {
  637. oneUpdate.camount = camount;
  638. clinfo.camount = camount;
  639. }
  640. }
  641. // else if (key === 'unit_price') {
  642. // // 可能要更新总金额了
  643. // oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  644. // clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  645. // }
  646. needUpdate = true;
  647. }
  648. });
  649. checkLeafKey.forEach(function (key) {
  650. // 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
  651. if (key === 'oamount') {
  652. if (leafInfo.quantity !== clinfo[key]) {
  653. oneUpdate[key] = leafInfo.quantity;
  654. clinfo[key] = leafInfo.quantity;
  655. needUpdate = true;
  656. }
  657. } else if (key === 'bwmx') {
  658. if (leafInfo[key] !== undefined && leafInfo[key] !== clinfo[key]) {
  659. oneUpdate[key] = leafInfo[key];
  660. clinfo[key] = leafInfo[key];
  661. needUpdate = true;
  662. } else if (leafInfo[key] === undefined && leafInfo.jldy !== clinfo[key]) {
  663. oneUpdate[key] = leafInfo.jldy;
  664. clinfo[key] = leafInfo.jldy;
  665. needUpdate = true;
  666. }
  667. } else {
  668. if (leafInfo[key] !== clinfo['xmj_' + key]) {
  669. oneUpdate['xmj_' + key] = leafInfo[key];
  670. clinfo['xmj_' + key] = leafInfo[key];
  671. needUpdate = true;
  672. }
  673. }
  674. });
  675. if (needUpdate) {
  676. updateList.push(oneUpdate);
  677. }
  678. } else {
  679. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  680. if (changeStatus !== auditConst.status.revise) {
  681. removeList.push(clinfo);
  682. } else {
  683. updateList.push(makeWhiteList(clinfo));
  684. }
  685. return false;
  686. }
  687. }
  688. }