change_information_set.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  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=""><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 : '';
  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=""><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. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  542. changeInfo[$(this).attr('name')] = $(this).val();
  543. judgeChange();
  544. });
  545. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  546. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  547. judgeChange();
  548. });
  549. $('body').on('change', '#change_form select', function (e, previous) {
  550. changeInfo[$(this).attr('name')] = $(this).val();
  551. judgeChange();
  552. });
  553. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  554. changeInfo[$(this).attr('name')] = $(this).val();
  555. judgeChange();
  556. });
  557. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  558. const typecheck = [];
  559. $.each($('#change_form input[name="type[]"]:checked'), function () {
  560. typecheck.push($(this).val());
  561. });
  562. changeInfo.type = typecheck.join(',');
  563. judgeChange();
  564. });
  565. // 保存修改ajax提交(不刷新页面)
  566. $('.save_change_btn').on('click', function () {
  567. // 保存修改modal
  568. if ($('input[name="code"]').val() === '') {
  569. toastr.error('申请编号不能为空!');
  570. return;
  571. }
  572. if ($('input[name="name"]').val() === '') {
  573. toastr.error('工程名称不能为空!');
  574. return;
  575. }
  576. // 更新至服务器
  577. postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
  578. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  579. toastr.success(result);
  580. $('#show-save-btn').hide();
  581. $('#sp-btn').show();
  582. $('.title-main').removeClass('bg-warning');
  583. back_changeInfo = Object.assign({}, changeInfo);
  584. });
  585. return false;
  586. });
  587. $('#cancel_change').on('click', function () {
  588. $('#show-save-btn').hide();
  589. $('#sp-btn').show();
  590. $('.title-main').removeClass('bg-warning');
  591. if (!isObjEqual(changeInfo, back_changeInfo)) {
  592. changeFormRemake();
  593. }
  594. toastr.success('已还原到上次保存状态');
  595. });
  596. });
  597. function checkChangeFrom() {
  598. let returnFlag = false;
  599. // 表单判断
  600. if ($('input[name="code"]').val() === '') {
  601. toastr.error('申请编号不能为空!');
  602. returnFlag = true;
  603. }
  604. if ($('input[name="name"]').val() === '') {
  605. toastr.error('工程名称不能为空!');
  606. returnFlag = true;
  607. }
  608. if ($('textarea[name="content"]').val() === '') {
  609. toastr.error('工程变更理由及内容不能为空!');
  610. returnFlag = true;
  611. }
  612. if (changeList.length === 0) {
  613. toastr.error('请添加变更清单!');
  614. returnFlag = true;
  615. } else {
  616. for (const [i,cl] of changeList.entries()) {
  617. if (cl.code === '' || cl.name === '' || cl.oamount === '') {
  618. toastr.error('变更清单第' + (i+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
  619. returnFlag = true;
  620. }
  621. }
  622. }
  623. if(!checkAuditorFrom ()) {
  624. returnFlag = true;
  625. }
  626. if (returnFlag) {
  627. return false;
  628. }
  629. }
  630. // 检查上报情况
  631. function checkAuditorFrom () {
  632. if ($('#auditList li').length === 0) {
  633. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  634. toastr.error('请联系管理员添加审批人');
  635. } else {
  636. toastr.error('请先选择审批人,再上报数据');
  637. }
  638. return false;
  639. }
  640. return true;
  641. }
  642. function findDecimal(unit) {
  643. let value = precision.other.value;
  644. const changeUnits = precision;
  645. for (const d in changeUnits) {
  646. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  647. value = changeUnits[d].value;
  648. break;
  649. }
  650. }
  651. return value;
  652. }
  653. function tableDataRemake(changeListData) {
  654. $('#table-list-select tr').removeClass('table-warning');
  655. $('#table-list-select tr').removeClass('table-success');
  656. $('#table-list-select tr').attr('data-bwmx', '');
  657. $('#code-list').html('');
  658. // 根据已添加的清单显示
  659. if (changeList.length > 0 && changeList[0]) {
  660. for (const [index,clinfo] of changeList.entries()) {
  661. if (clinfo.lid != 0) {
  662. let listinfo = changeListData.find(function (item) {
  663. 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);
  664. });
  665. if (listinfo === undefined) {
  666. // 针对旧数据获取清单信息
  667. listinfo = changeListData[clinfo.lid - 1];
  668. if (listinfo === undefined) {
  669. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  670. changeList.splice(index, 1);
  671. continue;
  672. }
  673. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
  674. let pushbwmx = '0*;*0';
  675. if (listinfo.leafXmjs !== undefined) {
  676. const leafInfo = listinfo.leafXmjs.find(function (item) {
  677. return (item.bwmx === undefined || item.bwmx === clinfo.bwmx) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  678. });
  679. console.log(leafInfo);
  680. if (leafInfo) {
  681. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' + (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : '') + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  682. } else {
  683. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  684. changeList.splice(index, 1);
  685. continue;
  686. }
  687. } else {
  688. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  689. }
  690. const bwmx = $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx');
  691. if (bwmx) {
  692. const bwmxArray = bwmx.split('$#$');
  693. bwmxArray.push(pushbwmx);
  694. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  695. } else {
  696. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  697. }
  698. } else {
  699. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
  700. let pushbwmx = '0*;*0';
  701. if (listinfo.leafXmjs !== undefined) {
  702. const leafInfo = listinfo.leafXmjs.find(function (item) {
  703. return (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  704. });
  705. if (leafInfo) {
  706. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' + (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (leafInfo.jldy ? leafInfo.jldy : '')) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  707. } else {
  708. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  709. changeList.splice(index, 1);
  710. continue;
  711. }
  712. } else {
  713. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  714. }
  715. const bwmx = $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx');
  716. if (bwmx) {
  717. const bwmxArray = bwmx.split('$#$');
  718. bwmxArray.push(pushbwmx);
  719. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  720. } else {
  721. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  722. }
  723. }
  724. }
  725. }
  726. }
  727. }
  728. // 清单搜索隐藏清单table部分值
  729. function makeListTable(changeListData, showListData = changeListData) {
  730. // 先加载台账数据
  731. let listHtml = '';
  732. let list_index = 1;
  733. let gcl_index = 0;
  734. for (const [index,gcl] of changeListData.entries()) {
  735. const isShow = _.find(showListData, gcl);
  736. $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  737. }
  738. }
  739. // 项目节搜索隐藏code-table部分值
  740. function makeCodeTable(search = '') {
  741. if (search === '') {
  742. $('#code-list tr').css('display', 'table-row');
  743. return;
  744. }
  745. for(let i = 0; i < $('#code-list tr').length; i++) {
  746. const length = $('#code-list tr').eq(i).children('td').length;
  747. if (length === 8) {
  748. const code = $('#code-list tr').eq(i).children('td').eq(0).text();
  749. const name = $('#code-list tr').eq(i).children('td').eq(1).text();
  750. const jldy = $('#code-list tr').eq(i).children('td').eq(5).text();
  751. const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
  752. $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
  753. } else {
  754. return;
  755. }
  756. }
  757. }
  758. function remakeChangeSpread() {
  759. const newTableList = [];
  760. // 获取选中的签约清单判断并插入到原有清单中
  761. $('#table-list-select .table-success').each(function(){
  762. let code = $(this).children('td').eq(1).text();
  763. let name = $(this).children('td').eq(2).text();
  764. let unit = $(this).children('td').eq(3).text();
  765. let price = $(this).children('td').eq(4).text();
  766. // let oamount = $(this).children('td').eq(5).text();
  767. // 根据单位获取数量的位数,并得出
  768. // let numdecimal = findDecimal(unit);
  769. // let scnum = makedecimalzero(numdecimal);
  770. let scnum = 0;
  771. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  772. let lid = $(this).data('lid');
  773. let lindex = $(this).data('index');
  774. // 原清单和数量改变
  775. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  776. for (const b of data_bwmx) {
  777. const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
  778. let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[3] : '';
  779. let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
  780. let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
  781. let gcl_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
  782. let trlist = {
  783. code,
  784. name,
  785. bwmx,
  786. unit,
  787. unit_price: price,
  788. oamount,
  789. camount: scnum,
  790. detail: '',
  791. lid,
  792. xmj_code,
  793. xmj_jldy,
  794. gcl_id,
  795. };
  796. const radionInfo = changeList.find(function (info) {
  797. return info.code === code && (info.lid == lid || parseInt(info.lid) === parseInt(lindex)) && gcl_id == info.gcl_id && info.bwmx === bwmx;
  798. });
  799. if (radionInfo) {
  800. trlist.camount = radionInfo.camount;
  801. trlist.detail = radionInfo.detail;
  802. }
  803. newTableList.push(trlist);
  804. }
  805. });
  806. // const changeWhiteList = _.filter(changeList, function (item) {
  807. // return item.lid == 0;
  808. // });
  809. // console.log(newTableList);
  810. // changeList = newTableList.concat(changeWhiteList);
  811. return newTableList;
  812. }
  813. //判断元素是否在数组中,相当于php的in_array();
  814. function in_array(arr, obj) {
  815. let i = arr.length;
  816. while (i--) {
  817. if (arr[i] == obj) {
  818. return true;
  819. }
  820. }
  821. return false;
  822. }
  823. function isObjEqual(o1,o2){
  824. var props1 = Object.getOwnPropertyNames(o1);
  825. var props2 = Object.getOwnPropertyNames(o2);
  826. if (props1.length != props2.length) {
  827. return false;
  828. }
  829. for (var i = 0,max = props1.length; i < max; i++) {
  830. var propName = props1[i];
  831. if (o1[propName] !== o2[propName]) {
  832. return false;
  833. }
  834. }
  835. return true;
  836. }
  837. // 判断是否有更改过
  838. function judgeChange() {
  839. let change = false;
  840. if (!isObjEqual(changeInfo, back_changeInfo)) {
  841. change = true;
  842. }
  843. if (change) {
  844. $('#show-save-btn').show();
  845. $('#sp-btn').hide();
  846. $('.title-main').addClass('bg-warning');
  847. } else {
  848. $('#show-save-btn').hide();
  849. $('#sp-btn').show();
  850. $('.title-main').removeClass('bg-warning');
  851. }
  852. }
  853. function changeFormRemake() {
  854. changeInfo = Object.assign({}, back_changeInfo);
  855. $('#change_form input[name="code"]').val(changeInfo.code);
  856. $('#change_form input[name="name"]').val(changeInfo.name);
  857. $('#change_form input[name="peg"]').val(changeInfo.peg);
  858. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  859. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  860. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  861. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  862. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  863. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  864. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  865. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  866. $('#change_form select[name="type"]').val(changeInfo.type);
  867. $('#change_form select[name="class"]').val(changeInfo.class);
  868. $('#change_form select[name="quality"]').val(changeInfo.quality);
  869. $('#change_form select[name="company"]').val(changeInfo.company);
  870. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  871. $('#change_form input[name="type[]"]').prop('checked', false);
  872. const typecheck = changeInfo.type.split(',');
  873. for (const type of typecheck) {
  874. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  875. }
  876. }