revenueAnalysis.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!-- 营收分析 -->
  2. <template>
  3. <view class="revenue">
  4. <template v-if="type === 'line'">
  5. <view class="revenue-line">
  6. <LineChart v-if="hasData"
  7. :chartData="chartData" :title="title" :opts="opts" />
  8. <view class="empty" v-else>
  9. <u-empty></u-empty>
  10. </view>
  11. </view>
  12. </template>
  13. <template v-else>
  14. <view class="revenue-line">
  15. <ColumnChart v-if="hasData"
  16. :chartData="chartData" :title="title" :opts="opts" />
  17. <view class="empty" v-else>
  18. <u-empty></u-empty>
  19. </view>
  20. </view>
  21. </template>
  22. <u-loading-page :loading="loading" loading-text="loading..."></u-loading-page>
  23. </view>
  24. </template>
  25. <script>
  26. import LineChart from '@/components/lineChart.vue'
  27. import ColumnChart from '@/components/columnChart.vue'
  28. export default {
  29. components: {
  30. LineChart,
  31. ColumnChart
  32. },
  33. props: {
  34. type: {
  35. type: String,
  36. default: 'line'
  37. },
  38. title: {
  39. type: String,
  40. default: ''
  41. },
  42. params: {
  43. type: Object,
  44. default: () => {}
  45. }
  46. },
  47. data() {
  48. return {
  49. chartData: {
  50. categories: [],
  51. series: []
  52. },
  53. hasData: false,
  54. loading: false,
  55. opts: {
  56. enableScroll: true,
  57. tooltip: {
  58. trigger: 'axis'
  59. },
  60. xAxis: {
  61. rotateLabel: true,
  62. scrollShow: true,
  63. itemCount: 8
  64. },
  65. yAxis: {
  66. showTitle: true,
  67. splitNumber: 5,
  68. data: [{
  69. title: '收益(元)',
  70. titleOffsetY: -3
  71. }]
  72. },
  73. legend: {
  74. show: true
  75. },
  76. dataLabel: false,
  77. padding: [20, 10, 10, 10],
  78. extra: {
  79. column: {
  80. width: 20
  81. }
  82. }
  83. }
  84. }
  85. },
  86. methods: {
  87. /**
  88. * 获取数据
  89. */
  90. getData({
  91. reportType,
  92. queryDate
  93. }) {
  94. this.hasData = false
  95. this.chartData.categories = []
  96. this.chartData.series = []
  97. this.getRoadData({ reportType, queryDate })
  98. },
  99. /**
  100. * 路段数据
  101. */
  102. getRoadData({ reportType, queryDate }) {
  103. this.loading = true
  104. uni.$u.api.operationalAnalysisApi.getRevenueDataApi({
  105. reportType,
  106. queryDate
  107. }).then(res => {
  108. if (res.code === 200) {
  109. if (res.data.itemList && res.data.itemList.length) {
  110. this.chartData.series[0] = {
  111. name: '路段',
  112. data: []
  113. }
  114. this.chartData.categories = res.data.itemList.map(item => {
  115. return item.statisTime
  116. })
  117. this.chartData.series[0].data = res.data.itemList.map(item => {
  118. return item.amt
  119. })
  120. }
  121. if (this.chartData.series.length && this.chartData.series[0].data.length) {
  122. this.hasData = true
  123. } else {
  124. this.hasData = false
  125. }
  126. this.loading = false
  127. }
  128. })
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .revenue {
  135. background-color: #fff;
  136. border-radius: 5px;
  137. .empty {
  138. padding: 15px;
  139. }
  140. }
  141. </style>