ration.js 29 KB

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