ration.js 32 KB

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