ration.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. var params = {}
  5. $("#dinge").click(function(){
  6. $(this).attr('href', "/rationRepository/ration" + "?params=" + JSON.stringify(params))
  7. })
  8. $("#gongliao").click(function(){
  9. $(this).attr('href', "/rationRepository/gongliao" + "?params=" + JSON.stringify(params))
  10. });
  11. var rationOprObj = {
  12. workBook: null,
  13. currentRations: {},
  14. currentSectionId: -1,
  15. setting: {
  16. header:[
  17. {headerName:"编码",headerWidth:120,dataCode:"code"},
  18. {headerName:"名称",headerWidth:300,dataCode:"name"},
  19. {headerName:"单位",headerWidth:120,dataCode:"unit"},
  20. {headerName:"基价",headerWidth:120,dataCode:"basePrice"},
  21. {headerName:"显示名称(以%s表示参数)",headerWidth:350,dataCode:"caption"},
  22. {headerName:"取费专业",headerWidth:120,dataCode:"feeType"}
  23. ],
  24. view:{
  25. comboBox:[
  26. {row:-1,col:2,rowCount:-1,colCount:1}
  27. ],
  28. lockedCells:[
  29. {row:-1,col:3,rowCount:-1, colCount:1}
  30. ]
  31. }
  32. },
  33. buildSheet: function(container) {
  34. var me = this;
  35. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  36. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  37. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  38. },
  39. onClipboardPasting: function(sender, args) {
  40. var me = rationOprObj;
  41. if (args.cellRange.colCount != me.setting.header.length) {
  42. args.cancel = true;
  43. }
  44. },
  45. onClipboardPasted: function(e, info) {
  46. var me = rationOprObj;
  47. var cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  48. var updateArr = [], addArr = [];
  49. var private_createRationItems = function() {
  50. var rst = [], propId = 0, preStrIdx = 0, itemObj = {};
  51. for (var i = 0; i < info.pasteData.text.length; i++) {
  52. if (info.pasteData.text[i] === "\n") {
  53. propId = 0;
  54. preStrIdx = i + 1;
  55. rst.push(itemObj);
  56. if (i < info.pasteData.text.length - 1) {
  57. itemObj = {};
  58. }
  59. } else if (info.pasteData.text[i] === "\t" || info.pasteData.text[i] === "\r") {
  60. itemObj[me.setting.header[propId].dataCode] = info.pasteData.text.slice(preStrIdx, i);
  61. propId++;
  62. preStrIdx = i + 1;
  63. //if the last copied-cell were empty, should check whether the end of text
  64. if (i == info.pasteData.text.length - 1) {
  65. itemObj[me.setting.header[propId].dataCode] = info.pasteData.text.slice(preStrIdx);
  66. rst.push(itemObj);
  67. }
  68. } else if (i == info.pasteData.text.length - 1) {
  69. itemObj[me.setting.header[propId].dataCode] = info.pasteData.text.slice(preStrIdx);
  70. rst.push(itemObj);
  71. }
  72. }
  73. return rst;
  74. };
  75. var items = private_createRationItems();
  76. for (var i = 0; i < items.length; i++) {
  77. if (cacheSection) {
  78. var hasCacheItem = false;
  79. for (var j = 0; j < cacheSection.length; j++) {
  80. if (cacheSection[j][me.setting.header[0].dataCode] == items[i][me.setting.header[0].dataCode]) {
  81. hasCacheItem = true;
  82. items[i]["ID"] = cacheSection[j]["ID"];
  83. break;
  84. }
  85. }
  86. if (!hasCacheItem) {
  87. addArr.push(items[i]);
  88. } else {
  89. updateArr.push(items[i]);
  90. }
  91. } else {
  92. addArr.push(items[i])
  93. }
  94. };
  95. if (updateArr.length > 0 || addArr.length > 0) {
  96. $.ajax({
  97. type:"POST",
  98. url:"api/mixUpdateRationItems",
  99. data:{"sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr)},
  100. dataType:"json",
  101. cache:false,
  102. timeout:5000,
  103. success:function(result){
  104. if (result.err) {
  105. alert(err);
  106. me.getRationItems(me.currentSectionId);
  107. } else {
  108. if (!(me.currentRations["_SEC_ID_" + me.currentSectionId])) {
  109. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  110. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  111. }
  112. if (addArr.length > 0) {
  113. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  114. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  115. }
  116. for (var i = 0; i < updateArr.length; i++) {
  117. for (var j = 0; j < cacheSection.length; j++) {
  118. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  119. cacheSection[j] = updateArr[i];
  120. }
  121. }
  122. }
  123. me.showRationItems(me.currentSectionId);
  124. }
  125. },
  126. error:function(){
  127. }
  128. })
  129. }
  130. },
  131. getRationItems: function(sectionID){
  132. if (sectionID != -1) {
  133. var me = rationOprObj;
  134. me.currentSectionId = sectionID;
  135. if (me.currentRations["_SEC_ID_" + sectionID]) {
  136. me.showRationItems(sectionID);
  137. } else {
  138. $.ajax({
  139. type:"POST",
  140. url:"api/getRationItems",
  141. data:{"sectionID": sectionID},
  142. dataType:"json",
  143. cache:false,
  144. timeout:1000,
  145. success:function(result){
  146. if (result) {
  147. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  148. me.showRationItems(sectionID);
  149. }
  150. },
  151. error:function(err){
  152. alert(err);
  153. }
  154. })
  155. }
  156. }
  157. },
  158. showRationItems: function(sectionID){
  159. var me = rationOprObj;
  160. if (me.workBook) {
  161. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  162. var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  163. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  164. sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  165. } else {
  166. //清除ration数据及工料机数据
  167. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  168. }
  169. }
  170. }
  171. }