index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <Card :title="title" :subTitle="subTitle" :icon="icon" class="online-pay">
  3. <div class="total display-flex" v-if="showTitle">
  4. <div class="img">
  5. <img src="./images/icon-total.png" alt="" class="icon">
  6. </div>
  7. <div>
  8. 总缴费(近12个月):¥{{ total }}
  9. </div>
  10. </div>
  11. <div class="bar-con">
  12. <div ref="onlinePayBar" class="online-pay-bar"></div>
  13. </div>
  14. </Card>
  15. </template>
  16. <script>
  17. import * as echarts from 'echarts'
  18. // import { getBigNumberWithUint } from '@/libs/tools.js'
  19. import { huiJiaApi } from '@/api'
  20. import Card from '@/views/hui-jia/components/card'
  21. import icon from './images/icon-title.png'
  22. export default {
  23. name: 'OnlinePay',
  24. components: {
  25. Card
  26. },
  27. props: {
  28. showLegend: {
  29. type: Boolean,
  30. default: true
  31. },
  32. showTitle: {
  33. type: Boolean,
  34. default: true
  35. }
  36. },
  37. data () {
  38. return {
  39. onlinePayInstance: null,
  40. xAxisData: ['十二月', '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月'],
  41. seriesData: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  42. total: 0,
  43. title: '线上缴费统计',
  44. subTitle: '近12个月',
  45. icon: icon
  46. }
  47. },
  48. mounted () {
  49. this.initChart()
  50. this.getOnlinePayMonth()
  51. window.addEventListener("resize", this.handleResize)
  52. },
  53. beforeDestroy() {
  54. if (this.onlinePayInstance) {
  55. this.onlinePayInstance.dispose()
  56. }
  57. window.removeEventListener("resize", this.handleResize)
  58. },
  59. methods: {
  60. getOnlinePayMonth () {
  61. huiJiaApi.getOnlinePayMonth().then(res => {
  62. if(res && res.data && res.data.data && res.data.data.list.length) {
  63. this.total = res.data.data.allSum
  64. this.xAxisData = res.data.data.list.map(item => item.statData)
  65. this.seriesData = res.data.data.list.map(item => item.payAmount)
  66. this.initChart()
  67. }
  68. })
  69. },
  70. /**
  71. * 获取一个和max最接近的能被5整除的无零头整数
  72. */
  73. getMax (max) {
  74. if (max <= 10) return 10
  75. let pow = max.toString().length - 2
  76. pow = Math.pow(10, pow)
  77. max = Math.ceil(max / pow / 10) * 10 * pow
  78. return max
  79. },
  80. initChart () {
  81. this.onlinePayInstance = echarts.init(this.$refs.onlinePayBar)
  82. const xAxisData = this.xAxisData
  83. const seriesData = this.seriesData
  84. // let max = 0
  85. // max = seriesData.reduce((max, num) => {
  86. // return Math.max(Number(max), Number(num))
  87. // })
  88. // max = this.getMax(max)
  89. const option = {
  90. tooltip: {},
  91. legend: {
  92. show: this.showLegend,
  93. right: '0',
  94. top: '20px',
  95. textStyle: {
  96. color: '#fff'
  97. }
  98. },
  99. grid: {
  100. top: this.showLegend ? '80px' : '5%',
  101. bottom: '0px',
  102. left: '0px',
  103. right: '0px',
  104. containLabel: true
  105. },
  106. xAxis: {
  107. axisLabel: {
  108. color: '#fff',
  109. margin: 15,
  110. fontSize: 12,
  111. formatter: function (val, idx) {
  112. let value = xAxisData[idx]
  113. return value
  114. }
  115. },
  116. axisLine: {
  117. show: true,
  118. lineStyle: {
  119. color: '#666',
  120. opacity: 1,
  121. cap: 'round'
  122. }
  123. },
  124. boundaryGap: true,
  125. axisTick: {
  126. alignWithLabel: true,
  127. length: 7,
  128. lineStyle: {
  129. width: 3,
  130. color: '#fff',
  131. opacity: 0.5
  132. }
  133. },
  134. splitLine: {
  135. show: true,
  136. lineStyle: {
  137. color: '#fff',
  138. opacity: 0.3,
  139. cap: 'round',
  140. type: [5, 10]
  141. }
  142. },
  143. max: function (value) { // x轴左侧留白
  144. return value.max + 0.3
  145. },
  146. min: function (value) { // x轴左侧留白
  147. return -0.3
  148. },
  149. data: xAxisData
  150. },
  151. yAxis: [
  152. {
  153. axisLabel: {
  154. color: 'rgba(160, 179, 214, 0.7)',
  155. fontSize: 11,
  156. margin: 12
  157. },
  158. axisLine: {
  159. show: false,
  160. lineStyle: {
  161. color: '#fff'
  162. }
  163. },
  164. axisTick: {
  165. length: 14,
  166. lineStyle: {
  167. width: 2,
  168. fontSize: 16
  169. }
  170. },
  171. splitLine: {
  172. show: true,
  173. lineStyle: {
  174. color: '#fff',
  175. opacity: 0.3,
  176. cap: 'round',
  177. type: 'dashed',
  178. dashOffset: 5
  179. }
  180. }
  181. },
  182. {
  183. type: 'value',
  184. position: 'right',
  185. axisLabel: {
  186. show: false
  187. },
  188. axisTick: {
  189. show: true,
  190. length: 14,
  191. lineStyle: {
  192. width: 2,
  193. fontSize: 16
  194. }
  195. },
  196. axisLine: {
  197. show: false
  198. }
  199. }
  200. ],
  201. series: [{
  202. name: '线上流水',
  203. type: 'bar',
  204. barWidth: '20%',
  205. labelLine: {
  206. show: false
  207. },
  208. itemStyle: {
  209. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  210. { offset: 0, color: '#0F67F8' },
  211. { offset: 0.5, color: '#98D7F1' },
  212. { offset: 1, color: '#77ECED' }
  213. ]),
  214. barBorderRadius: [10, 10, 0, 0]
  215. },
  216. data: seriesData
  217. }]
  218. }
  219. this.onlinePayInstance.setOption(option)
  220. this.onlinePayInstance.resize()
  221. },
  222. handleResize() {
  223. if (this.onlinePayInstance) {
  224. this.onlinePayInstance.resize()
  225. }
  226. },
  227. }
  228. }
  229. </script>
  230. <style lang="scss">
  231. @import '@/assets/css/function.scss';
  232. @import '@/assets/css/screen.scss';
  233. .bar-con{
  234. display: flex;
  235. flex-direction: column;
  236. height: 100%;
  237. width: 100%;
  238. .online-pay-bar {
  239. flex: 1;
  240. width: 100%;
  241. height: 100%;
  242. }
  243. }
  244. .online-pay {
  245. .total{
  246. position: absolute;
  247. height: halfH(24);
  248. line-height: halfH(24);
  249. padding: halfH(18) halfW(18);
  250. color: #fff;
  251. font-size: halfW(14);
  252. border-radius: 5px;
  253. background-color: rgba(17, 28, 48, 1);
  254. text-align: center;
  255. border: 1px solid rgba(0, 123, 211, 0.2);
  256. }
  257. .img{
  258. width: halfW(40);
  259. height: halfH(40);
  260. margin-right: halfW(27);
  261. margin-top: halfH(-7);
  262. padding: halfH(8) halfW(8);
  263. box-sizing: border-box;
  264. background: #12223C;
  265. border-radius: 50%;
  266. .icon{
  267. width: 100%;
  268. height: 100%;
  269. }
  270. }
  271. }
  272. </style>