ration.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. var rationOprObj = {
  8. workBook: null,
  9. currentRations: {},
  10. currentSectionId: -1,
  11. setting: {
  12. header:[
  13. {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String"},
  14. {headerName:"名称",headerWidth:300,dataCode:"name", dataType: "String"},
  15. {headerName:"单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center"},
  16. {headerName:"基价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  17. {headerName:"显示名称(以%s表示参数)",headerWidth:350,dataCode:"caption", dataType: "String"},
  18. {headerName:"取费专业",headerWidth:120,dataCode:"feeType", dataType: "Number", hAlign: "center"}
  19. ],
  20. view:{
  21. comboBox:[
  22. {row:-1,col:2,rowCount:-1,colCount:1}
  23. ],
  24. lockedCells:[
  25. {row:-1,col:3,rowCount:-1, colCount:1}
  26. ]
  27. }
  28. },
  29. buildSheet: function(container) {
  30. var me = this;
  31. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  32. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  33. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  34. },
  35. onClipboardPasting: function(sender, args) {
  36. var me = rationOprObj;
  37. if (args.cellRange.colCount != me.setting.header.length) {
  38. args.cancel = true;
  39. }
  40. },
  41. onClipboardPasted: function(e, info) {
  42. var me = rationOprObj;
  43. var cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  44. var updateArr = [], addArr = [];
  45. var items = sheetCommonObj.analyzePasteData(me.setting, info);
  46. for (var i = 0; i < items.length; i++) {
  47. if (cacheSection) {
  48. var hasCacheItem = false;
  49. for (var j = 0; j < cacheSection.length; j++) {
  50. if (cacheSection[j][me.setting.header[0].dataCode] == items[i][me.setting.header[0].dataCode]) {
  51. hasCacheItem = true;
  52. items[i]["ID"] = cacheSection[j]["ID"];
  53. break;
  54. }
  55. }
  56. if (!hasCacheItem) {
  57. addArr.push(items[i]);
  58. } else {
  59. updateArr.push(items[i]);
  60. }
  61. } else {
  62. addArr.push(items[i])
  63. }
  64. };
  65. if (updateArr.length > 0 || addArr.length > 0) {
  66. $.ajax({
  67. type:"POST",
  68. url:"api/mixUpdateRationItems",
  69. data:{"sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr)},
  70. dataType:"json",
  71. cache:false,
  72. timeout:5000,
  73. success:function(result){
  74. if (result.err) {
  75. alert(err);
  76. me.getRationItems(me.currentSectionId);
  77. } else {
  78. if (!(me.currentRations["_SEC_ID_" + me.currentSectionId])) {
  79. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  80. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  81. }
  82. if (addArr.length > 0) {
  83. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  84. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  85. }
  86. for (var i = 0; i < updateArr.length; i++) {
  87. for (var j = 0; j < cacheSection.length; j++) {
  88. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  89. cacheSection[j] = updateArr[i];
  90. }
  91. }
  92. }
  93. me.showRationItems(me.currentSectionId);
  94. }
  95. },
  96. error:function(){
  97. }
  98. })
  99. }
  100. },
  101. getRationItems: function(sectionID){
  102. if (sectionID != -1) {
  103. var me = rationOprObj;
  104. me.currentSectionId = sectionID;
  105. if (me.currentRations["_SEC_ID_" + sectionID]) {
  106. me.showRationItems(sectionID);
  107. } else {
  108. $.ajax({
  109. type:"POST",
  110. url:"api/getRationItems",
  111. data:{"sectionID": sectionID},
  112. dataType:"json",
  113. cache:false,
  114. timeout:1000,
  115. success:function(result){
  116. if (result) {
  117. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  118. me.showRationItems(sectionID);
  119. }
  120. },
  121. error:function(err){
  122. alert(err);
  123. }
  124. })
  125. }
  126. }
  127. },
  128. showRationItems: function(sectionID){
  129. var me = rationOprObj;
  130. if (me.workBook) {
  131. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  132. var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  133. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  134. sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  135. } else {
  136. //清除ration数据及工料机数据
  137. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  138. }
  139. }
  140. }
  141. }