change_information_add_list.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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 (_.find(changeUsedData, {cbid: cInfo.id})) {
  283. toastr.warning('该清单已被使用,无法取消变更');
  284. info.sheet.setValue(info.row, info.col, 1);
  285. return
  286. } else if (checkIsSettle(cInfo)) {
  287. toastr.warning('该清单已结算,无法取消变更');
  288. info.sheet.setValue(info.row, info.col, 1);
  289. return
  290. } else {
  291. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  292. type: 'del-change-list',
  293. ids: [cInfo.id],
  294. postData: null
  295. }, function (result) {
  296. changeList = result.changeList;
  297. select.is_change = 0;
  298. checkSelectAll(gclInfo);
  299. if (select.deal_id) {
  300. changeListData[gclIndex].is_change = 0;
  301. SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
  302. } else {
  303. let isChange = false;
  304. gclInfo.leafXmjs.forEach(function (item) {
  305. if (item.gcl_id === select.gcl_id && (item.mx_id === undefined || item.mx_id === select.mx_id) && item.is_change) {
  306. isChange = true;
  307. }
  308. });
  309. if (!isChange) {
  310. changeListData[gclIndex].is_change = 0;
  311. SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
  312. }
  313. }
  314. }, function () {
  315. info.sheet.setValue(info.row, info.col, 1);
  316. });
  317. }
  318. }
  319. }
  320. }
  321. }
  322. };
  323. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  324. let changeListData;
  325. let gclGatherData;
  326. const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
  327. const gclSpreadSheet = gclSpread.getActiveSheet();
  328. const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]);
  329. const xmjSpreadSheet = xmjSpread.getActiveSheet();
  330. sjsSettingObj.setGridSelectStyle(gclSpreadSetting);
  331. SpreadJsObj.initSheet(gclSpreadSheet, gclSpreadSetting);
  332. sjsSettingObj.setGridSelectStyle(xmjSpreadSetting);
  333. SpreadJsObj.initSpreadSettingEvents(xmjSpreadSetting, xmjCol);
  334. SpreadJsObj.initSheet(xmjSpreadSheet, xmjSpreadSetting);
  335. postData(preUrl + '/defaultBills', { from: 'batch' }, function (result) {
  336. gclGatherModel.loadLedgerData(result.bills);
  337. gclGatherModel.loadPosData(result.pos);
  338. gclGatherData = gclGatherModel.gatherGclData();
  339. gclGatherData = _.filter(gclGatherData, function (item) {
  340. return item.leafXmjs && item.leafXmjs.length !== 0;
  341. });
  342. for (const ggd in gclGatherData) {
  343. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  344. gclGatherData.splice(ggd, 1);
  345. }
  346. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  347. let hadcid = 0;
  348. for (const xmj of gclGatherData[ggd].leafXmjs) {
  349. const changeLedger = _.find(result.changeLedgerList, { id: xmj.gcl_id });
  350. const changePos = _.find(result.changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
  351. if (changeLedger || changePos) {
  352. xmj.cid = 1;
  353. xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
  354. hadcid = 1;
  355. }
  356. }
  357. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  358. }
  359. // 数组去重
  360. const dealBillList = result.dealBills;
  361. for (const db of gclGatherData) {
  362. const exist_index = dealBillList.findIndex(function (item) {
  363. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  364. });
  365. if (exist_index !== -1) {
  366. dealBillList.splice(exist_index, 1);
  367. }
  368. }
  369. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  370. for (const gcl of changeListData) {
  371. gcl.unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  372. gcl.quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (gcl.unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity).toString() : '0';
  373. gcl.unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? ZhCalc.round(gcl.unit_price, unitPriceUnit) : 0;
  374. // 用id值区分签约清单和台账
  375. if (gcl.id) {
  376. const cInfo = gcl.id ? _.find(changeList, { lid: gcl.id }) : null;
  377. gcl.is_change = cInfo ? 1 : 0;
  378. } else {
  379. const index = gcl.leafXmjs && gcl.leafXmjs.length !== 0 ? _.findIndex(gcl.leafXmjs, function (item) {
  380. return _.findIndex(changeList, { gcl_id: item.gcl_id }) !== -1;
  381. }) : -1;
  382. gcl.is_change = index !== -1 ? 1 : 0;
  383. }
  384. }
  385. console.log(changeListData);
  386. SpreadJsObj.loadSheetData(gclSpreadSheet, SpreadJsObj.DataType.Data, changeListData);
  387. gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
  388. });
  389. gclSpread.bind(spreadNS.Events.SelectionChanged, gclSpreadObj.selectionChanged);
  390. xmjSpread.bind(spreadNS.Events.ButtonClicked, xmjSpreadObj.buttonClicked)
  391. const xmjSearch = $.xmjSearch({
  392. selector: '#xmj-search',
  393. searchSpread: xmjSpread,
  394. searchRangeStr: '输入项目节编号、细目、计量单元查找',
  395. });
  396. $.divResizer({
  397. select: '#revise-right-spr',
  398. callback: function () {
  399. gclSpread.refresh();
  400. xmjSpread.refresh();
  401. if (searchGcl) searchGcl.spread.refresh();
  402. }
  403. });
  404. $.subMenu({
  405. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  406. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  407. key: 'menu.1.0.0',
  408. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  409. callback: function (info) {
  410. if (info.mini) {
  411. $('.panel-title').addClass('fluid');
  412. $('#sub-menu').removeClass('panel-sidebar');
  413. } else {
  414. $('.panel-title').removeClass('fluid');
  415. $('#sub-menu').addClass('panel-sidebar');
  416. }
  417. autoFlashHeight();
  418. gclSpread.refresh();
  419. xmjSpread.refresh();
  420. if (searchGcl) searchGcl.spread.refresh();
  421. }
  422. });
  423. gclSpread.refresh();
  424. xmjSpread.refresh();
  425. // 展开收起标准节点
  426. $('a', '#side-menu').bind('click', function (e) {
  427. e.preventDefault();
  428. const tab = $(this), tabPanel = $(tab.attr('content'));
  429. // 展开工具栏、切换标签
  430. if (!tab.hasClass('active')) {
  431. const close = $('.active', '#side-menu').length === 0;
  432. $('a', '#side-menu').removeClass('active');
  433. tab.addClass('active');
  434. $('.tab-content .tab-pane').removeClass('active');
  435. tabPanel.addClass('active');
  436. showSideTools(tab.hasClass('active'));
  437. if (tab.attr('content') === '#search') {
  438. if (!searchGcl) {
  439. searchGcl = $.listSearch({
  440. selector: '#search',
  441. searchSpread: gclSpread,
  442. searchOver: true,
  443. searchEmpty: true,
  444. resultSpreadSetting: {
  445. cols: [
  446. {title: '清单编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  447. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  448. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  449. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  450. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  451. ],
  452. emptyRows: 0,
  453. headRows: 1,
  454. headRowHeight: [32],
  455. headColWidth: [30],
  456. defaultRowHeight: 21,
  457. headerFont: '12px 微软雅黑',
  458. font: '12px 微软雅黑',
  459. selectedBackColor: '#fffacd',
  460. readOnly: true,
  461. },
  462. afterLocated: function () {
  463. gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
  464. },
  465. check: function(data, keyword) {
  466. return !keyword ||
  467. (data.code && data.code.indexOf(keyword) > -1) ||
  468. (data.name && data.name.indexOf(keyword) > -1);
  469. },
  470. customSearch: [
  471. {
  472. key: 'revise', title: '新增部位', valid: true, parent: true,
  473. check: function (node) {
  474. if (node.formc || node.cid) {
  475. return true;
  476. } else {
  477. return false;
  478. }
  479. }
  480. }
  481. ],
  482. });
  483. }
  484. searchGcl.spread.refresh();
  485. }
  486. }
  487. else {// 收起工具栏
  488. tab.removeClass('active');
  489. tabPanel.removeClass('active');
  490. showSideTools(tab.hasClass('active'));
  491. }
  492. gclSpread.refresh();
  493. xmjSpread.refresh();
  494. });
  495. // 全选及取消
  496. $('#code-select-all').click(function () {
  497. // 全选checkbox
  498. const data = SpreadJsObj.getSelectObject(gclSpreadSheet);
  499. if ($(this).is(':checked')){
  500. const addDatas = [];
  501. if (data && data.id) {
  502. if (_.findIndex(changeList, function (item) {
  503. return item.id && item.id === data.id;
  504. }) === -1) {
  505. addDatas.push({
  506. lid: data.id,
  507. code: data.code,
  508. name: data.name || '',
  509. unit: data.unit || '',
  510. unit_price: data.unit_price,
  511. oamount: data.quantity ? parseFloat(data.quantity) : 0,
  512. oamount2: data.quantity ? parseFloat(data.quantity) : 0,
  513. bwmx: '',
  514. xmj_code: '',
  515. xmj_jldy: '',
  516. xmj_dwgc: '',
  517. xmj_fbgc: '',
  518. xmj_fxgc: '',
  519. gcl_id: '',
  520. mx_id: '',
  521. });
  522. }
  523. } else if (data && data.leafXmjs) {
  524. for (const leaf of data.leafXmjs) {
  525. if (_.findIndex(changeList, function (item) {
  526. return item.gcl_id === leaf.gcl_id && item.mx_id === (leaf.mx_id || '');
  527. }) === -1) {
  528. addDatas.push({
  529. lid: leaf.gcl_id,
  530. code: data.code,
  531. name: data.name || '',
  532. unit: data.unit || '',
  533. unit_price: data.unit_price,
  534. oamount: leaf.quantity,
  535. oamount2: leaf.quantity,
  536. bwmx: leaf.bwmx || leaf.jldy || '',
  537. xmj_code: leaf.code || '',
  538. xmj_jldy: leaf.jldy || '',
  539. xmj_dwgc: leaf.dwgc || '',
  540. xmj_fbgc: leaf.fbgc || '',
  541. xmj_fxgc: leaf.fxgc || '',
  542. gcl_id: leaf.gcl_id,
  543. mx_id: leaf.mx_id,
  544. });
  545. }
  546. }
  547. }
  548. console.log(addDatas);
  549. if (addDatas.length > 0) {
  550. // 更新至服务器
  551. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  552. type: 'add-change-list',
  553. postData: addDatas,
  554. }, function (result) {
  555. changeList = result.changeList;
  556. const gclIndex = changeListData.indexOf(data);
  557. data.is_change = 1;
  558. changeListData[gclIndex].is_change = 1;
  559. SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
  560. gclSpreadObj.resetXmjSpread(data);
  561. }, function () {
  562. $('#code-select-all').prop('checked', false);
  563. });
  564. }
  565. } else {
  566. const cList = xmjSpreadSheet.zh_data;
  567. const removeDatas = [];
  568. let hadContinue = false;
  569. for (const c of cList) {
  570. const cInfo = c.deal_id ? _.find(changeList, { lid: c.deal_id }) : _.find(changeList, function (item) {
  571. return item.gcl_id === c.gcl_id && item.mx_id === c.mx_id;
  572. });
  573. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  574. hadContinue = true;
  575. continue;
  576. } else if (checkIsSettle(cInfo)) {
  577. hadContinue = true;
  578. continue;
  579. }
  580. removeDatas.push(cInfo);
  581. }
  582. console.log(removeDatas);
  583. if (removeDatas.length > 0) {
  584. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  585. type: 'del-change-list',
  586. ids: _.map(removeDatas, 'id'),
  587. postData: null
  588. }, function (result) {
  589. changeList = result.changeList;
  590. if (!hadContinue) {
  591. const gclIndex = changeListData.indexOf(data);
  592. data.is_change = 0;
  593. changeListData[gclIndex].is_change = 0;
  594. SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
  595. }
  596. gclSpreadObj.resetXmjSpread(data);
  597. }, function () {
  598. $('#code-select-all').prop('checked', true);
  599. });
  600. }
  601. }
  602. });
  603. // 选中所有新增部位/清单
  604. $('#select-all-revise').click(function() {
  605. const qtySpr = '*;*', infoSpr = '!_!', recSpr = '$#$';
  606. const gclTr = $('#table-list-select tr');
  607. for (const tr of gclTr) {
  608. const lid = $(tr).data('lid');
  609. let gcl = _.find(gclGatherData, function (item) {
  610. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  611. });
  612. if (!gcl) gcl = gclGatherData[$(this).data('gcl')];
  613. if (!gcl || !gcl.cid) continue;
  614. let data_bwmx = [];
  615. if ($(tr).attr('data-bwmx') !== '') {
  616. data_bwmx = $(tr).attr('data-bwmx').split(recSpr);
  617. data_bwmx = data_bwmx.filter(x => {
  618. const rec = x.split(qtySpr);
  619. const info = rec[0].split(infoSpr);
  620. if (info.length < 8) return true;
  621. const leaf = gcl.leafXmjs.find(lx => { return lx.mx_id === info[6]});
  622. return !leaf || !leaf.cid || leaf.ccid !== window.location.pathname.split('/')[4];
  623. });
  624. }
  625. let hasNew = false;
  626. for (const [index, leaf] of gcl.leafXmjs.entries()) {
  627. if (!leaf.cid || leaf.ccid !== window.location.pathname.split('/')[4]) continue;
  628. const bwmx = [leaf.code, leaf.jldy || '', leaf.dwgc || '', leaf.fbgc || '', leaf.fxgc || '', leaf.gcl_id, leaf.mx_id, leaf.bwmx || leaf.jldy || ''];
  629. const de_qu = bwmx.join(infoSpr) + qtySpr + (leaf.quantity || 0);
  630. if (data_bwmx.indexOf(de_qu) < 0) data_bwmx.push(de_qu);
  631. hasNew = true;
  632. }
  633. if (hasNew) $(tr).attr('data-bwmx', data_bwmx.join(recSpr)).addClass('table-success');
  634. }
  635. // 触发点击当前清单,重载当前全部部位
  636. const dataIndex = $('#code-list').attr('data-index');
  637. if (dataIndex) {
  638. $(`tr[data-index=${dataIndex}]`).trigger('click');
  639. }
  640. });
  641. });
  642. function checkSelectAll(data) {
  643. let check = false;
  644. if (data && data.id && data.is_change) {
  645. check = true;
  646. } else if(data && data.leafXmjs) {
  647. check = data.leafXmjs.length > 0 ? true : false;
  648. data.leafXmjs.forEach(function (item) {
  649. const is_change = _.findIndex(changeList, { gcl_id: item.gcl_id, mx_id: item.mx_id || '' }) !== -1
  650. if (!is_change) {
  651. check = false;
  652. return;
  653. }
  654. });
  655. }
  656. $('#code-select-all').prop('checked', check);
  657. }
  658. function findDecimal(unit) {
  659. let value = precision.other.value;
  660. const changeUnits = precision;
  661. for (const d in changeUnits) {
  662. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  663. value = changeUnits[d].value;
  664. break;
  665. }
  666. }
  667. return value;
  668. }
  669. // 判断是否是已结算清单
  670. function checkIsSettle(data) {
  671. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  672. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  673. return true;
  674. }
  675. return false;
  676. }