ration.js 31 KB

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