马宇豪
2024-11-12 7a7265353879a63d47553324c19ab4bd349d03f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<template>
  <div class="inner">
    <div id="charts" style="width: 100%;height: 400px"></div>
    <a-row type="flex" justify="space-between" style="margin-bottom: 20px">
      <a-col :span="20">
        <a-row type="flex" :gutter="18">
          <a-col :span="8">
            <a-range-picker
                v-model="timeRange"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="timeChange"
                @ok="timeOk"
                style="width: 100%"
            />
          </a-col>
          <a-col :span="6">
            <a-button type="primary" @click="searchData">查询</a-button>
            <a-button style="margin-left: 12px" @click="resetSearch">重置</a-button>
          </a-col>
        </a-row>
      </a-col>
    </a-row>
 
    <!-- 表格实体部分-->
    <div class="table-cont">
      <a-button type="primary" v-if="backButton" @click="backData" :loading="backLoading" style="margin-bottom: 20px">返回上级</a-button>
      <a-table :columns="columns" :data-source="data" bordered :pagination="false" :rowKey="record=>record.name">
        <template #index="text,record,index">
          {{ index + 1 }}
        </template>
        <template #name="text,record">
          <a-button type="link" v-if="record.chidren" @click="openSubData(record)">{{ text }}</a-button>
          <span v-else>{{ text }}</span>
        </template>
      </a-table>
    </div>
  </div>
</template>
<script>
import {getTotalStatistics, getTotalStatisticsByArea} from "@/api/list";
import {getReviewDetailByWorker} from "@/api/review";
import axios from "axios";
import Cookies from "js-cookie";
import {getUserInfo} from "@/util/storage";
import * as echarts from 'echarts';
const columns = [{
  title: '序号',
  dataIndex: 'index',
  scopedSlots: {
    customRender: 'index'
  }
},
  {
    title: '地区',
    dataIndex: 'name',
    scopedSlots: {
      customRender: 'name'
    }
  },
  {
    title: '本级任务数',
    dataIndex: 'curentTaskCount'
  },
  {
    title: '短信计费条数',
    dataIndex: 'currentSmsCount'
  },
  {
    title: '下级总任务数',
    dataIndex: 'subordinateTaskCount'
  },
  {
    title: '下级短信计费条数',
    dataIndex: 'subordinateSmsCount'
  },
  {
    title: '合计条数',
    dataIndex: 'smsTotalCount'
  }
];
export default {
  name: 'dataStatistic',
  components: {},
  data() {
    return {
      search:{
        startTime: '',
        endTime: ''
      },
      timeRange: [],
      category: 'default',
      data:[],
      columns,
      backButton: false,
      backLoading: false,
      areaName: null
    }
  },
  mounted() {
    if(getUserInfo().role.id == 1){
      this.columns = this.columns.filter(i=>i.dataIndex !== 'operation')
    }
    this.getChartsData()
  },
  created() {
    const t = this
    if(t.$route.query.name){
      t.areaName = t.$route.query.name
      t.$router.push(t.$route.path)
    }
    t.getData()
  },
  methods: {
    async getData(){
      const t = this
      t.backLoading = true
      const res = await getTotalStatisticsByArea(t.search)
      if(res.data.code == 100){
        if(t.areaName && t.areaName !== '新疆维吾尔自治区'){
          t.data = res.data.data.find(i=>i.name == t.areaName).chidren
          t.backButton = true
          t.areaName = null
        }else{
          t.data = res.data.data
          t.backButton = false
        }
        t.backLoading = false
      }else{
        this.$message.error(res.data.msg)
      }
    },
 
    async getChartsData(){
      const t = this
      const res = await getTotalStatistics()
      if(res.data.code == 100){
        const data = res.data.data
        await t.initChart(data)
      }else{
        this.$message.error(res.data.msg)
      }
    },
 
    async initChart(data){
      var chartDom = document.getElementById('charts');
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        title: {
          text: '近30日用量趋势'
        },
        tooltip: {
          trigger: 'axis',
          formatter: function (params){
            return '日期:' + params[0].name + '<br/>' + '用量:' + params[0].value + '条'
          }
        },
        xAxis: {
          type: 'category',
          data: data.map(i=>i.time)
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: data.map(i=>i.smsCount),
            type: 'line'
          }
        ],
        grid: [
          {
            left: '5%',
            right: '5%',
            top: '20%'
          }
        ],
        color: ['#91cc75']
      };
 
      option && myChart.setOption(option);
    },
 
    async openSubData(record){
      this.data = record.chidren
      this.backButton = true
    },
 
    async backData(){
      await this.getData()
      this.backButton = false
    },
 
    timeChange(value, dateString) {
      const t = this
      if(dateString){
        t.search.startTime = value[0].format('YYYY-MM-DD')
        t.search.endTime = value[1].format('YYYY-MM-DD')
      }
    },
 
    timeOk(value) {
      console.log('onOk: ', value);
    },
 
    searchData(){
      this.getData()
    },
 
    resetSearch(){
      const t = this
      t.search = {
        startTime: '',
        endTime: ''
      }
      t.timeRange = []
      t.getData()
    }
  }
}
 
</script>