abnormalRenewalChart.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="abnormal-renewal-chart-wrap">
  3. <div class="top-wrap">
  4. <el-date-picker
  5. v-model="date"
  6. type="monthrange"
  7. range-separator="至"
  8. start-placeholder="开始日期"
  9. end-placeholder="结束日期"
  10. :clearable="false"
  11. value-format="yyyy-MM"
  12. @change="handleDateChange"
  13. />
  14. <div style="color:#409EFF;cursor: pointer;" @click="handleClose">
  15. <img src="~@/assets/img/icons/changeLang.png" alt="">
  16. <span style="display:inline-block;position: relative;top:-3px;left:3px">数据表</span>
  17. </div>
  18. </div>
  19. <div class="chart-main-wrap">
  20. <h2 style="text-align:center;font-size:30px;margin:30px 0;">续约异常客户统计图</h2>
  21. <div class="chart-box" ref="chartBox"></div>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import { dataMainInterface } from '@/api/api.js';
  27. import { nextTick } from 'vue';
  28. export default {
  29. data() {
  30. return {
  31. date:'',
  32. myChart:null
  33. }
  34. },
  35. created() {
  36. this.date=[this.$moment().format('YYYY-01'),this.$moment().format('YYYY-MM')]
  37. },
  38. mounted() {
  39. this.getData()
  40. },
  41. methods: {
  42. async getData(){
  43. const res=await dataMainInterface.unusualRenewalCustomStatisticChartData({
  44. StartDate:this.date[0],
  45. EndDate:this.date[1]
  46. })
  47. if(res.Ret===200){
  48. this.$nextTick(()=>{
  49. this.renderChart(res.Data)
  50. })
  51. }
  52. },
  53. handleDateChange(){
  54. this.getData()
  55. },
  56. handleClose(){
  57. this.$emit('close')
  58. },
  59. renderChart(data){
  60. const arr=data.List||[]
  61. const options={
  62. legend: {
  63. name: [],
  64. icon:'circle',
  65. left: 'center',
  66. },
  67. tooltip: {
  68. formatter:function(params){
  69. let str=`${params.name}<br>
  70. <span style='display:inline-block;width:15px;height:15px;background:#FDB863;border-radius:100%'></span>
  71. ${params.seriesName}&nbsp;&nbsp;${params.value}`
  72. return str
  73. }
  74. },
  75. title: {
  76. text: '',
  77. },
  78. color: ['#FDB863'],
  79. textStyle: {
  80. fontSize: 12,
  81. },
  82. xAxis: {
  83. type: '',
  84. data: [],
  85. // /* x轴文字 */
  86. axisLabel: {
  87. show: true,
  88. rotate: '40', //字体倾斜
  89. textStyle: {
  90. color: '#999', //更改坐标轴文字颜色
  91. fontSize: 12, //更改坐标轴文字大小
  92. },
  93. },
  94. },
  95. yAxis: {
  96. type: 'value',
  97. minInterval:1,
  98. position: 'left',
  99. name:'家',
  100. splitLine:{
  101. lineStyle:{
  102. type:'dotted'
  103. }
  104. }
  105. },
  106. series: [
  107. {
  108. data:[],
  109. name:'续约异常客户合计',
  110. type:'bar',
  111. yAxisIndex: 0,
  112. }
  113. ],
  114. }
  115. arr.forEach(item => {
  116. options.xAxis.data.push(item.Date)
  117. options.series[0].data.push(item.CompanyNum)
  118. });
  119. console.log(options);
  120. const chart = this.$refs.chartBox;
  121. if(chart){
  122. this.$nextTick(()=>{
  123. if(!this.myChart){
  124. this.myChart = echarts.init(chart);
  125. this.myChart.setOption(options);
  126. }else{
  127. this.myChart.setOption(options,true);
  128. }
  129. })
  130. }
  131. }
  132. },
  133. }
  134. </script>
  135. <style lang="scss" scoped>
  136. .abnormal-renewal-chart-wrap{
  137. position: absolute;
  138. top: 0;
  139. left: 0;
  140. right: 0;
  141. bottom: 0;
  142. background-color: #fff;
  143. padding: 30px;
  144. .top-wrap{
  145. display: flex;
  146. justify-content: space-between;
  147. }
  148. .chart-box{
  149. margin: 0 auto;
  150. width: 80%;
  151. height: 500px;
  152. }
  153. }
  154. </style>