change_information_approval.js 40 KB

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