ration.js 30 KB

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