ration.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. $("#gongliao").click(function(){
  5. $(this).attr('href', "/rationRepository/lmm" + "?repository=" + getQueryString("repository"))
  6. });
  7. $("#fuzhu").click(function(){
  8. $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
  9. });
  10. var rationOprObj = {
  11. workBook: null,
  12. currentRations: {},
  13. currentEditingRation: null,
  14. currentSectionId: -1,
  15. activeCell: null,
  16. rationsCodes: [],
  17. setting: {
  18. header:[
  19. {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
  20. {headerName:"名称",headerWidth:280,dataCode:"name", dataType: "String"},
  21. {headerName:"单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center"},
  22. {headerName:"人工费",headerWidth:120,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  23. {headerName:"材料费",headerWidth:120,dataCode:"materialPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  24. {headerName:"机械费",headerWidth:120,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  25. {headerName:"基价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  26. {headerName:"显示名称(以%s表示参数)",headerWidth:280,dataCode:"caption", dataType: "String"},
  27. {headerName:"取费专业",headerWidth:100,dataCode:"feeType", dataType: "Number", hAlign: "center"}
  28. ],
  29. view:{
  30. comboBox:[
  31. {row:-1,col:2,rowCount:-1,colCount:1}
  32. ],
  33. lockedCells:[
  34. {row:-1,col:3,rowCount:-1, colCount:1}
  35. ],
  36. lockColumns: [
  37. 3, 4, 5, 6
  38. ]
  39. }
  40. },
  41. buildSheet: function(container) {
  42. let rationRepId = getQueryString("repository");
  43. var me = rationOprObj;
  44. let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
  45. console.log(gljLibID);
  46. if(!gljLibID || typeof gljLibID === 'undefined' || gljLibID == -1){
  47. alert("没有引用工料机库!");
  48. window.location.href = "/rationRepository/main";
  49. }
  50. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  51. me.workBook.options.showHorizontalScrollbar = true;
  52. me.getRationsCodes(rationRepId);
  53. me.rationDelOpr();
  54. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  55. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  56. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  57. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  58. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  59. //me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  60. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  61. },
  62. onCellClick: function(sender, args) {
  63. var me = rationOprObj,
  64. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  65. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  66. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
  67. me.activeCell = {row: args.row, col: args.col};
  68. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  69. sheetCommonObj.shieldAllCells(sheetGLJ);
  70. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  71. sheetCommonObj.shieldAllCells(sheetCoe);
  72. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  73. sheetCommonObj.shieldAllCells(sheetAss);
  74. if(!(args.sheetArea === GC.Spread.Sheets.SheetArea.colHeader || args.sheetArea === GC.Spread.Sheets.SheetArea.corner)){
  75. var cacheSection = me.getCache();
  76. if (cacheSection && args.row < cacheSection.length) {
  77. rationGLJOprObj.getGljItems(cacheSection[args.row], function () {
  78. me.workBook.focus(true);
  79. });
  80. rationCoeOprObj.getCoeItems(cacheSection[args.row], function () {
  81. me.workBook.focus(true);
  82. });
  83. rationAssistOprObj.getAssItems(cacheSection[args.row]);
  84. }
  85. };
  86. me.workBook.focus(true);
  87. },
  88. getCache: function() {
  89. var me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  90. if (!(rst)) {
  91. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  92. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  93. }
  94. return rst;
  95. },
  96. updateCache: function(addArr, updateArr, removeIds, result) {
  97. var me = this, cacheSection = me.getCache();
  98. if (addArr.length > 0) {
  99. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  100. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  101. }
  102. for (var i = removeIds.length - 1; i >= 0; i--) {
  103. for (var j = cacheSection.length - 1; j >= 0 ; j--) {
  104. if (cacheSection[j]["ID"] == removeIds[i]) {
  105. cacheSection.splice(j,1);
  106. }
  107. }
  108. }
  109. if (result && result.data.ops && result.data.ops.length > 0) {
  110. for (var i = 0; i < result.data.ops.length; i++) {
  111. for (var j = 0; j < cacheSection.length; j++) {
  112. if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
  113. cacheSection[j]["ID"] = result.data.ops[i]["ID"];
  114. cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
  115. }
  116. }
  117. }
  118. }
  119. for (var i = 0; i < updateArr.length; i++) {
  120. for (var j = 0; j < cacheSection.length; j++) {
  121. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  122. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  123. cacheSection[j] = updateArr[i];
  124. }
  125. } else {
  126. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  127. cacheSection[j] = updateArr[i];
  128. }
  129. }
  130. }
  131. }
  132. return cacheSection;
  133. },
  134. rationDelOpr: function () {
  135. let me = rationOprObj;
  136. me.workBook.commandManager().register('rationDelete', function () {
  137. let rationSheet = me.workBook.getActiveSheet();
  138. let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
  139. let cacheSection = me.getCache();
  140. if(sels.length > 0){
  141. for(let sel = 0; sel < sels.length; sel++){
  142. if(sels[sel].colCount === me.setting.header.length){
  143. if(cacheSection){
  144. for(let i = 0; i < sels[sel].rowCount; i++){
  145. if(sels[sel].row + i < cacheSection.length){
  146. removeArr.push(cacheSection[sels[sel].row + i].ID);
  147. me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code), 1);
  148. }
  149. }
  150. }
  151. }
  152. else{
  153. if(sels[sel].col === 0){
  154. $('#alertText').text("编号不能为空,修改失败!");
  155. $('#alertModalBtn').click();
  156. rationSheet.options.isProtected = true;
  157. $('#alertModalCls').click(function () {
  158. rationSheet.options.isProtected = false;
  159. });
  160. $('#alertModalCof').click(function () {
  161. rationSheet.options.isProtected = false;
  162. })
  163. }
  164. else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
  165. if(cacheSection){
  166. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  167. if(sels[sel].row + i < cacheSection.length){
  168. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  169. if(lockCols.indexOf(col) === -1){
  170. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
  171. }
  172. }
  173. }
  174. if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
  175. updateArr.push(cacheSection[sels[sel].row + i]);
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. if(updateArr.length > 0 || removeArr.length > 0){
  184. me.mixUpdateRequest(updateArr, [], removeArr);
  185. }
  186. });
  187. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  188. me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  189. },
  190. onRangeChanged: function(sender, args) {
  191. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  192. var me = rationOprObj, updateArr = [], removeArr = [];
  193. var cacheSection = me.getCache();
  194. if (cacheSection) {
  195. for (var i = 0; i < args.rowCount; i++) {
  196. //var hasUpdate = false, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row + i),
  197. var hasUpdate = false, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row + i),
  198. isEmpty = sheetCommonObj.chkIfEmpty(rObj, me.setting);
  199. for (var j = 0; j < cacheSection.length; j++) {
  200. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  201. rObj["ID"] = cacheSection[j]["ID"];
  202. hasUpdate = true;
  203. break;
  204. }
  205. }
  206. if(isEmpty){
  207. if(args.row + i < cacheSection.length){
  208. rObj.ID = cacheSection[args.row + i].ID;
  209. removeArr.push(rObj.ID);
  210. }
  211. }
  212. else{
  213. }
  214. if (hasUpdate) {
  215. if (isEmpty) {
  216. removeArr.push(rObj);
  217. } else updateArr.push(rObj);
  218. } else if (isEmpty) {
  219. if (args.row + i < cacheSection.length) {
  220. rObj["ID"] = cacheSection[args.row + i]["ID"];
  221. removeArr.push(rObj["ID"]);
  222. }
  223. }
  224. }
  225. // me.mixUpdateRequest(updateArr, [], removeArr);
  226. //removeRationItems
  227. }
  228. }
  229. },
  230. onEnterCell: function (sender, args) {
  231. let me = rationOprObj;
  232. me.cellRowIdx = args.row;
  233. let isHasData = false;
  234. if(me.addRationItem){
  235. for(let i=0; i<me.setting.header.length; i++){
  236. if(me.addRationItem[me.setting.header[i].dataCode]){
  237. isHasData = true;
  238. break;
  239. }
  240. }
  241. }
  242. if(isHasData){
  243. if(me.editingRowIdx !== me.cellRowIdx) {
  244. let focusToCol = !me.addRationItem.code ? 0 : -1;
  245. // else {
  246. if(focusToCol !== -1){
  247. $('#rationAlertBtn').click();
  248. me.workBook.getSheet(0).options.isProtected = true;
  249. $('#rationAlertCac').click(function () {
  250. me.workBook.getSheet(0).options.isProtected = false;
  251. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  252. });
  253. $('#rationAlertCls').click(function () {
  254. me.workBook.getSheet(0).options.isProtected = false;
  255. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  256. });
  257. $('#rationAlertCof').click(function () {
  258. me.workBook.getSheet(0).options.isProtected = false;
  259. me.addRationItem = null;
  260. for(let col=0; col<me.setting.header.length; col++){
  261. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value(me.currentEditingRation[me.setting.header[col].dataCode]);
  262. }
  263. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
  264. });
  265. }
  266. // }
  267. }
  268. }
  269. },
  270. onCellEditStart: function(sender, args) {
  271. var me = rationOprObj;
  272. //var rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
  273. var rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  274. me.currentEditingRation = rObj;
  275. var cacheSection = me.getCache();
  276. if (cacheSection) {
  277. for (var j = 0; j < cacheSection.length; j++) {
  278. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  279. rObj["ID"] = cacheSection[j]["ID"];
  280. break;
  281. }
  282. }
  283. }
  284. },
  285. onCellEditEnd: function(sender, args) {
  286. //var me = rationOprObj, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row),
  287. var me = rationOprObj, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  288. updateArr = [], addArr = [];
  289. let dataCode = me.setting.header[args.col].dataCode;
  290. me.editingRowIdx = args.row;
  291. if (me.currentEditingRation["ID"]) {
  292. rObj["ID"] = me.currentEditingRation["ID"];
  293. //updateArr.push(rObj);
  294. for(let col =0; col< me.setting.header.length; col++){
  295. if(me.currentEditingRation[me.setting.header[col].dataCode] !== rObj[me.setting.header[col].dataCode]){
  296. me.addRationItem = rObj;
  297. if(rObj[me.setting.header[0].dataCode]){
  298. updateArr.push(rObj);
  299. break;
  300. }
  301. }
  302. }
  303. } else if(!me.currentEditingRation["ID"]) {
  304. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  305. //addArr.push(rObj);
  306. me.addRationItem = rObj;
  307. if(rObj.code && rObj.code.trim().length > 0){
  308. if(me.rationsCodes.indexOf(rObj.code) === -1){
  309. addArr.push(rObj);
  310. me.rationsCodes.push(rObj.code);
  311. me.addRationItem = null;
  312. }
  313. else if(!rObj.code && rObj.code === ''){
  314. $('#alertModalBtn').click();
  315. me.workBook.getSheet(0).options.isProtected = true;
  316. $('#alertModalCls').click(function () {
  317. me.workBook.getSheet(0).options.isProtected = false;
  318. me.addRationItem.code = '';
  319. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  320. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  321. });
  322. $('#alertModalCof').click(function () {
  323. me.workBook.getSheet(0).options.isProtected = false;
  324. me.addRationItem.code = '';
  325. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  326. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  327. });
  328. }
  329. }
  330. else if(rObj.code && rObj.code.trim().length === 0){
  331. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  332. }
  333. }
  334. }
  335. if (updateArr.length > 0 || addArr.length > 0) {
  336. me.currentEditingRation = null;
  337. me.mixUpdateRequest(updateArr, addArr, []);
  338. }
  339. },
  340. onClipboardPasting: function(sender, args) {
  341. var me = rationOprObj;
  342. /* if (args.cellRange.colCount != me.setting.header.length) {
  343. args.cancel = true;
  344. }*/
  345. },
  346. onClipboardPasted: function(e, info) {
  347. var me = rationOprObj;
  348. var cacheSection = me.getCache();
  349. var updateArr = [], addArr = [];
  350. var items = sheetCommonObj.analyzePasteData(me.setting, info);
  351. let failPasteArr = [];
  352. for (var i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
  353. if (cacheSection) {
  354. //var hasCacheItem = false;
  355. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  356. if(me.rationsCodes.indexOf(items[i].code) === -1){
  357. addArr.push(items[i]);
  358. me.rationsCodes.push(items[i].code);
  359. }
  360. else{
  361. failPasteArr.push(items[i].code);
  362. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  363. }
  364. }
  365. else if(cacheSection[rowIdx]){
  366. for(let col = 0; col < me.setting.header.length; col++){
  367. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  368. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  369. }
  370. }
  371. if(info.cellRange.col === 0){
  372. if(me.rationsCodes.indexOf(items[i].code) === -1){
  373. items[i].ID = cacheSection[rowIdx].ID;
  374. updateArr.push(items[i]);
  375. }
  376. else{
  377. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  378. }
  379. }
  380. else{
  381. items[i].ID = cacheSection[rowIdx].ID;
  382. updateArr.push(items[i]);
  383. }
  384. }
  385. } else {
  386. //add
  387. if(info.cellRange.col === 0){
  388. //是否含有已存在的编号
  389. if(me.rationsCodes.indexOf(items[i].code) === -1){
  390. addArr.push(items[i]);
  391. }
  392. else{
  393. failPasteArr.push(items[i]);
  394. }
  395. }
  396. }
  397. };
  398. /* if(failPasteArr.length > 0 && !(updateArr.length > 0 || addArr.length > 0)){
  399. me.showRationItems(me.currentSectionId);
  400. }*/
  401. if (updateArr.length > 0 || addArr.length > 0) {
  402. me.mixUpdateRequest(updateArr, addArr, []);
  403. }
  404. },
  405. getRationsCodes: function (repId) {
  406. let me = rationOprObj;
  407. $.ajax({
  408. type: 'post',
  409. url: 'api/getRationsCodes',
  410. data: {data: JSON.stringify({repId: repId})},
  411. dataType: 'json',
  412. success: function (result) {
  413. if(!result.error){
  414. me.rationsCodes = result.data;
  415. }
  416. }
  417. })
  418. },
  419. mixUpdateRequest: function(updateArr, addArr, removeIds) {
  420. var me = rationOprObj;
  421. $.ajax({
  422. type:"POST",
  423. url:"api/mixUpdateRationItems",
  424. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  425. dataType:"json",
  426. cache:false,
  427. timeout:5000,
  428. success:function(result){
  429. if (result.error) {
  430. alert(`error`);
  431. me.getRationItems(me.currentSectionId);
  432. } else {
  433. var cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  434. cacheSection.sort(function(a, b){
  435. var rst = 0;
  436. if (a.code > b.code) rst = 1
  437. else if (a.code < b.code) rst = -1;
  438. return rst;
  439. });
  440. me.mixUpdate = 1;
  441. me.showRationItems(me.currentSectionId);
  442. me.workBook.getSheet(0).setActiveCell(me.activeCell.row, me.activeCell.col);
  443. }
  444. },
  445. error:function(){
  446. }
  447. });
  448. },
  449. getRationItems: function(sectionID){
  450. if (sectionID != -1) {
  451. var me = rationOprObj;
  452. me.mixUpdate = 0;
  453. me.currentSectionId = sectionID;
  454. if (me.currentRations["_SEC_ID_" + sectionID]) {
  455. me.showRationItems(sectionID);
  456. ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  457. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  458. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  459. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  460. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  461. } else {
  462. $.ajax({
  463. type:"POST",
  464. url:"api/getRationItems",
  465. data:{"sectionID": sectionID},
  466. dataType:"json",
  467. cache:false,
  468. timeout:1000,
  469. success:function(result){
  470. if (result) {
  471. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  472. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  473. me.showRationItems(sectionID);
  474. //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  475. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  476. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  477. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  478. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  479. } else {
  480. sheetCommonObj.shieldAllCells(me.workBook.getSheet(0));
  481. sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
  482. sheetCommonObj.shieldAllCells(rationCoeOprObj.sheet);
  483. sheetCommonObj.shieldAllCells(rationAssistOprObj.sheet);
  484. }
  485. },
  486. error:function(err){
  487. alert(err);
  488. }
  489. })
  490. }
  491. }
  492. },
  493. showRationItems: function(sectionID){
  494. var me = rationOprObj;
  495. if (me.workBook) {
  496. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  497. var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  498. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  499. sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  500. if(me.mixUpdate === 1){
  501. rationGLJOprObj.getGljItems(cacheSection[cacheSection.length - 1], function () {
  502. me.workBook.focus(true);
  503. });
  504. }
  505. } else {
  506. //清除ration数据及工料机数据
  507. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  508. }
  509. }
  510. },
  511. sortByCode: function(arr){
  512. function compare(){
  513. return function (a, b) {
  514. let rst = 0;
  515. if (a.code > b.code) {
  516. rst = 1;
  517. }
  518. else if (a.code < b.code) {
  519. rst = -1;
  520. }
  521. return rst;
  522. }
  523. }
  524. arr.sort(compare());
  525. }
  526. }