change_information_set.js 54 KB

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