<!--车辆排班   保养弹框-->
<template>
  <el-dialog :title="currentItem.title" :visible.sync="zhanlan" width="10%">
    <el-form :model="currentItem"  ref="currentItem" label-width="120px">
      <el-form-item label="车牌号:">
        <span>{{currentItem.item.numberPlate}}</span>
      </el-form-item>
      <el-form-item label="所属公司:">
        <span>{{currentItem.item.subordinateBranchName}}</span>
      </el-form-item>
      <el-form-item label="申请人:">
        <span>{{currentItem.ii.vehicleBookRecord.bookUserName}}</span>
      </el-form-item>
      <el-form-item label="当前停靠公司:">
        <span>{{currentItem.item.parkCompanyName}}</span>
      </el-form-item>
      <el-form-item label="还车公司:">
        <span>{{currentItem.ii.vehicleBookRecord.retCompanyName}}</span>
      </el-form-item>
      <el-form-item label="预定时间:">
        <span>{{currentItem.ii.vehicleBookRecord.bookStartDate}}~{{currentItem.ii.vehicleBookRecord.bookEndDate}}</span>
      </el-form-item>
      <el-form-item label="用途:">
        <!--bookType 1-租车、2-分公司使用、3-维修、4、展览、5、旅游、6、保养、7、预约中、8、禁用、9、客户用车、10、其他-->
        <span>{{currentItem.ii.bookType==1?"租房车":currentItem.ii.bookType==3?"维修":currentItem.ii.bookType==8?"禁用":currentItem.ii.bookType==9?"客户用车":currentItem.ii.bookType==10?"其他":currentItem.ii.bookType==4?"展览":currentItem.ii.bookType==5?"旅游":currentItem.ii.bookType==6?"保养":currentItem.ii.bookType==8?"禁用":currentItem.ii.bookType==2?"分公司使用":'未知用途'}}</span>
      </el-form-item>
      <el-form-item label="旅游详情:" v-if="currentItem.str">
        {{currentItem.str}}
      </el-form-item>
      <el-form-item label="申请说明:">
        <span>{{currentItem.ii.vehicleBookRecord.remark}}</span>
      </el-form-item>
    </el-form>
    <!--客户租车-已审核过-取消按钮权限-未出行-->
    <div slot="footer" v-if='currentItem.ii.vehicleBookRecord.status==2 && currentItem.ii.bookType==9 &&bookRecord_btn_unbook && !currentItem.ii.vehicleBookRecord.vehicleDepartureLogVo' class="dialog-footer">
      <el-button @click="cancel()">取消用车</el-button>
    </div>
    <div slot="footer" v-if='currentItem.ii.vehicleBookRecord.status==1' class="dialog-footer">
      <el-button type="primary" @click="agree()" v-if="bookRecord_btn_prove">同 意</el-button>
      <el-button @click="notAgree()" v-if="bookRecord_btn_reject">不同意</el-button>
    </div>
  </el-dialog>
</template>
<script>
  import {mapGetters} from 'vuex';
  import ElRow from "element-ui/packages/row/src/row";
  import ElCol from "element-ui/packages/col/src/col";
  import ElFormItem from "../../../../node_modules/element-ui/packages/form/src/form-item.vue";
  import {
    agreeBook,
    cancleBook,
    rejectBook
  } from 'api/vehicle/vehicleSchedulManage';
  export default {
    components: {
      ElFormItem,
      ElCol,
      ElRow},
    props: ["currentItem"],
    name: 'vehicleExhibitionModal',
    data() {
      return {
        zhanlan:false,
        bookRecord_btn_prove:false,
        bookRecord_btn_reject:false,
        bookRecord_btn_unbook:false,
      }
    },
    created() {
      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'];
      console.log(this.currentItem);
    },
    computed: {
      ...mapGetters([
        'elements',
      ]),
    },
    watch: {
      zhanlan(newValue, oldValue){
        if(!newValue){
          this.$emit("zhanlanDialogEvent", false);
        }
      },
    },
    mounted() {
      this.zhanlan = true;
    },
    methods: {
      /**
       * 弹框-取消
       * */
      cancel() {
        var obj = {
            vehicleBookRecordId:this.currentItem.ii.vehicleBookRecord.id
        };
        this.$confirm('确定取消吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          cancleBook(obj).then(response => {
            if(response.code==1){
              this.$emit("zhanlanDialogEvent", true);
            }else{
              this.$notify({
                title: '失败',
                message: response.message,
                type: 'error',
                duration: 2000
              });
            }
          });
        }).catch(() => {
          console.log("cancel");
        });
      },
      /**
       * 确定用车
       * */
      handelOk(){
        console.log("展览确定用车");
        agreeBook(this.currentItem.ii.vehicleBookRecord.id).then(response => {this.$emit("zhanlanDialogEvent", true);});
      },
      /**
       * 同意
       */
      agree(){
        console.log("同意");
        agreeBook(this.currentItem.ii.vehicleBookRecord.id).then(response => {this.$emit("zhanlanDialogEvent", true);});
      },
      /**
       * 不同意
       */
      notAgree(){
        console.log("不同意");
        var obj = {
            vehicleBookRecordId:this.currentItem.ii.vehicleBookRecord.id
        }
        rejectBook(obj).then(response => {
          if(response.code==1){
            this.$emit("zhanlanDialogEvent", true);
          }else{
            this.$notify({
              title: '失败',
              message: response.message,
              type: 'error',
              duration: 2000
            });
          }
        });
      },
    }
  }
</script>

