ration.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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,data:"code"},
  18. {headerName:"名称",headerWidth:300,data:"name"},
  19. {headerName:"单位",headerWidth:120,data:"unit"},
  20. {headerName:"基价",headerWidth:120,data:"basePrice"},
  21. {headerName:"显示名称(以%s表示参数)",headerWidth:350,data:"caption"},
  22. {headerName:"取费专业",headerWidth:120,data:"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);
  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].data] = info.pasteData.text.slice(preStrIdx, i);
  61. propId++;
  62. preStrIdx = i + 1;
  63. } else if (i == info.pasteData.text.length - 1) {
  64. itemObj[me.setting.header[propId].data] = info.pasteData.text.slice(preStrIdx);
  65. rst.push(itemObj);
  66. }
  67. }
  68. return rst;
  69. };
  70. var items = private_createRationItems();
  71. for (var i = 0; i < items.length; i++) {
  72. if (cacheSection) {
  73. var hasCacheItem = false;
  74. for (var j = 0; j < cacheSection.length; j++) {
  75. if (cacheSection[j][me.setting.header[0].data] == items[i][me.setting.header[0].data]) {
  76. hasCacheItem = true;
  77. break;
  78. }
  79. }
  80. if (hasCacheItem) addArr.push(items[i])
  81. else updateArr.push(items[i])
  82. } else {
  83. addArr.push(items[i])
  84. }
  85. };
  86. },
  87. getRationItems: function(sectionID){
  88. if (sectionID != -1) {
  89. var me = rationOprObj;
  90. me.currentSectionId = sectionID;
  91. if (me.currentRations["_SEC_ID_" + sectionID]) {
  92. me.showRationItems(sectionID);
  93. } else {
  94. $.ajax({
  95. type:"POST",
  96. url:"api/getRationItems",
  97. data:{"sectionID": sectionID},
  98. dataType:"json",
  99. cache:false,
  100. timeout:1000,
  101. success:function(result){
  102. if (result) {
  103. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  104. me.showRationItems(sectionID);
  105. }
  106. },
  107. error:function(){
  108. }
  109. })
  110. }
  111. }
  112. },
  113. showRationItems: function(sectionID){
  114. var me = rationOprObj;
  115. if (me.workBook) {
  116. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  117. //
  118. } else {
  119. //清除ration数据及工料机数据
  120. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, 3);
  121. }
  122. }
  123. }
  124. }