ration.js 32 KB

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