ration.js 33 KB

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