ration.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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.cleanSheet(sheetCoe, settingCoe, -1);
  67. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  68. let cacheSection = me.getCache();
  69. if (cacheSection && row < cacheSection.length) {
  70. rationGLJOprObj.getGljItems(cacheSection[row], function () {
  71. me.workBook.focus(true);
  72. });
  73. rationCoeOprObj.getCoeItems(cacheSection[row], function () {
  74. me.workBook.focus(true);
  75. });
  76. rationAssistOprObj.getAssItems(cacheSection[row]);
  77. }
  78. else {
  79. rationGLJOprObj.currentRationItem = null;
  80. }
  81. me.workBook.focus(true);
  82. }
  83. },
  84. isInt: function (num) {
  85. return !isNaN(num) && num % 1 === 0;
  86. },
  87. getCache: function() {
  88. let 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. let 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 (let i = removeIds.length - 1; i >= 0; i--) {
  102. for (let 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 (let i = 0; i < result.data.ops.length; i++) {
  110. for (let 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. cacheSection[j]["rationCoeList"] = result.data.ops[i]["rationCoeList"];
  115. cacheSection[j]["rationAssList"] = result.data.ops[i]["rationAssList"];
  116. }
  117. }
  118. }
  119. }
  120. for (let i = 0; i < updateArr.length; i++) {
  121. for (let 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. $('#alertModalCls').click(function () {
  158. });
  159. $('#alertModalCof').click(function () {
  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.mixDel = removeArr.length > 0 ? 1 : 0;
  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. onEnterCell: function (sender, args) {
  191. let me = rationOprObj;
  192. args.sheet.repaint();
  193. me.cellRowIdx = args.row;
  194. let isHasData = false;
  195. if(me.addRationItem){
  196. for(let i=0; i<me.setting.header.length; i++){
  197. if(me.addRationItem[me.setting.header[i].dataCode]){
  198. isHasData = true;
  199. break;
  200. }
  201. }
  202. }
  203. if(isHasData){
  204. if(me.editingRowIdx !== me.cellRowIdx) {
  205. let focusToCol = !me.addRationItem.code ? 0 : -1;
  206. if(focusToCol !== -1){
  207. $('#rationAlertBtn').click();
  208. $('#rationAlertCac').click(function () {
  209. me.addRationItem = null;
  210. for(let col=0; col<me.setting.header.length; col++){
  211. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
  212. }
  213. });
  214. $('#rationAlertCls').click(function () {
  215. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  216. });
  217. $('#rationAlertCof').click(function () {
  218. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  219. });
  220. }
  221. }
  222. }
  223. },
  224. onCellEditStart: function(sender, args) {
  225. let me = rationOprObj;
  226. if(!me.canRations || me.setting.view.lockColumns.indexOf(args.col) !== -1){
  227. args.cancel = true;
  228. }
  229. else{
  230. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  231. me.currentEditingRation = rObj;
  232. let cacheSection = me.getCache();
  233. if (cacheSection) {
  234. for (let j = 0; j < cacheSection.length; j++) {
  235. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  236. rObj["ID"] = cacheSection[j]["ID"];
  237. break;
  238. }
  239. }
  240. }
  241. }
  242. },
  243. onCellEditEnd: function(sender, args) {
  244. let me = rationOprObj, rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  245. updateArr = [], addArr = [];
  246. let dataCode = me.setting.header[args.col].dataCode;
  247. me.editingRowIdx = args.row;
  248. if (me.currentEditingRation["ID"]) {
  249. if((!args.editingText || args.editingText.toString().trim().length === 0) && args.col === 0){
  250. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode] + '');
  251. }
  252. else {
  253. rObj["ID"] = me.currentEditingRation["ID"];
  254. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  255. me.addRationItem = rObj;
  256. if(dataCode === 'code'){
  257. if(me.rationsCodes.indexOf(rObj.code) === -1){
  258. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code), 1);
  259. me.rationsCodes.push(rObj.code);
  260. updateArr.push(rObj);
  261. }
  262. else{
  263. alert("编码已存在!");
  264. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  265. }
  266. }
  267. else if(dataCode === 'feeType'){//取费专业控制为整数
  268. if(me.isInt(rObj[dataCode])){
  269. updateArr.push(rObj);
  270. }
  271. else {
  272. rObj[dataCode] = '';
  273. args.sheet.setValue(args.row, args.col, typeof me.currentEditingRation[dataCode] !== 'undefined' && me.currentEditingRation[dataCode] ? me.currentEditingRation[dataCode] : '');
  274. }
  275. }
  276. else{
  277. updateArr.push(rObj);
  278. }
  279. }
  280. }
  281. }
  282. else if(!me.currentEditingRation["ID"]) {
  283. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  284. //addArr.push(rObj);
  285. me.addRationItem = rObj;
  286. if(rObj.code && rObj.code.toString().trim().length > 0){
  287. if(me.rationsCodes.indexOf(rObj.code) === -1){
  288. //jobContent
  289. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  290. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  291. }
  292. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  293. rObj.annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  294. }
  295. me.setInitPrc(rObj);
  296. addArr.push(rObj);
  297. me.rationsCodes.push(rObj.code);
  298. me.addRationItem = null;
  299. }
  300. else{
  301. alert('编码已存在!');
  302. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  303. }
  304. }
  305. else if(rObj.code && rObj.code.toString.trim().length === 0){
  306. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  307. }
  308. }
  309. }
  310. if (updateArr.length > 0 || addArr.length > 0) {
  311. me.currentEditingRation = null;
  312. me.mixUpdate = 1;
  313. me.mixUpdateRequest(updateArr, addArr, []);
  314. }
  315. },
  316. canPasted: function (beginCol, maxCol) {
  317. let rst = false;
  318. if(maxCol < 3 || beginCol > 6){
  319. rst = true;
  320. }
  321. return rst;
  322. },
  323. onClipboardPasting: function(sender, args) {
  324. let me = rationOprObj;
  325. let maxCol = args.cellRange.col + args.cellRange.colCount -1;
  326. if(!me.canRations || !me.canPasted(args.cellRange.col, maxCol) || maxCol > me.setting.header.length - 1){
  327. args.cancel = true;
  328. }
  329. },
  330. //todo: overwrite?
  331. onClipboardPasted: function(e, info) {
  332. let me = rationOprObj;
  333. let cacheSection = me.getCache();
  334. let updateArr = [], addArr = [];
  335. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  336. for (let i = 0; i < items.length; i++) {
  337. let rowIdx = info.cellRange.row + i;
  338. if (cacheSection) {
  339. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  340. items[i].unit = rowIdx < cacheSection.length && typeof cacheSection[rowIdx].unit !== 'undefined' ? cacheSection[rowIdx].unit : '';
  341. }
  342. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  343. if(me.rationsCodes.indexOf(items[i].code) === -1){
  344. //jobConten
  345. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  346. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  347. }
  348. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  349. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  350. }
  351. me.setInitPrc(items[i]);
  352. addArr.push(items[i]);
  353. me.rationsCodes.push(items[i].code);
  354. }
  355. else{
  356. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  357. }
  358. }
  359. else if(cacheSection[rowIdx]){
  360. for(let col = 0; col < me.setting.header.length; col++){
  361. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  362. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  363. }
  364. }
  365. if(items[i].feeType && !me.isInt(items[i].feeType)){
  366. items[i].feeType = '';
  367. me.workBook.getSheet(0).setValue(rowIdx, 8, '');
  368. }
  369. if(info.cellRange.col === 0){
  370. if(me.rationsCodes.indexOf(items[i].code) === -1){
  371. items[i].ID = cacheSection[rowIdx].ID;
  372. updateArr.push(items[i]);
  373. }
  374. else{
  375. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  376. }
  377. }
  378. else{
  379. items[i].ID = cacheSection[rowIdx].ID;
  380. updateArr.push(items[i]);
  381. }
  382. }
  383. } else {
  384. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  385. items[i].unit = '';
  386. }
  387. //add
  388. if(info.cellRange.col === 0){
  389. //是否含有已存在的编号
  390. if(me.rationsCodes.indexOf(items[i].code) === -1){
  391. //jobConten
  392. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  393. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  394. }
  395. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  396. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  397. }
  398. me.setInitPrc(items[i]);
  399. addArr.push(items[i]);
  400. }
  401. }
  402. }
  403. };
  404. if (updateArr.length > 0 || addArr.length > 0) {
  405. me.mixUpdate = 1;
  406. me.mixUpdateRequest(updateArr, addArr, []);
  407. }
  408. else{
  409. me.getRationItems(me.currentSectionId);
  410. }
  411. },
  412. setInitPrc: function (obj) {
  413. obj.labourPrice = 0;
  414. obj.materialPrice = 0;
  415. obj.machinePrice = 0;
  416. obj.basePrice = 0;
  417. },
  418. isValidUnit: function (rationObj, validUnits) {
  419. let rst = true;
  420. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  421. rst = false;
  422. }
  423. return rst;
  424. },
  425. getRationsCodes: function (repId) {
  426. let me = rationOprObj;
  427. $.ajax({
  428. type: 'post',
  429. url: 'api/getRationsCodes',
  430. data: {data: JSON.stringify({repId: repId})},
  431. dataType: 'json',
  432. success: function (result) {
  433. if(!result.error){
  434. me.rationsCodes = result.data;
  435. }
  436. }
  437. })
  438. },
  439. mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
  440. let me = rationOprObj;
  441. $.ajax({
  442. type:"POST",
  443. url:"api/mixUpdateRationItems",
  444. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  445. dataType:"json",
  446. cache:false,
  447. timeout:5000,
  448. success:function(result){
  449. if (result.error) {
  450. alert(`error`);
  451. me.getRationItems(me.currentSectionId);
  452. } else {
  453. let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  454. cacheSection.sort(function(a, b){
  455. let rst = 0;
  456. if (a.code > b.code) rst = 1
  457. else if (a.code < b.code) rst = -1;
  458. return rst;
  459. });
  460. //jobContent
  461. if(jobContentOprObj ){
  462. jobContentOprObj.currentRationItems = cacheSection;
  463. jobContentOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, jobContentOprObj.radios);
  464. if(cacheSection.length === 0){
  465. jobContentOprObj.updateSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  466. }
  467. jobContentOprObj.setRadiosChecked(jobContentOprObj.currentSituation, jobContentOprObj.radios);
  468. if(jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
  469. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  470. }
  471. }
  472. if(annotationOprObj ){
  473. annotationOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, annotationOprObj.radios);
  474. if(cacheSection.length === 0){
  475. annotationOprObj.updateAnnoSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  476. }
  477. annotationOprObj.setRadiosChecked(annotationOprObj.currentSituation, annotationOprObj.radios);
  478. if(annotationOprObj.currentSituation === annotationOprObj.situations.PARTIAL){
  479. annotationOprObj.buildTablePartial(annotationOprObj.fzTablePartial, annotationOprObj.getGroup(cacheSection));
  480. }
  481. }
  482. me.showRationItems(me.currentSectionId);
  483. me.mixUpdate = 0;
  484. me.mixDel = 0;
  485. }
  486. if(callback) callback();
  487. },
  488. error:function(){
  489. }
  490. });
  491. },
  492. getRationItems: function(sectionID){
  493. if (sectionID != -1) {
  494. let me = rationOprObj;
  495. me.mixUpdate = 0;
  496. me.currentSectionId = sectionID;
  497. if (me.currentRations["_SEC_ID_" + sectionID]) {
  498. //jobContent--
  499. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  500. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  501. //annotation
  502. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  503. me.showRationItems(sectionID);
  504. } else {
  505. $.ajax({
  506. type:"POST",
  507. url:"api/getRationItems",
  508. data:{"sectionID": sectionID},
  509. dataType:"json",
  510. cache:false,
  511. timeout:1000,
  512. success:function(result){
  513. if (result) {
  514. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  515. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  516. //job--
  517. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  518. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  519. //annotation
  520. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  521. me.showRationItems(sectionID);
  522. }
  523. },
  524. error:function(err){
  525. alert(err);
  526. }
  527. })
  528. }
  529. }
  530. },
  531. showRationItems: function(sectionID){
  532. let me = rationOprObj,
  533. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  534. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  535. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
  536. if (me.workBook) {
  537. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  538. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  539. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  540. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  541. //combo
  542. sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 2, cacheSection.length, rationUnits, 10, false);
  543. sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), cacheSection.length, 2, me.workBook.getActiveSheet().getRowCount() - cacheSection.length, rationUnits, 10, false);
  544. if(me.mixDel === 1){
  545. let row = me.workBook.getSheet(0).getSelections()[0].row;
  546. if (cacheSection && row < cacheSection.length) {
  547. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  548. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  549. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  550. rationGLJOprObj.getGljItems(cacheSection[row]);
  551. rationCoeOprObj.getCoeItems(cacheSection[row]);
  552. rationAssistOprObj.getAssItems(cacheSection[row]);
  553. }
  554. else {
  555. rationGLJOprObj.currentRationItem = null;
  556. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  557. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  558. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  559. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  560. }
  561. }
  562. } else {
  563. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  564. sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  565. //清除ration数据及工料机数据
  566. rationGLJOprObj.currentRationItem = null;
  567. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  568. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  569. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  570. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  571. }
  572. me.workBook.focus(true);
  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. }