<template>
  <div>
    <a-card :bordered="false" style="margin-bottom: 10px;">
      <!-- 条件搜索 -->
      <div class="table-page-search-wrapper">
        <a-form>
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="统计时间">
                <a-range-picker show-time v-model="selDate">
                  <template slot="renderExtraFooter">
                    请选择日期时间
                  </template>
                </a-range-picker>
              </a-form-item>
            </a-col>
            <a-col>
              <span class="table-page-search-submitButtons" style="float: right;">
                <a-button type="primary" @click="handleQuery"><a-icon type="search" />查询</a-button>
                <a-button style="margin-left: 8px" @click="resetQuery"><a-icon type="redo" />重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false" class="table-card">
      <advance-table
        :columns="columns"
        :data-source="list"
        title="行驶里程统计（默认为当天数据）"
        :loading="loading"
        rowKey="objectid"
        tableKey="monitor-online-index-table"
        :isTableConfig="false"
        :isShowSetBtn="false"
        size="middle"
        :format-conditions="true"
      >
      </advance-table>

    </a-card>
  </div>
</template>

<script>

import { mileage } from '@/api/gps/gps'
import AdvanceTable from '@/components/pt/table/AdvanceTable'

export default {
  name: 'Online',
  components: {
    AdvanceTable
  },
  data () {
    return {
      startTime: '',
      endTime: '',
      list: [],
      loading: false,
      selDate: [],
      columns: [
        {
          title: '船只名称',
          dataIndex: 'platenumber',
          ellipsis: true,
          align: 'center'
        },
        {
          title: '超速次数',
          dataIndex: 'overspeedTimes',
          align: 'center'
        },
        {
          title: '停留次数',
          dataIndex: 'parkTimes',
          align: 'center'
        },
        {
          title: '行驶里程（单位：km)',
          dataIndex: 'mil',
          ellipsis: true,
          align: 'center'
        }
      ]
    }
  },
  filters: {
  },
  created () {
    this.mileageStatisics()
  },
  computed: {
  },
  watch: {
  },
  methods: {
    mileageStatisics() {
      mileage({ startTime: this.startTime,
        endTime: this.endTime }).then(res => {
          this.list = res.data
      })
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.startTime = new Date(this.selDate[0]).getTime()
      this.endTime = new Date(this.selDate[0]).getTime()
      this.mileageStatisics()
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.startTime = ''
      this.endTime = ''
      this.mileageStatisics()
    }
  }
}
</script>
