change_information_set.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  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. $.event.special.valuechange = {
  64. teardown: function (namespaces) {
  65. $(this).unbind('.valuechange');
  66. },
  67. handler: function (e) {
  68. $.event.special.valuechange.triggerChanged($(this));
  69. },
  70. add: function (obj) {
  71. $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
  72. },
  73. triggerChanged: function (element) {
  74. var current = element[0].contentEditable === 'true' ? element.html() : element.val()
  75. , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
  76. if (current !== previous) {
  77. element.trigger('valuechange', [element.data('previous')]);
  78. element.data('previous', current);
  79. }
  80. }
  81. };
  82. function getPasteHint (str, row = '') {
  83. let returnObj = str;
  84. if (row) {
  85. returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
  86. }
  87. return returnObj;
  88. }
  89. $(document).ready(() => {
  90. const changeSpreadSetting = {
  91. cols: [
  92. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit2'},
  93. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
  94. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  95. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: false},
  96. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  97. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit2', getValue: 'getValue.unit_price'},
  98. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  99. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  100. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: false, getValue: 'getValue.camount'},
  101. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  102. {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
  103. ],
  104. emptyRows: 0,
  105. headRows: 2,
  106. headRowHeight: [25, 25],
  107. defaultRowHeight: 21,
  108. headerFont: '12px 微软雅黑',
  109. font: '12px 微软雅黑',
  110. readOnly: readOnly,
  111. rowHeader:[
  112. {
  113. rowHeaderType: 'circle',
  114. setting: {
  115. size: 5,
  116. indent: 16,
  117. getColor: function (index, data) {
  118. if (!data) return;
  119. if(data.lid != 0) return;
  120. return '#007bff';
  121. }
  122. },
  123. },
  124. ],
  125. localCache: {
  126. key: 'changes-spread',
  127. colWidth: true,
  128. }
  129. };
  130. const changeCol = {
  131. getValue: {
  132. unit_price: function(data) {
  133. return ZhCalc.round(data.unit_price, unitPriceUnit);
  134. },
  135. oa_tp: function (data) {
  136. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  137. },
  138. ca_tp: function (data) {
  139. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  140. },
  141. oamount: function (data) {
  142. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  143. },
  144. camount: function (data) {
  145. return ZhCalc.round(data.camount, findDecimal(data.unit));
  146. },
  147. del_list: function (data) {
  148. return !_.find(changeUsedData, { id: data.id }) ? '移除' : '';
  149. }
  150. },
  151. readOnly: {
  152. isEdit: function (data) {
  153. return !readOnly && data.lid != 0;
  154. },
  155. isEdit2: function (data) {
  156. return !readOnly && (data.lid != 0 || (data.lid == 0 && _.findIndex(changeUsedData, { id: data.id }) !== -1));
  157. },
  158. },
  159. };
  160. const changeSpreadObj = {
  161. makeSjsFooter: function () {
  162. // 增加汇总行并设为锁定禁止编辑状态
  163. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  164. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  165. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  166. changeSpreadObj.countSum();
  167. },
  168. countSum: function() {
  169. const rowCount = changeSpreadSheet.getRowCount();
  170. let oSum = 0,
  171. cSum = 0;
  172. for(var i = 0; i < rowCount - 1; i++){
  173. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  174. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  175. }
  176. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  177. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  178. },
  179. add: function () {
  180. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  181. if (result) {
  182. changeList.push(result);
  183. changeSpreadSheet.addRows(changeList.length - 1, 1);
  184. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  185. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  186. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  187. changeSpreadObj.resetXmjSpread();
  188. }
  189. });
  190. },
  191. batchAdd: function(num) {
  192. postData(window.location.pathname + '/save', {type: 'batchadd', num}, function (result) {
  193. if (result) {
  194. changeList = _.concat(changeList, result);
  195. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  196. changeSpreadObj.makeSjsFooter();
  197. changeSpreadObj.resetXmjSpread();
  198. }
  199. });
  200. },
  201. del: function () {
  202. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  203. const index = changeList.indexOf(select);
  204. if (index > -1 && !_.find(changeUsedData, { id: select.id })) {
  205. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  206. changeList.splice(index, 1);
  207. changeSpreadSheet.deleteRows(index, 1);
  208. const sel = changeSpreadSheet.getSelections();
  209. changeSpreadSheet.setSelection(0, 0, 1, 1);
  210. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  211. if (select.lid != 0) {
  212. tableDataRemake(changeListData);
  213. }
  214. changeSpreadObj.countSum();
  215. });
  216. }
  217. },
  218. resetXmjSpread: function(data = null) {
  219. const xmj = [];
  220. if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
  221. const newData = JSON.parse(JSON.stringify(data));
  222. if (newData.bwmx === newData.xmj_jldy) {
  223. newData.bwmx = '';
  224. }
  225. xmj.push(newData);
  226. }
  227. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  228. },
  229. selectionChanged: function (e, info) {
  230. const sel = info.sheet.getSelections()[0];
  231. const col = info.sheet.zh_setting.cols[sel.col];
  232. const data = SpreadJsObj.getSelectObject(info.sheet);
  233. if (col && col.field === 'del_list' && !_.find(changeUsedData, { id: data.id })) {
  234. changeSpreadObj.del();
  235. }
  236. changeSpreadObj.resetXmjSpread(data);
  237. },
  238. deletePress: function (sheet) {
  239. return;
  240. },
  241. editEnded: function (e, info) {
  242. if (info.sheet.zh_setting) {
  243. const select = SpreadJsObj.getSelectObject(info.sheet);
  244. const col = info.sheet.zh_setting.cols[info.col];
  245. if (col.field === 'del_list') {
  246. return;
  247. }
  248. // 未改变值则不提交
  249. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  250. const orgValue = select[col.field];
  251. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  252. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  253. return;
  254. }
  255. // 判断部分值是否输入的是数字判断和数据计算
  256. if (col.type === 'Number') {
  257. if (isNaN(validText)) {
  258. toastr.error('不能输入其它非数字类型字符');
  259. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  260. return;
  261. }
  262. if (col.field === 'unit_price') {
  263. validText = ZhCalc.round(validText, unitPriceUnit);
  264. } else {
  265. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  266. }
  267. }
  268. if (col.field === 'unit') {
  269. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  270. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  271. }
  272. if(col.field === 'camount') {
  273. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  274. const usedInfo = _.find(changeUsedData, { id: select.id });
  275. if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
  276. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  277. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  278. return;
  279. } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
  280. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  281. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  282. return;
  283. }
  284. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  285. }
  286. select[col.field] = validText;
  287. console.log(select);
  288. delete select.waitingLoading;
  289. // 更新至服务器
  290. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  291. changeList.splice(info.row, 1, select);
  292. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  293. changeSpreadObj.countSum();
  294. }, function () {
  295. select[col.field] = orgValue;
  296. if(col.field === 'camount') {
  297. select.spamount = orgValue;
  298. }
  299. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  300. });
  301. }
  302. },
  303. clipboardPasted(e, info) {
  304. const hint = {
  305. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  306. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  307. };
  308. const range = info.cellRange;
  309. const sortData = info.sheet.zh_data || [];
  310. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  311. toastMessageUniq(hint.cellError);
  312. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  313. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  314. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  315. changeSpreadObj.makeSjsFooter();
  316. return;
  317. }
  318. if (sortData.length > 0 && range.col + range.colCount > 10) {
  319. toastMessageUniq(hint.cellError);
  320. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  321. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  322. changeSpreadObj.makeSjsFooter();
  323. return;
  324. }
  325. const data = [];
  326. // const rowData = [];
  327. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  328. let bPaste = true;
  329. const curRow = range.row + iRow;
  330. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  331. const cLData = { id: sortData[curRow].id };
  332. const hintRow = range.rowCount > 1 ? curRow : '';
  333. let sameCol = 0;
  334. for (let iCol = 0; iCol < range.colCount; iCol++) {
  335. const curCol = range.col + iCol;
  336. const colSetting = info.sheet.zh_setting.cols[curCol];
  337. if (!colSetting) continue;
  338. let validText = info.sheet.getText(curRow, curCol);
  339. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  340. const orgValue = sortData[curRow][colSetting.field];
  341. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  342. sameCol++;
  343. if (range.colCount === sameCol) {
  344. bPaste = false;
  345. }
  346. continue;
  347. }
  348. if (colSetting.type === 'Number') {
  349. if (isNaN(validText)) {
  350. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  351. bPaste = false;
  352. continue;
  353. }
  354. if (colSetting.field === 'unit_price') {
  355. validText = ZhCalc.round(validText, unitPriceUnit);
  356. } else {
  357. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  358. }
  359. if(colSetting.field === 'camount') {
  360. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  361. const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id });
  362. if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
  363. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  364. bPaste = false;
  365. continue;
  366. } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
  367. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  368. bPaste = false;
  369. continue;
  370. }
  371. }
  372. }
  373. let unitdecimal = validText;
  374. if (colSetting.field === 'unit') {
  375. //粘贴内容要为下拉列表里所有的单位,不然为空
  376. if (changeUnits.indexOf(validText) === -1) {
  377. unitdecimal = '';
  378. }
  379. cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  380. cLData.oamount = ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  381. }
  382. cLData[colSetting.field] = validText;
  383. sortData[curRow][colSetting.field] = validText;
  384. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  385. }
  386. if (bPaste) {
  387. data.push(cLData);
  388. // rowData.push(curRow);
  389. } else {
  390. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  391. }
  392. }
  393. if (data.length === 0) {
  394. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  395. return;
  396. }
  397. console.log(data);
  398. // 更新至服务器
  399. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  400. changeList = result;
  401. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  402. changeSpreadObj.makeSjsFooter();
  403. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  404. }, function () {
  405. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  406. return;
  407. });
  408. },
  409. valueChanged(e, info) {
  410. // 防止ctrl+z撤销数据
  411. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  412. }
  413. };
  414. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  415. let changeListData;
  416. let gclGatherData;
  417. postData(preUrl + '/defaultBills', {}, function (result) {
  418. gclGatherModel.loadLedgerData(result.bills);
  419. gclGatherModel.loadPosData(result.pos);
  420. gclGatherData = gclGatherModel.gatherGclData();
  421. gclGatherData = _.filter(gclGatherData, function (item) {
  422. return item.leafXmjs && item.leafXmjs.length !== 0;
  423. });
  424. for (const ggd in gclGatherData) {
  425. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  426. gclGatherData.splice(ggd, 1);
  427. }
  428. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  429. }
  430. // 数组去重
  431. const dealBillList = result.dealBills;
  432. for (const db of gclGatherData) {
  433. const exist_index = dealBillList.findIndex(function (item) {
  434. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  435. });
  436. if (exist_index !== -1) {
  437. dealBillList.splice(exist_index, 1);
  438. }
  439. }
  440. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  441. console.log(changeListData);
  442. // 先加载台账数据
  443. let listHtml = '';
  444. let list_index = 1;
  445. let gcl_index = 0;
  446. for (const gcl of changeListData) {
  447. const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  448. const quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
  449. const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
  450. let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"' : '';
  451. gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
  452. const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? (gcl.leafXmjs.length !== 0 ? gcl.leafXmjs[0].gcl_id : false) : gcl.id;
  453. if (lid) {
  454. listHtml += '<tr data-lid="' + lid + '"' + gclhtml + ' data-index="' + list_index + '" data-bwmx="">' +
  455. '<td class="text-center">' + list_index + '</td>' +
  456. '<td>' + gcl.code + '</td>' +
  457. '<td class="text-left">' + gcl.name + '</td>' +
  458. '<td class="text-center">' + unit + '</td>' +
  459. '<td class="text-right">' + (ZhCalc.round(unit_price, unitPriceUnit) ? ZhCalc.round(unit_price, unitPriceUnit) : 0) + '</td>' +
  460. '<td class="text-right">' + quantity + '</td>' +
  461. '</tr>';
  462. list_index++;
  463. }
  464. }
  465. $('#table-list-select').html(listHtml);
  466. tableDataRemake(changeListData);
  467. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  468. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  469. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  470. // changeSpreadSheet.options.protectionOptions = {
  471. // allowSort: true,
  472. // allowFilter: true
  473. // };
  474. // var option = changeSpreadSheet.options.protectionOptions;
  475. // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, changeSpreadSetting.cols.length)));
  476. // // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, 3)));
  477. // const filter = changeSpreadSheet.rowFilter();
  478. // filter.filterButtonVisible(false);
  479. // filter.filterButtonVisible(0, true);
  480. // filter.filterButtonVisible(2, true);
  481. // filter.filterDialogVisibleInfo({
  482. // sortByValue: true, //SortByValue item is visible.
  483. // sortByColor: false, //SortByColor item is visible.
  484. // filterByColor: false, //FilterByColor item is visible.
  485. // filterByValue: false, //FilterByValue item is visible.
  486. // listFilterArea: false //ListFilterArea item is visible.
  487. // });
  488. // function compareList(obj1, obj2) {
  489. // console.log(obj1, obj2);
  490. // var list = ["", '204-1-b', '合计'];
  491. // var index1 = list.indexOf(obj1), index2 = list.indexOf(obj2);
  492. // if (index1 > index2) {
  493. // return 1;
  494. // } else if (index1 < index2) {
  495. // return -1;
  496. // } else {
  497. // return 0;
  498. // }
  499. // }
  500. // changeSpreadSheet.sortRange(0, 0, changeSpreadSetting.cols.length, 1, true, [{index: 0, ascending: true, compareFunction: compareList}]);
  501. // changeSpreadSheet.bind(GC.Spread.Sheets.Events.RangeSorting, function (e, info) {
  502. // info.compareFunction = compareList;
  503. // });
  504. // filter.sortColumn(0, true);
  505. changeSpreadObj.makeSjsFooter();
  506. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  507. });
  508. if (!readOnly) {
  509. $('#add-white-btn').click(changeSpreadObj.add);
  510. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  511. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  512. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  513. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  514. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  515. changeSpreadSheet.getCell(-1, 10).foreColor('#dc3545');
  516. let batchInsertObj;
  517. $.contextMenu.types.batchInsert = function (item, opt, root) {
  518. const self = this;
  519. if ($.isFunction(item.icon)) {
  520. item._icon = item.icon.call(this, this, $t, key, item);
  521. } else {
  522. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  523. // to enable font awesome
  524. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  525. } else {
  526. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  527. }
  528. }
  529. this.addClass(item._icon);
  530. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  531. .appendTo(this);
  532. const $input = $obj.find('input');
  533. const event = () => {
  534. if (self.hasClass('context-menu-disabled')) return;
  535. item.batchInsert($input[0], root);
  536. };
  537. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  538. $input.click((e) => {e.stopPropagation();})
  539. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  540. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  541. };
  542. // 右键菜单
  543. $.contextMenu({
  544. selector: '#change-spread',
  545. build: function ($trigger, e) {
  546. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  547. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  548. },
  549. items: {
  550. 'createList': {
  551. name: '添加台账清单',
  552. icon: 'fa-sign-in',
  553. callback: function (key, opt) {
  554. $('#addlist').modal('show');
  555. },
  556. },
  557. 'createAdd': {
  558. name: '添加空白清单',
  559. icon: 'fa-sign-in',
  560. callback: function (key, opt) {
  561. changeSpreadObj.add(changeSpreadSheet);
  562. },
  563. },
  564. 'batchInsert': {
  565. name: '批量添加空白清单',
  566. type: 'batchInsert',
  567. value: '2',
  568. icon: 'fa-sign-in',
  569. batchInsert: function (obj, root) {
  570. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  571. obj.value = obj.max;
  572. toastr.warning('批量添加不可多于' + obj.max);
  573. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  574. obj.value = obj.min;
  575. toastr.warning('批量添加不可少于' + obj.min);
  576. } else {
  577. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  578. changeSpreadObj.batchAdd(obj.value);
  579. root.$menu.trigger('contextmenu:hide');
  580. }
  581. },
  582. },
  583. 'delete': {
  584. name: '删除',
  585. icon: 'fa-remove',
  586. callback: function (key, opt) {
  587. changeSpreadObj.del(changeSpreadSheet);
  588. },
  589. disabled: function (key, opt) {
  590. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  591. const sel = changeSpreadSheet.getSelections()[0];
  592. changeSpreadObj.resetXmjSpread(select);
  593. console.log(select, sel);
  594. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1 && !_.find(changeUsedData, { id: select.id })) {
  595. return false;
  596. } else {
  597. return true;
  598. }
  599. }
  600. },
  601. }
  602. });
  603. }
  604. // 清单选中和移除
  605. $('body').on('click', '#table-list-select tr', function () {
  606. $('#table-list-select tr').removeClass('table-warning');
  607. $(this).addClass('table-warning');
  608. const isCheck = $(this).hasClass('table-success') ? true : false;
  609. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  610. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  611. 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>';
  612. if (isDeal) {
  613. const lid = $(this).data('lid');
  614. let gcl = _.find(gclGatherData, function (item) {
  615. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  616. });
  617. if (!gcl) {
  618. gcl = gclGatherData[$(this).data('gcl')];
  619. }
  620. codeHtml = '';
  621. for (const leaf of gcl.leafXmjs) {
  622. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  623. const gcl_id = leaf.gcl_id ? leaf.gcl_id : '';
  624. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : (gcl.leafXmjs.length > 1 && gcl.name ? gcl.name : '');
  625. const isChecked = data_bwmx.indexOf(
  626. leaf.code + '!_!' + (leaf.jldy ? leaf.jldy : '') + '!_!' +
  627. (leaf.dwgc ? leaf.dwgc : '') + '!_!' + (leaf.fbgc ? leaf.fbgc : '') + '!_!' + (leaf.fxgc ? leaf.fxgc : '')
  628. + '!_!' + (leaf.gcl_id ? leaf.gcl_id : '0') + '!_!' +
  629. (bwmx !== '' ? bwmx : leaf.jldy ? leaf.jldy : '') + '*;*' + quantity) !== -1 && isCheck ?
  630. 'checked' : '';
  631. const isUsed = _.find(changeUsedData, { gcl_id: leaf.gcl_id, bwmx: (bwmx ? bwmx : leaf.jldy ? leaf.jldy : ''), oamount: leaf.quantity });
  632. const isDisabled = isUsed ? 'disabled ' : '';
  633. codeHtml += '<tr quantity="' + quantity + '" gcl_id="' + gcl_id + '"><td>' + leaf.code + '</td>' +
  634. '<td>' + (leaf.jldy ? leaf.jldy: '') + '</td>' +
  635. '<td>' + (leaf.dwgc ? leaf.dwgc : '') + '</td>' +
  636. '<td>' + (leaf.fbgc ? leaf.fbgc : '') + '</td>' +
  637. '<td>' + (leaf.fxgc ? leaf.fxgc : '') + '</td>' +
  638. '<td>' + bwmx + '</td>' +
  639. '<td class="text-right">' + (ZhCalc.round(quantity, findDecimal(gcl.unit)) ? ZhCalc.round(quantity, findDecimal(gcl.unit)) : 0) + '</td>' +
  640. '<td class="text-center"><input type="checkbox" ' + isDisabled + isChecked +
  641. '></td></tr>';
  642. }
  643. } else if (!isDeal && isCheck) {
  644. 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>';
  645. }
  646. $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
  647. $('#code-input').val('');
  648. $('#code-input').siblings('a').hide();
  649. $('#code-list').html(codeHtml);
  650. });
  651. // 右边项目节选择
  652. $('body').on('click', '#code-list input', function () {
  653. let index = $('#code-list').attr('data-index');
  654. if ($(this).is(':checked')) {
  655. // 去除其它可能已选的checked
  656. // $('#code-list input').prop('checked', false);
  657. $(this).prop('checked', true);
  658. // 左边表单传值并添加class
  659. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  660. // 去除部分data-detail值
  661. let data_bwmx = [];
  662. $('#code-list input:checked').each(function () {
  663. const tr = $(this).parents('tr');
  664. const length = tr.children('td').length;
  665. const gcl_id = tr.attr('gcl_id');
  666. const bwmx = length === 8 ?
  667. tr.children('td').eq(0).text() + '!_!' +
  668. tr.children('td').eq(1).text() + '!_!' +
  669. tr.children('td').eq(2).text() + '!_!' +
  670. tr.children('td').eq(3).text() + '!_!' +
  671. tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
  672. (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  673. const quantity = tr.attr('quantity');
  674. const de_qu = bwmx + '*;*' + quantity;
  675. data_bwmx.push(de_qu);
  676. });
  677. data_bwmx = data_bwmx.join('$#$');
  678. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  679. } else {
  680. // 判断还有无选中项目节编号
  681. if ($('#code-list input').is(':checked')) {
  682. // 去除部分data-detail值
  683. let data_bwmx = [];
  684. $('#code-list input:checked').each(function () {
  685. const tr = $(this).parents('tr');
  686. const length = tr.children('td').length;
  687. const gcl_id = tr.attr('gcl_id');
  688. const bwmx = length === 8 ?
  689. tr.children('td').eq(0).text() + '!_!' +
  690. tr.children('td').eq(1).text() + '!_!' +
  691. tr.children('td').eq(2).text() + '!_!' +
  692. tr.children('td').eq(3).text() + '!_!' +
  693. tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
  694. (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  695. const quantity = tr.attr('quantity');
  696. const de_qu = bwmx + '*;*' + quantity;
  697. data_bwmx.push(de_qu);
  698. });
  699. data_bwmx = data_bwmx.join('$#$');
  700. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  701. } else {
  702. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  703. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  704. }
  705. }
  706. });
  707. // 添加空白清单or签约清单
  708. $('.add-list-btn').on('click', function () {
  709. const newLedgerList = remakeChangeSpread();
  710. // 更新至服务器
  711. postData(window.location.pathname + '/save', { type:'ledger_list', updateData: newLedgerList }, function (result) {
  712. changeList = result.changeList;
  713. changeUsedData = result.usedList;
  714. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  715. changeSpreadObj.makeSjsFooter();
  716. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  717. changeSpreadObj.resetXmjSpread(select);
  718. $('#addlist').modal('hide');
  719. }, function () {
  720. $('#addlist').modal('hide');
  721. });
  722. });
  723. // 选中input所有值
  724. $('body').on('focus', ".clist input", function() {
  725. $(this).select();
  726. });
  727. // 取消选中清单
  728. $('#cancel-list-btn').click(function () {
  729. // $('#table-list-select tr').removeClass('table-success');
  730. // $('#table-list-select tr').attr('data-bwmx', '');
  731. // $('#code-list').html('');
  732. tableDataRemake(changeListData);
  733. });
  734. // 自动编号
  735. $('.reduction-code').click(function () {
  736. const code = $(this).attr('data-code');
  737. $('input[name="code"]').val(code);
  738. });
  739. $('#list-input').on('valuechange', function (e, previous) {
  740. const value = $(this).val();
  741. let showListData = changeListData;
  742. if (value !== '') {
  743. $(this).siblings('a').show();
  744. showListData = _.filter(changeListData, function (c) {
  745. return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  746. });
  747. } else {
  748. $(this).siblings('a').hide();
  749. }
  750. makeListTable(changeListData, showListData);
  751. $('#table-list-select tr').removeClass('table-warning');
  752. $('#code-input').val('');
  753. $('#code-input').siblings('a').hide();
  754. $('#code-list').html('');
  755. });
  756. $('#code-input').on('valuechange', function (e, previous) {
  757. const value = $(this).val();
  758. if (value !== '') {
  759. $(this).siblings('a').show();
  760. } else {
  761. $(this).siblings('a').hide();
  762. }
  763. makeCodeTable($(this).val());
  764. });
  765. $('.remove-btn').on('click', function () {
  766. $(this).hide();
  767. $(this).siblings('input').val('');
  768. if ($(this).data('btn') === 'list') {
  769. makeListTable(changeListData);
  770. $('#table-list-select tr').removeClass('table-warning');
  771. $('#code-list').html('');
  772. } else {
  773. makeCodeTable();
  774. }
  775. });
  776. // 记录变更信息操作
  777. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  778. changeInfo[$(this).attr('name')] = $(this).val();
  779. judgeChange();
  780. });
  781. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  782. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  783. judgeChange();
  784. });
  785. $('body').on('change', '#change_form select', function (e, previous) {
  786. changeInfo[$(this).attr('name')] = $(this).val();
  787. judgeChange();
  788. });
  789. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  790. changeInfo[$(this).attr('name')] = $(this).val();
  791. judgeChange();
  792. });
  793. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  794. const typecheck = [];
  795. $.each($('#change_form input[name="type[]"]:checked'), function () {
  796. typecheck.push($(this).val());
  797. });
  798. changeInfo.type = typecheck.join(',');
  799. judgeChange();
  800. });
  801. // 保存修改ajax提交(不刷新页面)
  802. $('.save_change_btn').on('click', function () {
  803. // 保存修改modal
  804. if ($('input[name="code"]').val() === '') {
  805. toastr.error('申请编号不能为空!');
  806. return;
  807. }
  808. if ($('input[name="name"]').val() === '') {
  809. toastr.error('工程名称不能为空!');
  810. return;
  811. }
  812. // 换行更改并提交
  813. changeInfo.content = changeInfo.content.replace(/<br><br>/g, '\r\n');
  814. changeInfo.basis = changeInfo.basis.replace(/<br><br>/g, '\r\n');
  815. changeInfo.expr = changeInfo.expr.replace(/<br><br>/g, '\r\n');
  816. changeInfo.memo = changeInfo.memo.replace(/<br><br>/g, '\r\n');
  817. // 后改为br
  818. // 更新至服务器
  819. postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
  820. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  821. toastr.success(result);
  822. $('#show-save-btn').hide();
  823. $('#sp-btn').show();
  824. $('.title-main').removeClass('bg-warning');
  825. changeInfo.content = changeInfo.content.replace(/[\r\n]/g, '<br>');
  826. changeInfo.basis = changeInfo.basis.replace(/[\r\n]/g, '<br>');
  827. changeInfo.expr = changeInfo.expr.replace(/[\r\n]/g, '<br>');
  828. changeInfo.memo = changeInfo.memo.replace(/[\r\n]/g, '<br>');
  829. back_changeInfo = Object.assign({}, changeInfo);
  830. });
  831. return false;
  832. });
  833. $('#cancel_change').on('click', function () {
  834. $('#show-save-btn').hide();
  835. $('#sp-btn').show();
  836. $('.title-main').removeClass('bg-warning');
  837. if (!isObjEqual(changeInfo, back_changeInfo)) {
  838. changeFormRemake();
  839. }
  840. toastr.success('已还原到上次保存状态');
  841. });
  842. });
  843. function checkChangeFrom() {
  844. let returnFlag = false;
  845. // 表单判断
  846. if ($('input[name="code"]').val() === '') {
  847. toastr.error('申请编号不能为空!');
  848. returnFlag = true;
  849. }
  850. if ($('input[name="name"]').val() === '') {
  851. toastr.error('工程名称不能为空!');
  852. returnFlag = true;
  853. }
  854. if ($('textarea[name="content"]').val() === '') {
  855. toastr.error('工程变更理由及内容不能为空!');
  856. returnFlag = true;
  857. }
  858. if (changeList.length === 0) {
  859. toastr.error('请添加变更清单!');
  860. returnFlag = true;
  861. } else {
  862. for (const [i,cl] of changeList.entries()) {
  863. if (cl.code === '' || cl.name === '' || cl.oamount === '') {
  864. toastr.error('变更清单第' + (i+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
  865. returnFlag = true;
  866. }
  867. }
  868. }
  869. if(!checkAuditorFrom ()) {
  870. returnFlag = true;
  871. }
  872. if (returnFlag) {
  873. return false;
  874. }
  875. }
  876. // 检查上报情况
  877. function checkAuditorFrom () {
  878. if ($('#auditList li').length === 0) {
  879. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  880. toastr.error('请联系管理员添加审批人');
  881. } else {
  882. toastr.error('请先选择审批人,再上报数据');
  883. }
  884. return false;
  885. }
  886. return true;
  887. }
  888. function tableDataRemake(changeListData) {
  889. $('#table-list-select tr').removeClass('table-warning');
  890. $('#table-list-select tr').removeClass('table-success');
  891. $('#table-list-select tr').attr('data-bwmx', '');
  892. $('#code-list').html('');
  893. // 根据已添加的清单显示
  894. if (changeList.length > 0 && changeList[0]) {
  895. const removeList = [];
  896. for (const [index,clinfo] of changeList.entries()) {
  897. if (clinfo.lid != 0) {
  898. let listinfo = changeListData.find(function (item) {
  899. 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);
  900. });
  901. if (listinfo === undefined) {
  902. // 针对旧数据获取清单信息
  903. listinfo = changeListData[clinfo.lid - 1];
  904. if (listinfo === undefined) {
  905. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  906. // changeList.splice(index, 1);
  907. removeList.push(clinfo);
  908. continue;
  909. }
  910. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
  911. let pushbwmx = '0*;*0';
  912. if (listinfo.leafXmjs !== undefined) {
  913. const leafInfo = listinfo.leafXmjs.find(function (item) {
  914. const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  915. if (flag && item.code === clinfo.xmj_code) {
  916. return flag && item.code === clinfo.xmj_code;
  917. }
  918. return flag;
  919. });
  920. if (leafInfo) {
  921. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  922. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  923. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  924. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  925. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  926. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  927. } else {
  928. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  929. // changeList.splice(index, 1);
  930. removeList.push(clinfo);
  931. continue;
  932. }
  933. } else {
  934. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  935. }
  936. const bwmx = $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx');
  937. if (bwmx) {
  938. const bwmxArray = bwmx.split('$#$');
  939. bwmxArray.push(pushbwmx);
  940. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  941. } else {
  942. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  943. }
  944. } else {
  945. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
  946. let pushbwmx = '0*;*0';
  947. if (listinfo.leafXmjs !== undefined) {
  948. const leafInfo = listinfo.leafXmjs.find(function (item) {
  949. const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  950. if (flag && item.code === clinfo.xmj_code) {
  951. return flag && item.code === clinfo.xmj_code;
  952. }
  953. return flag;
  954. });
  955. if (leafInfo) {
  956. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  957. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  958. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  959. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  960. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  961. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  962. } else {
  963. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  964. // changeList.splice(index, 1);
  965. removeList.push(clinfo);
  966. continue;
  967. }
  968. } else {
  969. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  970. }
  971. const bwmx = $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx');
  972. if (bwmx) {
  973. const bwmxArray = bwmx.split('$#$');
  974. bwmxArray.push(pushbwmx);
  975. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  976. } else {
  977. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  978. }
  979. }
  980. }
  981. }
  982. if(removeList.length > 0) {
  983. _.pullAll(changeList, removeList);
  984. postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
  985. }, function () {
  986. });
  987. }
  988. }
  989. }
  990. // 清单搜索隐藏清单table部分值
  991. function makeListTable(changeListData, showListData = changeListData) {
  992. // 先加载台账数据
  993. let listHtml = '';
  994. let list_index = 1;
  995. let gcl_index = 0;
  996. for (const [index,gcl] of changeListData.entries()) {
  997. const isShow = _.find(showListData, gcl);
  998. $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  999. }
  1000. }
  1001. // 项目节搜索隐藏code-table部分值
  1002. function makeCodeTable(search = '') {
  1003. if (search === '') {
  1004. $('#code-list tr').css('display', 'table-row');
  1005. return;
  1006. }
  1007. for(let i = 0; i < $('#code-list tr').length; i++) {
  1008. const length = $('#code-list tr').eq(i).children('td').length;
  1009. if (length === 8) {
  1010. const code = $('#code-list tr').eq(i).children('td').eq(0).text();
  1011. const name = $('#code-list tr').eq(i).children('td').eq(1).text();
  1012. const jldy = $('#code-list tr').eq(i).children('td').eq(5).text();
  1013. const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
  1014. $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
  1015. } else {
  1016. return;
  1017. }
  1018. }
  1019. }
  1020. function remakeChangeSpread() {
  1021. const newTableList = [];
  1022. // 获取选中的签约清单判断并插入到原有清单中
  1023. $('#table-list-select .table-success').each(function(){
  1024. let code = $(this).children('td').eq(1).text();
  1025. let name = $(this).children('td').eq(2).text();
  1026. let unit = $(this).children('td').eq(3).text();
  1027. let price = $(this).children('td').eq(4).text();
  1028. // let oamount = $(this).children('td').eq(5).text();
  1029. // 根据单位获取数量的位数,并得出
  1030. // let numdecimal = findDecimal(unit);
  1031. // let scnum = makedecimalzero(numdecimal);
  1032. let scnum = 0;
  1033. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  1034. let lid = $(this).data('lid');
  1035. let lindex = $(this).data('index');
  1036. // 原清单和数量改变
  1037. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  1038. for (const b of data_bwmx) {
  1039. const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
  1040. let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[6] : '';
  1041. let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
  1042. let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
  1043. let xmj_dwgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
  1044. let xmj_fbgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[3] : '';
  1045. let xmj_fxgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[4] : '';
  1046. let gcl_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[5] : '';
  1047. let trlist = {
  1048. code,
  1049. name,
  1050. bwmx,
  1051. unit,
  1052. unit_price: price,
  1053. oamount,
  1054. camount: scnum,
  1055. detail: '',
  1056. lid,
  1057. xmj_code,
  1058. xmj_jldy,
  1059. xmj_dwgc,
  1060. xmj_fbgc,
  1061. xmj_fxgc,
  1062. gcl_id,
  1063. };
  1064. const radionInfo = changeList.find(function (info) {
  1065. return info.code === code && (info.lid == lid || parseInt(info.lid) === parseInt(lindex)) && gcl_id == info.gcl_id && (info.bwmx === bwmx || info.bwmx === xmj_jldy) && parseInt(info.oamount) === parseInt(oamount);
  1066. });
  1067. if (radionInfo) {
  1068. trlist.camount = radionInfo.camount;
  1069. trlist.detail = radionInfo.detail;
  1070. }
  1071. newTableList.push(trlist);
  1072. }
  1073. });
  1074. // const changeWhiteList = _.filter(changeList, function (item) {
  1075. // return item.lid == 0;
  1076. // });
  1077. // console.log(newTableList);
  1078. // changeList = newTableList.concat(changeWhiteList);
  1079. return newTableList;
  1080. }
  1081. //判断元素是否在数组中,相当于php的in_array();
  1082. function in_array(arr, obj) {
  1083. let i = arr.length;
  1084. while (i--) {
  1085. if (arr[i] == obj) {
  1086. return true;
  1087. }
  1088. }
  1089. return false;
  1090. }
  1091. function isObjEqual(o1,o2){
  1092. var props1 = Object.getOwnPropertyNames(o1);
  1093. var props2 = Object.getOwnPropertyNames(o2);
  1094. if (props1.length != props2.length) {
  1095. return false;
  1096. }
  1097. for (var i = 0,max = props1.length; i < max; i++) {
  1098. var propName = props1[i];
  1099. if (o1[propName] !== o2[propName]) {
  1100. return false;
  1101. }
  1102. }
  1103. return true;
  1104. }
  1105. // 判断是否有更改过
  1106. function judgeChange() {
  1107. let change = false;
  1108. if (!isObjEqual(changeInfo, back_changeInfo)) {
  1109. change = true;
  1110. }
  1111. if (change) {
  1112. $('#show-save-btn').show();
  1113. $('#sp-btn').hide();
  1114. $('.title-main').addClass('bg-warning');
  1115. } else {
  1116. $('#show-save-btn').hide();
  1117. $('#sp-btn').show();
  1118. $('.title-main').removeClass('bg-warning');
  1119. }
  1120. }
  1121. function changeFormRemake() {
  1122. changeInfo = Object.assign({}, back_changeInfo);
  1123. $('#change_form input[name="code"]').val(changeInfo.code);
  1124. $('#change_form input[name="name"]').val(changeInfo.name);
  1125. $('#change_form input[name="peg"]').val(changeInfo.peg);
  1126. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  1127. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  1128. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  1129. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  1130. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  1131. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  1132. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  1133. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  1134. $('#change_form select[name="type"]').val(changeInfo.type);
  1135. $('#change_form select[name="class"]').val(changeInfo.class);
  1136. $('#change_form select[name="quality"]').val(changeInfo.quality);
  1137. $('#change_form select[name="company"]').val(changeInfo.company);
  1138. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  1139. $('#change_form input[name="type[]"]').prop('checked', false);
  1140. const typecheck = changeInfo.type.split(',');
  1141. for (const type of typecheck) {
  1142. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  1143. }
  1144. }