ration.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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.mixUpdateRequest(updateArr, [], removeArr);
  217. }
  218. });
  219. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  220. me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  221. },
  222. onEnterCell: function (sender, args) {
  223. let me = rationOprObj;
  224. me.cellRowIdx = args.row;
  225. let isHasData = false;
  226. if(me.addRationItem){
  227. for(let i=0; i<me.setting.header.length; i++){
  228. if(me.addRationItem[me.setting.header[i].dataCode]){
  229. isHasData = true;
  230. break;
  231. }
  232. }
  233. }
  234. if(isHasData){
  235. if(me.editingRowIdx !== me.cellRowIdx) {
  236. let focusToCol = !me.addRationItem.code ? 0 : -1;
  237. if(focusToCol !== -1){
  238. $('#rationAlertBtn').click();
  239. me.workBook.getSheet(0).options.isProtected = true;
  240. $('#rationAlertCac').click(function () {
  241. me.workBook.getSheet(0).options.isProtected = false;
  242. });
  243. $('#rationAlertCls').click(function () {
  244. me.workBook.getSheet(0).options.isProtected = false;
  245. });
  246. $('#rationAlertCof').click(function () {
  247. me.workBook.getSheet(0).options.isProtected = false;
  248. me.addRationItem = null;
  249. for(let col=0; col<me.setting.header.length; col++){
  250. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value(me.currentEditingRation[me.setting.header[col].dataCode]);
  251. }
  252. });
  253. }
  254. }
  255. }
  256. },
  257. onCellEditStart: function(sender, args) {
  258. let me = rationOprObj;
  259. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  260. me.currentEditingRation = rObj;
  261. let cacheSection = me.getCache();
  262. if (cacheSection) {
  263. for (let j = 0; j < cacheSection.length; j++) {
  264. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  265. rObj["ID"] = cacheSection[j]["ID"];
  266. break;
  267. }
  268. }
  269. }
  270. },
  271. onCellEditEnd: function(sender, args) {
  272. let me = rationOprObj, rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  273. updateArr = [], addArr = [];
  274. let dataCode = me.setting.header[args.col].dataCode;
  275. me.editingRowIdx = args.row;
  276. if (me.currentEditingRation["ID"]) {
  277. if((!args.editingText || args.editingText.toString().trim().length === 0) && args.col === 0){
  278. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode] + '');
  279. }
  280. else {
  281. rObj["ID"] = me.currentEditingRation["ID"];
  282. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  283. me.addRationItem = rObj;
  284. if(dataCode === 'code'){
  285. if(me.rationsCodes.indexOf(rObj.code) === -1){
  286. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code), 1);
  287. me.rationsCodes.push(rObj.code);
  288. updateArr.push(rObj);
  289. }
  290. else{
  291. alert("编码已存在!");
  292. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  293. }
  294. }
  295. else if(dataCode === 'feeType'){//取费专业控制为整数
  296. if(me.isInt(rObj[dataCode])){
  297. updateArr.push(rObj);
  298. }
  299. else {
  300. rObj[dataCode] = '';
  301. args.sheet.setValue(args.row, args.col, typeof me.currentEditingRation[dataCode] !== 'undefined' && me.currentEditingRation[dataCode] ? me.currentEditingRation[dataCode] : '');
  302. }
  303. }
  304. else{
  305. updateArr.push(rObj);
  306. }
  307. }
  308. }
  309. }
  310. else if(!me.currentEditingRation["ID"]) {
  311. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  312. //addArr.push(rObj);
  313. me.addRationItem = rObj;
  314. if(rObj.code && rObj.code.toString().trim().length > 0){
  315. if(me.rationsCodes.indexOf(rObj.code) === -1){
  316. //jobContent
  317. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  318. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  319. }
  320. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  321. rObj.annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  322. }
  323. me.setInitPrc(rObj);
  324. addArr.push(rObj);
  325. me.rationsCodes.push(rObj.code);
  326. me.addRationItem = null;
  327. }
  328. else{
  329. alert('编码已存在!');
  330. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  331. }
  332. /*else if(!rObj.code && rObj.code === ''){
  333. $('#alertModalBtn').click();
  334. me.workBook.getSheet(0).options.isProtected = true;
  335. $('#alertModalCls').click(function () {
  336. me.workBook.getSheet(0).options.isProtected = false;
  337. me.addRationItem.code = '';
  338. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  339. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  340. });
  341. $('#alertModalCof').click(function () {
  342. me.workBook.getSheet(0).options.isProtected = false;
  343. me.addRationItem.code = '';
  344. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  345. me.workBook.getSheet(0).setActiveCell(args.row, args.col);
  346. });
  347. }*/
  348. }
  349. else if(rObj.code && rObj.code.toString.trim().length === 0){
  350. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  351. }
  352. }
  353. }
  354. if (updateArr.length > 0 || addArr.length > 0) {
  355. me.currentEditingRation = null;
  356. me.mixUpdate = 1;
  357. me.mixUpdateRequest(updateArr, addArr, []);
  358. }
  359. },
  360. onClipboardPasting: function(sender, args) {
  361. let me = rationOprObj;
  362. },
  363. onClipboardPasted: function(e, info) {
  364. let me = rationOprObj;
  365. let cacheSection = me.getCache();
  366. let updateArr = [], addArr = [];
  367. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  368. //let failPasteArr = [];
  369. for (let i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
  370. if (cacheSection) {
  371. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  372. items[i].unit = typeof cacheSection[rowIdx].unit !== 'undefined' && !cacheSection[rowIdx] ? cacheSection[rowIdx].unit : '';
  373. }
  374. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  375. if(me.rationsCodes.indexOf(items[i].code) === -1){
  376. //jobConten
  377. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  378. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  379. }
  380. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  381. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  382. }
  383. me.setInitPrc(items[i]);
  384. addArr.push(items[i]);
  385. me.rationsCodes.push(items[i].code);
  386. }
  387. else{
  388. //failPasteArr.push(items[i].code);
  389. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  390. }
  391. }
  392. else if(cacheSection[rowIdx]){
  393. for(let col = 0; col < me.setting.header.length; col++){
  394. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  395. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  396. }
  397. }
  398. if(items[i].feeType && !me.isInt(items[i].feeType)){
  399. items[i].feeType = '';
  400. me.workBook.getSheet(0).setValue(rowIdx, 8, '');
  401. }
  402. if(info.cellRange.col === 0){
  403. if(me.rationsCodes.indexOf(items[i].code) === -1){
  404. items[i].ID = cacheSection[rowIdx].ID;
  405. updateArr.push(items[i]);
  406. }
  407. else{
  408. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  409. }
  410. }
  411. else{
  412. items[i].ID = cacheSection[rowIdx].ID;
  413. updateArr.push(items[i]);
  414. }
  415. }
  416. } else {
  417. if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  418. items[i].unit = '';
  419. }
  420. //add
  421. if(info.cellRange.col === 0){
  422. //是否含有已存在的编号
  423. if(me.rationsCodes.indexOf(items[i].code) === -1){
  424. //jobConten
  425. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  426. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  427. }
  428. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  429. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  430. }
  431. me.setInitPrc(items[i]);
  432. addArr.push(items[i]);
  433. }
  434. /*else{
  435. failPasteArr.push(items[i]);
  436. }*/
  437. }
  438. }
  439. };
  440. /* if(failPasteArr.length > 0 && !(updateArr.length > 0 || addArr.length > 0)){
  441. me.showRationItems(me.currentSectionId);
  442. }*/
  443. if (updateArr.length > 0 || addArr.length > 0) {
  444. me.mixUpdate = 1;
  445. me.mixUpdateRequest(updateArr, addArr, []);
  446. }
  447. },
  448. setInitPrc: function (obj) {
  449. obj.labourPrice = 0;
  450. obj.materialPrice = 0;
  451. obj.machinePrice = 0;
  452. obj.basePrice = 0;
  453. },
  454. isValidUnit: function (rationObj, validUnits) {
  455. let rst = true;
  456. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  457. rst = false;
  458. }
  459. return rst;
  460. },
  461. getRationsCodes: function (repId) {
  462. let me = rationOprObj;
  463. $.ajax({
  464. type: 'post',
  465. url: 'api/getRationsCodes',
  466. data: {data: JSON.stringify({repId: repId})},
  467. dataType: 'json',
  468. success: function (result) {
  469. if(!result.error){
  470. me.rationsCodes = result.data;
  471. }
  472. }
  473. })
  474. },
  475. mixUpdateRequest: function(updateArr, addArr, removeIds) {
  476. let me = rationOprObj;
  477. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, true);
  478. $.ajax({
  479. type:"POST",
  480. url:"api/mixUpdateRationItems",
  481. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  482. dataType:"json",
  483. cache:false,
  484. timeout:5000,
  485. success:function(result){
  486. if (result.error) {
  487. alert(`error`);
  488. me.getRationItems(me.currentSectionId);
  489. } else {
  490. let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  491. cacheSection.sort(function(a, b){
  492. let rst = 0;
  493. if (a.code > b.code) rst = 1
  494. else if (a.code < b.code) rst = -1;
  495. return rst;
  496. });
  497. //jobContent
  498. if(jobContentOprObj ){
  499. jobContentOprObj.currentRationItems = cacheSection;
  500. jobContentOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, jobContentOprObj.radios);
  501. if(cacheSection.length === 0){
  502. jobContentOprObj.updateSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  503. }
  504. jobContentOprObj.setRadiosChecked(jobContentOprObj.currentSituation, jobContentOprObj.radios);
  505. if(jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
  506. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  507. }
  508. }
  509. if(annotationOprObj ){
  510. annotationOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, annotationOprObj.radios);
  511. if(cacheSection.length === 0){
  512. annotationOprObj.updateAnnoSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  513. }
  514. annotationOprObj.setRadiosChecked(annotationOprObj.currentSituation, annotationOprObj.radios);
  515. if(annotationOprObj.currentSituation === annotationOprObj.situations.PARTIAL){
  516. annotationOprObj.buildTablePartial(annotationOprObj.fzTablePartial, annotationOprObj.getGroup(cacheSection));
  517. }
  518. }
  519. me.showRationItems(me.currentSectionId);
  520. me.mixUpdate = 0;
  521. }
  522. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, false);
  523. },
  524. error:function(){
  525. }
  526. });
  527. },
  528. getRationItems: function(sectionID){
  529. if (sectionID != -1) {
  530. let me = rationOprObj;
  531. me.mixUpdate = 0;
  532. me.currentSectionId = sectionID;
  533. if (me.currentRations["_SEC_ID_" + sectionID]) {
  534. //jobContent--
  535. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  536. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  537. //annotation
  538. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  539. me.showRationItems(sectionID);
  540. ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  541. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  542. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  543. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  544. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  545. } else {
  546. $.ajax({
  547. type:"POST",
  548. url:"api/getRationItems",
  549. data:{"sectionID": sectionID},
  550. dataType:"json",
  551. cache:false,
  552. timeout:1000,
  553. success:function(result){
  554. if (result) {
  555. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  556. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  557. //job--
  558. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  559. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  560. //annotation
  561. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  562. me.showRationItems(sectionID);
  563. //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
  564. sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
  565. sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
  566. sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
  567. sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
  568. } else {
  569. sheetCommonObj.shieldAllCells(me.workBook.getSheet(0));
  570. sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
  571. sheetCommonObj.shieldAllCells(rationCoeOprObj.sheet);
  572. sheetCommonObj.shieldAllCells(rationAssistOprObj.sheet);
  573. }
  574. },
  575. error:function(err){
  576. alert(err);
  577. }
  578. })
  579. }
  580. }
  581. },
  582. setCombo: function (sheet, items) {
  583. sheet.suspendPaint();
  584. for(let i = 0, len = sheet.getRowCount(); i < len; i++){
  585. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  586. combo.items(items);
  587. combo.itemHeight(10);
  588. sheet.getCell(i, 2).cellType(combo);
  589. }
  590. sheet.resumePaint();
  591. },
  592. showRationItems: function(sectionID){
  593. let me = rationOprObj;
  594. if (me.workBook) {
  595. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  596. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  597. //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  598. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  599. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  600. sheetCommonObj.setLockCol(me.workBook.getSheet(0), 4, true);
  601. //combo
  602. me.setCombo(me.workBook.getActiveSheet(), rationUnits);
  603. if(me.mixUpdate === 1){
  604. rationGLJOprObj.getGljItems(cacheSection[cacheSection.length - 1], function () {
  605. me.workBook.focus(true);
  606. });
  607. }
  608. } else {
  609. //清除ration数据及工料机数据
  610. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  611. }
  612. }
  613. },
  614. sortByCode: function(arr){
  615. function compare(){
  616. return function (a, b) {
  617. let rst = 0;
  618. if (a.code > b.code) {
  619. rst = 1;
  620. }
  621. else if (a.code < b.code) {
  622. rst = -1;
  623. }
  624. return rst;
  625. }
  626. }
  627. arr.sort(compare());
  628. }
  629. }