change_information_approval.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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) {
  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. const pData = {
  445. change_id: $('#changeId').val(),
  446. w_code: $.trim($('#w_code').val()),
  447. }
  448. if ($(this).hasClass('btn-success')) {
  449. const sdesc = $('#success-approval').find('textarea').val();
  450. if (sdesc === '') {
  451. toastr.error('审批意见不能为空!');
  452. returnflag = false;
  453. }
  454. if ($('input[name="p_code"]').val() === '') {
  455. toastr.error('变更令号(批复编号)不能为空!');
  456. returnflag = false;
  457. } else if ($('input[name="p_code"]').val() !== undefined) {
  458. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  459. const postData2 = {
  460. p_code: $('input[name="p_code"]').val(),
  461. };
  462. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData2, function (result) {
  463. }, function (data) {
  464. returnflag = false;
  465. });
  466. pData.p_code = $('input[name="p_code"]').val();
  467. }
  468. if(returnflag) {
  469. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  470. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  471. if ($('#warning-text').length) $('#warning-text').remove();
  472. // $('#success-approval').submit();
  473. pData.status = auditConst.status.checked;
  474. pData.sdesc = sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  475. }
  476. } else {
  477. const sdesc = $('#fail-approval').find('textarea').val();
  478. if (sdesc === '') {
  479. toastr.error('审批意见不能为空!');
  480. returnflag = false;
  481. }
  482. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  483. if (type === undefined) {
  484. // toastr.error('请选择退回类型!');
  485. if (!$('#warning-text').length) {
  486. $('#change-back-content').append('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  487. }
  488. returnflag = false;
  489. }
  490. if(returnflag) {
  491. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  492. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  493. // $('#fail-approval').submit();
  494. pData.status = type;
  495. pData.sdesc = sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  496. }
  497. }
  498. if (pData.status) {
  499. console.log(pData);
  500. postData('/tender/' + $('#tenderId').val() + '/change/approval', pData, function (result) {
  501. window.location.reload();
  502. });
  503. }
  504. })
  505. });
  506. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  507. if (showWaiting) showWaitingView();
  508. $.ajax({
  509. type:"POST",
  510. url: url,
  511. data: {'data': JSON.stringify(data)},
  512. dataType: 'json',
  513. cache: false,
  514. async: false,
  515. timeout: 60000,
  516. beforeSend: function(xhr) {
  517. let csrfToken = Cookies.get('csrfToken_j');
  518. xhr.setRequestHeader('x-csrf-token', csrfToken);
  519. },
  520. success: function(result){
  521. if (result.err === 0) {
  522. if (successCallback) {
  523. successCallback(result.data);
  524. }
  525. } else {
  526. toastr.error(result.msg);
  527. if (errorCallBack) {
  528. errorCallBack(result.msg);
  529. }
  530. }
  531. if (showWaiting) closeWaitingView();
  532. },
  533. error: function(jqXHR, textStatus, errorThrown){
  534. toastr.error('error: ' + textStatus + " " + errorThrown);
  535. if (errorCallBack) {
  536. errorCallBack();
  537. }
  538. if (showWaiting) closeWaitingView();
  539. }
  540. });
  541. };
  542. function auditCheck(i) {
  543. const inlineRadio1 = $('#change-back:checked').val()
  544. const inlineRadio2 = $('#chagne-backnew:checked').val()
  545. const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  546. $('textarea[name="sdesc"]').eq(i).val(opinion);
  547. if (i === 1) {
  548. if (!inlineRadio1 && !inlineRadio2) {
  549. if (!$('#warning-text').length) {
  550. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  551. }
  552. return false;
  553. }
  554. if ($('#warning-text').length) $('#warning-text').remove()
  555. }
  556. return true;
  557. }
  558. function checkAndChange(changeListData) {
  559. // 根据已添加的清单显示
  560. if (changeList.length > 0 && changeList[0]) {
  561. const removeList = [];
  562. const updateList = [];
  563. const updateGclIdList = [];
  564. for (const [index,clinfo] of changeList.entries()) {
  565. if (clinfo.lid != 0) {
  566. let listinfo = changeListData.find(function (item) {
  567. 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);
  568. });
  569. if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
  570. // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
  571. const newlistinfo = changeListData.find(function (item) {
  572. 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 }));
  573. });
  574. if ((listinfo === undefined && newlistinfo) || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
  575. listinfo = newlistinfo;
  576. updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
  577. // 更新lid
  578. changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
  579. }
  580. }
  581. if (listinfo === undefined) {
  582. // 针对旧数据获取清单信息
  583. listinfo = changeListData[clinfo.lid - 1];
  584. if (listinfo === undefined) {
  585. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  586. if (changeStatus !== auditConst.status.revise) {
  587. removeList.push(clinfo);
  588. } else {
  589. updateList.push(makeWhiteList(clinfo));
  590. }
  591. continue;
  592. }
  593. }
  594. const info = makePushBwmx(clinfo, listinfo, removeList, updateList);
  595. if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
  596. // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
  597. const updateInfo = {};
  598. if (info.code !== clinfo.xmj_code) {
  599. updateInfo.xmj_code = info.code;
  600. changeList[index].xmj_code = info.code;
  601. }
  602. if (info.jldy !== clinfo.xmj_jldy) {
  603. updateInfo.xmj_jldy = info.jldy;
  604. changeList[index].xmj_jldy = info.jldy;
  605. }
  606. if (info.dwgc !== clinfo.xmj_dwgc) {
  607. updateInfo.xmj_dwgc = info.dwgc;
  608. changeList[index].xmj_dwgc = info.dwgc;
  609. }
  610. if (info.fbgc !== clinfo.xmj_fbgc) {
  611. updateInfo.xmj_fbgc = info.fbgc;
  612. changeList[index].xmj_fbgc = info.fbgc;
  613. }
  614. if (info.fxgc !== clinfo.xmj_fxgc) {
  615. updateInfo.xmj_fxgc = info.fxgc;
  616. changeList[index].xmj_fxgc = info.fxgc;
  617. }
  618. if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
  619. updateGclIdList.push(clinfo.gcl_id);
  620. // updateInfo.gcl_id = info.id;
  621. updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
  622. }
  623. }
  624. }
  625. }
  626. if(updateList.length > 0) {
  627. console.log(updateList);
  628. postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
  629. }, function () {
  630. });
  631. }
  632. if(removeList.length > 0) {
  633. _.pullAll(changeList, removeList);
  634. postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
  635. }, function () {
  636. });
  637. }
  638. }
  639. }
  640. function makePushBwmx(clinfo, listinfo, removeList, updateList) {
  641. let info = '';
  642. const checkKey = ['name', 'code', 'unit', 'unit_price'];
  643. const checkLeafKey = ['oamount', 'bwmx', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
  644. if (listinfo.leafXmjs !== undefined) {
  645. const leafInfo = listinfo.leafXmjs.find(function (item) {
  646. // 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));
  647. const flag = item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id));
  648. if (flag && item.code === clinfo.xmj_code) {
  649. return flag && item.code === clinfo.xmj_code;
  650. }
  651. return flag;
  652. });
  653. if (leafInfo) {
  654. const oneUpdate = { id: clinfo.id };
  655. let needUpdate = false;
  656. // 判断要不要更新名称,单位,原数量,单价
  657. checkKey.forEach(function (key) {
  658. if ((key === 'name' || key === 'unit') && listinfo[key] === null) {
  659. listinfo[key] = '';
  660. }
  661. if (listinfo[key] !== clinfo[key]) {
  662. oneUpdate[key] = listinfo[key];
  663. clinfo[key] = listinfo[key];
  664. if (key === 'unit') {
  665. const changeKey = ['oamount', 'oamount2', 'camount'];
  666. changeKey.forEach(function (key) {
  667. const value = ZhCalc.round(clinfo[key], findDecimal(listinfo[key]));
  668. if (value !== clinfo[key]) {
  669. oneUpdate[key] = value;
  670. clinfo[key] = value;
  671. }
  672. });
  673. }
  674. // else if (key === 'unit_price') {
  675. // // 可能要更新总金额了
  676. // oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  677. // clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  678. // }
  679. needUpdate = true;
  680. }
  681. });
  682. checkLeafKey.forEach(function (key) {
  683. // 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
  684. if (key === 'oamount') {
  685. if (leafInfo.quantity !== clinfo[key]) {
  686. oneUpdate[key] = leafInfo.quantity;
  687. clinfo[key] = leafInfo.quantity;
  688. needUpdate = true;
  689. }
  690. } else if (key === 'bwmx') {
  691. if (leafInfo[key] !== undefined && leafInfo[key] !== clinfo[key]) {
  692. oneUpdate[key] = leafInfo[key];
  693. clinfo[key] = leafInfo[key];
  694. needUpdate = true;
  695. } else if (leafInfo[key] === undefined && leafInfo.jldy !== clinfo[key]) {
  696. oneUpdate[key] = leafInfo.jldy;
  697. clinfo[key] = leafInfo.jldy;
  698. needUpdate = true;
  699. }
  700. } else {
  701. if (leafInfo[key] !== clinfo['xmj_' + key]) {
  702. oneUpdate['xmj_' + key] = leafInfo[key];
  703. clinfo['xmj_' + key] = leafInfo[key];
  704. needUpdate = true;
  705. }
  706. }
  707. });
  708. if (needUpdate) {
  709. updateList.push(oneUpdate);
  710. }
  711. info = leafInfo;
  712. } else {
  713. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  714. if (changeStatus !== auditConst.status.revise) {
  715. removeList.push(clinfo);
  716. } else {
  717. updateList.push(makeWhiteList(clinfo));
  718. }
  719. return false;
  720. }
  721. }
  722. return info;
  723. }
  724. function isObjEqual(o1,o2){
  725. var props1 = Object.getOwnPropertyNames(o1);
  726. var props2 = Object.getOwnPropertyNames(o2);
  727. if (props1.length != props2.length) {
  728. return false;
  729. }
  730. for (var i = 0,max = props1.length; i < max; i++) {
  731. var propName = props1[i];
  732. if (o1[propName] !== o2[propName]) {
  733. return false;
  734. }
  735. }
  736. return true;
  737. }