revenueAnalysis.vue 2.6 KB

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