ration.js 31 KB

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