change_information_set.js 55 KB

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