<template>
  <div>
    <a-page-header
      :ghost="false"
      style="border-bottom: 1px solid rgb(235, 237, 240)"
      title="磅秤台账"
      @back="() => $router.go(-1)"
    />
    <div class="type-button">
      <div :class="['tabs-button',activeTabsButton == null?'active-tabs-button':'']" @click="tabsChange(null)">
        全部
      </div>
      <div :class="['tabs-button',activeTabsButton == 1?'active-tabs-button':'']" @click="tabsChange(1)">
        东门
      </div>
      <div :class="['tabs-button',activeTabsButton == 2?'active-tabs-button':'']" @click="tabsChange(2)">
        东门
      </div>
      <div :class="['tabs-button',activeTabsButton == 3?'active-tabs-button':'']" @click="tabsChange(3)">
        东门
      </div>
      <div :class="['tabs-button',activeTabsButton == 4?'active-tabs-button':'']" @click="tabsChange(4)">
        东门
      </div>
    </div>

    <div class="data-info">
      <div class="left-table">
        <Curd
          hide-action
          hide-search
          hide-button
          :columns="columns"
          :api-conf="apiConf"
          :form-items="formItems"
          @edit="editHandler"
          @viewDetails="viewDetails"
        >
          <template slot="search-button" slot-scope="{ search }">
            <a-button type="primary" @click="exportList(search)">导出历史数据</a-button>
          </template>
        </Curd>
      </div>
      <div class="right-details" v-if="isShowInfoDetails">
        <div class="header-title">驾驶人详情</div>

        <img src=""/>

        <div class="group-button">
          <div :class="['_button',activeButton == 1?'active_button':'']" @click="viewImgByType(1)">出入场抓拍图</div>
          <div :class="['_button',activeButton == 2?'active_button':'']" @click="viewImgByType(2)">行驶证-正面</div>
          <div :class="['_button',activeButton == 3?'active_button':'']" @click="viewImgByType(3)">行驶证-反面</div>
          <div :class="['_button',activeButton == 4?'active_button':'']" @click="viewImgByType(4)">环保清单</div>
        </div>

        <div class="details-info">
          <div class="details-info-item">
            <div class="_title">排放标准：</div>
            <div class="_title">国0</div>
          </div>
          <div class="details-info-item">
            <div class="_title">VIN：</div>
            <div class="_title">国0</div>
          </div>
          <div class="details-info-item">
            <div class="_title">发动机号：</div>
            <div class="_title">国0</div>
          </div>
          <div class="details-info-item">
            <div class="_title">注册日期：</div>
            <div class="_title">国0</div>
          </div>
        </div>

        <div class="footer-button">
          <Button type="primary" @click="closeDetails">关闭详情</Button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Curd from "../../components/smallCommon/Curd.vue";
import moment from 'moment'

export default {
  name: "user",
  layout: "user",
  components: {
    Curd
  },
  data() {
    return {
      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: '出厂日期'
        },
        {
          title: '操作',
          key: 'operation',
          scopedSlots: {customRender: 'details'},
          fixed: 'right',
          width: 100
        },
      ],
      apiConf: {
        listApi: {api: '/api/Ledger/list', method: 'get'},
      },
      isShowInfoDetails: false,
      activeButton: 1,
      activeTabsButton: null
    }
  },

  computed: {
    formItems() {
      return [
        {
          type: 'dateRange',
          key: 'time',
          label: '日期',
          isSearch: true,
          placeholder: ['请选择开始日期', '请选择结束日期'],
          rules: [
            {required: true, message: '请选择时间范围'}
          ],
          fields: ['startTime', 'endTime']
        }
      ]
    }
  },
  created() {
  },

  methods: {
    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')
    },
    viewDetails(data) {
      console.log('data:', data)
      this.isShowInfoDetails = true
    },
    //根据选中的图片类型查看图片
    viewImgByType(value) {
      this.activeButton = value
    },
    //关闭详情
    closeDetails() {
      this.isShowInfoDetails = false
    },

    //方位改变
    tabsChange(value){
      this.activeTabsButton = value
    }

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

.type-button {
  margin: 20px 300px;
  display: flex;
  flex-flow: row;
  justify-content: space-between;

  .tabs-button {
    height: 40px;
    cursor: pointer;
    border: 1px solid #e8e8e8;
    width: 200px;
    text-align: center;
    line-height: 40px;
  }

  .active-tabs-button {
    background: #0088ff;
    color: #FFFFFF;
  }
}


.data-info {
  display: flex;
  flex-flow: row;

  .left-table {
    flex: 1;
  }

  .right-details {
    width: 600px;
    height: 700px;
    display: flex;
    flex-flow: column;
    align-items: center;
    border: 1px solid #e8e8e8;
    margin-left: 10px;

    .header-title {
      font-size: 18px;
      text-align: center;
    }

    img {
      margin-top: 10px;
      width: 500px;
      height: 300px;
    }

    .group-button {
      margin-top: 20px;
      display: flex;
      flex-flow: row;
      width: 500px;
      justify-content: space-between;

      ._button {
        width: 100px;
        height: 50px;
        border: 1px solid #777777;
        cursor: pointer;
        text-align: center;
        line-height: 50px;
      }

      .active_button {
        background: #0088ff;
        color: #FFFFFF;
      }
    }

    .details-info {
      padding-left: 50px;
      width: 100%;
      flex: 1;
      display: flex;
      flex-flow: column;
      justify-content: space-around;
      align-items: flex-start;

      .details-info-item {
        display: flex;
        flex-flow: row;
      }

    }

    .footer-button {
      height: 30px;
      margin-bottom: 10px;
      cursor: pointer;
    }
  }
}
</style>
