ration.js 32 KB

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