subsidy-cost.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. var reqList = [];
  2. var util = {};
  3. util.treeTableXcode = function(data, xcode) {
  4. xcode = xcode || "";
  5. for(var i = 0; i < data.length; i++) {
  6. var item = data[i];
  7. item.xcode = xcode + i;
  8. if(item.children && item.children.length > 0) {
  9. util.treeTableXcode(item.children, item.xcode + "-");
  10. }
  11. }
  12. };
  13. Vue.use(Vuedals.default);
  14. new Vue({
  15. el: "#main",
  16. data: {
  17. tableData: [],
  18. valueArea: "350203",
  19. optionsArea: [{code:"350203",name:"思明区"}],
  20. dateValue: [],
  21. pickerOptions: {
  22. disabledDate: function(d) {
  23. return d > new Date();
  24. }
  25. },
  26. isloading:false, //加载中
  27. },
  28. components: {
  29. vuedals: Vuedals.Component
  30. },
  31. mounted: function() {
  32. var vm = this
  33. //初始化时间
  34. var end = new Date();
  35. var start = new Date();
  36. start.setDate(1)
  37. vm.dateValue = [start.format("yyyy-MM-dd"), end.format("yyyy-MM-dd")]
  38. //初始化数据
  39. vm.initData()
  40. // vm.getDistrict()
  41. $("#main").removeClass("c-hide");
  42. //监听后退按钮的操作
  43. EventBus.$on("back-click", function(arg) {
  44. history.go(-1);
  45. });
  46. //监听页面刷新
  47. EventBus.$on("refresh-click", function(arg) {
  48. vm.initData()
  49. });
  50. window.onresize = function() {
  51. }
  52. },
  53. methods: {
  54. initData: function() {
  55. var vm=this
  56. var startDate,endDate
  57. if(vm.dateValue[0]>vm.dateValue[1]){
  58. vm.$message.warning("开始时间应小于结束时间")
  59. return false
  60. }
  61. vm.isloading=true
  62. startDate=vm.dateValue[0]
  63. endDate=vm.dateValue[1]
  64. var params={
  65. userAgent:localStorage.getItem('wlyyAgentForDoc'),
  66. area:vm.valueArea,startDate:startDate,endDate:endDate,
  67. }
  68. statisticAPI.subsidyExpense(params).then(function(res) {
  69. vm.isloading=false
  70. if(res.status == 200) {
  71. vm.tableData=res.data
  72. util.treeTableXcode(vm.tableData);
  73. } else {
  74. vm.$message.error(res.msg)
  75. }
  76. })
  77. },
  78. changeDateValue: function() {
  79. alert(JSON.stringify(this.dateValue))
  80. },
  81. getDistrict: function() {
  82. var vm=this
  83. var params={
  84. type:3,code:"350200"
  85. }
  86. homeAPI.getDistrict(params).then(function(res) {
  87. if(res.status == 200) {
  88. vm.optionsArea=res.list
  89. vm.valueArea=vm.optionsArea[0].code
  90. vm.initData()
  91. } else {
  92. vm.$message.error(res.msg)
  93. }
  94. })
  95. },
  96. exportData: function() {
  97. var vm=this
  98. var startDate,endDate
  99. if(typeof(vm.dateValue[0])!="string"){
  100. startDate=vm.dateValue[0].format("yyyy-MM-dd")
  101. endDate=vm.dateValue[1].format("yyyy-MM-dd")
  102. }else{
  103. startDate=vm.dateValue[0]
  104. endDate=vm.dateValue[1]
  105. }
  106. var params={
  107. userAgent:localStorage.getItem('wlyyAgentForDoc'),
  108. area:vm.valueArea,startDate:startDate,endDate:endDate,
  109. }
  110. var str = statisticAPI.subsidyExpenseExport+"?area="+vm.valueArea+"&startDate="+startDate+"&endDate="+endDate;
  111. window.open(str, "接收包数据导出")//导出数据
  112. },
  113. treeClick: function(item, index) {
  114. if(item.open) {
  115. this.collapse(item, index);
  116. } else {
  117. this.expand(item, index);
  118. }
  119. },
  120. expand: function(item, index) {
  121. if(!item.children) {
  122. return index;
  123. }
  124. //展开
  125. for(var i = 0; item.children && i < item.children.length; i++) {
  126. var child = item.children[i];
  127. this.tableData.splice(++index, 0, child);
  128. if(child.children && child.children.length > 0 && child.open) {
  129. index = this.expand(child, index);
  130. }
  131. }
  132. item.open = true;
  133. return index;
  134. },
  135. collapse: function(item, index) {
  136. if(!item.children) {
  137. return index;
  138. }
  139. //收缩
  140. item.open = false;
  141. var len = this.tableData[index].children.length;
  142. this.tableData.splice(index + 1, len);
  143. }
  144. }
  145. });