ration.js 32 KB

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