change_information_set.js 57 KB

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