change_information_approval.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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: 'oamount2', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount2', readOnly: 'readOnly.isSettle'},
  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.oamount2, 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. oamount2: function (data) {
  96. return ZhCalc.round(data.oamount2, 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.oamount2, 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.oamount2, 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. const oneSum = ZhCalc.round(ZhCalc.mul(data.unit_price, parseFloat(changeSpreadSheet.getValue(row, startLimit - 1))), totalPriceUnit);
  171. changeSpreadSheet.setValue(row, startLimit, oneSum !== 0 ? oneSum : null);
  172. for (const j in aidList) {
  173. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, parseFloat(changeSpreadSheet.getValue(row, startLimit + 3 + parseInt(j)*2))), totalPriceUnit);
  174. changeSpreadSheet.setValue(row, startLimit + 4 + j*2, sum !== 0 ? sum : null);
  175. }
  176. // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.spamount), totalPriceUnit);
  177. // changeSpreadSheet.setValue(row, col+1, sum !== 0 ? sum : null);
  178. const rowCount = changeSpreadSheet.getRowCount();
  179. // 用户的数据合计
  180. // 变更后数据合计
  181. let audit_sum = 0;
  182. let oSum = 0;
  183. let changed_sum = 0;
  184. for(let i = 0; i < rowCount - 1; i++){
  185. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, col+1));
  186. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, startLimit));
  187. changed_sum = ZhCalc.add(changed_sum, changeSpreadSheet.getValue(i, (startLimit + 4 + aidList.length*2)));
  188. }
  189. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, col+1, audit_sum !== 0 ? audit_sum : null);
  190. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit, oSum !== 0 ? oSum : null);
  191. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, (startLimit + 4 + aidList.length*2), changed_sum !== 0 ? changed_sum : null);
  192. },
  193. countSum: function() {
  194. const rowCount = changeSpreadSheet.getRowCount();
  195. let oSum = 0,
  196. cSum = 0,
  197. cdSum = 0;
  198. for(let i = 0; i < rowCount - 1; i++){
  199. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, startLimit));
  200. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, startLimit + 2));
  201. cdSum = ZhCalc.add(cdSum, changeSpreadSheet.getValue(i, (startLimit + 4 + aidList.length*2)));
  202. }
  203. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit, oSum !== 0 ? oSum : null);
  204. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 2, cSum !== 0 ? cSum : null);
  205. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, (startLimit + 4 + aidList.length*2), cdSum !== 0 ? cdSum : null);
  206. // 用户的数据合计
  207. for (const j in aidList) {
  208. let audit_sum = 0;
  209. for(let i = 0; i < rowCount - 1; i++){
  210. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, startLimit + 4 + j*2));
  211. }
  212. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 4 + j*2, audit_sum !== 0 ? audit_sum : null);
  213. }
  214. },
  215. deletePress: function (sheet) {
  216. return;
  217. },
  218. editEnded: function (e, info) {
  219. if (info.sheet.zh_setting) {
  220. const select = SpreadJsObj.getSelectObject(info.sheet);
  221. const col = info.sheet.zh_setting.cols[info.col];
  222. // 未改变值则不提交
  223. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  224. const orgValue = select[col.field];
  225. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  226. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  227. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  228. return;
  229. }
  230. // 判断部分值是否输入的是数字判断和数据计算
  231. if (col.type === 'Number') {
  232. if (isNaN(validText)) {
  233. toastr.error('不能输入其它非数字类型字符');
  234. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  235. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  236. return;
  237. }
  238. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  239. if (col.field !== 'oamount2') {
  240. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  241. const usedInfo = _.find(changeUsedData, {cbid: select.id});
  242. if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
  243. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  244. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  245. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  246. return;
  247. } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
  248. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  249. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  250. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  251. return;
  252. }
  253. }
  254. }
  255. select[col.field] = validText;
  256. if (col.field !== 'oamount2') select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  257. const data = {
  258. id: select.id,
  259. };
  260. if (col.field === 'oamount2') {
  261. data[col.field] = select[col.field];
  262. } else {
  263. data.spamount = select.spamount;
  264. }
  265. console.log(data, select);
  266. // 更新至服务器
  267. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  268. changeList.splice(info.row, 1, select);
  269. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  270. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  271. }, function () {
  272. select[col.field] = orgValue;
  273. if (col.field !== 'oamount2') select.spamount = orgValue;
  274. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  275. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  276. });
  277. }
  278. },
  279. clipboardPasted(e, info) {
  280. const hint = {
  281. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  282. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  283. qtyError: {type: 'error', msg: '变更数值必须大于等于已调用值'},
  284. };
  285. const range = info.cellRange;
  286. const sortData = info.sheet.zh_data || [];
  287. // console.log(info, range);
  288. // if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  289. // toastMessageUniq(hint.cellError);
  290. // // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  291. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  292. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  293. // changeSpreadObj.setAuditValue();
  294. // changeSpreadObj.makeSjsFooter();
  295. // return;
  296. // }
  297. // if (sortData.length > 0 && range.col + range.colCount > 10) {
  298. // toastMessageUniq(hint.cellError);
  299. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  300. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  301. // changeSpreadObj.setAuditValue();
  302. // changeSpreadObj.makeSjsFooter();
  303. // return;
  304. // }
  305. const data = [];
  306. // const rowData = [];
  307. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  308. let bPaste = true;
  309. const curRow = range.row + iRow;
  310. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  311. const cLData = { id: sortData[curRow].id };
  312. const hintRow = range.rowCount > 1 ? curRow : '';
  313. let sameCol = 0;
  314. for (let iCol = 0; iCol < range.colCount; iCol++) {
  315. const curCol = range.col + iCol;
  316. const colSetting = info.sheet.zh_setting.cols[curCol];
  317. if (!colSetting) continue;
  318. let validText = info.sheet.getText(curRow, curCol);
  319. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  320. const orgValue = sortData[curRow][colSetting.field];
  321. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  322. sameCol++;
  323. if (range.colCount === sameCol) {
  324. bPaste = false;
  325. }
  326. continue;
  327. }
  328. if (colSetting.type === 'Number') {
  329. if (isNaN(validText)) {
  330. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  331. bPaste = false;
  332. continue;
  333. }
  334. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  335. if (colSetting.field !== 'oamount2') {
  336. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  337. const usedInfo = _.find(changeUsedData, {id: sortData[curRow].id});
  338. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  339. toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  340. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  341. changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
  342. bPaste = false;
  343. continue;
  344. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  345. toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  346. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  347. changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
  348. bPaste = false;
  349. continue;
  350. }
  351. }
  352. }
  353. // cLData[colSetting.field] = validText;
  354. sortData[curRow][colSetting.field] = validText;
  355. if (colSetting.field === 'oamount2') {
  356. cLData[colSetting.field] = validText;
  357. } else {
  358. cLData.spamount = validText;
  359. }
  360. }
  361. if (bPaste) {
  362. data.push(cLData);
  363. // rowData.push(curRow);
  364. } else {
  365. // SpreadJsObj.reLoadRowData(info.sheet, curRow);
  366. }
  367. }
  368. if (data.length === 0) {
  369. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  370. return;
  371. }
  372. console.log(data);
  373. // 更新至服务器
  374. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  375. changeList = result;
  376. changeSpreadObj.setAuditValue();
  377. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  378. changeSpreadObj.makeSjsFooter();
  379. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  380. }, function () {
  381. changeSpreadObj.setAuditValue();
  382. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  383. return;
  384. });
  385. },
  386. };
  387. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  388. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  389. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  390. let changeListData;
  391. let gclGatherData;
  392. postData(preUrl + '/defaultBills', {}, function (result) {
  393. gclGatherModel.loadLedgerData(result.bills);
  394. gclGatherModel.loadPosData(result.pos);
  395. gclGatherData = gclGatherModel.gatherGclData();
  396. gclGatherData = _.filter(gclGatherData, function (item) {
  397. return item.leafXmjs && item.leafXmjs.length !== 0;
  398. });
  399. for (const ggd in gclGatherData) {
  400. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  401. gclGatherData.splice(ggd, 1);
  402. }
  403. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  404. let hadcid = 0;
  405. for (const xmj of gclGatherData[ggd].leafXmjs) {
  406. const changeLedger = _.find(changeLedgerList, { id: xmj.gcl_id });
  407. const changePos = _.find(changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
  408. if (changeLedger || changePos) {
  409. xmj.cid = 1;
  410. xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
  411. hadcid = 1;
  412. }
  413. }
  414. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  415. }
  416. console.log(gclGatherData);
  417. // 数组去重
  418. const dealBillList = result.dealBills;
  419. for (const db of gclGatherData) {
  420. const exist_index = dealBillList.findIndex(function (item) {
  421. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  422. });
  423. if (exist_index !== -1) {
  424. dealBillList.splice(exist_index, 1);
  425. }
  426. }
  427. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  428. checkAndChange(changeListData);
  429. changeSpreadObj.setAuditValue();
  430. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  431. console.log(changeList);
  432. changeSpreadObj.makeSjsFooter();
  433. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  434. });
  435. const userIndex = aidList.indexOf(parseInt(accountId));
  436. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  437. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  438. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  439. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  440. // 审批提交与判断
  441. $('.approval-btn').on('click', function () {
  442. // 判断审批状态
  443. let returnflag = true;
  444. if ($(this).hasClass('btn-success')) {
  445. const sdesc = $('#success-approval').find('textarea').val();
  446. if (sdesc === '') {
  447. toastr.error('审批意见不能为空!');
  448. returnflag = false;
  449. }
  450. if ($('input[name="p_code"]').val() === '') {
  451. toastr.error('变更令号(批复编号)不能为空!');
  452. returnflag = false;
  453. } else if ($('input[name="p_code"]').val() !== undefined) {
  454. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  455. const postData = {
  456. p_code: $('input[name="p_code"]').val(),
  457. };
  458. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) {
  459. }, function (data) {
  460. returnflag = false;
  461. });
  462. }
  463. if(returnflag) {
  464. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  465. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  466. if ($('#warning-text').length) $('#warning-text').remove()
  467. $('#success-approval').submit();
  468. }
  469. } else {
  470. const sdesc = $('#fail-approval').find('textarea').val();
  471. if (sdesc === '') {
  472. toastr.error('审批意见不能为空!');
  473. returnflag = false;
  474. }
  475. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  476. if (type === undefined) {
  477. // toastr.error('请选择退回类型!');
  478. if (!$('#warning-text').length) {
  479. $('#change-back-content').append('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  480. }
  481. returnflag = false;
  482. }
  483. if(returnflag) {
  484. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  485. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  486. $('#fail-approval').submit();
  487. }
  488. }
  489. })
  490. });
  491. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  492. if (showWaiting) showWaitingView();
  493. $.ajax({
  494. type:"POST",
  495. url: url,
  496. data: {'data': JSON.stringify(data)},
  497. dataType: 'json',
  498. cache: false,
  499. async: false,
  500. timeout: 60000,
  501. beforeSend: function(xhr) {
  502. let csrfToken = Cookies.get('csrfToken_j');
  503. xhr.setRequestHeader('x-csrf-token', csrfToken);
  504. },
  505. success: function(result){
  506. if (result.err === 0) {
  507. if (successCallback) {
  508. successCallback(result.data);
  509. }
  510. } else {
  511. toastr.error(result.msg);
  512. if (errorCallBack) {
  513. errorCallBack(result.msg);
  514. }
  515. }
  516. if (showWaiting) closeWaitingView();
  517. },
  518. error: function(jqXHR, textStatus, errorThrown){
  519. toastr.error('error: ' + textStatus + " " + errorThrown);
  520. if (errorCallBack) {
  521. errorCallBack();
  522. }
  523. if (showWaiting) closeWaitingView();
  524. }
  525. });
  526. };
  527. function auditCheck(i) {
  528. const inlineRadio1 = $('#change-back:checked').val()
  529. const inlineRadio2 = $('#chagne-backnew:checked').val()
  530. const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  531. $('textarea[name="sdesc"]').eq(i).val(opinion);
  532. if (i === 1) {
  533. if (!inlineRadio1 && !inlineRadio2) {
  534. if (!$('#warning-text').length) {
  535. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  536. }
  537. return false;
  538. }
  539. if ($('#warning-text').length) $('#warning-text').remove()
  540. }
  541. return true;
  542. }
  543. function checkAndChange(changeListData) {
  544. // 根据已添加的清单显示
  545. if (changeList.length > 0 && changeList[0]) {
  546. const removeList = [];
  547. const updateList = [];
  548. const updateGclIdList = [];
  549. for (const [index,clinfo] of changeList.entries()) {
  550. if (clinfo.lid != 0) {
  551. let listinfo = changeListData.find(function (item) {
  552. 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);
  553. });
  554. if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
  555. // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
  556. const newlistinfo = changeListData.find(function (item) {
  557. 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 }));
  558. });
  559. if ((listinfo === undefined && newlistinfo) || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
  560. listinfo = newlistinfo;
  561. updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
  562. // 更新lid
  563. changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
  564. }
  565. }
  566. if (listinfo === undefined) {
  567. // 针对旧数据获取清单信息
  568. listinfo = changeListData[clinfo.lid - 1];
  569. if (listinfo === undefined) {
  570. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  571. if (changeStatus !== auditConst.status.revise) {
  572. removeList.push(clinfo);
  573. } else {
  574. updateList.push(makeWhiteList(clinfo));
  575. }
  576. continue;
  577. }
  578. }
  579. const info = makePushBwmx(clinfo, listinfo, removeList, updateList);
  580. if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
  581. // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
  582. const updateInfo = {};
  583. if (info.code !== clinfo.xmj_code) {
  584. updateInfo.xmj_code = info.code;
  585. changeList[index].xmj_code = info.code;
  586. }
  587. if (info.jldy !== clinfo.xmj_jldy) {
  588. updateInfo.xmj_jldy = info.jldy;
  589. changeList[index].xmj_jldy = info.jldy;
  590. }
  591. if (info.dwgc !== clinfo.xmj_dwgc) {
  592. updateInfo.xmj_dwgc = info.dwgc;
  593. changeList[index].xmj_dwgc = info.dwgc;
  594. }
  595. if (info.fbgc !== clinfo.xmj_fbgc) {
  596. updateInfo.xmj_fbgc = info.fbgc;
  597. changeList[index].xmj_fbgc = info.fbgc;
  598. }
  599. if (info.fxgc !== clinfo.xmj_fxgc) {
  600. updateInfo.xmj_fxgc = info.fxgc;
  601. changeList[index].xmj_fxgc = info.fxgc;
  602. }
  603. if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
  604. updateGclIdList.push(clinfo.gcl_id);
  605. // updateInfo.gcl_id = info.id;
  606. updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
  607. }
  608. }
  609. }
  610. }
  611. if(updateList.length > 0) {
  612. console.log(updateList);
  613. postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
  614. }, function () {
  615. });
  616. }
  617. if(removeList.length > 0) {
  618. _.pullAll(changeList, removeList);
  619. postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
  620. }, function () {
  621. });
  622. }
  623. }
  624. }
  625. function makePushBwmx(clinfo, listinfo, removeList, updateList) {
  626. let info = '';
  627. const checkKey = ['name', 'code', 'unit', 'unit_price'];
  628. const checkLeafKey = ['oamount', 'bwmx', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
  629. if (listinfo.leafXmjs !== undefined) {
  630. const leafInfo = listinfo.leafXmjs.find(function (item) {
  631. // 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));
  632. const flag = item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id));
  633. if (flag && item.code === clinfo.xmj_code) {
  634. return flag && item.code === clinfo.xmj_code;
  635. }
  636. return flag;
  637. });
  638. if (leafInfo) {
  639. const oneUpdate = { id: clinfo.id };
  640. let needUpdate = false;
  641. // 判断要不要更新名称,单位,原数量,单价
  642. checkKey.forEach(function (key) {
  643. if (listinfo[key] !== clinfo[key]) {
  644. oneUpdate[key] = listinfo[key];
  645. clinfo[key] = listinfo[key];
  646. if (key === 'unit') {
  647. const changeKey = ['oamount', 'oamount2', 'camount'];
  648. changeKey.forEach(function (key) {
  649. const value = ZhCalc.round(clinfo[key], findDecimal(listinfo[key]));
  650. if (value !== clinfo[key]) {
  651. oneUpdate[key] = value;
  652. clinfo[key] = value;
  653. }
  654. });
  655. }
  656. // else if (key === 'unit_price') {
  657. // // 可能要更新总金额了
  658. // oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  659. // clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  660. // }
  661. needUpdate = true;
  662. }
  663. });
  664. checkLeafKey.forEach(function (key) {
  665. // 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
  666. if (key === 'oamount') {
  667. if (leafInfo.quantity !== clinfo[key]) {
  668. oneUpdate[key] = leafInfo.quantity;
  669. clinfo[key] = leafInfo.quantity;
  670. needUpdate = true;
  671. }
  672. } else if (key === 'bwmx') {
  673. if (leafInfo[key] !== undefined && leafInfo[key] !== clinfo[key]) {
  674. oneUpdate[key] = leafInfo[key];
  675. clinfo[key] = leafInfo[key];
  676. needUpdate = true;
  677. } else if (leafInfo[key] === undefined && leafInfo.jldy !== clinfo[key]) {
  678. oneUpdate[key] = leafInfo.jldy;
  679. clinfo[key] = leafInfo.jldy;
  680. needUpdate = true;
  681. }
  682. } else {
  683. if (leafInfo[key] !== clinfo['xmj_' + key]) {
  684. oneUpdate['xmj_' + key] = leafInfo[key];
  685. clinfo['xmj_' + key] = leafInfo[key];
  686. needUpdate = true;
  687. }
  688. }
  689. });
  690. if (needUpdate) {
  691. updateList.push(oneUpdate);
  692. }
  693. } else {
  694. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  695. if (changeStatus !== auditConst.status.revise) {
  696. removeList.push(clinfo);
  697. } else {
  698. updateList.push(makeWhiteList(clinfo));
  699. }
  700. return false;
  701. }
  702. }
  703. }
  704. function isObjEqual(o1,o2){
  705. var props1 = Object.getOwnPropertyNames(o1);
  706. var props2 = Object.getOwnPropertyNames(o2);
  707. if (props1.length != props2.length) {
  708. return false;
  709. }
  710. for (var i = 0,max = props1.length; i < max; i++) {
  711. var propName = props1[i];
  712. if (o1[propName] !== o2[propName]) {
  713. return false;
  714. }
  715. }
  716. return true;
  717. }