change_information_set.js 54 KB

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