Newer
Older
baseResourceFront / src / views / mile / listTime.vue
zhangyingjie on 24 Mar 2021 4 KB 车辆里程统计样式修改
<template>
  <app-container>
    <!--筛选条件-->
    <search-area size="small" @search="search">
      <search-item>
        <el-date-picker
          v-model="timeRange"
          :picker-options="pickerOptions"
          :clearable="false"
          type="daterange"
          value-format="yyyy-MM-dd"
          align="right"
          size="small"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"/>
      </search-item>
      <search-item>
        <dept-select v-model="listQuery.deptId" :dept-show="deptShow" placeholder="使用单位" clearable size="small" value=""/>
      </search-item>
    </search-area>

    <!--查询结果Table显示-->
    <normal-table :data="list" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" class="table" border size="small" @selection-change="handleSelectionChange" @change="changePage"/>
  </app-container>
</template>
<script>
import { staticsByTime } from '@/api/mile'
// import { getDictCode } from '@/api/dict'
import DeptSelect from '@/components/DeptSelect'
export default {
  name: 'ListTime',
  components: { DeptSelect },
  data() {
    return {
      deptShow: true,
      timeRange: [],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      listQuery: {
        startDate: '',
        endDate: '',
        // carType: '',
        deptId: '',
        offset: 1,
        limit: 20
      }, // 查询条件
      columns: [
        {
          text: '车辆描述',
          value: 'description',
          align: 'center'
        },
        {
          text: '车辆类型',
          value: 'carTypeName',
          align: 'center'
        },
        {
          text: '品牌型号',
          value: 'brandModel',
          align: 'center'
        },
        {
          text: '车牌号',
          value: 'carCode',
          align: 'center'
        },
        {
          text: '使用单位',
          value: 'deptName',
          align: 'center'
        },
        {
          text: '里程',
          value: 'totalMile',
          align: 'center'
        }
      ], // 动态加载的表头
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 加载动画
      fullscreenLoading: false, // 全屏加载动画
      dialogFormVisible: false, // 是否显示编辑框
      cartypelist: [], // 类型列表
      deptlist: [] // 类型列表
    }
  },
  watch: {
    timeRange(val) {
      if (val && val.length > 0) {
        this.listQuery.startDate = val[0]
        this.listQuery.endDate = val[1]
      } else {
        this.listQuery.startDate = ''
        this.listQuery.endDate = ''
      }
    }
  },
  created() {
    const date = new Date()
    const year = date.getFullYear() // 年
    const month = date.getMonth() + 1 // 月
    const day = date.getDate() // 日
    this.timeRange = [year + '-' + month + '-' + day, year + '-' + month + '-' + day]
    this.fetchData()
  },
  methods: {
    search() {
      this.fetchData(false)
    },
    fetchData(isNowPage = true) {
      console.log('fetchData')
      this.listLoading = true
      if (!isNowPage) {
        this.listQuery.offset = 1
      }
      staticsByTime(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = parseInt(response.data.total)
        this.listLoading = false
      })
    },
    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.fetchData()
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.listQuery.offset = val
      this.fetchData()
    },
    // 多选触发方法
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>