ration.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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. if (me.currentEditingRation["ID"]) {
  292. rObj["ID"] = me.currentEditingRation["ID"];
  293. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  294. me.addRationItem = rObj;
  295. if(dataCode === 'code'){
  296. if(me.rationsCodes.indexOf(rObj.code) === -1){
  297. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code), 1);
  298. me.rationsCodes.push(rObj.code);
  299. updateArr.push(rObj);
  300. }
  301. else{
  302. alert("编码已存在!");
  303. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  304. }
  305. }
  306. else{
  307. updateArr.push(rObj);
  308. }
  309. }
  310. }
  311. else if(!me.currentEditingRation["ID"]) {
  312. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  313. //addArr.push(rObj);
  314. me.addRationItem = rObj;
  315. if(rObj.code && rObj.code.toString().trim().length > 0){
  316. if(me.rationsCodes.indexOf(rObj.code) === -1){
  317. //jobContent
  318. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  319. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  320. }
  321. addArr.push(rObj);
  322. me.rationsCodes.push(rObj.code);
  323. me.addRationItem = null;
  324. }
  325. else{
  326. alert('编码已存在!');
  327. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  328. }
  329. /*else if(!rObj.code && rObj.code === ''){
  330. $('#alertModalBtn').click();
  331. me.workBook.getSheet(0).options.isProtected = true;
  332. $('#alertModalCls').click(function () {
  333. me.workBook.getSheet(0).options.isProtected = false;
  334. me.addRationItem.code = '';
  335. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  336. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  337. });
  338. $('#alertModalCof').click(function () {
  339. me.workBook.getSheet(0).options.isProtected = false;
  340. me.addRationItem.code = '';
  341. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  342. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  343. });
  344. }*/
  345. }
  346. else if(rObj.code && rObj.code.toString.trim().length === 0){
  347. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  348. }
  349. }
  350. }
  351. if (updateArr.length > 0 || addArr.length > 0) {
  352. me.currentEditingRation = null;
  353. me.mixUpdate = 1;
  354. me.mixUpdateRequest(updateArr, addArr, []);
  355. }
  356. },
  357. onClipboardPasting: function(sender, args) {
  358. var me = rationOprObj;
  359. /* if (args.cellRange.colCount != me.setting.header.length) {
  360. args.cancel = true;
  361. }*/
  362. },
  363. onClipboardPasted: function(e, info) {
  364. var me = rationOprObj;
  365. var cacheSection = me.getCache();
  366. var updateArr = [], addArr = [];
  367. var items = sheetCommonObj.analyzePasteData(me.setting, info);
  368. let failPasteArr = [];
  369. for (var i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
  370. if (cacheSection) {
  371. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  372. items[i].unit = typeof cacheSection[rowIdx].unit !== 'undefined' && !cacheSection[rowIdx] ? cacheSection[rowIdx].unit : '';
  373. }
  374. //var hasCacheItem = false;
  375. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  376. if(me.rationsCodes.indexOf(items[i].code) === -1){
  377. //jobConten
  378. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  379. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  380. }
  381. addArr.push(items[i]);
  382. me.rationsCodes.push(items[i].code);
  383. }
  384. else{
  385. failPasteArr.push(items[i].code);
  386. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  387. }
  388. }
  389. else if(cacheSection[rowIdx]){
  390. for(let col = 0; col < me.setting.header.length; col++){
  391. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  392. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  393. }
  394. }
  395. if(info.cellRange.col === 0){
  396. if(me.rationsCodes.indexOf(items[i].code) === -1){
  397. items[i].ID = cacheSection[rowIdx].ID;
  398. updateArr.push(items[i]);
  399. }
  400. else{
  401. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  402. }
  403. }
  404. else{
  405. items[i].ID = cacheSection[rowIdx].ID;
  406. updateArr.push(items[i]);
  407. }
  408. }
  409. } else {
  410. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  411. items[i].unit = '';
  412. }
  413. //add
  414. if(info.cellRange.col === 0){
  415. //是否含有已存在的编号
  416. if(me.rationsCodes.indexOf(items[i].code) === -1){
  417. //jobConten
  418. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  419. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  420. }
  421. addArr.push(items[i]);
  422. }
  423. else{
  424. failPasteArr.push(items[i]);
  425. }
  426. }
  427. }
  428. };
  429. /* if(failPasteArr.length > 0 && !(updateArr.length > 0 || addArr.length > 0)){
  430. me.showRationItems(me.currentSectionId);
  431. }*/
  432. if (updateArr.length > 0 || addArr.length > 0) {
  433. me.mixUpdate = 1;
  434. me.mixUpdateRequest(updateArr, addArr, []);
  435. }
  436. },
  437. isValidUnit: function (rationObj, validUnits) {
  438. let rst = true;
  439. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  440. rst = false;
  441. }
  442. return rst;
  443. },
  444. getRationsCodes: function (repId) {
  445. let me = rationOprObj;
  446. $.ajax({
  447. type: 'post',
  448. url: 'api/getRationsCodes',
  449. data: {data: JSON.stringify({repId: repId})},
  450. dataType: 'json',
  451. success: function (result) {
  452. if(!result.error){
  453. me.rationsCodes = result.data;
  454. }
  455. }
  456. })
  457. },
  458. mixUpdateRequest: function(updateArr, addArr, removeIds) {
  459. var me = rationOprObj;
  460. $.ajax({
  461. type:"POST",
  462. url:"api/mixUpdateRationItems",
  463. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  464. dataType:"json",
  465. cache:false,
  466. timeout:5000,
  467. success:function(result){
  468. if (result.error) {
  469. alert(`error`);
  470. me.getRationItems(me.currentSectionId);
  471. } else {
  472. var cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  473. cacheSection.sort(function(a, b){
  474. var rst = 0;
  475. if (a.code > b.code) rst = 1
  476. else if (a.code < b.code) rst = -1;
  477. return rst;
  478. });
  479. //jobContent
  480. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
  481. jobContentOprObj.currentRationItems = cacheSection;
  482. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  483. }
  484. me.showRationItems(me.currentSectionId);
  485. me.mixUpdate = 0;
  486. me.workBook.getSheet(0).setActiveCell(me.activeCell.row, me.activeCell.col);
  487. }
  488. },
  489. error:function(){
  490. }
  491. });
  492. },
  493. getRationItems: function(sectionID){
  494. if (sectionID != -1) {
  495. var me = rationOprObj;
  496. me.mixUpdate = 0;
  497. me.currentSectionId = sectionID;
  498. if (me.currentRations["_SEC_ID_" + sectionID]) {
  499. //jobContent--
  500. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  501. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  502. //jobContent--
  503. me.showRationItems(sectionID);
  504. ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  505. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  506. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  507. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  508. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  509. } else {
  510. $.ajax({
  511. type:"POST",
  512. url:"api/getRationItems",
  513. data:{"sectionID": sectionID},
  514. dataType:"json",
  515. cache:false,
  516. timeout:1000,
  517. success:function(result){
  518. if (result) {
  519. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  520. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  521. //job--
  522. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  523. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  524. //job--
  525. me.showRationItems(sectionID);
  526. //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  527. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  528. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  529. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  530. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  531. } else {
  532. sheetCommonObj.shieldAllCells(me.workBook.getSheet(0));
  533. sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
  534. sheetCommonObj.shieldAllCells(rationCoeOprObj.sheet);
  535. sheetCommonObj.shieldAllCells(rationAssistOprObj.sheet);
  536. }
  537. },
  538. error:function(err){
  539. alert(err);
  540. }
  541. })
  542. }
  543. }
  544. },
  545. setCombo: function (sheet, items) {
  546. sheet.suspendPaint();
  547. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  548. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  549. combo.items(items);
  550. combo.itemHeight(10);
  551. sheet.getCell(i, 2).cellType(combo);
  552. }
  553. sheet.resumePaint();
  554. },
  555. showRationItems: function(sectionID){
  556. var me = rationOprObj;
  557. if (me.workBook) {
  558. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  559. var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  560. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  561. sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  562. //combo
  563. me.setCombo(me.workBook.getActiveSheet(), rationUnits);
  564. if(me.mixUpdate === 1){
  565. rationGLJOprObj.getGljItems(cacheSection[cacheSection.length - 1], function () {
  566. me.workBook.focus(true);
  567. });
  568. }
  569. } else {
  570. //清除ration数据及工料机数据
  571. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  572. }
  573. }
  574. },
  575. sortByCode: function(arr){
  576. function compare(){
  577. return function (a, b) {
  578. let rst = 0;
  579. if (a.code > b.code) {
  580. rst = 1;
  581. }
  582. else if (a.code < b.code) {
  583. rst = -1;
  584. }
  585. return rst;
  586. }
  587. }
  588. arr.sort(compare());
  589. }
  590. }