change_information_approval.js 38 KB

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