feeRate.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * Created by CSL on 2017-03-23.
  3. */
  4. var region = '重庆';
  5. var feeRateFileID = 5;
  6. var spreadView;
  7. $(document).ready(function () {
  8. $("#inlineFormCustomSelect").change(function () {
  9. var libID = $("#inlineFormCustomSelect").val();
  10. loadLibFeeRates(libID);
  11. });
  12. $("#projectFeeFile").click(function () {
  13. loadProjectFeeRates(feeRateFileID);
  14. });
  15. });
  16. function loadProjectFeeRates(fileID) {
  17. $.ajax({
  18. type: "POST",
  19. url: '/fees/getProjectFeeRates',
  20. data: {"fileID": fileID},
  21. success: function (result) {
  22. if (result.data) {
  23. createSpreadView(result.data[0].rates, true);
  24. }
  25. },
  26. error: function (result) {
  27. alert('内部程序错误!');
  28. }
  29. });
  30. }
  31. function loadStdFeeRateLibNames(region) {
  32. $('#inlineFormCustomSelect').empty();
  33. $.ajax({
  34. type: "POST",
  35. url: '/fees/getLibNames',
  36. data: {"region": region},
  37. success: function (result) {
  38. if (result.data) {
  39. for (var i = 0; i < result.data.length; i++) {
  40. $("#inlineFormCustomSelect").append("<option value=" + result.data[i].libID + '>' +
  41. result.data[i].libName + "</option>");
  42. }
  43. $("#inlineFormCustomSelect").get(0).selectedIndex = 0;
  44. }
  45. },
  46. error: function (result) {
  47. alert('内部程序错误!');
  48. }
  49. });
  50. }
  51. function loadLibFeeRates(libID) {
  52. $.ajax({
  53. type: "POST",
  54. url: '/fees/getLibFeeRates',
  55. data: {"libID": libID},
  56. success: function (result) {
  57. if (result.data) {
  58. createSpreadView(result.data[0].rates, false);
  59. }
  60. },
  61. error: function (result) {
  62. alert('内部程序错误!');
  63. }
  64. });
  65. }
  66. function createSpreadView(data, canEdit) {
  67. // 创建前先销毁旧树表。
  68. //$('#divFee').empty(); // 清空不行,浏览器跟踪显示错误数狂飚:TypeError: G is null
  69. //$('#divFee').remove(); // 删除可以,但是太山寨。
  70. //$('#content').append($('<div class="grid" id="divFee"></div>'));
  71. // 以下找到官方的处理方法,比较面向对象
  72. if (spreadView) {
  73. spreadView.destroy();
  74. spreadView = null;
  75. }
  76. var columns = [
  77. {
  78. id: 'name',
  79. caption: '名称',
  80. dataField: 'name',
  81. width: 250
  82. },
  83. {
  84. id: 'rate',
  85. caption: '费率',
  86. dataField: 'rate',
  87. format: '0.000',
  88. width: 80,
  89. minWidth: 50
  90. },
  91. {
  92. id: 'memo',
  93. caption: '说明',
  94. dataField: 'memo',
  95. width: 200,
  96. minWidth: 120
  97. },
  98. {
  99. id: 'ID',
  100. caption: 'ID',
  101. dataField: 'ID',
  102. width: 80,
  103. visible: false
  104. },
  105. {
  106. id: 'ParentID',
  107. caption: '父结点ID',
  108. dataField: 'ParentID',
  109. width: 80,
  110. visible: false
  111. }
  112. ];
  113. var option = {
  114. allowSorting: false,
  115. showRowHeader: true,
  116. colMinWidth: 80,
  117. colHeaderHeight: 35,
  118. rowHeight: 30,
  119. allowEditing: canEdit,
  120. hierarchy: {
  121. keyField: 'ID',
  122. parentField: 'ParentID',
  123. collapsed: false,
  124. column: 'name'
  125. }
  126. };
  127. spreadView = new GC.Spread.Views.DataView($('#divFee')[0],
  128. data, columns, new GC.Spread.Views.Plugins.GridLayout(option));
  129. var opts = spreadView.layoutEngine.options;
  130. opts.editMode = 'inline';
  131. opts.editUnit = 'cell';
  132. if (canEdit){ opts.selectionUnit = 'cell'; }
  133. else{ opts.selectionUnit = 'row'; }
  134. spreadView.invalidate();
  135. document.querySelector('#divFee').focus();
  136. }