change_information_set.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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])) {
  19. return code1[i].charCodeAt() - code2[i].charCodeAt();
  20. } else {
  21. return parseInt(code1[i]) - parseInt(code2[i]);
  22. }
  23. } else if (i+1 == code1length && code1[i] == code2[i]) {
  24. if (code1length == code2length) {
  25. return 0;
  26. } else {
  27. return code1length - code2length;
  28. }
  29. }
  30. } else {
  31. if (i+1 >= code1length) {
  32. return 1;
  33. } else {
  34. return -1;
  35. }
  36. }
  37. }
  38. }
  39. const is_numeric = (value) => {
  40. if (typeof(value) === 'object') {
  41. return false;
  42. } else {
  43. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  44. }
  45. };
  46. $.event.special.valuechange = {
  47. teardown: function (namespaces) {
  48. $(this).unbind('.valuechange');
  49. },
  50. handler: function (e) {
  51. $.event.special.valuechange.triggerChanged($(this));
  52. },
  53. add: function (obj) {
  54. $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
  55. },
  56. triggerChanged: function (element) {
  57. var current = element[0].contentEditable === 'true' ? element.html() : element.val()
  58. , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
  59. if (current !== previous) {
  60. element.trigger('valuechange', [element.data('previous')]);
  61. element.data('previous', current);
  62. }
  63. }
  64. };
  65. $(document).ready(() => {
  66. const style1 = new GC.Spread.Sheets.Style();
  67. style1.locked = true;
  68. const changeCol = {
  69. getValue: {
  70. unit_price: function(data) {
  71. return ZhCalc.round(data.unit_price, unitPriceUnit);
  72. },
  73. oa_tp: function (data) {
  74. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  75. },
  76. ca_tp: function (data) {
  77. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  78. },
  79. oamount: function (data) {
  80. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  81. },
  82. camount: function (data) {
  83. return ZhCalc.round(data.camount, findDecimal(data.unit));
  84. },
  85. del_list: function (data) {
  86. return '移除';
  87. }
  88. },
  89. readOnly: {
  90. isEdit: function (data) {
  91. return !readOnly && data.lid != 0;
  92. },
  93. },
  94. };
  95. const changeSpreadObj = {
  96. makeSjsFooter: function () {
  97. // 增加汇总行并设为锁定禁止编辑状态
  98. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  99. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  100. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  101. changeSpreadObj.countSum();
  102. },
  103. countSum: function() {
  104. const rowCount = changeSpreadSheet.getRowCount();
  105. let oSum = 0,
  106. cSum = 0;
  107. for(var i = 0; i < rowCount - 1; i++){
  108. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  109. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  110. }
  111. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  112. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  113. },
  114. add: function () {
  115. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  116. if (result) {
  117. changeList.push(result);
  118. changeSpreadSheet.addRows(changeList.length - 1, 1);
  119. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  120. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  121. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  122. }
  123. });
  124. },
  125. del: function () {
  126. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  127. const index = changeList.indexOf(select);
  128. if (index > -1) {
  129. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  130. changeList.splice(index, 1);
  131. changeSpreadSheet.deleteRows(index, 1);
  132. const sel = changeSpreadSheet.getSelections();
  133. changeSpreadSheet.setSelection(0, 0, 1, 1);
  134. if (select.lid != 0) {
  135. tableDataRemake(changeListData);
  136. }
  137. changeSpreadObj.countSum();
  138. });
  139. }
  140. },
  141. selectionChanged: function (e, info) {
  142. const sel = info.sheet.getSelections()[0];
  143. const col = info.sheet.zh_setting.cols[sel.col];
  144. const data = SpreadJsObj.getSelectObject(info.sheet);
  145. if (col.field === 'del_list') {
  146. changeSpreadObj.del();
  147. }
  148. },
  149. editEnded: function (e, info) {
  150. if (info.sheet.zh_setting) {
  151. const select = SpreadJsObj.getSelectObject(info.sheet);
  152. const col = info.sheet.zh_setting.cols[info.col];
  153. if (col.field === 'del_list') {
  154. return;
  155. }
  156. // 未改变值则不提交
  157. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  158. const orgValue = select[col.field];
  159. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  160. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  161. return;
  162. }
  163. // 判断部分值是否输入的是数字判断和数据计算
  164. if (col.type === 'Number') {
  165. if (isNaN(validText)) {
  166. toastr.error('不能输入其它非数字类型字符');
  167. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  168. return;
  169. }
  170. if (col.field === 'unit_price') {
  171. validText = ZhCalc.round(validText, unitPriceUnit);
  172. } else {
  173. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  174. }
  175. }
  176. if (col.field === 'unit') {
  177. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  178. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  179. }
  180. select[col.field] = validText;
  181. if(col.field === 'camount') {
  182. select.spamount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  183. }
  184. console.log(select);
  185. // 更新至服务器
  186. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  187. changeList.splice(info.row, 1, select);
  188. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  189. changeSpreadObj.countSum();
  190. }, function () {
  191. select[col.field] = orgValue;
  192. if(col.field === 'camount') {
  193. select.spamount = orgValue;
  194. }
  195. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  196. });
  197. }
  198. },
  199. clipboardPasted(e, info) {
  200. const hint = {
  201. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  202. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  203. };
  204. const range = info.cellRange;
  205. const sortData = info.sheet.zh_data || [];
  206. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  207. toastMessageUniq(hint.cellError);
  208. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  209. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  210. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  211. return;
  212. }
  213. if (sortData.length > 0 && range.col + range.colCount > 10) {
  214. toastMessageUniq(hint.cellError);
  215. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  216. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  217. return;
  218. }
  219. const data = [];
  220. // const rowData = [];
  221. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  222. let bPaste = true;
  223. const curRow = range.row + iRow;
  224. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  225. const cLData = { id: sortData[curRow].id };
  226. const hintRow = range.rowCount > 1 ? curRow : '';
  227. let sameCol = 0;
  228. for (let iCol = 0; iCol < range.colCount; iCol++) {
  229. const curCol = range.col + iCol;
  230. const colSetting = info.sheet.zh_setting.cols[curCol];
  231. if (!colSetting) continue;
  232. let validText = info.sheet.getText(curRow, curCol);
  233. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  234. const orgValue = sortData[curRow][colSetting.field];
  235. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  236. sameCol++;
  237. if (range.colCount === sameCol) {
  238. bPaste = false;
  239. }
  240. continue;
  241. }
  242. if (colSetting.type === 'Number') {
  243. if (isNaN(validText)) {
  244. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  245. bPaste = false;
  246. continue;
  247. }
  248. if (colSetting.field === 'unit_price') {
  249. validText = ZhCalc.round(validText, unitPriceUnit);
  250. } else {
  251. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  252. }
  253. }
  254. if (colSetting.field === 'unit') {
  255. cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(validText)) || 0;
  256. cLData.oamount = ZhCalc.round(sortData[curRow].oamount, findDecimal(validText)) || 0;
  257. }
  258. cLData[colSetting.field] = validText;
  259. sortData[curRow][colSetting.field] = validText;
  260. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(validText)) || 0;
  261. }
  262. if (bPaste) {
  263. data.push(cLData);
  264. // rowData.push(curRow);
  265. } else {
  266. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  267. }
  268. }
  269. if (data.length === 0) {
  270. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  271. return;
  272. }
  273. console.log(data);
  274. // 更新至服务器
  275. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  276. changeList = result;
  277. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  278. changeSpreadObj.makeSjsFooter();
  279. }, function () {
  280. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  281. return;
  282. });
  283. },
  284. };
  285. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  286. let changeListData;
  287. let gclGatherData;
  288. postData(preUrl + '/defaultBills', {}, function (result) {
  289. gclGatherModel.loadLedgerData(result.bills);
  290. gclGatherModel.loadPosData(result.pos);
  291. gclGatherData = gclGatherModel.gatherGclData();
  292. gclGatherData = _.filter(gclGatherData, function (item) {
  293. return item.leafXmjs && item.leafXmjs.length !== 0;
  294. });
  295. for (const ggd in gclGatherData) {
  296. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  297. gclGatherData.splice(ggd, 1);
  298. }
  299. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  300. }
  301. // 数组去重
  302. const dealBillList = result.dealBills;
  303. for (const db of gclGatherData) {
  304. const exist_index = dealBillList.findIndex(function (item) {
  305. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  306. });
  307. if (exist_index !== -1) {
  308. dealBillList.splice(exist_index, 1);
  309. }
  310. }
  311. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  312. // 先加载台账数据
  313. let listHtml = '';
  314. let list_index = 1;
  315. let gcl_index = 0;
  316. for (const gcl of changeListData) {
  317. const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  318. const quantity = gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
  319. const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
  320. let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"' : '';
  321. gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
  322. const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? (gcl.leafXmjs.length !== 0 ? gcl.leafXmjs[0].gcl_id : false) : gcl.id;
  323. if (lid) {
  324. listHtml += '<tr data-lid="' + lid + '"' + gclhtml + ' data-index="' + list_index + '" data-bwmx="">' +
  325. '<td class="text-center">' + list_index + '</td>' +
  326. '<td>' + gcl.code + '</td>' +
  327. '<td class="text-left">' + gcl.name + '</td>' +
  328. '<td class="text-center">' + unit + '</td>' +
  329. '<td class="text-right">' + ZhCalc.round(unit_price, unitPriceUnit) + '</td>' +
  330. '<td class="text-right">' + quantity + '</td>' +
  331. '</tr>';
  332. list_index++;
  333. }
  334. }
  335. $('#table-list-select').html(listHtml);
  336. tableDataRemake(changeListData);
  337. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  338. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  339. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  340. changeSpreadObj.makeSjsFooter();
  341. });
  342. if (!readOnly) {
  343. $('#add-white-btn').click(changeSpreadObj.add);
  344. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  345. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  346. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  347. changeSpreadSheet.getCell(-1, 10).foreColor('#dc3545');
  348. // 右键菜单
  349. $.contextMenu({
  350. selector: '#change-spread',
  351. build: function ($trigger, e) {
  352. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  353. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  354. },
  355. items: {
  356. 'createList': {
  357. name: '添加台账清单',
  358. icon: 'fa-sign-in',
  359. callback: function (key, opt) {
  360. $('#addlist').modal('show');
  361. },
  362. },
  363. 'createAdd': {
  364. name: '添加空白清单',
  365. icon: 'fa-sign-in',
  366. callback: function (key, opt) {
  367. changeSpreadObj.add(changeSpreadSheet);
  368. },
  369. },
  370. 'delete': {
  371. name: '删除',
  372. icon: 'fa-remove',
  373. callback: function (key, opt) {
  374. changeSpreadObj.del(changeSpreadSheet);
  375. },
  376. disabled: function (key, opt) {
  377. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  378. const sel = changeSpreadSheet.getSelections()[0];
  379. console.log(select, sel);
  380. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  381. return false;
  382. } else {
  383. return true;
  384. }
  385. }
  386. },
  387. }
  388. });
  389. }
  390. // 清单选中和移除
  391. $('body').on('click', '#table-list-select tr', function () {
  392. $('#table-list-select tr').removeClass('table-warning');
  393. $(this).addClass('table-warning');
  394. const isCheck = $(this).hasClass('table-success') ? true : false;
  395. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  396. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  397. let codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'" gcl_id="0"><td colspan="7" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox"></td></tr>';
  398. if (isDeal) {
  399. const lid = $(this).data('lid');
  400. let gcl = _.find(gclGatherData, function (item) {
  401. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  402. });
  403. if (!gcl) {
  404. gcl = gclGatherData[$(this).data('gcl')];
  405. }
  406. codeHtml = '';
  407. for (const leaf of gcl.leafXmjs) {
  408. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  409. const gcl_id = leaf.gcl_id ? leaf.gcl_id : '0';
  410. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : '';
  411. const isChecked = data_bwmx.indexOf(leaf.code + '!_!' + (leaf.jldy ? leaf.jldy : '') + '!_!' + (leaf.gcl_id ? leaf.gcl_id : '0') + '!_!' + (bwmx !== '' ? bwmx : leaf.jldy ? leaf.jldy : '') + '*;*' + quantity) !== -1 && isCheck ? 'checked' : '';
  412. codeHtml += '<tr quantity="' + quantity + '" gcl_id="' + gcl_id + '"><td>' + leaf.code + '</td>' +
  413. '<td>' + (leaf.jldy ? leaf.jldy: '') + '</td>' +
  414. '<td>' + (leaf.dwgc ? leaf.dwgc : '') + '</td>' +
  415. '<td>' + (leaf.fbgc ? leaf.fbgc : '') + '</td>' +
  416. '<td>' + (leaf.fxgc ? leaf.fxgc : '') + '</td>' +
  417. '<td>' + bwmx + '</td>' +
  418. '<td class="text-right">' + ZhCalc.round(quantity, findDecimal(gcl.unit)) + '</td>' +
  419. '<td class="text-center"><input type="checkbox"' + isChecked +
  420. '></td></tr>';
  421. }
  422. } else if (!isDeal && isCheck) {
  423. codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'" gcl_id="0"><td colspan="7" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox" checked></td></tr>';
  424. }
  425. $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
  426. $('#code-input').val('');
  427. $('#code-input').siblings('a').hide();
  428. $('#code-list').html(codeHtml);
  429. });
  430. // 右边项目节选择
  431. $('body').on('click', '#code-list input', function () {
  432. let index = $('#code-list').attr('data-index');
  433. if ($(this).is(':checked')) {
  434. // 去除其它可能已选的checked
  435. // $('#code-list input').prop('checked', false);
  436. $(this).prop('checked', true);
  437. // 左边表单传值并添加class
  438. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  439. // 去除部分data-detail值
  440. let data_bwmx = [];
  441. $('#code-list input:checked').each(function () {
  442. const tr = $(this).parents('tr');
  443. const length = tr.children('td').length;
  444. const gcl_id = tr.attr('gcl_id');
  445. const bwmx = length === 8 ? tr.children('td').eq(0).text() + '!_!' + tr.children('td').eq(1).text() + '!_!' + gcl_id + '!_!' + (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  446. const quantity = tr.attr('quantity');
  447. const de_qu = bwmx + '*;*' + quantity;
  448. data_bwmx.push(de_qu);
  449. });
  450. data_bwmx = data_bwmx.join('$#$');
  451. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  452. } else {
  453. // 判断还有无选中项目节编号
  454. if ($('#code-list input').is(':checked')) {
  455. // 去除部分data-detail值
  456. let data_bwmx = [];
  457. $('#code-list input:checked').each(function () {
  458. const tr = $(this).parents('tr');
  459. const length = tr.children('td').length;
  460. const gcl_id = tr.attr('gcl_id');
  461. const bwmx = length === 8 ? tr.children('td').eq(0).text() + '!_!'+ tr.children('td').eq(1).text() + '!_!' + gcl_id + '!_!' + (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  462. const quantity = tr.attr('quantity');
  463. const de_qu = bwmx + '*;*' + quantity;
  464. data_bwmx.push(de_qu);
  465. });
  466. data_bwmx = data_bwmx.join('$#$');
  467. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  468. } else {
  469. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  470. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  471. }
  472. }
  473. });
  474. // 添加空白清单or签约清单
  475. $('.add-list-btn').on('click', function () {
  476. const newLedgerList = remakeChangeSpread();
  477. // 更新至服务器
  478. postData(window.location.pathname + '/save', { type:'ledger_list', updateData: newLedgerList }, function (result) {
  479. changeList = result;
  480. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  481. changeSpreadObj.makeSjsFooter();
  482. $('#addlist').modal('hide');
  483. }, function () {
  484. $('#addlist').modal('hide');
  485. });
  486. });
  487. // 选中input所有值
  488. $('body').on('focus', ".clist input", function() {
  489. $(this).select();
  490. });
  491. // 取消选中清单
  492. $('#cancel-list-btn').click(function () {
  493. // $('#table-list-select tr').removeClass('table-success');
  494. // $('#table-list-select tr').attr('data-bwmx', '');
  495. // $('#code-list').html('');
  496. tableDataRemake(changeListData);
  497. });
  498. // 自动编号
  499. $('.reduction-code').click(function () {
  500. const code = $(this).attr('data-code');
  501. $('input[name="code"]').val(code);
  502. });
  503. $('#list-input').on('valuechange', function (e, previous) {
  504. const value = $(this).val();
  505. let showListData = changeListData;
  506. if (value !== '') {
  507. $(this).siblings('a').show();
  508. showListData = _.filter(changeListData, function (c) {
  509. return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  510. });
  511. } else {
  512. $(this).siblings('a').hide();
  513. }
  514. makeListTable(changeListData, showListData);
  515. $('#table-list-select tr').removeClass('table-warning');
  516. $('#code-input').val('');
  517. $('#code-input').siblings('a').hide();
  518. $('#code-list').html('');
  519. });
  520. $('#code-input').on('valuechange', function (e, previous) {
  521. const value = $(this).val();
  522. if (value !== '') {
  523. $(this).siblings('a').show();
  524. } else {
  525. $(this).siblings('a').hide();
  526. }
  527. makeCodeTable($(this).val());
  528. });
  529. $('.remove-btn').on('click', function () {
  530. $(this).hide();
  531. $(this).siblings('input').val('');
  532. if ($(this).data('btn') === 'list') {
  533. makeListTable(changeListData);
  534. $('#table-list-select tr').removeClass('table-warning');
  535. $('#code-list').html('');
  536. } else {
  537. makeCodeTable();
  538. }
  539. })
  540. });
  541. function findDecimal(unit) {
  542. let value = precision.other.value;
  543. const changeUnits = precision;
  544. for (const d in changeUnits) {
  545. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  546. value = changeUnits[d].value;
  547. break;
  548. }
  549. }
  550. return value;
  551. }
  552. function tableDataRemake(changeListData) {
  553. $('#table-list-select tr').removeClass('table-warning');
  554. $('#table-list-select tr').removeClass('table-success');
  555. $('#table-list-select tr').attr('data-bwmx', '');
  556. $('#code-list').html('');
  557. // 根据已添加的清单显示
  558. if (changeList.length > 0 && changeList[0]) {
  559. for (const [index,clinfo] of changeList.entries()) {
  560. if (clinfo.lid != 0) {
  561. let listinfo = changeListData.find(function (item) {
  562. return (item.id !== undefined && item.id == clinfo.lid) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && item.leafXmjs[0].gcl_id == clinfo.lid);
  563. });
  564. if (listinfo === undefined) {
  565. // 针对旧数据获取清单信息
  566. listinfo = changeListData[clinfo.lid - 1];
  567. if (listinfo === undefined) {
  568. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  569. changeList.splice(index, 1);
  570. continue;
  571. }
  572. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
  573. let pushbwmx = '0*;*0';
  574. if (listinfo.leafXmjs !== undefined) {
  575. const leafInfo = listinfo.leafXmjs.find(function (item) {
  576. return (item.bwmx === undefined || item.bwmx === clinfo.bwmx) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  577. });
  578. console.log(leafInfo);
  579. if (leafInfo) {
  580. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' + (leafInfo.gcl_id ? leafInfo.gcl_id : '0') + '!_!' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : '') + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  581. } else {
  582. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  583. changeList.splice(index, 1);
  584. continue;
  585. }
  586. } else {
  587. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  588. }
  589. const bwmx = $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx');
  590. if (bwmx) {
  591. const bwmxArray = bwmx.split('$#$');
  592. bwmxArray.push(pushbwmx);
  593. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  594. } else {
  595. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  596. }
  597. } else {
  598. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
  599. let pushbwmx = '0*;*0';
  600. if (listinfo.leafXmjs !== undefined) {
  601. const leafInfo = listinfo.leafXmjs.find(function (item) {
  602. return (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  603. });
  604. if (leafInfo) {
  605. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' + (leafInfo.gcl_id ? leafInfo.gcl_id : '0') + '!_!' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (leafInfo.jldy ? leafInfo.jldy : '')) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  606. } else {
  607. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  608. changeList.splice(index, 1);
  609. continue;
  610. }
  611. } else {
  612. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  613. }
  614. const bwmx = $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx');
  615. if (bwmx) {
  616. const bwmxArray = bwmx.split('$#$');
  617. bwmxArray.push(pushbwmx);
  618. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  619. } else {
  620. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  621. }
  622. }
  623. }
  624. }
  625. }
  626. }
  627. // 清单搜索隐藏清单table部分值
  628. function makeListTable(changeListData, showListData = changeListData) {
  629. // 先加载台账数据
  630. let listHtml = '';
  631. let list_index = 1;
  632. let gcl_index = 0;
  633. for (const [index,gcl] of changeListData.entries()) {
  634. const isShow = _.find(showListData, gcl);
  635. $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  636. }
  637. }
  638. // 项目节搜索隐藏code-table部分值
  639. function makeCodeTable(search = '') {
  640. if (search === '') {
  641. $('#code-list tr').css('display', 'table-row');
  642. return;
  643. }
  644. for(let i = 0; i < $('#code-list tr').length; i++) {
  645. const length = $('#code-list tr').eq(i).children('td').length;
  646. if (length === 8) {
  647. const code = $('#code-list tr').eq(i).children('td').eq(0).text();
  648. const name = $('#code-list tr').eq(i).children('td').eq(1).text();
  649. const jldy = $('#code-list tr').eq(i).children('td').eq(5).text();
  650. const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
  651. $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
  652. } else {
  653. return;
  654. }
  655. }
  656. }
  657. function remakeChangeSpread() {
  658. const newTableList = [];
  659. // 获取选中的签约清单判断并插入到原有清单中
  660. $('#table-list-select .table-success').each(function(){
  661. let code = $(this).children('td').eq(1).text();
  662. let name = $(this).children('td').eq(2).text();
  663. let unit = $(this).children('td').eq(3).text();
  664. let price = $(this).children('td').eq(4).text();
  665. // let oamount = $(this).children('td').eq(5).text();
  666. // 根据单位获取数量的位数,并得出
  667. // let numdecimal = findDecimal(unit);
  668. // let scnum = makedecimalzero(numdecimal);
  669. let scnum = 0;
  670. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  671. let lid = $(this).data('lid');
  672. let lindex = $(this).data('index');
  673. // 原清单和数量改变
  674. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  675. for (const b of data_bwmx) {
  676. const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
  677. let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[3] : '';
  678. let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
  679. let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
  680. let gcl_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
  681. let trlist = {
  682. code,
  683. name,
  684. bwmx,
  685. unit,
  686. unit_price: price,
  687. oamount,
  688. camount: scnum,
  689. detail: '',
  690. lid,
  691. xmj_code,
  692. xmj_jldy,
  693. gcl_id,
  694. };
  695. const radionInfo = changeList.find(function (info) {
  696. return info.code === code && (info.lid == lid || parseInt(info.lid) === parseInt(lindex)) && info.bwmx === bwmx;
  697. });
  698. if (radionInfo) {
  699. trlist.camount = radionInfo.camount;
  700. trlist.detail = radionInfo.detail;
  701. }
  702. newTableList.push(trlist);
  703. }
  704. });
  705. // const changeWhiteList = _.filter(changeList, function (item) {
  706. // return item.lid == 0;
  707. // });
  708. // console.log(newTableList);
  709. // changeList = newTableList.concat(changeWhiteList);
  710. return newTableList;
  711. }