change_information_add_list.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. // 编号排序,多重判断
  10. function sortByCode(a, b) {
  11. let code1 = a.code.split('-');
  12. let code2 = b.code.split('-');
  13. let code1length = code1.length;
  14. let code2length = code2.length;
  15. for (let i = 0; i < code1length; i ++) {
  16. if (i+1 <= code2length) {
  17. if (code1[i] != code2[i]) {
  18. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  19. return parseInt(code1[i]) - parseInt(code2[i]);
  20. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  21. return 1;
  22. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  23. return -1;
  24. } else {
  25. const str1length = code1[i].length;
  26. const str2length = code2[i].length;
  27. for (let j = 0; j < str1length; j++) {
  28. if (j+1 <= str2length) {
  29. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  30. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  31. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  32. if (str1length == str2length) {
  33. return 0;
  34. } else {
  35. return str1length - str2length;
  36. }
  37. }
  38. } else {
  39. if (j+1 >= str1length) {
  40. return 1;
  41. } else {
  42. return -1;
  43. }
  44. }
  45. }
  46. }
  47. } else if (i+1 == code1length && code1[i] == code2[i]) {
  48. if (code1length == code2length) {
  49. return 0;
  50. } else {
  51. return code1length - code2length;
  52. }
  53. }
  54. } else {
  55. if (i+1 >= code1length) {
  56. return 1;
  57. } else {
  58. return -1;
  59. }
  60. }
  61. }
  62. }
  63. let searchCodeList = [];
  64. $(document).ready(() => {
  65. let searchGcl;
  66. autoFlashHeight();
  67. const gclSpreadSetting = {
  68. cols: [
  69. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  70. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 300, formatter: '@'},
  71. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 100, formatter: '@'},
  72. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 100},
  73. {title: '数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100},
  74. ],
  75. emptyRows: 0,
  76. headRows: 2,
  77. headRowHeight: [25, 25],
  78. defaultRowHeight: 21,
  79. headerFont: '12px 微软雅黑',
  80. font: '12px 微软雅黑',
  81. readOnly: true,
  82. rowHeader:[
  83. {
  84. rowHeaderType: 'circle',
  85. setting: {
  86. size: 5,
  87. indent: 16,
  88. getColor: function (index, data) {
  89. if (!data) return;
  90. if (data.cid) {
  91. return '#dc3545';
  92. }
  93. }
  94. },
  95. },
  96. ],
  97. localCache: {
  98. key: 'change-add-list-gcl-spread',
  99. colWidth: true,
  100. }
  101. };
  102. gclSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  103. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  104. return spreadColor.stage.settle;
  105. }
  106. if (data && data.is_change) {
  107. return '#c3e6cb';
  108. }
  109. return defaultColor;
  110. }
  111. const gclSpreadObj = {
  112. resetXmjSpread: function(data = null) {
  113. const xmjs = [];
  114. if (data && data.id) {
  115. xmjs.push({
  116. deal_id: data.id,
  117. cid: '',
  118. is_change: _.findIndex(changeList, { lid: data.id }) !== -1 ? 1 : 0,
  119. code: '',
  120. jldy: '',
  121. dwgc: '',
  122. fbgc: '',
  123. fxgc: '',
  124. bwmx: '',
  125. quantity: '',
  126. })
  127. } else if (data && data.leafXmjs) {
  128. for (const leaf of data.leafXmjs) {
  129. xmjs.push({
  130. gcl_id: leaf.gcl_id,
  131. mx_id: leaf.mx_id || '',
  132. is_change: _.findIndex(changeList, { gcl_id: leaf.gcl_id, mx_id: leaf.mx_id || '' }) !== -1 ? 1 : 0,
  133. cid: leaf.cid || '',
  134. code: leaf.code,
  135. jldy: leaf.jldy || '',
  136. dwgc: leaf.dwgc || '',
  137. fbgc: leaf.fbgc || '',
  138. fxgc: leaf.fxgc || '',
  139. bwmx: leaf.bwmx || '',
  140. quantity: leaf.quantity ? ZhCalc.round(leaf.quantity, findDecimal(data.unit)).toString() : '0',
  141. });
  142. }
  143. }
  144. SpreadJsObj.loadSheetData(xmjSpreadSheet, SpreadJsObj.DataType.Data, xmjs);
  145. checkSelectAll(data);
  146. },
  147. selectionChanged: function (e, info) {
  148. const data = SpreadJsObj.getSelectObject(info.sheet);
  149. gclSpreadObj.resetXmjSpread(data);
  150. xmjSearch.searchAndLocate($('#xmj-keyword').val());
  151. }
  152. };
  153. const xmjSpreadSetting = {
  154. cols: [
  155. { title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList'},
  156. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  157. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  158. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  159. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 150, readOnly: true},
  160. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 150, readOnly: true},
  161. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 150, readOnly: true},
  162. {title: '数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, readOnly: true},
  163. ],
  164. emptyRows: 0,
  165. headRows: 2,
  166. headRowHeight: [25, 25],
  167. defaultRowHeight: 21,
  168. headerFont: '12px 微软雅黑',
  169. font: '12px 微软雅黑',
  170. rowHeader:[
  171. {
  172. rowHeaderType: 'circle',
  173. setting: {
  174. size: 5,
  175. indent: 16,
  176. getColor: function (index, data) {
  177. if (!data) return;
  178. if (data.cid) {
  179. return '#dc3545';
  180. }
  181. }
  182. },
  183. },
  184. ],
  185. };
  186. const xmjCol = {
  187. readOnly: {
  188. isChangeList: function (data) {
  189. if (!data) return true;
  190. return readOnly;
  191. }
  192. }
  193. };
  194. const xmjSpreadObj = {
  195. buttonClicked: function (e, info) {
  196. if (info.sheet.zh_setting) {
  197. const select = SpreadJsObj.getSelectObject(info.sheet);
  198. const col = info.sheet.zh_setting.cols[info.col];
  199. const gclInfo = SpreadJsObj.getSelectObject(gclSpreadSheet);
  200. const gclIndex = changeListData.indexOf(gclInfo);
  201. if (col.field === 'is_change') {
  202. if (xmjCol.readOnly.isChangeList(select)) {
  203. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  204. return
  205. }
  206. if (info.sheet.isEditing()) {
  207. info.sheet.endEdit(true);
  208. }
  209. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  210. if (!gclInfo) {
  211. info.sheet.setValue(info.row, info.col, 0);
  212. return;
  213. }
  214. if (is_change) {
  215. const oldCInfo = select.deal_id ? _.find(oldChangeList, { lid: select.deal_id }) : _.find(oldChangeList, { gcl_id: select.gcl_id, mx_id: select.mx_id });
  216. const data = {};
  217. if (oldCInfo) {
  218. data.detail = oldCInfo.detail;
  219. data.camount = oldCInfo.camount;
  220. data.spamount = oldCInfo.spamount;
  221. data.is_valuation = oldCInfo.is_valuation;
  222. data.delimit = oldCInfo.delimit;
  223. }
  224. if (select.deal_id) {
  225. const newData = {
  226. lid: select.deal_id,
  227. code: gclInfo.code,
  228. name: gclInfo.name,
  229. unit: gclInfo.unit,
  230. unit_price: gclInfo.unit_price,
  231. oamount: gclInfo.quantity ? parseFloat(gclInfo.quantity) : 0,
  232. oamount2: oldCInfo ? oldCInfo.oamount2 : gclInfo.quantity ? parseFloat(gclInfo.quantity) : 0,
  233. bwmx: '',
  234. xmj_code: '',
  235. xmj_jldy: '',
  236. xmj_dwgc: '',
  237. xmj_fbgc: '',
  238. xmj_fxgc: '',
  239. gcl_id: '',
  240. mx_id: '',
  241. }
  242. _.assign(data, newData);
  243. } else if (gclInfo.leafXmjs) {
  244. const xmjInfo = _.find(gclInfo.leafXmjs, function (item) {
  245. return item.gcl_id === select.gcl_id && (item.mx_id === undefined || item.mx_id === select.mx_id);
  246. });
  247. const newData = {
  248. lid: select.gcl_id,
  249. code: gclInfo.b_code,
  250. name: gclInfo.name,
  251. unit: gclInfo.unit,
  252. unit_price: gclInfo.unit_price,
  253. oamount: xmjInfo.quantity,
  254. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  255. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  256. xmj_code: xmjInfo.code || '',
  257. xmj_jldy: xmjInfo.jldy || '',
  258. xmj_dwgc: xmjInfo.dwgc || '',
  259. xmj_fbgc: xmjInfo.fbgc || '',
  260. xmj_fxgc: xmjInfo.fxgc || '',
  261. gcl_id: select.gcl_id,
  262. mx_id: select.mx_id,
  263. }
  264. _.assign(data, newData);
  265. }
  266. console.log(data);
  267. // 更新至服务器
  268. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  269. type: 'add-change-list',
  270. postData: [data]
  271. }, function (result) {
  272. changeList = result.changeList;
  273. select.is_change = 1;
  274. changeListData[gclIndex].is_change = 1;
  275. SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
  276. checkSelectAll(gclInfo);
  277. }, function () {
  278. info.sheet.setValue(info.row, info.col, 0);
  279. });
  280. } else {
  281. const cInfo = select.deal_id ? _.find(changeList, { lid: select.deal_id }) : _.find(changeList, { gcl_id: select.gcl_id, mx_id: select.mx_id });
  282. if (changeOrder && _.findIndex(oldChangeList, { id: cInfo.id }) !== -1) {
  283. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  284. info.sheet.setValue(info.row, info.col, 1);
  285. return
  286. }
  287. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  288. toastr.warning('该清单已被使用,无法取消变更');
  289. info.sheet.setValue(info.row, info.col, 1);
  290. return
  291. } else if (checkIsSettle(cInfo)) {
  292. toastr.warning('该清单已结算,无法取消变更');
  293. info.sheet.setValue(info.row, info.col, 1);
  294. return
  295. } else {
  296. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  297. type: 'del-change-list',
  298. ids: [cInfo.id],
  299. }, function (result) {
  300. changeList = result.changeList;
  301. select.is_change = 0;
  302. checkSelectAll(gclInfo);
  303. if (select.deal_id) {
  304. changeListData[gclIndex].is_change = 0;
  305. SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
  306. } else {
  307. let isChange = false;
  308. gclInfo.leafXmjs.forEach(function (item) {
  309. if (item.gcl_id === select.gcl_id && (item.mx_id === undefined || item.mx_id === select.mx_id) && item.is_change) {
  310. isChange = true;
  311. }
  312. });
  313. if (!isChange) {
  314. changeListData[gclIndex].is_change = 0;
  315. SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
  316. }
  317. }
  318. }, function () {
  319. info.sheet.setValue(info.row, info.col, 1);
  320. });
  321. }
  322. }
  323. }
  324. }
  325. }
  326. };
  327. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  328. let changeListData;
  329. let gclGatherData;
  330. const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
  331. const gclSpreadSheet = gclSpread.getActiveSheet();
  332. const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]);
  333. const xmjSpreadSheet = xmjSpread.getActiveSheet();
  334. sjsSettingObj.setGridSelectStyle(gclSpreadSetting);
  335. SpreadJsObj.initSheet(gclSpreadSheet, gclSpreadSetting);
  336. sjsSettingObj.setGridSelectStyle(xmjSpreadSetting);
  337. SpreadJsObj.initSpreadSettingEvents(xmjSpreadSetting, xmjCol);
  338. SpreadJsObj.initSheet(xmjSpreadSheet, xmjSpreadSetting);
  339. postData(preUrl + '/defaultBills', { from: 'batch' }, function (result) {
  340. gclGatherModel.loadLedgerData(result.bills);
  341. gclGatherModel.loadPosData(result.pos);
  342. gclGatherData = gclGatherModel.gatherGclData();
  343. gclGatherData = _.filter(gclGatherData, function (item) {
  344. return item.leafXmjs && item.leafXmjs.length !== 0;
  345. });
  346. for (const ggd in gclGatherData) {
  347. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  348. gclGatherData.splice(ggd, 1);
  349. }
  350. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  351. let hadcid = 0;
  352. for (const xmj of gclGatherData[ggd].leafXmjs) {
  353. const changeLedger = _.find(result.changeLedgerList, { id: xmj.gcl_id });
  354. const changePos = _.find(result.changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
  355. if (changeLedger || changePos) {
  356. xmj.cid = 1;
  357. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  358. hadcid = 1;
  359. }
  360. }
  361. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  362. }
  363. // 数组去重
  364. const dealBillList = result.dealBills;
  365. for (const db of gclGatherData) {
  366. const exist_index = dealBillList.findIndex(function (item) {
  367. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  368. });
  369. if (exist_index !== -1) {
  370. dealBillList.splice(exist_index, 1);
  371. }
  372. }
  373. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  374. for (const gcl of changeListData) {
  375. gcl.unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  376. gcl.quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (gcl.unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity).toString() : '0';
  377. gcl.unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? ZhCalc.round(gcl.unit_price, unitPriceUnit) : 0;
  378. // 用id值区分签约清单和台账
  379. if (gcl.id) {
  380. const cInfo = gcl.id ? _.find(changeList, { lid: gcl.id }) : null;
  381. gcl.is_change = cInfo ? 1 : 0;
  382. } else {
  383. const index = gcl.leafXmjs && gcl.leafXmjs.length !== 0 ? _.findIndex(gcl.leafXmjs, function (item) {
  384. return _.findIndex(changeList, { gcl_id: item.gcl_id }) !== -1;
  385. }) : -1;
  386. gcl.is_change = index !== -1 ? 1 : 0;
  387. }
  388. }
  389. console.log(changeListData);
  390. SpreadJsObj.loadSheetData(gclSpreadSheet, SpreadJsObj.DataType.Data, changeListData);
  391. gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
  392. });
  393. gclSpread.bind(spreadNS.Events.SelectionChanged, gclSpreadObj.selectionChanged);
  394. xmjSpread.bind(spreadNS.Events.ButtonClicked, xmjSpreadObj.buttonClicked)
  395. const xmjSearch = $.xmjSearch({
  396. selector: '#xmj-search',
  397. searchSpread: xmjSpread,
  398. searchRangeStr: '输入项目节编号、细目、计量单元查找',
  399. });
  400. $.divResizer({
  401. select: '#revise-right-spr',
  402. callback: function () {
  403. gclSpread.refresh();
  404. xmjSpread.refresh();
  405. if (searchGcl) searchGcl.spread.refresh();
  406. }
  407. });
  408. $.subMenu({
  409. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  410. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  411. key: 'menu.1.0.0',
  412. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  413. callback: function (info) {
  414. if (info.mini) {
  415. $('.panel-title').addClass('fluid');
  416. $('#sub-menu').removeClass('panel-sidebar');
  417. } else {
  418. $('.panel-title').removeClass('fluid');
  419. $('#sub-menu').addClass('panel-sidebar');
  420. }
  421. autoFlashHeight();
  422. gclSpread.refresh();
  423. xmjSpread.refresh();
  424. if (searchGcl) searchGcl.spread.refresh();
  425. }
  426. });
  427. gclSpread.refresh();
  428. xmjSpread.refresh();
  429. // 展开收起标准节点
  430. $('a', '#side-menu').bind('click', function (e) {
  431. e.preventDefault();
  432. const tab = $(this), tabPanel = $(tab.attr('content'));
  433. // 展开工具栏、切换标签
  434. if (!tab.hasClass('active')) {
  435. const close = $('.active', '#side-menu').length === 0;
  436. $('a', '#side-menu').removeClass('active');
  437. tab.addClass('active');
  438. $('.tab-content .tab-pane').removeClass('active');
  439. tabPanel.addClass('active');
  440. showSideTools(tab.hasClass('active'));
  441. if (tab.attr('content') === '#search') {
  442. if (!searchGcl) {
  443. searchGcl = $.listSearch({
  444. selector: '#search',
  445. searchSpread: gclSpread,
  446. searchOver: true,
  447. searchEmpty: true,
  448. resultSpreadSetting: {
  449. cols: [
  450. {title: '清单编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  451. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  452. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  453. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  454. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  455. ],
  456. emptyRows: 0,
  457. headRows: 1,
  458. headRowHeight: [32],
  459. headColWidth: [30],
  460. defaultRowHeight: 21,
  461. headerFont: '12px 微软雅黑',
  462. font: '12px 微软雅黑',
  463. selectedBackColor: '#fffacd',
  464. readOnly: true,
  465. },
  466. afterLocated: function () {
  467. gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
  468. },
  469. check: function(data, keyword) {
  470. return !keyword ||
  471. (data.code && data.code.indexOf(keyword) > -1) ||
  472. (data.name && data.name.indexOf(keyword) > -1);
  473. },
  474. customSearch: [
  475. {
  476. key: 'revise', title: '新增部位', valid: true, parent: true,
  477. check: function (node) {
  478. if (node.formc || node.cid) {
  479. return true;
  480. } else {
  481. return false;
  482. }
  483. }
  484. }
  485. ],
  486. });
  487. }
  488. searchGcl.spread.refresh();
  489. }
  490. }
  491. else {// 收起工具栏
  492. tab.removeClass('active');
  493. tabPanel.removeClass('active');
  494. showSideTools(tab.hasClass('active'));
  495. }
  496. gclSpread.refresh();
  497. xmjSpread.refresh();
  498. });
  499. // 全选及取消
  500. $('#code-select-all').click(function () {
  501. // 全选checkbox
  502. const data = SpreadJsObj.getSelectObject(gclSpreadSheet);
  503. if ($(this).is(':checked')){
  504. const addDatas = [];
  505. if (data && data.id) {
  506. if (_.findIndex(changeList, function (item) {
  507. return item.id && item.id === data.id;
  508. }) === -1) {
  509. addDatas.push({
  510. lid: data.id,
  511. code: data.code,
  512. name: data.name || '',
  513. unit: data.unit || '',
  514. unit_price: data.unit_price,
  515. oamount: data.quantity ? parseFloat(data.quantity) : 0,
  516. oamount2: data.quantity ? parseFloat(data.quantity) : 0,
  517. bwmx: '',
  518. xmj_code: '',
  519. xmj_jldy: '',
  520. xmj_dwgc: '',
  521. xmj_fbgc: '',
  522. xmj_fxgc: '',
  523. gcl_id: '',
  524. mx_id: '',
  525. });
  526. }
  527. } else if (data && data.leafXmjs) {
  528. for (const leaf of data.leafXmjs) {
  529. if (_.findIndex(changeList, function (item) {
  530. return item.gcl_id === leaf.gcl_id && item.mx_id === (leaf.mx_id || '');
  531. }) === -1) {
  532. addDatas.push({
  533. lid: leaf.gcl_id,
  534. code: data.code,
  535. name: data.name || '',
  536. unit: data.unit || '',
  537. unit_price: data.unit_price,
  538. oamount: leaf.quantity,
  539. oamount2: leaf.quantity,
  540. bwmx: leaf.bwmx || leaf.jldy || '',
  541. xmj_code: leaf.code || '',
  542. xmj_jldy: leaf.jldy || '',
  543. xmj_dwgc: leaf.dwgc || '',
  544. xmj_fbgc: leaf.fbgc || '',
  545. xmj_fxgc: leaf.fxgc || '',
  546. gcl_id: leaf.gcl_id,
  547. mx_id: leaf.mx_id,
  548. });
  549. }
  550. }
  551. }
  552. console.log(addDatas);
  553. if (addDatas.length > 0) {
  554. // 更新至服务器
  555. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  556. type: 'add-change-list',
  557. postData: addDatas,
  558. }, function (result) {
  559. changeList = result.changeList;
  560. const gclIndex = changeListData.indexOf(data);
  561. console.log(gclIndex, data);
  562. data.is_change = 1;
  563. changeListData[gclIndex].is_change = 1;
  564. SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
  565. gclSpreadObj.resetXmjSpread(data);
  566. }, function () {
  567. $('#code-select-all').prop('checked', false);
  568. });
  569. }
  570. } else {
  571. const cList = xmjSpreadSheet.zh_data;
  572. const removeDatas = [];
  573. let hadContinue = false;
  574. for (const c of cList) {
  575. const cInfo = c.deal_id ? _.find(changeList, { lid: c.deal_id }) : _.find(changeList, function (item) {
  576. return item.gcl_id === c.gcl_id && item.mx_id === c.mx_id;
  577. });
  578. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  579. hadContinue = true;
  580. continue;
  581. } else if (checkIsSettle(cInfo)) {
  582. hadContinue = true;
  583. continue;
  584. }
  585. removeDatas.push(cInfo);
  586. }
  587. console.log(removeDatas);
  588. if (removeDatas.length > 0) {
  589. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  590. type: 'del-change-list',
  591. ids: _.map(removeDatas, 'id'),
  592. postData: null
  593. }, function (result) {
  594. changeList = result.changeList;
  595. if (!hadContinue) {
  596. const gclIndex = changeListData.indexOf(data);
  597. data.is_change = 0;
  598. changeListData[gclIndex].is_change = 0;
  599. SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
  600. }
  601. gclSpreadObj.resetXmjSpread(data);
  602. }, function () {
  603. $('#code-select-all').prop('checked', true);
  604. });
  605. }
  606. }
  607. });
  608. // 选中所有新增部位/清单
  609. $('#add-all-revise').click(function() {
  610. const this_cid = window.location.pathname.split('/')[4];
  611. const addDatas = [];
  612. const refreshIndexs = [];
  613. for (const gclInfo of _.filter(changeListData, { cid: 1 })) {
  614. const leafXmjs = _.filter(gclInfo.leafXmjs, { ccid: this_cid });
  615. if (leafXmjs.length > 0) {
  616. gclInfo.is_change = 1;
  617. refreshIndexs.push(changeListData.indexOf(gclInfo));
  618. for (const xmj of leafXmjs) {
  619. if (_.findIndex(changeList, function (item) {
  620. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  621. }) === -1) {
  622. addDatas.push({
  623. lid: xmj.gcl_id,
  624. code: gclInfo.code,
  625. name: gclInfo.name || '',
  626. unit: gclInfo.unit || '',
  627. unit_price: gclInfo.unit_price,
  628. oamount: xmj.quantity,
  629. oamount2: xmj.quantity,
  630. bwmx: xmj.bwmx || xmj.jldy || '',
  631. xmj_code: xmj.code || '',
  632. xmj_jldy: xmj.jldy || '',
  633. xmj_dwgc: xmj.dwgc || '',
  634. xmj_fbgc: xmj.fbgc || '',
  635. xmj_fxgc: xmj.fxgc || '',
  636. gcl_id: xmj.gcl_id,
  637. mx_id: xmj.mx_id || '',
  638. });
  639. }
  640. }
  641. }
  642. }
  643. console.log(addDatas);
  644. if (addDatas.length > 0) {
  645. // 更新至服务器
  646. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  647. type: 'add-change-list',
  648. postData: addDatas,
  649. }, function (result) {
  650. toastr.success('已新增当前变更令新增的所有部位/清单');
  651. changeList = result.changeList;
  652. refreshIndexs.forEach(function (index) {
  653. changeListData[index].is_change = 1;
  654. SpreadJsObj.reLoadRowData(gclSpreadSheet, index);
  655. });
  656. const data = SpreadJsObj.getSelectObject(gclSpreadSheet);
  657. gclSpreadObj.resetXmjSpread(data);
  658. });
  659. } else {
  660. toastr.warning('未存在当前变更令新增的部位/清单');
  661. }
  662. });
  663. $('#show-select-btn').click(function() {
  664. if ($(this).is(':checked')) {
  665. const selectList = changeListData.filter(function (item) {
  666. return item.is_change === 1;
  667. });
  668. SpreadJsObj.loadSheetData(gclSpreadSheet, SpreadJsObj.DataType.Data, selectList);
  669. } else {
  670. SpreadJsObj.loadSheetData(gclSpreadSheet, SpreadJsObj.DataType.Data, changeListData);
  671. }
  672. gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
  673. });
  674. });
  675. function checkSelectAll(data) {
  676. let check = false;
  677. if (data && data.id && data.is_change) {
  678. check = true;
  679. } else if(data && data.leafXmjs) {
  680. check = data.leafXmjs.length > 0 ? true : false;
  681. data.leafXmjs.forEach(function (item) {
  682. const is_change = _.findIndex(changeList, { gcl_id: item.gcl_id, mx_id: item.mx_id || '' }) !== -1
  683. if (!is_change) {
  684. check = false;
  685. return;
  686. }
  687. });
  688. }
  689. $('#code-select-all').prop('checked', check);
  690. }
  691. function findDecimal(unit) {
  692. let value = precision.other.value;
  693. const changeUnits = precision;
  694. for (const d in changeUnits) {
  695. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  696. value = changeUnits[d].value;
  697. break;
  698. }
  699. }
  700. return value;
  701. }
  702. // 判断是否是已结算清单
  703. function checkIsSettle(data) {
  704. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  705. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  706. return true;
  707. }
  708. return false;
  709. }