ration.js 31 KB

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