feeRate.js 4.9 KB

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