revenueAnalysis.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. }
  119. this.getParkingData({ reportType, queryDate })
  120. })
  121. },
  122. /**
  123. * 停车场数据
  124. */
  125. getParkingData({ reportType, queryDate }) {
  126. uni.$u.api.operationalAnalysisApi.getParkingRevenueDataApi({
  127. reportType,
  128. queryDate
  129. }).then(res => {
  130. if (res.code === 200) {
  131. if (res.data.itemList && res.data.itemList.length) {
  132. if (this.chartData.series.length) {
  133. this.chartData.series[1] = {
  134. name: '停车场',
  135. data: []
  136. }
  137. this.chartData.series[1].data = res.data.itemList.map(item => {
  138. return item.amt
  139. })
  140. } else {
  141. this.chartData.series[0] = {
  142. name: '停车场',
  143. data: []
  144. }
  145. this.chartData.series[0].data = res.data.itemList.map(item => {
  146. return item.amt
  147. })
  148. }
  149. if (!this.chartData.categories.length) {
  150. this.chartData.categories = res.data.itemList.map(item => {
  151. return item.statisTime
  152. })
  153. }
  154. this.hasData = true
  155. } else if (this.chartData.series.length === 1) {
  156. this.hasData = true
  157. } else if (!this.chartData.series.length) {
  158. this.hasData = false
  159. }
  160. }
  161. })
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .revenue {
  168. background-color: #fff;
  169. border-radius: 5px;
  170. .empty {
  171. padding: 15px;
  172. }
  173. }
  174. </style>