ration.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. $("#gongliao").click(function(){
  5. $(this).attr('href', "/rationRepository/lmm" + "?repository=" + getQueryString("repository"))
  6. });
  7. $("#fuzhu").click(function(){
  8. $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
  9. });
  10. let rationOprObj = {
  11. workBook: null,
  12. currentRations: {},
  13. currentEditingRation: null,
  14. currentSectionId: -1,
  15. rationsCodes: [],
  16. setting: {
  17. header:[
  18. {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
  19. {headerName:"名称",headerWidth:280,dataCode:"name", dataType: "String"},
  20. {headerName:"计量单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center"},
  21. {headerName:"人工费",headerWidth:120,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  22. {headerName:"材料费",headerWidth:120,dataCode:"materialPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  23. {headerName:"机械费",headerWidth:120,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  24. {headerName:"基价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  25. {headerName:"显示名称(以%s表示参数)",headerWidth:280,dataCode:"caption", dataType: "String"},
  26. {headerName:"取费专业",headerWidth:100,dataCode:"feeType", dataType: "Number", hAlign: "center"}
  27. ],
  28. view:{
  29. comboBox:[
  30. {row:-1,col:2,rowCount:-1,colCount:1}
  31. ],
  32. lockedCells:[
  33. {row:-1,col:3,rowCount:-1, colCount:1}
  34. ],
  35. lockColumns: [
  36. 3, 4, 5, 6
  37. ]
  38. }
  39. },
  40. buildSheet: function(container) {
  41. let rationRepId = getQueryString("repository");
  42. let me = rationOprObj;
  43. let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
  44. if(!gljLibID || typeof gljLibID === 'undefined' || gljLibID == -1){
  45. alert("没有引用工料机库!");
  46. window.location.href = "/rationRepository/main";
  47. }
  48. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  49. me.getRationsCodes(rationRepId);
  50. me.rationDelOpr();
  51. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  52. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  53. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  54. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  55. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  56. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  57. },
  58. onSelectionChanged: function (sender, info) {
  59. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  60. let row = info.newSelections[0].row;
  61. let me = rationOprObj,
  62. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  63. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  64. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
  65. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  66. sheetCommonObj.shieldAllCells(sheetGLJ);
  67. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  68. sheetCommonObj.shieldAllCells(sheetCoe);
  69. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  70. sheetCommonObj.shieldAllCells(sheetAss);
  71. let cacheSection = me.getCache();
  72. if (cacheSection && row < cacheSection.length) {
  73. rationGLJOprObj.getGljItems(cacheSection[row], function () {
  74. me.workBook.focus(true);
  75. });
  76. rationCoeOprObj.getCoeItems(cacheSection[row], function () {
  77. me.workBook.focus(true);
  78. });
  79. rationAssistOprObj.getAssItems(cacheSection[row]);
  80. }
  81. else {
  82. rationGLJOprObj.currentRationItem = null;
  83. }
  84. me.workBook.focus(true);
  85. }
  86. },
  87. isInt: function (num) {
  88. return !isNaN(num) && num % 1 === 0;
  89. },
  90. getCache: function() {
  91. let me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  92. if (!(rst)) {
  93. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  94. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  95. }
  96. return rst;
  97. },
  98. updateCache: function(addArr, updateArr, removeIds, result) {
  99. let me = this, cacheSection = me.getCache();
  100. if (addArr.length > 0) {
  101. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  102. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  103. }
  104. for (let i = removeIds.length - 1; i >= 0; i--) {
  105. for (let j = cacheSection.length - 1; j >= 0 ; j--) {
  106. if (cacheSection[j]["ID"] == removeIds[i]) {
  107. cacheSection.splice(j,1);
  108. }
  109. }
  110. }
  111. if (result && result.data.ops && result.data.ops.length > 0) {
  112. for (let i = 0; i < result.data.ops.length; i++) {
  113. for (let j = 0; j < cacheSection.length; j++) {
  114. if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
  115. cacheSection[j]["ID"] = result.data.ops[i]["ID"];
  116. cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
  117. }
  118. }
  119. }
  120. }
  121. for (let i = 0; i < updateArr.length; i++) {
  122. for (let j = 0; j < cacheSection.length; j++) {
  123. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  124. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  125. cacheSection[j] = updateArr[i];
  126. }
  127. } else {
  128. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  129. cacheSection[j] = updateArr[i];
  130. }
  131. }
  132. }
  133. }
  134. return cacheSection;
  135. },
  136. rationDelOpr: function () {
  137. let me = rationOprObj;
  138. me.workBook.commandManager().register('rationDelete', function () {
  139. let rationSheet = me.workBook.getActiveSheet();
  140. let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
  141. let cacheSection = me.getCache();
  142. if(sels.length > 0){
  143. for(let sel = 0; sel < sels.length; sel++){
  144. if(sels[sel].colCount === me.setting.header.length){
  145. if(cacheSection){
  146. for(let i = 0; i < sels[sel].rowCount; i++){
  147. if(sels[sel].row + i < cacheSection.length){
  148. removeArr.push(cacheSection[sels[sel].row + i].ID);
  149. me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code), 1);
  150. }
  151. }
  152. }
  153. }
  154. else{
  155. if(sels[sel].col === 0){
  156. $('#alertText').text("编号不能为空,修改失败!");
  157. $('#alertModalBtn').click();
  158. rationSheet.options.isProtected = true;
  159. $('#alertModalCls').click(function () {
  160. rationSheet.options.isProtected = false;
  161. });
  162. $('#alertModalCof').click(function () {
  163. rationSheet.options.isProtected = false;
  164. })
  165. }
  166. else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
  167. if(cacheSection){
  168. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  169. if(sels[sel].row + i < cacheSection.length){
  170. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  171. if(lockCols.indexOf(col) === -1){
  172. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
  173. }
  174. }
  175. }
  176. if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
  177. updateArr.push(cacheSection[sels[sel].row + i]);
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }
  185. if(updateArr.length > 0 || removeArr.length > 0){
  186. me.mixUpdate = 1;
  187. me.mixDel = removeArr.length > 0 ? 1 : 0;
  188. me.mixUpdateRequest(updateArr, [], removeArr);
  189. }
  190. });
  191. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  192. me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  193. },
  194. onEnterCell: function (sender, args) {
  195. let me = rationOprObj;
  196. args.sheet.repaint();
  197. me.cellRowIdx = args.row;
  198. let isHasData = false;
  199. if(me.addRationItem){
  200. for(let i=0; i<me.setting.header.length; i++){
  201. if(me.addRationItem[me.setting.header[i].dataCode]){
  202. isHasData = true;
  203. break;
  204. }
  205. }
  206. }
  207. if(isHasData){
  208. if(me.editingRowIdx !== me.cellRowIdx) {
  209. let focusToCol = !me.addRationItem.code ? 0 : -1;
  210. if(focusToCol !== -1){
  211. $('#rationAlertBtn').click();
  212. me.workBook.getSheet(0).options.isProtected = true;
  213. $('#rationAlertCac').click(function () {
  214. me.workBook.getSheet(0).options.isProtected = false;
  215. me.addRationItem = null;
  216. for(let col=0; col<me.setting.header.length; col++){
  217. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
  218. }
  219. });
  220. $('#rationAlertCls').click(function () {
  221. me.workBook.getSheet(0).options.isProtected = false;
  222. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  223. });
  224. $('#rationAlertCof').click(function () {
  225. me.workBook.getSheet(0).options.isProtected = false;
  226. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  227. });
  228. }
  229. }
  230. }
  231. },
  232. onCellEditStart: function(sender, args) {
  233. let me = rationOprObj;
  234. if(!me.canRations){
  235. args.cancel = true;
  236. }
  237. else{
  238. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  239. me.currentEditingRation = rObj;
  240. let cacheSection = me.getCache();
  241. if (cacheSection) {
  242. for (let j = 0; j < cacheSection.length; j++) {
  243. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  244. rObj["ID"] = cacheSection[j]["ID"];
  245. break;
  246. }
  247. }
  248. }
  249. }
  250. },
  251. onCellEditEnd: function(sender, args) {
  252. let me = rationOprObj, rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  253. updateArr = [], addArr = [];
  254. let dataCode = me.setting.header[args.col].dataCode;
  255. me.editingRowIdx = args.row;
  256. if (me.currentEditingRation["ID"]) {
  257. if((!args.editingText || args.editingText.toString().trim().length === 0) && args.col === 0){
  258. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode] + '');
  259. }
  260. else {
  261. rObj["ID"] = me.currentEditingRation["ID"];
  262. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  263. me.addRationItem = rObj;
  264. if(dataCode === 'code'){
  265. if(me.rationsCodes.indexOf(rObj.code) === -1){
  266. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code), 1);
  267. me.rationsCodes.push(rObj.code);
  268. updateArr.push(rObj);
  269. }
  270. else{
  271. alert("编码已存在!");
  272. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  273. }
  274. }
  275. else if(dataCode === 'feeType'){//取费专业控制为整数
  276. if(me.isInt(rObj[dataCode])){
  277. updateArr.push(rObj);
  278. }
  279. else {
  280. rObj[dataCode] = '';
  281. args.sheet.setValue(args.row, args.col, typeof me.currentEditingRation[dataCode] !== 'undefined' && me.currentEditingRation[dataCode] ? me.currentEditingRation[dataCode] : '');
  282. }
  283. }
  284. else{
  285. updateArr.push(rObj);
  286. }
  287. }
  288. }
  289. }
  290. else if(!me.currentEditingRation["ID"]) {
  291. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  292. //addArr.push(rObj);
  293. me.addRationItem = rObj;
  294. if(rObj.code && rObj.code.toString().trim().length > 0){
  295. if(me.rationsCodes.indexOf(rObj.code) === -1){
  296. //jobContent
  297. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  298. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  299. }
  300. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  301. rObj.annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  302. }
  303. me.setInitPrc(rObj);
  304. addArr.push(rObj);
  305. me.rationsCodes.push(rObj.code);
  306. me.addRationItem = null;
  307. }
  308. else{
  309. alert('编码已存在!');
  310. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  311. }
  312. /*else if(!rObj.code && rObj.code === ''){
  313. $('#alertModalBtn').click();
  314. me.workBook.getSheet(0).options.isProtected = true;
  315. $('#alertModalCls').click(function () {
  316. me.workBook.getSheet(0).options.isProtected = false;
  317. me.addRationItem.code = '';
  318. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  319. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  320. });
  321. $('#alertModalCof').click(function () {
  322. me.workBook.getSheet(0).options.isProtected = false;
  323. me.addRationItem.code = '';
  324. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  325. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  326. });
  327. }*/
  328. }
  329. else if(rObj.code && rObj.code.toString.trim().length === 0){
  330. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  331. }
  332. }
  333. }
  334. if (updateArr.length > 0 || addArr.length > 0) {
  335. me.currentEditingRation = null;
  336. me.mixUpdate = 1;
  337. me.mixUpdateRequest(updateArr, addArr, []);
  338. }
  339. },
  340. onClipboardPasting: function(sender, args) {
  341. let me = rationOprObj;
  342. if(!me.canRations){
  343. args.cancel = true;
  344. }
  345. },
  346. //todo: overwrite
  347. onClipboardPasted: function(e, info) {
  348. let me = rationOprObj;
  349. let cacheSection = me.getCache();
  350. let updateArr = [], addArr = [];
  351. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  352. //let failPasteArr = [];
  353. for (let i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
  354. if (cacheSection) {
  355. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  356. items[i].unit = typeof cacheSection[rowIdx].unit !== 'undefined' && !cacheSection[rowIdx] ? cacheSection[rowIdx].unit : '';
  357. }
  358. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  359. if(me.rationsCodes.indexOf(items[i].code) === -1){
  360. //jobConten
  361. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  362. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  363. }
  364. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  365. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  366. }
  367. me.setInitPrc(items[i]);
  368. addArr.push(items[i]);
  369. me.rationsCodes.push(items[i].code);
  370. }
  371. else{
  372. //failPasteArr.push(items[i].code);
  373. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  374. }
  375. }
  376. else if(cacheSection[rowIdx]){
  377. for(let col = 0; col < me.setting.header.length; col++){
  378. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  379. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  380. }
  381. }
  382. if(items[i].feeType && !me.isInt(items[i].feeType)){
  383. items[i].feeType = '';
  384. me.workBook.getSheet(0).setValue(rowIdx, 8, '');
  385. }
  386. if(info.cellRange.col === 0){
  387. if(me.rationsCodes.indexOf(items[i].code) === -1){
  388. items[i].ID = cacheSection[rowIdx].ID;
  389. updateArr.push(items[i]);
  390. }
  391. else{
  392. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  393. }
  394. }
  395. else{
  396. items[i].ID = cacheSection[rowIdx].ID;
  397. updateArr.push(items[i]);
  398. }
  399. }
  400. } else {
  401. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  402. items[i].unit = '';
  403. }
  404. //add
  405. if(info.cellRange.col === 0){
  406. //是否含有已存在的编号
  407. if(me.rationsCodes.indexOf(items[i].code) === -1){
  408. //jobConten
  409. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  410. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  411. }
  412. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  413. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  414. }
  415. me.setInitPrc(items[i]);
  416. addArr.push(items[i]);
  417. }
  418. /*else{
  419. failPasteArr.push(items[i]);
  420. }*/
  421. }
  422. }
  423. };
  424. /* if(failPasteArr.length > 0 && !(updateArr.length > 0 || addArr.length > 0)){
  425. me.showRationItems(me.currentSectionId);
  426. }*/
  427. if (updateArr.length > 0 || addArr.length > 0) {
  428. me.mixUpdate = 1;
  429. me.mixUpdateRequest(updateArr, addArr, []);
  430. }
  431. },
  432. setInitPrc: function (obj) {
  433. obj.labourPrice = 0;
  434. obj.materialPrice = 0;
  435. obj.machinePrice = 0;
  436. obj.basePrice = 0;
  437. },
  438. isValidUnit: function (rationObj, validUnits) {
  439. let rst = true;
  440. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  441. rst = false;
  442. }
  443. return rst;
  444. },
  445. getRationsCodes: function (repId) {
  446. let me = rationOprObj;
  447. $.ajax({
  448. type: 'post',
  449. url: 'api/getRationsCodes',
  450. data: {data: JSON.stringify({repId: repId})},
  451. dataType: 'json',
  452. success: function (result) {
  453. if(!result.error){
  454. me.rationsCodes = result.data;
  455. }
  456. }
  457. })
  458. },
  459. mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
  460. let me = rationOprObj;
  461. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, true);
  462. $.ajax({
  463. type:"POST",
  464. url:"api/mixUpdateRationItems",
  465. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  466. dataType:"json",
  467. cache:false,
  468. timeout:5000,
  469. success:function(result){
  470. if (result.error) {
  471. alert(`error`);
  472. me.getRationItems(me.currentSectionId);
  473. } else {
  474. let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  475. cacheSection.sort(function(a, b){
  476. let rst = 0;
  477. if (a.code > b.code) rst = 1
  478. else if (a.code < b.code) rst = -1;
  479. return rst;
  480. });
  481. //jobContent
  482. if(jobContentOprObj ){
  483. jobContentOprObj.currentRationItems = cacheSection;
  484. jobContentOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, jobContentOprObj.radios);
  485. if(cacheSection.length === 0){
  486. jobContentOprObj.updateSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  487. }
  488. jobContentOprObj.setRadiosChecked(jobContentOprObj.currentSituation, jobContentOprObj.radios);
  489. if(jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
  490. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  491. }
  492. }
  493. if(annotationOprObj ){
  494. annotationOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, annotationOprObj.radios);
  495. if(cacheSection.length === 0){
  496. annotationOprObj.updateAnnoSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  497. }
  498. annotationOprObj.setRadiosChecked(annotationOprObj.currentSituation, annotationOprObj.radios);
  499. if(annotationOprObj.currentSituation === annotationOprObj.situations.PARTIAL){
  500. annotationOprObj.buildTablePartial(annotationOprObj.fzTablePartial, annotationOprObj.getGroup(cacheSection));
  501. }
  502. }
  503. me.showRationItems(me.currentSectionId);
  504. me.mixUpdate = 0;
  505. me.mixDel = 0;
  506. }
  507. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, false);
  508. if(callback) callback();
  509. },
  510. error:function(){
  511. }
  512. });
  513. },
  514. getRationItems: function(sectionID){
  515. if (sectionID != -1) {
  516. let me = rationOprObj;
  517. me.mixUpdate = 0;
  518. me.currentSectionId = sectionID;
  519. if (me.currentRations["_SEC_ID_" + sectionID]) {
  520. //jobContent--
  521. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  522. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  523. //annotation
  524. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  525. me.showRationItems(sectionID);
  526. ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  527. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  528. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  529. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  530. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  531. } else {
  532. $.ajax({
  533. type:"POST",
  534. url:"api/getRationItems",
  535. data:{"sectionID": sectionID},
  536. dataType:"json",
  537. cache:false,
  538. timeout:1000,
  539. success:function(result){
  540. if (result) {
  541. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  542. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  543. //job--
  544. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  545. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  546. //annotation
  547. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  548. me.showRationItems(sectionID);
  549. //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  550. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  551. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  552. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  553. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  554. } else {
  555. sheetCommonObj.shieldAllCells(me.workBook.getSheet(0));
  556. sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
  557. sheetCommonObj.shieldAllCells(rationCoeOprObj.sheet);
  558. sheetCommonObj.shieldAllCells(rationAssistOprObj.sheet);
  559. }
  560. },
  561. error:function(err){
  562. alert(err);
  563. }
  564. })
  565. }
  566. }
  567. },
  568. showRationItems: function(sectionID){
  569. let me = rationOprObj,
  570. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  571. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  572. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
  573. if (me.workBook) {
  574. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  575. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  576. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  577. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  578. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 4, true);
  579. //combo
  580. sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 2, cacheSection.length, rationUnits, 10, false);
  581. sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), cacheSection.length, 2, me.workBook.getActiveSheet().getRowCount() - cacheSection.length, rationUnits, 10, false);
  582. if(me.mixDel === 1){
  583. let row = me.workBook.getSheet(0).getSelections()[0].row;
  584. if (cacheSection && row < cacheSection.length) {
  585. rationGLJOprObj.getGljItems(cacheSection[row]);
  586. rationCoeOprObj.getCoeItems(cacheSection[row]);
  587. rationAssistOprObj.getAssItems(cacheSection[row]);
  588. }
  589. else {
  590. rationGLJOprObj.currentRationItem = null;
  591. }
  592. }
  593. } else {
  594. sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  595. //清除ration数据及工料机数据
  596. rationGLJOprObj.currentRationItem = null;
  597. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  598. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  599. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  600. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  601. }
  602. me.workBook.focus(true);
  603. }
  604. },
  605. sortByCode: function(arr){
  606. function compare(){
  607. return function (a, b) {
  608. let rst = 0;
  609. if (a.code > b.code) {
  610. rst = 1;
  611. }
  612. else if (a.code < b.code) {
  613. rst = -1;
  614. }
  615. return rst;
  616. }
  617. }
  618. arr.sort(compare());
  619. }
  620. }