<!--车辆排班记录-->
<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-input style="width: 200px;" placeholder="车牌号"
                v-model="listQuery.numberPlate"></el-input>
      <el-date-picker
        v-model="listQuery.selectedMonth"
        type="month"
        format = "yyyy-MM"
        placeholder="选择月">
      </el-date-picker>
      <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table :key='tableKey' :data="list" v-loading.body="listLoading" border fit highlight-current-row
              style="width: 100%">
      <el-table-column align="center" label="日期" width="200">
        <template scope="scope">
          <div>起：{{scope.row.bookStartDate}}</div>
          <div>止：{{scope.row.bookEndDate}}</div>
        </template>
      </el-table-column>
      <el-table-column width="100" align="center" label="用途">
        <template scope="scope">
          <!--/*2-租车、1-分公司使用、3-维修、4、展览、5、旅游、6、保养、7、预约中、8、禁用*/-->
          <span>{{scope.row.bookType==2?"租房车":scope.row.bookType==4?"展览":scope.row.bookType==5?"房车游":scope.row.bookType==6?"保养":scope.row.bookType==7?"预约中":scope.row.bookType==8?"禁用":'未知用途'}}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="订单号">
        <template scope="scope">
          <span>{{scope.row.orderNo}}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="出车分公司">
        <template scope="scope">
          <span>{{scope.row.mileage}}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="还车分公司">
        <template scope="scope">
          <span>{{scope.row.retCompanyName}}</span>
        </template>
      </el-table-column>
      <el-table-column width="150" align="center" label="使用人">
        <template scope="scope">
          <span>{{scope.row.vehicleUsername}}</span>
        </template>
      </el-table-column>
      <el-table-column width="150" align="center" label="使用人联系方式">
        <template scope="scope">
          <span>{{scope.row.vehicleUserPhone}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="300">
        <template scope="scope">
          <el-button size="small" type="success" @click="handleDetail(scope.row)">详情</el-button>
          <el-button size="small" type="success" @click="getLogInfo(scope.row)">重新安排</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                     :current-page.sync="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
                     layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
    </div>

    <!--详情-->
    <el-dialog title="详情" :visible.sync="dialogVisible">
      <el-form :model="currentItem"  ref="currentItem" label-width="120px">
        <el-form-item label="车牌号:">
          <span>{{currentItem.numberPlate}}</span>
        </el-form-item>
        <!--<el-form-item label="停靠公司:">-->
          <!--<span>{{currentItem.parkCompanyName}}</span>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="申请人:">-->
          <!--<span>{{currentItem.ii.vehicleBookRecord.bookUserName}}</span>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="禁用时间:">-->
          <!--<span>{{currentItem.ii.vehicleBookRecord.bookStartDate}}~{{currentItem.ii.vehicleBookRecord.bookEndDate}}</span>-->
        <!--</el-form-item>-->
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
  import {
    getBookRecord
  } from 'api/vehicle/vehicleSchedulManage';
  import rsCode from '../../../utils/rsCode';
  import {
    formatDate
  } from 'utils/dateFormattor';
  export default {
    name: 'vehicleRecords',
    data() {
      return {
        currentItem: {},//当前操作表单
        dialogVisible: false,//记录详情
        form: {
          vehicleId: null,
          numberPlate: null,
          operator: null,
          date: null,
          mileage: null,
          amount: null,
          approvers: null,
          branchCompanyId: null,
          branchCompanyName: null,
          upkeepItems: []
        },
        list: null,
        total: null,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          selectedMonth: "",
          numberPlate: undefined
        },
        tableKey: 0,
        dialogFormVisible: false
      }
    },
    created() {
    },
    mounted() {
      this.listQuery.selectedMonth = this.$route.query.selectedMonth;
      this.listQuery.numberPlate = this.$route.query.numberPlate;
      this.getList();
    },
    methods: {
      handleFilter() {
        this.getList();
      },
      /**
       * 获取排班记录列表数据
       */
      getList() {
        this.listLoading = true;
        if(this.listQuery.selectedMonth  && (typeof this.listQuery.selectedMonth == "object")){
          this.listQuery.selectedMonth = formatDate(this.listQuery.selectedMonth, "yyyy-MM");//预定开始时间;
        }
        getBookRecord(this.listQuery).then(response => {
          this.list = response.data.data;
          this.total = response.data.totalCount;
          this.listLoading = false;
        });
      },
      handleSizeChange(val) {
        this.listQuery.limit = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.page = val;
        this.getList();
      },
      /**
       * 详情
       */
      handleDetail(row){
        this.currentItem = row;
        this.dialogVisible = true;
      },
    }
  }
</script>

