<!-- * @Description: 每日矛盾趋势 * @Author: 王晓颖 * @Date: 2020-12-02 10:46:42 --> <template> <single-layout title="渣土车违章趋势"> <div style="width: 100%;height:100%;padding-top:0rem;padding-left:0.1rem"> <radio-group v-model="type"/> <gradient-line-chart :id="options.id" :unit="options.unit" :height="options.height" :legend="options.xAxisData" :xAxisData="options.xAxisData" :seriesData="options.seriesData" /> </div> </single-layout> </template> <script> import ColorfulBarChart from '@/components/barChart/colorfulBarChart' import GradientLineChart from '@/components/lineChart/gradientLineChart' import mockData from '../../../../../../static/city.json' import {fetchTruckCaseCountByFrom} from '@/api/cityManage' import SingleLayout from '@/components/layout/singleLayout' import RadioGroup from '../../../../../components/radioGroup/index' export default { name: 'truckLine', components: {RadioGroup, SingleLayout, GradientLineChart, ColorfulBarChart}, data () { return { type: 'month', options: { id: 'truck_line', height: '100%', width: '100%', unit: '次', xAxisData: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], seriesData: [ {name: '违章次数', data: [0, 0, 0, 0, 0, 0, 0], color: '255,45,85'} ] } } }, watch: { type: { handler (newval, oldval) { const today = new Date() if (newval === 'week') { this.options.xAxisData = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] this.options.seriesData = mockData.truck.line.week } else if (newval === 'month') { this.options.xAxisData = ['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'].slice(0, today.getDate()) this.options.seriesData = mockData.truck.line.month.slice(0, today.getDate()) } else if (newval === 'year') { this.options.xAxisData = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'].slice(0, today.getMonth() + 1) this.options.seriesData = mockData.truck.line.year.slice(0, today.getMonth() + 1) } }, immediate: true // 添加立即执行选项 } }, created () { // this.getData() }, methods: { getData () { fetchTruckCaseCountByFrom(this.type).then(response => { if (response.code === 200) { const data = response.data this.options.xAxisData = data.map(item => { return item.name }) const value = data.map(item => { return item.value }) this.options.seriesData = [ {name: '违章数', data: value, color: '255,45,85'} ] } }) } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> </style>