

<template>
  <div>
    <a-page-header
      :ghost="false"
      style="border-bottom: 1px solid rgb(235, 237, 240)"
      title="厂区车辆台账"
      @back="() => $router.go(-1)"
    />
    <a-row :gutter="16">
      <a-col :span="6">
        <a-card title="运输车辆" size="small">
          <p>{{ headCount.t1 || 0 }}</p>
        </a-card>
      </a-col>
      <a-col :span="6">
        <a-card title="国Ⅵ输车辆" size="small">
          <p>{{ headCount.t2 || 0 }}</p>
        </a-card>
      </a-col>
      <a-col :span="6">
        <a-card title="非道路工程机械" size="small">
          <p>{{ headCount.t3 || 0 }}</p>
        </a-card>
      </a-col>
      <a-col :span="6">
        <a-card title="燃油运输车辆"  size="small">
          <p>{{ headCount.t4 || 0 }}</p>
        </a-card>
      </a-col>
    </a-row>

    <a-divider />
    <Curd
      hide-search
      hide-action
      :columns="columns"
      :api-conf="apiConf"
      :form-items="formItems"
      @edit="editHandler"
    >
      <template slot="search-button" slot-scope="{ search }">
        <a-button type="primary" @click="exportList(search)">导出历史数据</a-button>
      </template>
    </Curd>
  </div>
</template>
<script>
import Curd from "../../components/smallCommon/Curd.vue";
import moment from 'moment'
export default {
  name: "user",
  layout: "user",
  components: {
    Curd
  },
  data () {
    return {
      headCount: {},
      isEdit: false,
      roles: [],
      columns: [
        {
          dataIndex: 'outTime',
          key: 'outTime',
          title: '日期'
        },
        {
          dataIndex: 'carNum',
          key: 'carNum',
          title: '车牌号'
        },
        {
          dataIndex: 'carModel',
          key: 'carModel',
          title: '车型'
        },
        {
          dataIndex: 'newCar',
          key: 'newCar',
          title: '新能源',
          customRender (text) {
            if (text) return '是'
            return '否'
          }
        },
        {
          dataIndex: 'emissions',
          key: 'emissions',
          title: '燃油车标准'
        },
        {
          dataIndex: 'createDateTime',
          key: 'createDateTime',
          title: '出厂日期'
        }
      ],
      apiConf: {
        listApi: { api: '/api/Ledger/list', method: 'get' },
        addApi: {api: '/api/Ledger/add', method: 'post',}
      }
    }
  },

  computed: {
    formItems () {
      return [
        {
          type: 'dateRange',
          key: 'time',
          label: '日期',
          isSearch: true,
          hide: true,
          placeholder: ['请选择开始日期', '请选择结束日期'],
          rules: [
            { required: true, message: '请选择时间范围' }
          ],
          fields: ['startTime', 'endTime']
        },
        {
          type: 'date',
          key: 'outTime',
          label: '日期',
          placeholder: '请选择日期'
        },
        {
          type: 'input',
          key: 'carNum',
          label: '车牌号',
          placeholder: '请输入车牌号'
        },
        {
          type: 'input',
          key: 'carModel',
          label: '车型',
          placeholder: '请输入车型'
        },
        {
          type: 'select',
          key: 'newCar',
          label: '新能源',
          placeholder: '是否新能源',
          children: [
            { label: '是', value: '是' },
            { label: '否', value: '否' },
          ]
        },
        {
          type: 'select',
          key: 'emissions',
          label: '燃油车标准',
          placeholder: '',
        },
        {
          type: 'date',
          key: 'createDateTime',
          label: '出厂日期',
          placeholder: '',
        }
      ]
    }
  },
  created() {
    this.$http.get('/api/Ledger/HeaderCount').then(({data}) => {
      this.headCount = data || {}
    })


  },

  methods: {
    add () {

    },
    editHandler (isEdit) {
      this.isEdit = isEdit
    },
    exportList ({ time }) {
      const [ start, end ] = time
      const fmt = 'YYYY-MM-DD'
      window.open(`http://101.43.201.20:5000/api/Ledger/export?start=${moment(start).format(fmt)}&end=${moment(end).format(fmt)}`, '_blank')
    }

  }
}
</script>
<style scoped lang="less">

</style>
