ration.js 34 KB

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