ration.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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.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.RangeChanged, me.onRangeChanged);
  58. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  59. },
  60. onCellClick: function(sender, args) {
  61. var me = rationOprObj,
  62. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  63. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  64. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
  65. me.activeCell = {row: args.row, col: args.col};
  66. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  67. sheetCommonObj.shieldAllCells(sheetGLJ);
  68. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  69. sheetCommonObj.shieldAllCells(sheetCoe);
  70. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  71. sheetCommonObj.shieldAllCells(sheetAss);
  72. if(!(args.sheetArea === GC.Spread.Sheets.SheetArea.colHeader || args.sheetArea === GC.Spread.Sheets.SheetArea.corner)){
  73. var cacheSection = me.getCache();
  74. if (cacheSection && args.row < cacheSection.length) {
  75. rationGLJOprObj.getGljItems(cacheSection[args.row], function () {
  76. me.workBook.focus(true);
  77. });
  78. rationCoeOprObj.getCoeItems(cacheSection[args.row], function () {
  79. me.workBook.focus(true);
  80. });
  81. rationAssistOprObj.getAssItems(cacheSection[args.row]);
  82. }
  83. else {
  84. rationGLJOprObj.currentRationItem = null;
  85. }
  86. };
  87. me.workBook.focus(true);
  88. },
  89. getCache: function() {
  90. var me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  91. if (!(rst)) {
  92. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  93. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  94. }
  95. return rst;
  96. },
  97. updateCache: function(addArr, updateArr, removeIds, result) {
  98. var me = this, cacheSection = me.getCache();
  99. if (addArr.length > 0) {
  100. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  101. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  102. }
  103. for (var i = removeIds.length - 1; i >= 0; i--) {
  104. for (var j = cacheSection.length - 1; j >= 0 ; j--) {
  105. if (cacheSection[j]["ID"] == removeIds[i]) {
  106. cacheSection.splice(j,1);
  107. }
  108. }
  109. }
  110. if (result && result.data.ops && result.data.ops.length > 0) {
  111. for (var i = 0; i < result.data.ops.length; i++) {
  112. for (var j = 0; j < cacheSection.length; j++) {
  113. if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
  114. cacheSection[j]["ID"] = result.data.ops[i]["ID"];
  115. cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
  116. }
  117. }
  118. }
  119. }
  120. for (var i = 0; i < updateArr.length; i++) {
  121. for (var j = 0; j < cacheSection.length; j++) {
  122. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  123. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  124. cacheSection[j] = updateArr[i];
  125. }
  126. } else {
  127. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  128. cacheSection[j] = updateArr[i];
  129. }
  130. }
  131. }
  132. }
  133. return cacheSection;
  134. },
  135. rationDelOpr: function () {
  136. let me = rationOprObj;
  137. me.workBook.commandManager().register('rationDelete', function () {
  138. let rationSheet = me.workBook.getActiveSheet();
  139. let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
  140. let cacheSection = me.getCache();
  141. if(sels.length > 0){
  142. for(let sel = 0; sel < sels.length; sel++){
  143. if(sels[sel].colCount === me.setting.header.length){
  144. if(cacheSection){
  145. for(let i = 0; i < sels[sel].rowCount; i++){
  146. if(sels[sel].row + i < cacheSection.length){
  147. removeArr.push(cacheSection[sels[sel].row + i].ID);
  148. me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code), 1);
  149. }
  150. }
  151. }
  152. }
  153. else{
  154. if(sels[sel].col === 0){
  155. $('#alertText').text("编号不能为空,修改失败!");
  156. $('#alertModalBtn').click();
  157. rationSheet.options.isProtected = true;
  158. $('#alertModalCls').click(function () {
  159. rationSheet.options.isProtected = false;
  160. });
  161. $('#alertModalCof').click(function () {
  162. rationSheet.options.isProtected = false;
  163. })
  164. }
  165. else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
  166. if(cacheSection){
  167. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  168. if(sels[sel].row + i < cacheSection.length){
  169. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  170. if(lockCols.indexOf(col) === -1){
  171. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
  172. }
  173. }
  174. }
  175. if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
  176. updateArr.push(cacheSection[sels[sel].row + i]);
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. if(updateArr.length > 0 || removeArr.length > 0){
  185. me.mixUpdate = 1;
  186. me.mixUpdateRequest(updateArr, [], removeArr);
  187. }
  188. });
  189. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  190. me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  191. },
  192. onRangeChanged: function(sender, args) {
  193. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  194. var me = rationOprObj, updateArr = [], removeArr = [];
  195. var cacheSection = me.getCache();
  196. if (cacheSection) {
  197. for (var i = 0; i < args.rowCount; i++) {
  198. //var hasUpdate = false, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row + i),
  199. var hasUpdate = false, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row + i),
  200. isEmpty = sheetCommonObj.chkIfEmpty(rObj, me.setting);
  201. for (var j = 0; j < cacheSection.length; j++) {
  202. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  203. rObj["ID"] = cacheSection[j]["ID"];
  204. hasUpdate = true;
  205. break;
  206. }
  207. }
  208. if(isEmpty){
  209. if(args.row + i < cacheSection.length){
  210. rObj.ID = cacheSection[args.row + i].ID;
  211. removeArr.push(rObj.ID);
  212. }
  213. }
  214. else{
  215. }
  216. if (hasUpdate) {
  217. if (isEmpty) {
  218. removeArr.push(rObj);
  219. } else updateArr.push(rObj);
  220. } else if (isEmpty) {
  221. if (args.row + i < cacheSection.length) {
  222. rObj["ID"] = cacheSection[args.row + i]["ID"];
  223. removeArr.push(rObj["ID"]);
  224. }
  225. }
  226. }
  227. // me.mixUpdateRequest(updateArr, [], removeArr);
  228. //removeRationItems
  229. }
  230. }
  231. },
  232. onEnterCell: function (sender, args) {
  233. let me = rationOprObj;
  234. me.cellRowIdx = args.row;
  235. let isHasData = false;
  236. if(me.addRationItem){
  237. for(let i=0; i<me.setting.header.length; i++){
  238. if(me.addRationItem[me.setting.header[i].dataCode]){
  239. isHasData = true;
  240. break;
  241. }
  242. }
  243. }
  244. if(isHasData){
  245. if(me.editingRowIdx !== me.cellRowIdx) {
  246. let focusToCol = !me.addRationItem.code ? 0 : -1;
  247. // else {
  248. if(focusToCol !== -1){
  249. $('#rationAlertBtn').click();
  250. me.workBook.getSheet(0).options.isProtected = true;
  251. $('#rationAlertCac').click(function () {
  252. me.workBook.getSheet(0).options.isProtected = false;
  253. //me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  254. });
  255. $('#rationAlertCls').click(function () {
  256. me.workBook.getSheet(0).options.isProtected = false;
  257. // me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  258. });
  259. $('#rationAlertCof').click(function () {
  260. me.workBook.getSheet(0).options.isProtected = false;
  261. me.addRationItem = null;
  262. for(let col=0; col<me.setting.header.length; col++){
  263. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value(me.currentEditingRation[me.setting.header[col].dataCode]);
  264. }
  265. //me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
  266. });
  267. }
  268. // }
  269. }
  270. }
  271. },
  272. onCellEditStart: function(sender, args) {
  273. var me = rationOprObj;
  274. //var rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
  275. var rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  276. me.currentEditingRation = rObj;
  277. var cacheSection = me.getCache();
  278. if (cacheSection) {
  279. for (var j = 0; j < cacheSection.length; j++) {
  280. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  281. rObj["ID"] = cacheSection[j]["ID"];
  282. break;
  283. }
  284. }
  285. }
  286. },
  287. onCellEditEnd: function(sender, args) {
  288. //var me = rationOprObj, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row),
  289. var me = rationOprObj, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  290. updateArr = [], addArr = [];
  291. let dataCode = me.setting.header[args.col].dataCode;
  292. me.editingRowIdx = args.row;
  293. if (me.currentEditingRation["ID"]) {
  294. rObj["ID"] = me.currentEditingRation["ID"];
  295. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  296. me.addRationItem = rObj;
  297. if(dataCode === 'code'){
  298. if(me.rationsCodes.indexOf(rObj.code) === -1){
  299. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code), 1);
  300. me.rationsCodes.push(rObj.code);
  301. updateArr.push(rObj);
  302. }
  303. else{
  304. alert("编码已存在!");
  305. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  306. }
  307. }
  308. else{
  309. updateArr.push(rObj);
  310. }
  311. }
  312. }
  313. else if(!me.currentEditingRation["ID"]) {
  314. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  315. //addArr.push(rObj);
  316. me.addRationItem = rObj;
  317. if(rObj.code && rObj.code.toString().trim().length > 0){
  318. if(me.rationsCodes.indexOf(rObj.code) === -1){
  319. //jobContent
  320. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  321. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  322. }
  323. addArr.push(rObj);
  324. me.rationsCodes.push(rObj.code);
  325. me.addRationItem = null;
  326. }
  327. else{
  328. alert('编码已存在!');
  329. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  330. }
  331. /*else if(!rObj.code && rObj.code === ''){
  332. $('#alertModalBtn').click();
  333. me.workBook.getSheet(0).options.isProtected = true;
  334. $('#alertModalCls').click(function () {
  335. me.workBook.getSheet(0).options.isProtected = false;
  336. me.addRationItem.code = '';
  337. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  338. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  339. });
  340. $('#alertModalCof').click(function () {
  341. me.workBook.getSheet(0).options.isProtected = false;
  342. me.addRationItem.code = '';
  343. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  344. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  345. });
  346. }*/
  347. }
  348. else if(rObj.code && rObj.code.toString.trim().length === 0){
  349. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  350. }
  351. }
  352. }
  353. if (updateArr.length > 0 || addArr.length > 0) {
  354. me.currentEditingRation = null;
  355. me.mixUpdate = 1;
  356. me.mixUpdateRequest(updateArr, addArr, []);
  357. }
  358. },
  359. onClipboardPasting: function(sender, args) {
  360. var me = rationOprObj;
  361. /* if (args.cellRange.colCount != me.setting.header.length) {
  362. args.cancel = true;
  363. }*/
  364. },
  365. onClipboardPasted: function(e, info) {
  366. var me = rationOprObj;
  367. var cacheSection = me.getCache();
  368. var updateArr = [], addArr = [];
  369. var items = sheetCommonObj.analyzePasteData(me.setting, info);
  370. let failPasteArr = [];
  371. for (var i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
  372. if (cacheSection) {
  373. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  374. items[i].unit = typeof cacheSection[rowIdx].unit !== 'undefined' && !cacheSection[rowIdx] ? cacheSection[rowIdx].unit : '';
  375. }
  376. //var hasCacheItem = false;
  377. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  378. if(me.rationsCodes.indexOf(items[i].code) === -1){
  379. //jobConten
  380. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  381. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  382. }
  383. addArr.push(items[i]);
  384. me.rationsCodes.push(items[i].code);
  385. }
  386. else{
  387. failPasteArr.push(items[i].code);
  388. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  389. }
  390. }
  391. else if(cacheSection[rowIdx]){
  392. for(let col = 0; col < me.setting.header.length; col++){
  393. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  394. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  395. }
  396. }
  397. if(info.cellRange.col === 0){
  398. if(me.rationsCodes.indexOf(items[i].code) === -1){
  399. items[i].ID = cacheSection[rowIdx].ID;
  400. updateArr.push(items[i]);
  401. }
  402. else{
  403. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  404. }
  405. }
  406. else{
  407. items[i].ID = cacheSection[rowIdx].ID;
  408. updateArr.push(items[i]);
  409. }
  410. }
  411. } else {
  412. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  413. items[i].unit = '';
  414. }
  415. //add
  416. if(info.cellRange.col === 0){
  417. //是否含有已存在的编号
  418. if(me.rationsCodes.indexOf(items[i].code) === -1){
  419. //jobConten
  420. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  421. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  422. }
  423. addArr.push(items[i]);
  424. }
  425. else{
  426. failPasteArr.push(items[i]);
  427. }
  428. }
  429. }
  430. };
  431. /* if(failPasteArr.length > 0 && !(updateArr.length > 0 || addArr.length > 0)){
  432. me.showRationItems(me.currentSectionId);
  433. }*/
  434. if (updateArr.length > 0 || addArr.length > 0) {
  435. me.mixUpdate = 1;
  436. me.mixUpdateRequest(updateArr, addArr, []);
  437. }
  438. },
  439. isValidUnit: function (rationObj, validUnits) {
  440. let rst = true;
  441. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  442. rst = false;
  443. }
  444. return rst;
  445. },
  446. getRationsCodes: function (repId) {
  447. let me = rationOprObj;
  448. $.ajax({
  449. type: 'post',
  450. url: 'api/getRationsCodes',
  451. data: {data: JSON.stringify({repId: repId})},
  452. dataType: 'json',
  453. success: function (result) {
  454. if(!result.error){
  455. me.rationsCodes = result.data;
  456. }
  457. }
  458. })
  459. },
  460. mixUpdateRequest: function(updateArr, addArr, removeIds) {
  461. var me = rationOprObj;
  462. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, true);
  463. $.ajax({
  464. type:"POST",
  465. url:"api/mixUpdateRationItems",
  466. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  467. dataType:"json",
  468. cache:false,
  469. timeout:5000,
  470. success:function(result){
  471. if (result.error) {
  472. alert(`error`);
  473. me.getRationItems(me.currentSectionId);
  474. } else {
  475. var cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  476. cacheSection.sort(function(a, b){
  477. var rst = 0;
  478. if (a.code > b.code) rst = 1
  479. else if (a.code < b.code) rst = -1;
  480. return rst;
  481. });
  482. //jobContent
  483. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
  484. jobContentOprObj.currentRationItems = cacheSection;
  485. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  486. }
  487. me.showRationItems(me.currentSectionId);
  488. me.mixUpdate = 0;
  489. // me.workBook.getSheet(0).setActiveCell(me.activeCell.row, me.activeCell.col);
  490. }
  491. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, false);
  492. },
  493. error:function(){
  494. }
  495. });
  496. },
  497. getRationItems: function(sectionID){
  498. if (sectionID != -1) {
  499. var me = rationOprObj;
  500. me.mixUpdate = 0;
  501. me.currentSectionId = sectionID;
  502. if (me.currentRations["_SEC_ID_" + sectionID]) {
  503. //jobContent--
  504. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  505. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  506. //jobContent--
  507. me.showRationItems(sectionID);
  508. ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  509. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  510. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  511. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  512. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  513. } else {
  514. $.ajax({
  515. type:"POST",
  516. url:"api/getRationItems",
  517. data:{"sectionID": sectionID},
  518. dataType:"json",
  519. cache:false,
  520. timeout:1000,
  521. success:function(result){
  522. if (result) {
  523. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  524. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  525. //job--
  526. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  527. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  528. //job--
  529. me.showRationItems(sectionID);
  530. //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  531. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  532. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  533. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  534. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  535. } else {
  536. sheetCommonObj.shieldAllCells(me.workBook.getSheet(0));
  537. sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
  538. sheetCommonObj.shieldAllCells(rationCoeOprObj.sheet);
  539. sheetCommonObj.shieldAllCells(rationAssistOprObj.sheet);
  540. }
  541. },
  542. error:function(err){
  543. alert(err);
  544. }
  545. })
  546. }
  547. }
  548. },
  549. setCombo: function (sheet, items) {
  550. sheet.suspendPaint();
  551. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  552. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  553. combo.items(items);
  554. combo.itemHeight(10);
  555. sheet.getCell(i, 2).cellType(combo);
  556. }
  557. sheet.resumePaint();
  558. },
  559. showRationItems: function(sectionID){
  560. var me = rationOprObj;
  561. if (me.workBook) {
  562. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  563. var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  564. //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  565. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  566. sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  567. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 4, true);
  568. //combo
  569. me.setCombo(me.workBook.getActiveSheet(), rationUnits);
  570. if(me.mixUpdate === 1){
  571. rationGLJOprObj.getGljItems(cacheSection[cacheSection.length - 1], function () {
  572. me.workBook.focus(true);
  573. });
  574. }
  575. } else {
  576. //清除ration数据及工料机数据
  577. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  578. }
  579. }
  580. },
  581. sortByCode: function(arr){
  582. function compare(){
  583. return function (a, b) {
  584. let rst = 0;
  585. if (a.code > b.code) {
  586. rst = 1;
  587. }
  588. else if (a.code < b.code) {
  589. rst = -1;
  590. }
  591. return rst;
  592. }
  593. }
  594. arr.sort(compare());
  595. }
  596. }