<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container" ref="filter-container">
      <el-form :rules="rules4Query" ref="queryForm" :inline="inline" :model="listQuery">
        <el-form-item label="申请状态">
          <el-select class="filter-item" v-model="listQuery.status" placeholder="请选择申请状态">
            <el-option :key="undefined" label="无" :value="undefined"></el-option>
            <el-option v-for="(val, key, index)   in statusList " :key="val.code" :label="val.val"
                       :value="val.code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车牌号">
          <el-input v-model="listQuery.numberPlate" placeholder="请输入车牌号"></el-input>
        </el-form-item>

        <el-form-item label="所属大区">
					<el-select class="filter-item" v-model="listQuery.zoneId" placeholder="请选择" @change="getProvinceRegions">
					  <el-option :key="undefined" label="无" :value="undefined"></el-option>
					  <el-option v-for="val in getAllZoneList" :key="val.id" :label="val.name" :value="val.id"> </el-option>
					</el-select>
				</el-form-item>

        <el-form-item label="停靠公司">
					<el-select class="filter-item" v-model="listQuery.liftCompany" placeholder="请选择" @change="getAllBranchCompanyChange">
            <el-option :key="undefined" label="无" :value="undefined"></el-option>
            <el-option v-for="val in allBranchCompany" :key="val.id" :label="val.name" :value="val.id"> </el-option>
					</el-select>
				</el-form-item>
        <el-form-item label="预订月份" prop="selectedMonth4Query">
          <el-date-picker
            v-model="selectedMonth4Query"
            type="month"
            :editable="true"
            format="yyyy-MM"
            placeholder="请选择预订月份">
          </el-date-picker>
        </el-form-item>
        <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleFilter">搜索</el-button>
      </el-form>
    </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="120">
        <template scope="scope">
          <span>{{scope.row.numberPlate}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="停靠公司" width="120">
        <template scope="scope">
          <span>{{scope.row.liftCompanyName}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="申请状态" width="150">
        <template scope="scope">
          <span>{{getBookRecordStatus(scope.row.status)}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="使用人/联系方式" width="250">
        <template scope="scope">
          <span>{{scope.row.vehicleUsername}}/{{scope.row.vehicleUserPhone}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="出车用途" width="250">
        <template scope="scope">
          <span v-if="scope.row.bookType==1">租车</span>
          <span v-if="scope.row.bookType==2">用户租赁</span>
          <span v-if="scope.row.bookType==3">维修</span>
          <span v-if="scope.row.bookType==4">展览</span>
          <span v-if="scope.row.bookType==5">旅游</span>
          <span v-if="scope.row.bookType==6">保养</span>
          <span v-if="scope.row.bookType==7">预约中</span>
          <span v-if="scope.row.bookType==8">禁用</span>
          <span v-if="scope.row.bookType==9">客户用车</span>
          <span v-if="scope.row.bookType==10">其他</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="预定时间" width="220">
        <template scope="scope">
          <span>{{scope.row.bookStartDate}} 至 {{scope.row.bookEndDate}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" label="预定时间" width="220">
        <template scope="scope">
        <span
          v-if="checkIfApply(scope.row.status) && checkIfBooked(scope.row.bookedDate, [scope.row.bookStartDate, scope.row.bookEndDate])"
          style="color: red">
          {{getDatePeriodStr([scope.row.bookStartDate, scope.row.bookEndDate])}}(已被预订)
        </span>
          <span v-else>{{getDatePeriodStr([scope.row.bookStartDate, scope.row.bookEndDate])}}</span>

        </template>
      </el-table-column> -->

      <!--      <el-table-column align="center" label="提车地址" width="200">-->
      <!--        <template scope="scope">-->
      <!--          <span>{{scope.row.liftAddr}}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <!-- <el-table-column align="center" label="目的地" width="200">
        <template scope="scope">
          <span>{{scope.row.destination}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="备注" width="200">
        <template scope="scope">
          <span>{{scope.row.remark}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="申请审核人" width="120">
        <template scope="scope">
          <span>{{scope.row.reviewerNameApply}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="取消人" width="100">
        <template scope="scope">
          <span>{{scope.row.reviewerNameCancel}}</span>
        </template>
      </el-table-column> -->

      <el-table-column align="center" label="提车公司" width="200">
        <template scope="scope">
          <span>{{scope.row.liftCompanyName}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" label="提车审核人" width="120">
        <template scope="scope">
          <span>{{scope.row.reviewerNameLift}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="提车时间" width="120">
        <template scope="scope">
          <span>{{scope.row.actualStartDate}}</span>
        </template>
      </el-table-column> -->

      <el-table-column align="center" label="还车公司" width="200">
        <template scope="scope">
          <span>{{scope.row.retCompanyName}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" label="还车审核人" width="120">
        <template scope="scope">
          <span>{{scope.row.reviewerNameReturn}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="还车时间" width="120">
        <template scope="scope">
          <span>{{scope.row.actualEndDate}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="随车物品" width="120">
        <template scope="scope">
          <el-button size="small" type="success" @click="handleAccItemInfo(scope.row)">查看随车物品</el-button>
        </template>
      </el-table-column>


      <el-table-column align="center" label="提车里程数" width="100">
        <template scope="scope">
          <span>{{scope.row.mileageLift}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="还车里程数" width="100">
        <template scope="scope">
          <span>{{scope.row.mileageRet}}</span>
        </template>
      </el-table-column>

      <el-table-column width="65" align="center" label="是否违章">
        <template scope="scope">
          <span>{{scope.row.haveViolation?'是':'否'}}</span>
        </template>
      </el-table-column> -->
        <el-table-column align="center" label="详情" width="100">
            <template scope="scope">
              <span style="color: #13CE66;cursor: pointer;" @click="handleDetail(scope.row)">订单详情</span>
            </template>
        </el-table-column>
      <el-table-column align="center" label="操作" width="250">
        <template scope="scope">
          <!-- <el-button size="small" type="success" @click="handleBookInfo(scope.row)">预订信息</el-button> -->
          <el-button  size="small" type="success" v-if="scope.row.status==3" @click="illegalInquiry(scope.row)">违章记录</el-button>
          <el-button v-if="bookRecord_btn_prove&&scope.row.status==1" size="small" type="success" @click="handleProve(scope.row)">通过
          </el-button>
          <el-button v-if="bookRecord_btn_reject&&scope.row.status==1" size="small" type="danger" @click="handleReject(scope.row)">驳回
          </el-button>
          <!-- <el-button v-if="bookRecord_btn_lift  && checkIfProved(scope.row.status)" size="small" type="success"
                     @click="handleLift(scope.row)">提车
          </el-button>
          <el-button v-if="bookRecord_btn_ret  && checkIfLift(scope.row.status)" size="small" type="success"
                     @click="handleRet(scope.row)">还车
          </el-button> -->
          <el-button v-if="bookRecord_btn_unbook  && checkIfProved(scope.row.status)" size="small" type="danger"
                     @click="handleUnbook(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,40,50]" :page-size="listQuery.limit"
                     layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
    </div>

    <book-info-viewer ref="bookInfoViewer"></book-info-viewer>
    <acc-item-selector :selectedAccItem="selectedAccItem" :isReadOnly="true" ref="accItemSelector"></acc-item-selector>

    <!-- 查看详情 -->
    <el-dialog title="预约详情" :visible.sync="dialogDetailVisible" class="order-details">

      <el-form label-width="100px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="申请状态">
              <span v-if="detailItem.status==1">申请中</span>
              <span v-if="detailItem.status==2">已通过</span>
              <span v-if="detailItem.status==3">已归还</span>
              <span v-if="detailItem.status==4">拒绝</span>
              <span v-if="detailItem.status==5">逾期归还</span>
              <span v-if="detailItem.status==6">取消预订</span>
              <span v-if="detailItem.status==7">已提车</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <el-form-item label="车牌号">
              <span>{{detailItem.numberPlate}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车辆编号">
              <span>{{detailItem.vehicleId}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="当前停靠公司">
              <span>{{detailItem.liftCompanyName}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="申请账号">
              <span>{{detailItem.bookUserName}}</span>
              <span style="margin-left:10px"></span>
            </el-form-item>
          </el-col>
        </el-row>
        <hr>
        <el-row>
          <el-col :span="24">
            <el-form-item label="使用人">
              <span v-if="detailItem.vehicleDepartureLogVo">{{detailItem.vehicleDepartureLogVo.user}}</span>
              <span style="margin-left:10px" v-if="detailItem.vehicleDepartureLogVo">{{detailItem.vehicleDepartureLogVo.userTel}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="预定时间">
              <span>{{detailItem.bookStartDate}}</span> 至  <span>{{detailItem.bookEndDate}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="出车用途">
              <span v-if="detailItem.bookType==1">租车</span>
              <span v-if="detailItem.bookType==2">用户租赁</span>
              <span v-if="detailItem.bookType==3">维修</span>
              <span v-if="detailItem.bookType==4">展览</span>
              <span v-if="detailItem.bookType==5">旅游</span>
              <span v-if="detailItem.bookType==6">保养</span>
              <span v-if="detailItem.bookType==7">预约中</span>
              <span v-if="detailItem.bookType==8">禁用</span>
              <span v-if="detailItem.bookType==9">客户用车</span>
              <span v-if="detailItem.bookType==10">其他</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
              <span>{{detailItem.remark}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="随车物品">
              <span></span>
            </el-form-item>
          </el-col>
        </el-row>
        <hr>
        <el-row>
          <el-col :span="8">
            <el-form-item label="提车分公司">
              <span>{{detailItem.liftCompanyName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="操作人">
              <span v-if="detailItem.vehicleDepartureLogVo">{{detailItem.vehicleDepartureLogVo.checkMan}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="操作时间">
              <span v-if="detailItem.vehicleDepartureLogVo">{{detailItem.vehicleDepartureLogVo.departureTime}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="还车分公司">
              <span>{{detailItem.retCompanyName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="操作人">
              <span v-if="detailItem.vehicleDepartureLogVo">{{detailItem.vehicleDepartureLogVo.recycleMan}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="操作时间">
              <span v-if="detailItem.vehicleDepartureLogVo">{{detailItem.vehicleDepartureLogVo.arrivalTime}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="提车公里数">
              <span v-if="detailItem.vehicleDepartureLogVo">{{detailItem.vehicleDepartureLogVo.mileageStart}}KM</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="还车公里数">
              <span v-if="detailItem.vehicleDepartureLogVo">{{detailItem.vehicleDepartureLogVo.mileageEnd}}KM</span>
            </el-form-item>
          </el-col>
        </el-row>
        <hr>
        <el-row>
          <el-col :span="8">
            <el-form-item label="审核人操作">
              <span>{{detailItem.reviewerNameApply}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="通过操作">
              <span></span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="detailItem.status==1" @click="handleReject(detailItem)">驳回</el-button>
        <el-button v-if="detailItem.status==1" type="primary" @click="handleProve(detailItem)">通过</el-button>
      </div>
    </el-dialog>

    <!--     提车对话框相关html元素  -->
    <el-dialog title="提车" :visible.sync="dialogForm4LiftVisible">

      <el-form :model="form4Lift" :rules="rules4Lift" ref="form4Lift" label-width="120px">

        <el-form-item label="提车分公司" prop="liftCompany">
          <el-autocomplete
            class="inline-input"
            v-model="form4Lift.state1"
            :fetch-suggestions="querySearch"
            placeholder="请输入内容"
            @select="handleSelect1"
          ></el-autocomplete>
        </el-form-item>

        <el-form-item label="提车里程数" prop="mileageLift">
          <el-input v-model.number="form4Lift.mileageLift" placeholder="请输入当前车辆里程数"></el-input>
        </el-form-item>

        <el-form-item label="提车备注" prop="liftRemark">
          <el-input v-model="form4Lift.liftRemark" placeholder="请输入备注信息"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelDialog4Lift('form4Lift')">取 消</el-button>
        <el-button type="primary" @click="liftOk('form4Lift')">确 定</el-button>
      </div>
    </el-dialog>

    <!--     提车对话框相关html元素  -->
    <el-dialog title="还车" :visible.sync="dialogForm4RetVisible">

      <el-form :model="form4Ret" :rules="rules4Ret" ref="form4Ret" label-width="120px">

        <el-form-item label="还车分公司" prop="retCompany">
          <el-select class="filter-item" v-model.number="form4Ret.retCompany" placeholder="请选择还车分公司">
            <el-option :key="undefined" label="无" :value="undefined"></el-option>
            <el-option v-for="item in allCompanies" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="还车里程数" prop="mileageRet">
          <el-input v-model.number="form4Ret.mileageRet" placeholder="请输入当前车辆里程数"></el-input>
        </el-form-item>

        <el-form-item label="是否违章" prop="haveViolation">
          <el-select class="filter-item" v-model="form4Ret.haveViolation" placeholder="请选择是否违章">
            <el-option key="1" label="是" value="1"></el-option>
            <el-option key="0" label="否" value="0"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="还车备注" prop="retRemark">
          <el-input v-model="form4Ret.retRemark" placeholder="请输入备注信息"></el-input>
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelDialog4Ret('form4Ret')">取 消</el-button>
        <el-button type="primary" @click="ret('form4Ret')">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="违章查询" :visible.sync="illegalVisible">
      <el-form>
        <el-row>
          <el-col>
            <el-form-item label="违章截图" :style="{display:'block'}">
              <el-upload
                class="upload-demo"
                :headers="getHeaderWithToken"
                action="https://xxtest.upyuns.com/api/universal/file/app/unauth/admin/upload"
                :on-remove="handleRemove"
                :file-list="fileList2"
                :on-success="handleSuccess"
                list-type="picture-card">
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
              <el-form-item label="违章罚款">
                <el-input v-model="price" type="number" placeholder="请输入违章罚款金额" style="width: 50%;margin-right:10px"></el-input>元
              </el-form-item>
            </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="okHandler('form')">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import {
    page,
    prove,
    reject,
    getObj,
    lift,
    ret,
    unbook,
    getOneIllegalRow,
    saveOrderViolation
  } from 'api/vehicle/bookRecord';


  import {
    getAllCompany,
    getAll
  } from 'api/base_info/branch_company/';
  import {
	  getAllZone
  } from 'api/base_info/constant/';
   import {
		getAllBranchCompanyByZoneId
  } from 'api/order/rentVehicle';
  import {
    formatDate
  } from 'utils/dateFormattor';

  import rsCode from '../../../utils/rsCode';

  import {mapGetters} from 'vuex';

  import {
    toEast8Date,
    deepCopyDate,
    newEast8Date
  } from 'utils/dateUtils';
  import {
    getToken
  } from '../../../utils/auth';
  import {
    BOOK_RECORD_STATUS_APPLY,
    BOOK_RECORD_STATUS_PROVED,
    BOOK_RECORD_STATUS_LIFT
  } from '../../../store/modules/baseInfo';

  import bookInfoViewer from '../bookInfoViewer';
  import accItemSelector from '../accompanyingItem/accItemSelector.vue';

  export default {
    name: 'bookRecord',
    components: {
      bookInfoViewer,
      accItemSelector
    },
    data() {
      return {
        statusList:[
          {
            code:'1',
            val:'申请中'
          },
          {
            code:'2',
            val:'已通过'
          },
          {
            code:'3',
            val:'已归还'
          },
          {
            code:'4',
            val:'拒绝'
          },
          {
            code:'5',
            val:'逾期归还'
          },
          {
            code:'6',
            val:'取消预订'
          },
          {
            code:'7',
            val:'已提车'
          },
        ],
        detailId:'',
        illegalVisible:false,
        price: undefined,//违章罚款金额
        fileList2:[],//违章截图
        detailItem:{},
        dialogDetailVisible:false,
        baranchQuery: {
					zoneId:null
        },
        allZoneArr:[],//全部片区
				allBranchCompany:[],
        state2: '',//搜索-分公司名称
        rules4Query: {
          
        },
        list: null,
        total: null,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          zoneId:undefined,
					liftCompany: undefined,
          numberPlate: undefined,
          selectedMonth: undefined,
          status: undefined
        },
        inline: true,
        dialogFormVisible: false,
        dialogStatus: '',
        bookRecord_btn_prove: false,
        bookRecord_btn_unbook: false,
        bookRecord_btn_reject: false,
        bookRecord_btn_lift: false,
        bookRecord_btn_ret: false,
        dialogForm4LiftVisible: false,
        dialogForm4RetVisible: false,
        allCompanies: {},
        allCompaniesArr: [],
        tableKey: 0,
        form4Lift: {
          state1: '',
          id: undefined,
          mileageLift: undefined,
          liftCompany: undefined,
          liftRemark: undefined
        },
        rules4Lift: {
          liftCompany: [
            {
              required: true,
              message: '请选择提车分公司',
              trigger: 'blur',
              type: 'integer'
            }
          ],
          mileageLift: [
            {
              required: true,
              message: '请输入当前里程数',
              trigger: 'blur',
              type: 'integer'
            },
            {
              validator: (rule, value, callback) => {
                if (this.$utils.isUndefined(value) || this.$utils.isNull(value)) {
                  return callback();
                }
                if (!this.$utils.isInteger(value)) {
                  return callback(new Error('里程数必须为整数'));
                }
                if (value < 0 || value > 9999999999) {
                  return callback(new Error('里程数合法范围：[0 - 9999999999]'));
                }
                callback();
              },
              trigger: 'blur'
            }
          ],
          retRemark: [
            {
              min: 0,
              max: 2000,
              message: '长度小于 2000 个字符',
              trigger: 'blur'
            }
          ]
        },
        form4Ret: {
          id: undefined,
          mileageRet: undefined,
          haveViolation: undefined,
          retCompany: undefined,
          retRemark: undefined
        },
        rules4Ret: {
          retCompany: [
            {
              required: true,
              message: '请选择提车分公司',
              trigger: 'blur',
              type: 'integer'
            }
          ],
          mileageRet: [
            {
              required: true,
              message: '请输入当前里程数',
              trigger: 'blur',
              type: 'integer'
            },
            {
              validator: (rule, value, callback) => {
                if (this.$utils.isUndefined(value) || this.$utils.isNull(value)) {
                  return callback();
                }
                if (!this.$utils.isInteger(value)) {
                  return callback(new Error('里程数必须为整数'));
                }
                if (value < 0 || value > 9999999999) {
                  return callback(new Error('里程数合法范围：[0 - 9999999999]'));
                }
                callback();
              },
              trigger: 'blur'
            }
          ],
          retRemark: [
            {
              min: 0,
              max: 2000,
              message: '长度小于 2000 个字符',
              trigger: 'blur'
            }
          ]
        },
        selectedAccItem: undefined
      }
    },
    created() {
      this.getList();
      getAll()
        .then(response => {
          this.allCompaniesArr = response.data;
        })
      getAllCompany(codeAndBranchCompany => {//初始化公司列表
        this.allCompanies = codeAndBranchCompany;
      });
      this.bookRecord_btn_prove = this.elements['bookRecord:btn_prove'];
      this.bookRecord_btn_reject = this.elements['bookRecord:btn_reject'];
      this.bookRecord_btn_unbook = this.elements['bookRecord:btn_unbook'];
      this.bookRecord_btn_lift = this.elements['bookRecord:btn_lift'];
      this.bookRecord_btn_ret = this.elements['bookRecord:btn_ret'];
    },
    computed: {
      ...mapGetters([
        'elements',
        'bookRecordStatus'
      ]),
      getHeaderWithToken() {
        return {Authorization: getToken()};
      },
      //获取大区列表
			getAllZoneList(){
			  return getAllZone();
			},
      selectedMonth4Query: {
        get: function () {
          if (this.$utils.isString(this.listQuery.selectedMonth) && this.listQuery.selectedMonth !== '') {
            return toEast8Date(this.listQuery.selectedMonth);
          }
          return undefined;
        },
        set: function (date) {
          if (this.$utils.isDate(date)) {
            this.listQuery.selectedMonth = formatDate(date, 'yyyy-MM');
          } else {
            this.listQuery.selectedMonth = undefined;
          }
        }
      }
    },
    methods: {
      /**
       * 确定
       * */
      okHandler() {
        let arr = [];
        this.fileList2.map(function(item){
          arr.push(item.url);
        });
        let params = {
          illegalPic:arr.join(","),
          illegalAmount:this.price,
          id: this.detailId,
        };
        saveOrderViolation(params).then(response => {
          if (response.status === 200) {
            this.$notify({
              title: '成功',
              message: '创建成功',
              type: 'success',
              duration: 2000
            });
            this.illegalVisible = false;
            this.getList();
          } else {
            this.$notify({
              title: '创建失败',
              message: '操作失败！',
              type: 'error',
              duration: 2000
            });
          }
        });
      },
       /**
       * 上传成功
       * */
      handleSuccess(res, file) {
        let c = {url: res.data};
        this.fileList2.push(c);
        this.showLoadingBody = false;
      },
      /**
       * 删除违章图片
       * */
      handleRemove(file, fileList){
        this.fileList2 = fileList;
      },
      /**
       * 操作-违章查询按钮，显示违章弹框
       */
      illegalInquiry(row){
        var t = this;
        this.fileList2 = [];
        this.price = '';
        if(row.vehicleDepartureLogVo.illegalPic){
          let arr = row.vehicleDepartureLogVo.illegalPic.split(",");
          let fileList2 = [];
          let p = {};
          arr.map(function(item){
            p = {
              url: item
            };
            fileList2.push(p);
          });
          t.fileList2 = fileList2;
        }
        if(row.vehicleDepartureLogVo.illegalAmount){
          t.price = parseFloat(row.vehicleDepartureLogVo.illegalAmount);
        }
        this.detailId = row.vehicleDepartureLogVo.id;
        this.illegalVisible = true;
      },
      /**
       * 弹框-取消
       * */
      cancel() {
        this.illegalVisible = false;
      },
      handleDetail(row){
        this.detailItem = row;
        this.dialogDetailVisible = true;
      },
      //监听change事件
			 getProvinceRegions(item) {
					this.listQuery.zoneId = item
					this.baranchQuery.zoneId = item
          this.listQuery.liftCompany = undefined;
					getAllBranchCompanyByZoneId(this.baranchQuery)
					.then(response => {
					  this.allBranchCompany = response.data;
					})
			 },
			 getAllBranchCompanyChange(item) {
				 this.listQuery.liftCompany = item
			 },
      querySearch(queryString, cb) {
        let selectArry = [];
        let iitem = {
          value: "全部",
          name: "全部"
        };
        selectArry.push(iitem);
        this.allCompaniesArr.map(function(item){
          item.value = item.name;
          selectArry.push(item);
        });
        this.selectArry = selectArry;
        var results = queryString ? selectArry.filter(this.createFilter(queryString)) : selectArry;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.name.indexOf(queryString.toLowerCase()) != -1);
        };
      },
      /**
       * 分公司搜索
       * */
      handleSelect2(item){
        this.listQuery.subordinateBranch = item.id;
        console.log(item);
      },
      /**
       * 提车分公司
       * */
      handleSelect1(item){
        this.form4Lift.liftCompany = item.id;
        console.log(item);
      },
      cancelDialog4Lift(formName) {
        this.dialogForm4LiftVisible = false;
        this.$refs[formName].resetFields();
      },
      cancelDialog4Ret(formName) {
        this.dialogForm4RetVisible = false;
        this.$refs[formName].resetFields();
      },
      /**
       * 提车弹框-确定
       * */
      liftOk(formName) {
        if(this.form4Lift.state1 == "" || this.form4Lift.state1 == "全部"){
          this.form4Lift.liftCompany = undefined;
          this.$notify({
            title: '失败',
            message: '请选择提车分公司',
            type: 'warning',
            duration: 2000
          });
          return;
        }
        const set = this.$refs;
        set[formName].validate(valid => {
          if (valid) {
            lift(this.form4Lift).then((response) => {
              if (response.code === rsCode.code.VEHICLE_BOOKED_RECORD_STATUS_CHANGED) {
                this.$notify({
                  title: '失败',
                  message: rsCode.msg[rsCode.code.VEHICLE_BOOKED_RECORD_STATUS_CHANGED],
                  type: 'error',
                  duration: 2000
                });
              } else if (response.code === rsCode.RS_CODE_SUC) {
                this.$notify({
                  title: '成功',
                  message: '操作成功',
                  type: 'success',
                  duration: 2000
                });
                this.dialogForm4LiftVisible = false;
                this.getList();
              } else {
                this.$notify({
                  title: '失败',
                  message: '操作失败',
                  type: 'error',
                  duration: 2000
                });
              }
            });
          } else {
            return false;
          }
        });
      },
      handleBookInfo(row) {
        this.$refs.bookInfoViewer.handleBookInfo(row.vehicle);
      },
      handleAccItemInfo(row) {
        this.selectedAccItem = row.accItemAndAmount;
        this.$refs.accItemSelector.show();
      },
      checkIfBooked(bookedDate, [startDateStr, endDateStr]) {
        if (this.$utils.isInteger(bookedDate) &&
          this.$utils.isString(startDateStr) && startDateStr !== '' &&
          this.$utils.isString(endDateStr) && endDateStr !== '') {
          let startDate = toEast8Date(startDateStr);
          let endDate = toEast8Date(endDateStr);
          for (; this.$utils.toDateString(startDate, 'yyyy-MM-dd') <= this.$utils.toDateString(endDate, 'yyyy-MM-dd');
                 startDate.setDate(startDate.getDate() + 1)) {
            if ((bookedDate & (1 << (startDate.getDate() - 1))) !== 0) {
              return true;
            }
          }
        }
        return false;
      },
      checkIfApply(code) {
        return code === BOOK_RECORD_STATUS_APPLY;
      },
      checkIfProved(code) {
        return code === BOOK_RECORD_STATUS_PROVED;
      },
      checkIfLift(code) {
        return code === BOOK_RECORD_STATUS_LIFT;
      },
      getList() {
        this.listLoading = true;
        page(this.listQuery)
          .then(response => {
            this.list = response.data.data;
            this.total = response.data.totalCount;
            this.listLoading = false;
          })
      },
      getBookRecordStatus: function (code) {
        if (!this.$utils.isInteger(code)) {
          return '未知';
        }
        return this.bookRecordStatus[code + ''].val;
      },
      getAllBookRecordStatus: function () {
        return this.bookRecordStatus;
      },
      getDatePeriodStr([startDate, endDate]) {
        if (this.$utils.isString(startDate) && startDate !== '' &&
          this.$utils.isString(endDate) && endDate !== '') {
          return formatDate(toEast8Date(startDate), 'yyyy-MM-dd') + ' 至 ' + formatDate(toEast8Date(endDate), 'yyyy-MM-dd');
        }
        return '未知';
      },
      /**
       * 搜索按钮
       * */
      handleFilter() {
        this.listQuery.page = 1;
        this.$refs.queryForm.validate(valid => {
          if (valid) {
            this.getList();
          } else {
            return false;
          }
        });
      },
      handleSizeChange(val) {
        this.listQuery.limit = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.page = val;
        this.getList();
      },
      handleProve(row) {
        this.$confirm('确定批准申请?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          prove(row.id)
            .then(response => {
              if (response.code === rsCode.code.VEHICLE_BOOKED_INFO_ALREADY_CHANGED) {
                this.$notify({
                  title: '失败',
                  message: rsCode.msg[rsCode.code.VEHICLE_BOOKED_INFO_ALREADY_CHANGED],
                  type: 'error',
                  duration: 2000
                });
              } else if (response.code === rsCode.code.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED) {
                this.$notify({
                  title: '失败',
                  message: rsCode.msg[rsCode.code.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED],
                  type: 'error',
                  duration: 2000
                });
              } else if (response.code === rsCode.RS_CODE_SUC) {
                this.$notify({
                  title: '成功',
                  message: '操作成功',
                  type: 'success',
                  duration: 2000
                });
                if(this.dialogDetailVisible){
                  this.dialogDetailVisible = false
                }
              }
              this.getList();
            });
        });
      },
      handleReject(row) {
        this.$confirm('确定拒绝申请?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          reject(row.id)
            .then(response => {
              if (response.code === rsCode.code.VEHICLE_BOOKED_INFO_ALREADY_CHANGED) {
                this.$notify({
                  title: '失败',
                  message: rsCode.msg[rsCode.code.VEHICLE_BOOKED_INFO_ALREADY_CHANGED],
                  type: 'error',
                  duration: 2000
                });
              } else if (response.code === rsCode.code.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED) {
                this.$notify({
                  title: '失败',
                  message: rsCode.msg[rsCode.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED],
                  type: 'error',
                  duration: 2000
                });
              } else if (response.code === rsCode.RS_CODE_SUC) {
                this.$notify({
                  title: '成功',
                  message: '操作成功',
                  type: 'success',
                  duration: 2000
                });
                if(this.dialogDetailVisible){
                  this.dialogDetailVisible = false
                }
              }
              this.getList();
            });
        });
      },
      /**
       * 操作-提车
       * @param row
       */
      handleLift(row) {
        this.resetTemp4Lift();
        getObj(row.id, row.bookEndDate)
          .then(response => {
            if (!this.$utils.isEmpty(response.data) && this.$utils.isInteger(response.data.liftCompany)) {
              this.form4Lift.liftCompany = response.data.liftCompany;
            }
            let that = this;
            let selectArry = [];
            this.allCompaniesArr.map(function(item){
              item.value = item.name;
              selectArry.push(item);
            });
            selectArry.map(function (iitem) {
              if( that.form4Lift.liftCompany == iitem.id){
                that.form4Lift.state1 = iitem.name;
              }
            });
            this.form4Lift.id = row.id;
            this.dialogForm4LiftVisible = true;
          });
      },
      handleRet(row) {
        this.resetTemp4Ret();
        getObj(row.id, row.bookEndDate)
          .then(response => {
            if (!this.$utils.isEmpty(response.data) && this.$utils.isInteger(response.data.retCompany)) {
              this.form4Ret.retCompany = response.data.retCompany;
            }
            this.form4Ret.id = row.id;
            this.dialogForm4RetVisible = true;
          });
      },
      ret(formName) {
        const set = this.$refs;
        set[formName].validate(valid => {
          if (valid) {
            ret(this.form4Ret).then((response) => {
              if (response.code === rsCode.code.VEHICLE_BOOKED_RECORD_STATUS_CHANGED) {
                this.$notify({
                  title: '失败',
                  message: rsCode.msg[rsCode.code.VEHICLE_BOOKED_RECORD_STATUS_CHANGED],
                  type: 'error',
                  duration: 2000
                });
              } else if (response.code === rsCode.RS_CODE_SUC) {
                this.$notify({
                  title: '成功',
                  message: '操作成功',
                  type: 'success',
                  duration: 2000
                });
                this.dialogForm4RetVisible = false;
                this.getList();
              } else {
                this.$notify({
                  title: '失败',
                  message: '操作失败',
                  type: 'error',
                  duration: 2000
                });
              }
            });
          } else {
            return false;
          }
        });
      },
      handleUnbook(row) {
        this.$confirm('确定取消预定?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          unbook(row.id)
            .then(response => {
              if(response.status==500){
                this.$notify({
                  title: '失败',
                  message: response.message,
                  type: 'error',
                  duration: 2000
                });
              }else if (response.code === rsCode.code.VEHICLE_BOOKED_INFO_ALREADY_CHANGED) {
                this.$notify({
                  title: '失败',
                  message: rsCode.msg[rsCode.code.VEHICLE_BOOKED_INFO_ALREADY_CHANGED],
                  type: 'error',
                  duration: 2000
                });
              } else if (response.code === rsCode.code.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED) {
                this.$notify({
                  title: '失败',
                  message: rsCode.msg[rsCode.code.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED],
                  type: 'error',
                  duration: 2000
                });
              } else if (response.code === rsCode.RS_CODE_SUC) {
                this.$notify({
                  title: '成功',
                  message: '操作成功',
                  type: 'success',
                  duration: 2000
                });
              }
              this.getList();
            }).catch(response=>{
              console.log(response)
            }

            );
        });
      },
      resetTemp4Lift() {
        this.form4Lift = {
          id: undefined,
          state1: '',
          mileageLift: undefined,
          liftCompany: undefined,
          liftRemark: undefined
        };
      },
      resetTemp4Ret() {
        this.form4Ret = {
          id: undefined,
          mileageRet: undefined,
          haveViolation: undefined,
          retCompany: undefined,
          retRemark: undefined
        };
      }
    }
  }
</script>

<style>
   .order-details .el-form-item{
     margin-bottom: 0px !important;
   }
   .order-details hr {
      height: 1px;
      background-color: #ccc;
      border: none;
    }
</style>