change_information_add_list.js 35 KB

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