ration.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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. if(!gljLibID || typeof gljLibID === 'undefined' || gljLibID == -1){
  46. alert("没有引用工料机库!");
  47. window.location.href = "/rationRepository/main";
  48. }
  49. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  50. me.workBook.options.showHorizontalScrollbar = true;
  51. me.getRationsCodes(rationRepId);
  52. me.rationDelOpr();
  53. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  54. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  55. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  56. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  57. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  58. //me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  59. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  60. },
  61. onCellClick: function(sender, args) {
  62. var me = rationOprObj,
  63. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  64. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  65. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
  66. me.activeCell = {row: args.row, col: args.col};
  67. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  68. sheetCommonObj.shieldAllCells(sheetGLJ);
  69. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  70. sheetCommonObj.shieldAllCells(sheetCoe);
  71. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  72. sheetCommonObj.shieldAllCells(sheetAss);
  73. if(!(args.sheetArea === GC.Spread.Sheets.SheetArea.colHeader || args.sheetArea === GC.Spread.Sheets.SheetArea.corner)){
  74. var cacheSection = me.getCache();
  75. if (cacheSection && args.row < cacheSection.length) {
  76. rationGLJOprObj.getGljItems(cacheSection[args.row], function () {
  77. me.workBook.focus(true);
  78. });
  79. rationCoeOprObj.getCoeItems(cacheSection[args.row], function () {
  80. me.workBook.focus(true);
  81. });
  82. rationAssistOprObj.getAssItems(cacheSection[args.row]);
  83. }
  84. };
  85. me.workBook.focus(true);
  86. },
  87. getCache: function() {
  88. var me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  89. if (!(rst)) {
  90. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  91. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  92. }
  93. return rst;
  94. },
  95. updateCache: function(addArr, updateArr, removeIds, result) {
  96. var me = this, cacheSection = me.getCache();
  97. if (addArr.length > 0) {
  98. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  99. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  100. }
  101. for (var i = removeIds.length - 1; i >= 0; i--) {
  102. for (var j = cacheSection.length - 1; j >= 0 ; j--) {
  103. if (cacheSection[j]["ID"] == removeIds[i]) {
  104. cacheSection.splice(j,1);
  105. }
  106. }
  107. }
  108. if (result && result.data.ops && result.data.ops.length > 0) {
  109. for (var i = 0; i < result.data.ops.length; i++) {
  110. for (var j = 0; j < cacheSection.length; j++) {
  111. if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
  112. cacheSection[j]["ID"] = result.data.ops[i]["ID"];
  113. cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
  114. }
  115. }
  116. }
  117. }
  118. for (var i = 0; i < updateArr.length; i++) {
  119. for (var j = 0; j < cacheSection.length; j++) {
  120. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  121. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  122. cacheSection[j] = updateArr[i];
  123. }
  124. } else {
  125. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  126. cacheSection[j] = updateArr[i];
  127. }
  128. }
  129. }
  130. }
  131. return cacheSection;
  132. },
  133. rationDelOpr: function () {
  134. let me = rationOprObj;
  135. me.workBook.commandManager().register('rationDelete', function () {
  136. let rationSheet = me.workBook.getActiveSheet();
  137. let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
  138. let cacheSection = me.getCache();
  139. if(sels.length > 0){
  140. for(let sel = 0; sel < sels.length; sel++){
  141. if(sels[sel].colCount === me.setting.header.length){
  142. if(cacheSection){
  143. for(let i = 0; i < sels[sel].rowCount; i++){
  144. if(sels[sel].row + i < cacheSection.length){
  145. removeArr.push(cacheSection[sels[sel].row + i].ID);
  146. me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code), 1);
  147. }
  148. }
  149. }
  150. }
  151. else{
  152. if(sels[sel].col === 0){
  153. $('#alertText').text("编号不能为空,修改失败!");
  154. $('#alertModalBtn').click();
  155. rationSheet.options.isProtected = true;
  156. $('#alertModalCls').click(function () {
  157. rationSheet.options.isProtected = false;
  158. });
  159. $('#alertModalCof').click(function () {
  160. rationSheet.options.isProtected = false;
  161. })
  162. }
  163. else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
  164. if(cacheSection){
  165. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  166. if(sels[sel].row + i < cacheSection.length){
  167. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  168. if(lockCols.indexOf(col) === -1){
  169. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
  170. }
  171. }
  172. }
  173. if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
  174. updateArr.push(cacheSection[sels[sel].row + i]);
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. if(updateArr.length > 0 || removeArr.length > 0){
  183. me.mixUpdate = 1;
  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. console.log(rObj);
  292. if (me.currentEditingRation["ID"]) {
  293. rObj["ID"] = me.currentEditingRation["ID"];
  294. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  295. me.addRationItem = rObj;
  296. if(dataCode === 'code'){
  297. if(me.rationsCodes.indexOf(rObj.code) === -1){
  298. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code), 1);
  299. me.rationsCodes.push(rObj.code);
  300. updateArr.push(rObj);
  301. }
  302. else{
  303. alert("编码已存在!");
  304. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  305. }
  306. }
  307. else{
  308. updateArr.push(rObj);
  309. }
  310. }
  311. }
  312. else if(!me.currentEditingRation["ID"]) {
  313. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  314. //addArr.push(rObj);
  315. me.addRationItem = rObj;
  316. if(rObj.code && rObj.code.trim().length > 0){
  317. if(me.rationsCodes.indexOf(rObj.code) === -1){
  318. addArr.push(rObj);
  319. me.rationsCodes.push(rObj.code);
  320. me.addRationItem = null;
  321. }
  322. else{
  323. alert('编码已存在!');
  324. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  325. }
  326. /*else if(!rObj.code && rObj.code === ''){
  327. $('#alertModalBtn').click();
  328. me.workBook.getSheet(0).options.isProtected = true;
  329. $('#alertModalCls').click(function () {
  330. me.workBook.getSheet(0).options.isProtected = false;
  331. me.addRationItem.code = '';
  332. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  333. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  334. });
  335. $('#alertModalCof').click(function () {
  336. me.workBook.getSheet(0).options.isProtected = false;
  337. me.addRationItem.code = '';
  338. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  339. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  340. });
  341. }*/
  342. }
  343. else if(rObj.code && rObj.code.trim().length === 0){
  344. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  345. }
  346. }
  347. }
  348. if (updateArr.length > 0 || addArr.length > 0) {
  349. me.currentEditingRation = null;
  350. me.mixUpdate = 1;
  351. me.mixUpdateRequest(updateArr, addArr, []);
  352. }
  353. },
  354. onClipboardPasting: function(sender, args) {
  355. var me = rationOprObj;
  356. /* if (args.cellRange.colCount != me.setting.header.length) {
  357. args.cancel = true;
  358. }*/
  359. },
  360. onClipboardPasted: function(e, info) {
  361. var me = rationOprObj;
  362. var cacheSection = me.getCache();
  363. var updateArr = [], addArr = [];
  364. var items = sheetCommonObj.analyzePasteData(me.setting, info);
  365. let failPasteArr = [];
  366. for (var i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
  367. if (cacheSection) {
  368. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  369. items[i].unit = typeof cacheSection[rowIdx].unit !== 'undefined' && !cacheSection[rowIdx] ? cacheSection[rowIdx].unit : '';
  370. };
  371. //var hasCacheItem = false;
  372. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  373. if(me.rationsCodes.indexOf(items[i].code) === -1){
  374. addArr.push(items[i]);
  375. me.rationsCodes.push(items[i].code);
  376. }
  377. else{
  378. failPasteArr.push(items[i].code);
  379. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  380. }
  381. }
  382. else if(cacheSection[rowIdx]){
  383. for(let col = 0; col < me.setting.header.length; col++){
  384. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  385. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  386. }
  387. }
  388. if(info.cellRange.col === 0){
  389. if(me.rationsCodes.indexOf(items[i].code) === -1){
  390. items[i].ID = cacheSection[rowIdx].ID;
  391. updateArr.push(items[i]);
  392. }
  393. else{
  394. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  395. }
  396. }
  397. else{
  398. items[i].ID = cacheSection[rowIdx].ID;
  399. updateArr.push(items[i]);
  400. }
  401. }
  402. } else {
  403. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  404. items[i].unit = '';
  405. };
  406. //add
  407. if(info.cellRange.col === 0){
  408. //是否含有已存在的编号
  409. if(me.rationsCodes.indexOf(items[i].code) === -1){
  410. addArr.push(items[i]);
  411. }
  412. else{
  413. failPasteArr.push(items[i]);
  414. }
  415. }
  416. }
  417. };
  418. /* if(failPasteArr.length > 0 && !(updateArr.length > 0 || addArr.length > 0)){
  419. me.showRationItems(me.currentSectionId);
  420. }*/
  421. if (updateArr.length > 0 || addArr.length > 0) {
  422. me.mixUpdate = 1;
  423. me.mixUpdateRequest(updateArr, addArr, []);
  424. }
  425. },
  426. isValidUnit: function (rationObj, validUnits) {
  427. let rst = true;
  428. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  429. rst = false;
  430. }
  431. return rst;
  432. },
  433. getRationsCodes: function (repId) {
  434. let me = rationOprObj;
  435. $.ajax({
  436. type: 'post',
  437. url: 'api/getRationsCodes',
  438. data: {data: JSON.stringify({repId: repId})},
  439. dataType: 'json',
  440. success: function (result) {
  441. if(!result.error){
  442. me.rationsCodes = result.data;
  443. }
  444. }
  445. })
  446. },
  447. mixUpdateRequest: function(updateArr, addArr, removeIds) {
  448. var me = rationOprObj;
  449. $.ajax({
  450. type:"POST",
  451. url:"api/mixUpdateRationItems",
  452. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  453. dataType:"json",
  454. cache:false,
  455. timeout:5000,
  456. success:function(result){
  457. if (result.error) {
  458. alert(`error`);
  459. me.getRationItems(me.currentSectionId);
  460. } else {
  461. var cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  462. cacheSection.sort(function(a, b){
  463. var rst = 0;
  464. if (a.code > b.code) rst = 1
  465. else if (a.code < b.code) rst = -1;
  466. return rst;
  467. });
  468. me.showRationItems(me.currentSectionId);
  469. me.mixUpdate = 0;
  470. me.workBook.getSheet(0).setActiveCell(me.activeCell.row, me.activeCell.col);
  471. }
  472. },
  473. error:function(){
  474. }
  475. });
  476. },
  477. getRationItems: function(sectionID){
  478. if (sectionID != -1) {
  479. var me = rationOprObj;
  480. me.mixUpdate = 0;
  481. me.currentSectionId = sectionID;
  482. if (me.currentRations["_SEC_ID_" + sectionID]) {
  483. me.showRationItems(sectionID);
  484. ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  485. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  486. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  487. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  488. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  489. } else {
  490. $.ajax({
  491. type:"POST",
  492. url:"api/getRationItems",
  493. data:{"sectionID": sectionID},
  494. dataType:"json",
  495. cache:false,
  496. timeout:1000,
  497. success:function(result){
  498. if (result) {
  499. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  500. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  501. me.showRationItems(sectionID);
  502. //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  503. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  504. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  505. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  506. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  507. } else {
  508. sheetCommonObj.shieldAllCells(me.workBook.getSheet(0));
  509. sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
  510. sheetCommonObj.shieldAllCells(rationCoeOprObj.sheet);
  511. sheetCommonObj.shieldAllCells(rationAssistOprObj.sheet);
  512. }
  513. },
  514. error:function(err){
  515. alert(err);
  516. }
  517. })
  518. }
  519. }
  520. },
  521. setCombo: function (sheet, items) {
  522. sheet.suspendPaint();
  523. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  524. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  525. combo.items(items);
  526. combo.itemHeight(10);
  527. sheet.getCell(i, 2).cellType(combo);
  528. }
  529. sheet.resumePaint();
  530. },
  531. showRationItems: function(sectionID){
  532. var me = rationOprObj;
  533. if (me.workBook) {
  534. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  535. var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  536. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  537. sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  538. //combo
  539. me.setCombo(me.workBook.getActiveSheet(), rationUnits);
  540. if(me.mixUpdate === 1){
  541. rationGLJOprObj.getGljItems(cacheSection[cacheSection.length - 1], function () {
  542. me.workBook.focus(true);
  543. });
  544. }
  545. } else {
  546. //清除ration数据及工料机数据
  547. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  548. }
  549. }
  550. },
  551. sortByCode: function(arr){
  552. function compare(){
  553. return function (a, b) {
  554. let rst = 0;
  555. if (a.code > b.code) {
  556. rst = 1;
  557. }
  558. else if (a.code < b.code) {
  559. rst = -1;
  560. }
  561. return rst;
  562. }
  563. }
  564. arr.sort(compare());
  565. }
  566. }