change_information_set.js 53 KB

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