ration.js 32 KB

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