ration.js 29 KB

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