change_information_add_list.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. cid: '',
  117. is_change: _.findIndex(changeList, { lid: data.id }) !== -1 ? 1 : 0,
  118. code: '',
  119. jldy: '',
  120. dwgc: '',
  121. fbgc: '',
  122. fxgc: '',
  123. bwmx: '',
  124. quantity: '',
  125. })
  126. } else if (data && data.leafXmjs) {
  127. for (const leaf of data.leafXmjs) {
  128. xmjs.push({
  129. is_change: _.findIndex(changeList, { gcl_id: leaf.gcl_id, mx_id: leaf.mx_id || '' }) !== -1 ? 1 : 0,
  130. cid: leaf.cid || '',
  131. code: leaf.code,
  132. jldy: leaf.jldy || '',
  133. dwgc: leaf.dwgc || '',
  134. fbgc: leaf.fbgc || '',
  135. fxgc: leaf.fxgc || '',
  136. bwmx: leaf.bwmx || '',
  137. quantity: leaf.quantity ? ZhCalc.round(leaf.quantity, findDecimal(data.unit)).toString() : '0',
  138. });
  139. }
  140. }
  141. SpreadJsObj.loadSheetData(xmjSpreadSheet, SpreadJsObj.DataType.Data, xmjs);
  142. checkSelectAll();
  143. },
  144. selectionChanged: function (e, info) {
  145. const data = SpreadJsObj.getSelectObject(info.sheet);
  146. gclSpreadObj.resetXmjSpread(data);
  147. }
  148. };
  149. const xmjSpreadSetting = {
  150. cols: [
  151. { title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList'},
  152. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  153. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  154. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  155. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 150, readOnly: true},
  156. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 150, readOnly: true},
  157. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 150, readOnly: true},
  158. {title: '数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, readOnly: true},
  159. ],
  160. emptyRows: 0,
  161. headRows: 2,
  162. headRowHeight: [25, 25],
  163. defaultRowHeight: 21,
  164. headerFont: '12px 微软雅黑',
  165. font: '12px 微软雅黑',
  166. rowHeader:[
  167. {
  168. rowHeaderType: 'circle',
  169. setting: {
  170. size: 5,
  171. indent: 16,
  172. getColor: function (index, data) {
  173. if (!data) return;
  174. if (data.cid) {
  175. return '#dc3545';
  176. }
  177. }
  178. },
  179. },
  180. ],
  181. };
  182. const xmjCol = {
  183. readOnly: {
  184. isChangeList: function (data) {
  185. if (!data) return true;
  186. return !readOnly;
  187. }
  188. }
  189. };
  190. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  191. let changeListData;
  192. let gclGatherData;
  193. const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
  194. const gclSpreadSheet = gclSpread.getActiveSheet();
  195. const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]);
  196. const xmjSpreadSheet = xmjSpread.getActiveSheet();
  197. sjsSettingObj.setGridSelectStyle(gclSpreadSetting);
  198. SpreadJsObj.initSheet(gclSpreadSheet, gclSpreadSetting);
  199. SpreadJsObj.initSpreadSettingEvents(xmjSpreadSetting, xmjCol);
  200. SpreadJsObj.initSheet(xmjSpreadSheet, xmjSpreadSetting);
  201. postData(preUrl + '/defaultBills', { from: 'batch' }, function (result) {
  202. gclGatherModel.loadLedgerData(result.bills);
  203. gclGatherModel.loadPosData(result.pos);
  204. gclGatherData = gclGatherModel.gatherGclData();
  205. gclGatherData = _.filter(gclGatherData, function (item) {
  206. return item.leafXmjs && item.leafXmjs.length !== 0;
  207. });
  208. for (const ggd in gclGatherData) {
  209. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  210. gclGatherData.splice(ggd, 1);
  211. }
  212. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  213. let hadcid = 0;
  214. for (const xmj of gclGatherData[ggd].leafXmjs) {
  215. const changeLedger = _.find(result.changeLedgerList, { id: xmj.gcl_id });
  216. const changePos = _.find(result.changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
  217. if (changeLedger || changePos) {
  218. xmj.cid = 1;
  219. xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
  220. hadcid = 1;
  221. }
  222. }
  223. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  224. }
  225. // 数组去重
  226. const dealBillList = result.dealBills;
  227. for (const db of gclGatherData) {
  228. const exist_index = dealBillList.findIndex(function (item) {
  229. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  230. });
  231. if (exist_index !== -1) {
  232. dealBillList.splice(exist_index, 1);
  233. }
  234. }
  235. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  236. for (const gcl of changeListData) {
  237. gcl.unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  238. gcl.quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (gcl.unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity).toString() : '0';
  239. gcl.unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? ZhCalc.round(gcl.unit_price, unitPriceUnit) : 0;
  240. // 用id值区分签约清单和台账
  241. if (gcl.id) {
  242. const cInfo = gcl.id ? _.find(changeList, { lid: gcl.id }) : null;
  243. gcl.is_change = cInfo ? 1 : 0;
  244. } else {
  245. const index = gcl.leafXmjs && gcl.leafXmjs.length !== 0 ? _.findIndex(gcl.leafXmjs, function (item) {
  246. return _.findIndex(changeList, { gcl_id: item.gcl_id }) !== -1;
  247. }) : -1;
  248. gcl.is_change = index !== -1 ? 1 : 0;
  249. }
  250. }
  251. console.log(changeListData);
  252. SpreadJsObj.loadSheetData(gclSpreadSheet, SpreadJsObj.DataType.Data, changeListData);
  253. gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
  254. });
  255. gclSpread.bind(spreadNS.Events.SelectionChanged, gclSpreadObj.selectionChanged);
  256. $.divResizer({
  257. select: '#revise-right-spr',
  258. callback: function () {
  259. gclSpread.refresh();
  260. xmjSpread.refresh();
  261. if (searchGcl) searchGcl.spread.refresh();
  262. }
  263. });
  264. $.subMenu({
  265. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  266. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  267. key: 'menu.1.0.0',
  268. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  269. callback: function (info) {
  270. if (info.mini) {
  271. $('.panel-title').addClass('fluid');
  272. $('#sub-menu').removeClass('panel-sidebar');
  273. } else {
  274. $('.panel-title').removeClass('fluid');
  275. $('#sub-menu').addClass('panel-sidebar');
  276. }
  277. autoFlashHeight();
  278. gclSpread.refresh();
  279. xmjSpread.refresh();
  280. if (searchGcl) searchGcl.spread.refresh();
  281. }
  282. });
  283. gclSpread.refresh();
  284. xmjSpread.refresh();
  285. // 展开收起标准节点
  286. $('a', '#side-menu').bind('click', function (e) {
  287. e.preventDefault();
  288. const tab = $(this), tabPanel = $(tab.attr('content'));
  289. // 展开工具栏、切换标签
  290. if (!tab.hasClass('active')) {
  291. const close = $('.active', '#side-menu').length === 0;
  292. $('a', '#side-menu').removeClass('active');
  293. tab.addClass('active');
  294. $('.tab-content .tab-pane').removeClass('active');
  295. tabPanel.addClass('active');
  296. showSideTools(tab.hasClass('active'));
  297. if (tab.attr('content') === '#search') {
  298. if (!searchGcl) {
  299. searchGcl = $.listSearch({
  300. selector: '#search',
  301. searchSpread: gclSpread,
  302. searchOver: true,
  303. searchEmpty: true,
  304. resultSpreadSetting: {
  305. cols: [
  306. {title: '清单编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  307. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  308. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  309. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  310. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  311. ],
  312. emptyRows: 0,
  313. headRows: 1,
  314. headRowHeight: [32],
  315. headColWidth: [30],
  316. defaultRowHeight: 21,
  317. headerFont: '12px 微软雅黑',
  318. font: '12px 微软雅黑',
  319. selectedBackColor: '#fffacd',
  320. readOnly: true,
  321. },
  322. afterLocated: function () {
  323. gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
  324. },
  325. check: function(data, keyword) {
  326. return !keyword ||
  327. (data.code && data.code.indexOf(keyword) > -1) ||
  328. (data.name && data.name.indexOf(keyword) > -1);
  329. },
  330. customSearch: [
  331. {
  332. key: 'revise', title: '新增部位', valid: true, parent: true,
  333. check: function (node) {
  334. if (node.formc || node.cid) {
  335. return true;
  336. } else {
  337. return false;
  338. }
  339. }
  340. }
  341. ],
  342. });
  343. }
  344. searchGcl.spread.refresh();
  345. }
  346. }
  347. else {// 收起工具栏
  348. tab.removeClass('active');
  349. tabPanel.removeClass('active');
  350. showSideTools(tab.hasClass('active'));
  351. }
  352. gclSpread.refresh();
  353. xmjSpread.refresh();
  354. });
  355. // 回车提交
  356. $('#list-input').on('keypress', function () {
  357. if(window.event.keyCode === 13) {
  358. $(this).blur();
  359. }
  360. });
  361. $('#list-input').on('blur', function () {
  362. const select = parseInt($('#select-list').val());
  363. const value = _.trim($(this).val());
  364. const valueList = _.slice(_.without(_.uniq(_.replace(_.replace(value, /\'|\"/g, ''), /\t/g, ' ').split(' ')), ''), 0, 10);
  365. // console.log(valueList);
  366. // 判断是否存在多个分词,以换行或空格分隔,多个则显示左侧菜单
  367. if (value !== '' && valueList.length > 1) {
  368. if (_.without(_.uniq(value.split(' ')), '').length > 10) {
  369. toastr.warning('最多筛选以空格分割的前10个不重复关键词');
  370. }
  371. $('#table-list').addClass('col-9').removeClass('col-12');
  372. $('#table-list').siblings('.col-3').show();
  373. $('#list-search-keyword').html('<tr data-keyword="" class="text-white bg-primary"><td class="border-primary">全部</td></tr>');
  374. for (const v of valueList) {
  375. $('#list-search-keyword').append(`<tr data-keyword="${v}" class=""><td>${v}</td></tr>`);
  376. }
  377. $('#list-input').val(valueList.join(' '));
  378. } else {
  379. $('#table-list').addClass('col-12').removeClass('col-9');
  380. $('#table-list').siblings('.col-3').hide();
  381. $('#list-search-keyword').html('<tr data-keyword="" class="text-white bg-primary border-primary"><td class="border-primary">全部</td></tr>');
  382. }
  383. let showListData = changeListData;
  384. if (select === 1 && value !== '') {
  385. $(this).siblings('a').show();
  386. showListData = _.filter(changeListData, function (c) {
  387. let flag = false;
  388. if (c.cid) {
  389. for(const v of valueList) {
  390. if ((c.code && c.code.indexOf(v) !== -1) || (c.name && c.name.indexOf(v) !== -1)) {
  391. flag = true;
  392. break;
  393. }
  394. }
  395. }
  396. return flag;
  397. // return ((c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1)) && c.cid;
  398. });
  399. } else if (select === 1 && value === '') {
  400. $(this).siblings('a').hide();
  401. showListData = _.filter(changeListData, function (c) {
  402. return c.cid;
  403. });
  404. } else if (value !== '') {
  405. $(this).siblings('a').show();
  406. showListData = _.filter(changeListData, function (c) {
  407. let flag = false;
  408. for(const v of valueList) {
  409. if ((c.code && c.code.indexOf(v) !== -1) || (c.name && c.name.indexOf(v) !== -1)) {
  410. flag = true;
  411. break;
  412. }
  413. }
  414. return flag;
  415. // return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  416. });
  417. } else {
  418. $(this).siblings('a').hide();
  419. }
  420. makeListTable(changeListData, showListData);
  421. $('#table-list-select tr').removeClass('table-warning');
  422. $('#code-input').val('');
  423. $('#code-input').siblings('a').hide();
  424. $('#code-list').html('');
  425. $('#code-select-all').prop('checked', false);
  426. });
  427. // 双击编辑搜索值
  428. $('body').on('dblclick', '#list-search-keyword tr', function () {
  429. if ($(this).attr('data-keyword') !== '') {
  430. $(this).children('td').html(`<input class="form-control form-control-sm" value="">`);
  431. $(this).find('input').focus();
  432. $(this).find('input').val($(this).attr('data-keyword'));
  433. }
  434. });
  435. // 光标离开
  436. $('body').on('blur', '#list-search-keyword tr td input', function () {
  437. let val = $(this).val();
  438. const oldVal = $(this).parents('tr').attr('data-keyword');
  439. if (_.trim(val) === '') {
  440. toastr.warning('不能为空');
  441. val = oldVal;
  442. } else if (_.trim(val) === oldVal) {
  443. val = oldVal;
  444. } else {
  445. const value = _.trim($('#list-input').val());
  446. const valueList = _.slice(_.without(_.uniq(_.replace(value, /\t/g, ' ').split(' ')), ''), 0, 10);
  447. // console.log(_.indexOf(valueList, oldVal), valueList, val, oldVal);
  448. if (_.indexOf(valueList, val) !== -1) {
  449. toastr.warning('已存在相同的检索词');
  450. val = oldVal;
  451. }
  452. valueList.splice(_.indexOf(valueList, oldVal), 1, val);
  453. $('#list-input').val(valueList.join(' '));
  454. const select = parseInt($('#select-list').val());
  455. const showListData = _.filter(changeListData, function (c) {
  456. return ((c.code && c.code.indexOf(val) !== -1) || (c.name && c.name.indexOf(val) !== -1)) && (select === 1 ? c.cid : 1);
  457. });
  458. makeListTable(changeListData, showListData);
  459. $('#table-list-select tr').removeClass('table-warning');
  460. $('#code-input').val('');
  461. $('#code-input').siblings('a').hide();
  462. $('#code-list').html('');
  463. $('#code-select-all').prop('checked', false);
  464. }
  465. $(this).parents('tr').attr('data-keyword', val);
  466. $(this).parents('td').html(`${val}`);
  467. });
  468. $('body').on('keypress', '#list-search-keyword tr td input', function () {
  469. if(window.event.keyCode === 13) {
  470. $(this).blur();
  471. }
  472. });
  473. $("#addlist").draggable({ handle: '.modal-header, .modal-footer'});
  474. // 检索关键字切换
  475. $('body').on('click', '#list-search-keyword tr', function () {
  476. if (!$(this).hasClass('bg-primary')) {
  477. const keyword = $(this).attr('data-keyword');
  478. $(this).siblings().removeClass('text-white bg-primary');
  479. $(this).siblings().children('td').removeClass('border-primary');
  480. $(this).addClass('text-white bg-primary');
  481. $(this).children('td').addClass('border-primary');
  482. if (keyword === '') {
  483. $('#list-input').blur();
  484. } else {
  485. const select = parseInt($('#select-list').val());
  486. const showListData = _.filter(changeListData, function (c) {
  487. return ((c.code && c.code.indexOf(keyword) !== -1) || (c.name && c.name.indexOf(keyword) !== -1)) && (select === 1 ? c.cid : 1);
  488. });
  489. makeListTable(changeListData, showListData);
  490. $('#table-list-select tr').removeClass('table-warning');
  491. $('#code-input').val('');
  492. $('#code-input').siblings('a').hide();
  493. $('#code-list').html('');
  494. $('#code-select-all').prop('checked', false);
  495. }
  496. }
  497. });
  498. // 回车提交
  499. $('#code-input').on('keypress', function () {
  500. if(window.event.keyCode === 13) {
  501. $(this).blur();
  502. }
  503. });
  504. $('#code-input').on('blur', function () {
  505. const value = $(this).val();
  506. if (value !== '') {
  507. $(this).siblings('a').show();
  508. } else {
  509. $(this).siblings('a').hide();
  510. }
  511. makeCodeTable($(this).val());
  512. checkSelectAll();
  513. });
  514. $('.remove-btn').on('click', function () {
  515. $(this).hide();
  516. $(this).siblings('input').val('');
  517. if ($(this).data('btn') === 'list') {
  518. const select = parseInt($('#select-list').val());
  519. let showListData = changeListData;
  520. if (select === 1) {
  521. showListData = _.filter(changeListData, function (c) {
  522. return c.cid;
  523. });
  524. }
  525. makeListTable(changeListData, showListData);
  526. $('#table-list-select tr').removeClass('table-warning');
  527. $('#code-list').html('');
  528. $('#table-list').addClass('col-12').removeClass('col-9');
  529. $('#table-list').siblings('.col-3').hide();
  530. $('#list-search-keyword').html('');
  531. $('#list-search-keyword').siblings('a').addClass('active');
  532. } else {
  533. makeCodeTable();
  534. }
  535. checkSelectAll();
  536. });
  537. // 全选及取消
  538. $('#code-select-all').click(function () {
  539. // 全选checkbox
  540. let index = $('#code-list').attr('data-index');
  541. if (index) {
  542. if ($(this).is(':checked')){
  543. $('#code-list tr').each(function () {
  544. if ($(this).css('display') !== 'none' && $(this).find('input').prop('disabled') !== true) {
  545. $(this).find('input').prop('checked', true);
  546. }
  547. })
  548. } else {
  549. $('#code-list tr').each(function () {
  550. if ($(this).css('display') !== 'none' && $(this).find('input').prop('disabled') !== true) {
  551. $(this).find('input').prop('checked', false);
  552. }
  553. });
  554. }
  555. // 判断还有无选中项目节编号
  556. if ($('#code-list input').is(':checked')) {
  557. // 去除部分data-detail值
  558. let data_bwmx = [];
  559. let data_charu = [];
  560. $('#code-list input:checked').each(function () {
  561. const tr = $(this).parents('tr');
  562. const length = tr.children('td').length;
  563. const gcl_id = tr.attr('gcl_id');
  564. const mx_id = tr.attr('mx_id');
  565. const bwmx = length === 9 ?
  566. tr.children('td').eq(1).text() + '!_!' +
  567. tr.children('td').eq(2).text() + '!_!' +
  568. tr.children('td').eq(3).text() + '!_!' +
  569. tr.children('td').eq(4).text() + '!_!' +
  570. tr.children('td').eq(5).text() + '!_!' + gcl_id + '!_!' + mx_id + '!_!' +
  571. (tr.children('td').eq(6).text() !== '' ? tr.children('td').eq(6).text() : tr.children('td').eq(2).text()) : '0';
  572. const quantity = tr.attr('quantity');
  573. const de_qu = bwmx + '*;*' + quantity;
  574. data_bwmx.push(de_qu);
  575. if (changeOrder && $(this).prop('disabled') !== true) {
  576. data_charu.push(de_qu);
  577. }
  578. });
  579. data_bwmx = data_bwmx.join('$#$');
  580. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  581. if (changeOrder) {
  582. data_charu = data_charu.join('$#$');
  583. $('#table-list-select tr[data-index="' + index + '"]').attr('data-charu', data_charu);
  584. }
  585. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  586. } else {
  587. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  588. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  589. if (changeOrder) {
  590. $('#table-list-select tr[data-index="' + index + '"]').attr('data-charu', '');
  591. }
  592. }
  593. }
  594. });
  595. // 选中所有新增部位/清单
  596. $('#select-all-revise').click(function() {
  597. const qtySpr = '*;*', infoSpr = '!_!', recSpr = '$#$';
  598. const gclTr = $('#table-list-select tr');
  599. for (const tr of gclTr) {
  600. const lid = $(tr).data('lid');
  601. let gcl = _.find(gclGatherData, function (item) {
  602. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  603. });
  604. if (!gcl) gcl = gclGatherData[$(this).data('gcl')];
  605. if (!gcl || !gcl.cid) continue;
  606. let data_bwmx = [];
  607. if ($(tr).attr('data-bwmx') !== '') {
  608. data_bwmx = $(tr).attr('data-bwmx').split(recSpr);
  609. data_bwmx = data_bwmx.filter(x => {
  610. const rec = x.split(qtySpr);
  611. const info = rec[0].split(infoSpr);
  612. if (info.length < 8) return true;
  613. const leaf = gcl.leafXmjs.find(lx => { return lx.mx_id === info[6]});
  614. return !leaf || !leaf.cid || leaf.ccid !== window.location.pathname.split('/')[4];
  615. });
  616. }
  617. let hasNew = false;
  618. for (const [index, leaf] of gcl.leafXmjs.entries()) {
  619. if (!leaf.cid || leaf.ccid !== window.location.pathname.split('/')[4]) continue;
  620. const bwmx = [leaf.code, leaf.jldy || '', leaf.dwgc || '', leaf.fbgc || '', leaf.fxgc || '', leaf.gcl_id, leaf.mx_id, leaf.bwmx || leaf.jldy || ''];
  621. const de_qu = bwmx.join(infoSpr) + qtySpr + (leaf.quantity || 0);
  622. if (data_bwmx.indexOf(de_qu) < 0) data_bwmx.push(de_qu);
  623. hasNew = true;
  624. }
  625. if (hasNew) $(tr).attr('data-bwmx', data_bwmx.join(recSpr)).addClass('table-success');
  626. }
  627. // 触发点击当前清单,重载当前全部部位
  628. const dataIndex = $('#code-list').attr('data-index');
  629. if (dataIndex) {
  630. $(`tr[data-index=${dataIndex}]`).trigger('click');
  631. }
  632. });
  633. });
  634. function checkSelectAll() {
  635. let check = $('#code-list tr').length > 0 ? true : false;
  636. const codeNum = $('#code-list tr').length;
  637. let i = 0;
  638. $('#code-list tr').each(function () {
  639. if ($(this).css('display') !== 'none' && !$(this).find('input').is(':checked')) {
  640. check = false;
  641. return;
  642. }
  643. else if ($(this).css('display') === 'none') {
  644. i++;
  645. }
  646. });
  647. if (check && i === codeNum) {
  648. check = false;
  649. }
  650. $('#code-select-all').prop('checked', check);
  651. }
  652. function findDecimal(unit) {
  653. let value = precision.other.value;
  654. const changeUnits = precision;
  655. for (const d in changeUnits) {
  656. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  657. value = changeUnits[d].value;
  658. break;
  659. }
  660. }
  661. return value;
  662. }