ration.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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. let 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. let 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.getRationsCodes(rationRepId);
  51. me.rationDelOpr();
  52. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  53. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  54. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  55. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  56. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  57. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  58. },
  59. onCellClick: function(sender, args) {
  60. let me = rationOprObj,
  61. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  62. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  63. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
  64. me.activeCell = {row: args.row, col: args.col};
  65. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  66. sheetCommonObj.shieldAllCells(sheetGLJ);
  67. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  68. sheetCommonObj.shieldAllCells(sheetCoe);
  69. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  70. sheetCommonObj.shieldAllCells(sheetAss);
  71. if(!(args.sheetArea === GC.Spread.Sheets.SheetArea.colHeader || args.sheetArea === GC.Spread.Sheets.SheetArea.corner)){
  72. let cacheSection = me.getCache();
  73. if (cacheSection && args.row < cacheSection.length) {
  74. rationGLJOprObj.getGljItems(cacheSection[args.row], function () {
  75. me.workBook.focus(true);
  76. });
  77. rationCoeOprObj.getCoeItems(cacheSection[args.row], function () {
  78. me.workBook.focus(true);
  79. });
  80. rationAssistOprObj.getAssItems(cacheSection[args.row]);
  81. }
  82. else {
  83. rationGLJOprObj.currentRationItem = null;
  84. }
  85. };
  86. me.workBook.focus(true);
  87. },
  88. getCache: function() {
  89. let 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. let 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 (let i = removeIds.length - 1; i >= 0; i--) {
  103. for (let 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 (let i = 0; i < result.data.ops.length; i++) {
  111. for (let 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 (let i = 0; i < updateArr.length; i++) {
  120. for (let 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.mixUpdate = 1;
  185. me.mixUpdateRequest(updateArr, [], removeArr);
  186. }
  187. });
  188. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  189. me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  190. },
  191. onEnterCell: function (sender, args) {
  192. let me = rationOprObj;
  193. me.cellRowIdx = args.row;
  194. let isHasData = false;
  195. if(me.addRationItem){
  196. for(let i=0; i<me.setting.header.length; i++){
  197. if(me.addRationItem[me.setting.header[i].dataCode]){
  198. isHasData = true;
  199. break;
  200. }
  201. }
  202. }
  203. if(isHasData){
  204. if(me.editingRowIdx !== me.cellRowIdx) {
  205. let focusToCol = !me.addRationItem.code ? 0 : -1;
  206. if(focusToCol !== -1){
  207. $('#rationAlertBtn').click();
  208. me.workBook.getSheet(0).options.isProtected = true;
  209. $('#rationAlertCac').click(function () {
  210. me.workBook.getSheet(0).options.isProtected = false;
  211. });
  212. $('#rationAlertCls').click(function () {
  213. me.workBook.getSheet(0).options.isProtected = false;
  214. });
  215. $('#rationAlertCof').click(function () {
  216. me.workBook.getSheet(0).options.isProtected = false;
  217. me.addRationItem = null;
  218. for(let col=0; col<me.setting.header.length; col++){
  219. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value(me.currentEditingRation[me.setting.header[col].dataCode]);
  220. }
  221. });
  222. }
  223. }
  224. }
  225. },
  226. onCellEditStart: function(sender, args) {
  227. let me = rationOprObj;
  228. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  229. me.currentEditingRation = rObj;
  230. let cacheSection = me.getCache();
  231. if (cacheSection) {
  232. for (let j = 0; j < cacheSection.length; j++) {
  233. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  234. rObj["ID"] = cacheSection[j]["ID"];
  235. break;
  236. }
  237. }
  238. }
  239. },
  240. onCellEditEnd: function(sender, args) {
  241. let me = rationOprObj, rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  242. updateArr = [], addArr = [];
  243. let dataCode = me.setting.header[args.col].dataCode;
  244. me.editingRowIdx = args.row;
  245. if (me.currentEditingRation["ID"]) {
  246. rObj["ID"] = me.currentEditingRation["ID"];
  247. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  248. me.addRationItem = rObj;
  249. if(dataCode === 'code'){
  250. if(me.rationsCodes.indexOf(rObj.code) === -1){
  251. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code), 1);
  252. me.rationsCodes.push(rObj.code);
  253. updateArr.push(rObj);
  254. }
  255. else{
  256. alert("编码已存在!");
  257. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  258. }
  259. }
  260. else{
  261. updateArr.push(rObj);
  262. }
  263. }
  264. }
  265. else if(!me.currentEditingRation["ID"]) {
  266. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  267. //addArr.push(rObj);
  268. me.addRationItem = rObj;
  269. if(rObj.code && rObj.code.toString().trim().length > 0){
  270. if(me.rationsCodes.indexOf(rObj.code) === -1){
  271. //jobContent
  272. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  273. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  274. }
  275. me.setInitPrc(rObj);
  276. addArr.push(rObj);
  277. me.rationsCodes.push(rObj.code);
  278. me.addRationItem = null;
  279. }
  280. else{
  281. alert('编码已存在!');
  282. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  283. }
  284. /*else if(!rObj.code && rObj.code === ''){
  285. $('#alertModalBtn').click();
  286. me.workBook.getSheet(0).options.isProtected = true;
  287. $('#alertModalCls').click(function () {
  288. me.workBook.getSheet(0).options.isProtected = false;
  289. me.addRationItem.code = '';
  290. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  291. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  292. });
  293. $('#alertModalCof').click(function () {
  294. me.workBook.getSheet(0).options.isProtected = false;
  295. me.addRationItem.code = '';
  296. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  297. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  298. });
  299. }*/
  300. }
  301. else if(rObj.code && rObj.code.toString.trim().length === 0){
  302. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  303. }
  304. }
  305. }
  306. if (updateArr.length > 0 || addArr.length > 0) {
  307. me.currentEditingRation = null;
  308. me.mixUpdate = 1;
  309. me.mixUpdateRequest(updateArr, addArr, []);
  310. }
  311. },
  312. onClipboardPasting: function(sender, args) {
  313. let me = rationOprObj;
  314. },
  315. onClipboardPasted: function(e, info) {
  316. let me = rationOprObj;
  317. let cacheSection = me.getCache();
  318. let updateArr = [], addArr = [];
  319. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  320. let failPasteArr = [];
  321. for (let i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
  322. if (cacheSection) {
  323. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  324. items[i].unit = typeof cacheSection[rowIdx].unit !== 'undefined' && !cacheSection[rowIdx] ? cacheSection[rowIdx].unit : '';
  325. }
  326. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  327. if(me.rationsCodes.indexOf(items[i].code) === -1){
  328. //jobConten
  329. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  330. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  331. }
  332. me.setInitPrc(items[i]);
  333. addArr.push(items[i]);
  334. me.rationsCodes.push(items[i].code);
  335. }
  336. else{
  337. failPasteArr.push(items[i].code);
  338. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  339. }
  340. }
  341. else if(cacheSection[rowIdx]){
  342. for(let col = 0; col < me.setting.header.length; col++){
  343. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  344. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  345. }
  346. }
  347. if(info.cellRange.col === 0){
  348. if(me.rationsCodes.indexOf(items[i].code) === -1){
  349. items[i].ID = cacheSection[rowIdx].ID;
  350. updateArr.push(items[i]);
  351. }
  352. else{
  353. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  354. }
  355. }
  356. else{
  357. items[i].ID = cacheSection[rowIdx].ID;
  358. updateArr.push(items[i]);
  359. }
  360. }
  361. } else {
  362. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  363. items[i].unit = '';
  364. }
  365. //add
  366. if(info.cellRange.col === 0){
  367. //是否含有已存在的编号
  368. if(me.rationsCodes.indexOf(items[i].code) === -1){
  369. //jobConten
  370. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  371. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  372. }
  373. me.setInitPrc(items[i]);
  374. addArr.push(items[i]);
  375. }
  376. else{
  377. failPasteArr.push(items[i]);
  378. }
  379. }
  380. }
  381. };
  382. /* if(failPasteArr.length > 0 && !(updateArr.length > 0 || addArr.length > 0)){
  383. me.showRationItems(me.currentSectionId);
  384. }*/
  385. if (updateArr.length > 0 || addArr.length > 0) {
  386. me.mixUpdate = 1;
  387. me.mixUpdateRequest(updateArr, addArr, []);
  388. }
  389. },
  390. setInitPrc: function (obj) {
  391. obj.labourPrice = 0;
  392. obj.materialPrice = 0;
  393. obj.machinePrice = 0;
  394. obj.basePrice = 0;
  395. },
  396. isValidUnit: function (rationObj, validUnits) {
  397. let rst = true;
  398. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  399. rst = false;
  400. }
  401. return rst;
  402. },
  403. getRationsCodes: function (repId) {
  404. let me = rationOprObj;
  405. $.ajax({
  406. type: 'post',
  407. url: 'api/getRationsCodes',
  408. data: {data: JSON.stringify({repId: repId})},
  409. dataType: 'json',
  410. success: function (result) {
  411. if(!result.error){
  412. me.rationsCodes = result.data;
  413. }
  414. }
  415. })
  416. },
  417. mixUpdateRequest: function(updateArr, addArr, removeIds) {
  418. let me = rationOprObj;
  419. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, true);
  420. $.ajax({
  421. type:"POST",
  422. url:"api/mixUpdateRationItems",
  423. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  424. dataType:"json",
  425. cache:false,
  426. timeout:5000,
  427. success:function(result){
  428. if (result.error) {
  429. alert(`error`);
  430. me.getRationItems(me.currentSectionId);
  431. } else {
  432. let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  433. cacheSection.sort(function(a, b){
  434. let rst = 0;
  435. if (a.code > b.code) rst = 1
  436. else if (a.code < b.code) rst = -1;
  437. return rst;
  438. });
  439. //jobContent
  440. if(jobContentOprObj ){
  441. jobContentOprObj.currentRationItems = cacheSection;
  442. jobContentOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, jobContentOprObj.radios);
  443. if(cacheSection.length === 0){
  444. jobContentOprObj.updateSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  445. }
  446. jobContentOprObj.setRadiosChecked(jobContentOprObj.currentSituation, jobContentOprObj.radios);
  447. if(jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
  448. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  449. }
  450. }
  451. me.showRationItems(me.currentSectionId);
  452. me.mixUpdate = 0;
  453. }
  454. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, false);
  455. },
  456. error:function(){
  457. }
  458. });
  459. },
  460. getRationItems: function(sectionID){
  461. if (sectionID != -1) {
  462. let me = rationOprObj;
  463. me.mixUpdate = 0;
  464. me.currentSectionId = sectionID;
  465. if (me.currentRations["_SEC_ID_" + sectionID]) {
  466. //jobContent--
  467. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  468. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  469. //jobContent--
  470. me.showRationItems(sectionID);
  471. ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  472. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  473. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  474. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  475. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  476. } else {
  477. $.ajax({
  478. type:"POST",
  479. url:"api/getRationItems",
  480. data:{"sectionID": sectionID},
  481. dataType:"json",
  482. cache:false,
  483. timeout:1000,
  484. success:function(result){
  485. if (result) {
  486. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  487. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  488. //job--
  489. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  490. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  491. //job--
  492. me.showRationItems(sectionID);
  493. //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  494. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  495. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  496. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  497. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  498. } else {
  499. sheetCommonObj.shieldAllCells(me.workBook.getSheet(0));
  500. sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
  501. sheetCommonObj.shieldAllCells(rationCoeOprObj.sheet);
  502. sheetCommonObj.shieldAllCells(rationAssistOprObj.sheet);
  503. }
  504. },
  505. error:function(err){
  506. alert(err);
  507. }
  508. })
  509. }
  510. }
  511. },
  512. setCombo: function (sheet, items) {
  513. sheet.suspendPaint();
  514. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  515. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  516. combo.items(items);
  517. combo.itemHeight(10);
  518. sheet.getCell(i, 2).cellType(combo);
  519. }
  520. sheet.resumePaint();
  521. },
  522. showRationItems: function(sectionID){
  523. let me = rationOprObj;
  524. if (me.workBook) {
  525. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  526. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  527. //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  528. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  529. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  530. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 4, true);
  531. //combo
  532. me.setCombo(me.workBook.getActiveSheet(), rationUnits);
  533. if(me.mixUpdate === 1){
  534. rationGLJOprObj.getGljItems(cacheSection[cacheSection.length - 1], function () {
  535. me.workBook.focus(true);
  536. });
  537. }
  538. } else {
  539. //清除ration数据及工料机数据
  540. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  541. }
  542. }
  543. },
  544. sortByCode: function(arr){
  545. function compare(){
  546. return function (a, b) {
  547. let rst = 0;
  548. if (a.code > b.code) {
  549. rst = 1;
  550. }
  551. else if (a.code < b.code) {
  552. rst = -1;
  553. }
  554. return rst;
  555. }
  556. }
  557. arr.sort(compare());
  558. }
  559. }