fee_rate.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. $("#logout").click(function () {
  17. location.href = '/logout';
  18. });
  19. });
  20. function loadProjectFeeRates(fileID) {
  21. $.ajax({
  22. type: "POST",
  23. url: '/feeRates/getProjectFeeRates',
  24. data: {"fileID": fileID},
  25. success: function (result) {
  26. if (result.data) {
  27. datas = result.data[0].rates;
  28. datas=rate_data;
  29. createSpreadView(true);
  30. }
  31. },
  32. error: function (jqXHR, textStatus, errorThrown) {
  33. ajaxErrorInfo(jqXHR, textStatus, errorThrown);
  34. }
  35. });
  36. }
  37. function loadStdFeeRateLibNames(region) {
  38. $('#inlineFormCustomSelect').empty();
  39. $.ajax({
  40. type: "POST",
  41. url: '/feeRates/getLibNames',
  42. data: {"region": region},
  43. success: function (result) {
  44. if (result.data) {
  45. for (var i = 0; i < result.data.length; i++) {
  46. $("#inlineFormCustomSelect").append("<option value=" + result.data[i].libID + '>' +
  47. result.data[i].libName + "</option>");
  48. }
  49. $("#inlineFormCustomSelect").get(0).selectedIndex = 0;
  50. }
  51. },
  52. error: function (jqXHR, textStatus, errorThrown) {
  53. ajaxErrorInfo(jqXHR, textStatus, errorThrown);
  54. }
  55. });
  56. }
  57. function loadLibFeeRates(libID) {
  58. $.ajax({
  59. type: "POST",
  60. url: '/feeRates/getLibFeeRates',
  61. data: {"libID": libID},
  62. success: function (result) {
  63. if (result.data) {
  64. datas = result.data[0].rates;
  65. createSpreadView(false);
  66. }
  67. },
  68. error: function (jqXHR, textStatus, errorThrown) {
  69. ajaxErrorInfo(jqXHR, textStatus, errorThrown);
  70. }
  71. });
  72. }
  73. function createSpreadView(canEdit) {
  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(rate_data);
  141. },
  142. update: function(params) {
  143. $.ajax({
  144. type: 'POST',
  145. url: '/feeRates/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. function rowClickFun(sender, args) {
  165. alert(args.item.dataItem.rate);
  166. }
  167. spreadView = new GC.Spread.Views.DataView($('#divFee')[0],
  168. dataSource, columns, new GC.Spread.Views.Plugins.GridLayout(options));
  169. spreadView["rowDbClick"].addHandler(rowClickFun);
  170. spreadView.invalidate();
  171. document.querySelector('#divFee').focus();
  172. }
  173. function reFreshRateViews() {
  174. if(spreadView){
  175. spreadView.refresh();
  176. }else {
  177. loadProjectFeeRates(feeRateFileID);
  178. }
  179. }
  180. var feeRateObj = {
  181. getFeeRate: function (){
  182. }
  183. }
  184. $('#tab_fee_rate').bind('click', function () {
  185. reFreshRateViews();
  186. //creatennnSpreadView();
  187. });