张卓
2022-09-29 4ef1c909df36c48f7f040e9ec408fc15e6745e71
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
<template>
  <div class="topChangeAnalysis">
    <div style="display:flex;height:60px;padding: 20px 15px 0px 15px;">
      <MouthPicker
        :value1="currentDate"
        style="padding-left:0;margin-left:10px;width:160px"
        @sendPickerChild="showPickerChild"
      />
      <RegionCityCX style="margin-left:10px" @regionCode="regionData" />
 
      <el-button style="margin-left:100px" type="primary" @click="getData">查询</el-button>
    </div>
    <div class="content" style="margin:30px 15px 20px 20px ">
      <!-- 在vue中操作dom元素,必须使用ref属性进行注册 -->
      <el-table
        :id="'mytable'"
        :data="tableData"
        border
        :cell-style="columnStyle"
        :header-cell-style="headerColumnStyle"
      >
        <el-table-column label="月份" prop="month" />
        <el-table-column label="AQI达标天数">
          <el-table-column label="天数" prop="aqiComplianceDays" />
          <el-table-column label="同期" prop="comAqiComplianceDays" />
        </el-table-column>
        <el-table-column label="AQI达标率">
          <el-table-column label="达标率" prop="aqiCompliancePer" />
          <el-table-column label="同期" prop="comAqiCompliancePer" />
        </el-table-column>
        <el-table-column label="污染物超标天数">
          <el-table-column label="PM2.5" prop="PM2_5Days" />
          <el-table-column label="PM10" prop="PM10Days" />
          <el-table-column label="SO2" prop="SO2Days" />
          <el-table-column label="NO2" prop="NO2Days" />
          <el-table-column label="CO" prop="CODays" />
          <el-table-column label="03" prop="O3Days" />
        </el-table-column>
        <el-table-column label="首要污染物天数">
          <el-table-column label="PM2.5" prop="PM2_5FirstDays" />
          <el-table-column label="PM10" prop="PM10FirstDays" />
          <el-table-column label="SO2" prop="SO2FirstDays" />
          <el-table-column label="NO2" prop="NO2FirstDays" />
          <el-table-column label="CO" prop="COFirstDays" />
          <el-table-column label="03" prop="O3FirstDays" />
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
 
<script>
import MouthPicker from '@/components/Form/MouthPicker1'
import RegionCityCX from '@/components/Cascader/regionCityCX'
 
export default {
  components: {
    MouthPicker,
    RegionCityCX
  },
  data() {
    return {
      regionDefault: this.$store.state.regionCode,
      currentDate: '',
      tableData: []
    }
  },
 
  created() {
    this.currentYear()
  },
  methods: {
    // table列头背景色,居中
    headerColumnStyle({ row, column, rowIndex, columnIndex }) {
      return 'background:#EAEAEA;text-align:center;border-color: #D3D3D3'
    },
 
    // 列居中
    columnStyle({ row, column, rowIndex, columnIndex }) {
      let str = ''
      let style = ''
      for (const key in row) {
        if (key === column.property) {
          const code = column.property
          if (
            code !== 'month' &&
            code !== 'aqiComplianceDays' &&
            code !== 'comAqiComplianceDays' &&
            code !== 'aqiCompliancePer' &&
            code !== 'comAqiCompliancePer'
          ) {
            const str =  row[key].replace('天', '')
            if (str !== null) {
              if (str >= 0 && str <= 4) {
                style = 'background:#65dd77;color:#007400'
              } else if (str > 4 && str < 10) {
                style = 'background:#fcdf56;color:#868600'
              } else if (str >= 10 && str <= 14) {
                style = 'background:#fd7c43;color:#844100'
              } else if (str > 15 && str <= 19) {
                style = 'background:#fc5656;color:#790000'
              } else if (str > 19 && str <= 24) {
                style = 'background:#fc5689;color:#14000a'
              } else if (str > 24 && str <= 31) {
                style = 'background:#cd3a3a;'
              }
            }
          }
        }
      }
 
      // aqi达标天数
      if (columnIndex === 1 && row.aqiComplianceDays !== null) {
        // 如果等于1, 赋值,判断,填充颜色,
 
        str = row.aqiComplianceDays.replace('天', '')
        style = this.getAqiDaysBackground(str)
      }
      if (columnIndex === 2 && row.comAqiComplianceDays !== null) {
        str = row.comAqiComplianceDays.replace('天', '')
        style = this.getAqiDaysBackground(str)
      }
      // aqi达标率
      if (columnIndex === 3 && row.aqiCompliancePer !== null) {
        str = row.aqiCompliancePer.replace('%', '')
        style = this.getAqiRateBackground(str)
      }
      if (columnIndex === 4 && row.comAqiCompliancePer !== null) {
        str = row.comAqiCompliancePer.replace('%', '')
        style = this.getAqiRateBackground(str)
      }
      if (columnIndex > 4) {
      }
      return style + 'font-family:微软雅黑;text-align:center;'
    },
 
    // 获取aqi达标天数table背景色判定 从红到绿
    getAqiDaysBackground(str) {
      let style = ''
      if (str >= 0 && str <= 4) {
        style = 'background:#cd3a3a;'
      } else if (str >= 5 && str <= 9) {
        style = 'background:#fc5689;color:#14000a'
      } else if (str >= 10 && str <= 14) {
        style = 'background:#fc5656;color:#790000'
      } else if (str >= 15 && str <= 19) {
        style = 'background:#fd7c43;color:#844100'
      } else if (str >= 20 && str <= 24) {
        style = 'background:#fcdf56;color:#868600'
      } else if (str >= 25 && str <= 31) {
        style = 'background:#65dd77;color:#007400'
      }
      return style + 'font-weight:bold;'
    },
    // 获取aqi达标率table背景颜色判定  从绿到红
    getAqiRateBackground(str) {
      let style = ''
      if (str >= 80 && str <= 100) {
        style = 'background:#65dd77;color:#007400'
      } else if (str >= 60 && str < 80) {
        style = 'background:#fcdf56;color:#868600'
      } else if (str >= 50 && str < 60) {
        style = 'background:#fd7c43;color:#844100'
      } else if (str >= 20 && str < 50) {
        style = 'background:#fc5656;color:#790000'
      } else if (str >= 10 && str < 20) {
        style = 'background:#fc5689;color:#14000a'
      } else if (str >= 0 && str < 10) {
        style = 'background:#cd3a3a;'
      }
      return style + 'font-weight:bold;'
    },
 
    // 获得子组件时间选择器传递的数据
    showPickerChild(data) {
      if (typeof data === Array) {
        this.currentTimeD = data
      } else {
        this.currentYearD = data
      }
      this.currentDate = data
    },
 
    // 查询数据
    getData() {
      this.$request({
        url: 'aqi/queryComplianceDaysAnalysis',
        methods: 'get',
        params: {
          year: this.currentDate,
          cityCode: this.regionDefault
        }
      }).then(res => {
        // 每次请求,清空表格数据
        this.tableData = []
        this.tableData = res.data
      })
    },
 
    // 获得地区级联选择器的返回值
    regionData(data) {
      this.regionDefault = data[0]
    },
 
    // 当前年份默认值
    currentYear() {
      var aData = new Date()
      var currentDate = aData.getFullYear()
      this.currentDate = currentDate.toString()
    }
  }
}
</script>
 
<style>
</style>