feeRate.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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(datas, 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. allowEditing: false
  83. },
  84. {
  85. id: 'rate',
  86. caption: '费率',
  87. dataField: 'rate',
  88. format: '0.000',
  89. width: 80,
  90. minWidth: 50,
  91. allowEditing: true
  92. },
  93. {
  94. id: 'memo',
  95. caption: '说明',
  96. dataField: 'memo',
  97. width: 200,
  98. minWidth: 120,
  99. allowEditing: false
  100. },
  101. {
  102. id: 'ID',
  103. caption: 'ID',
  104. dataField: 'ID',
  105. width: 80,
  106. visible: false,
  107. allowEditing: false
  108. },
  109. {
  110. id: 'ParentID',
  111. caption: '父结点ID',
  112. dataField: 'ParentID',
  113. width: 80,
  114. visible: false,
  115. allowEditing: false
  116. }
  117. ];
  118. var options = {
  119. allowSorting: false,
  120. showRowHeader: true,
  121. colMinWidth: 80,
  122. colHeaderHeight: 35,
  123. rowHeight: 30,
  124. allowEditing: canEdit,
  125. editMode: 'inline',
  126. editUnit: 'cell',
  127. selectionUnit: (canEdit == true) ? "cell" : "row",
  128. hierarchy: {
  129. keyField: 'ID',
  130. parentField: 'ParentID',
  131. collapsed: false,
  132. column: 'name'
  133. }
  134. };
  135. spreadView = new GC.Spread.Views.DataView($('#divFee')[0],
  136. datas, columns, new GC.Spread.Views.Plugins.GridLayout(options));
  137. spreadView.invalidate();
  138. document.querySelector('#divFee').focus();
  139. }