<template>
  <div>
    <xy-dialog ref="dialog" :width="40" :is-show.sync="isShow" :type="'form'" :title="type=='show'?'预约查看':'预约审核'"
      :form="form">
      <template v-slot:name>
        <div class="xy-table-item" style="padding:0">
          <div class="xy-table-item-label" style="font-weight: bold;width:0;padding:0;display:none">
            <span style="color: red;font-weight: bold;padding-right: 4px;"></span>
          </div>
          <div class="xy-table-item-content" style="flex-grow:1;text-align:center">
            <div class="bookInfo">
              <div>
                <span>预约日期：</span>
                <span>{{submitObj.date}}</span>
              </div>
              <div>
                <span>时间段：</span>
                <span></span>
              </div>
              <div>
                <span>预约事项：</span>
                <span>{{submitObj.content}}</span>
              </div>
              <div>
                <span>预约场地：</span>
                <span>{{submitObj.appointment_config?submitObj.appointment_config.name:''}}</span>
              </div>
              <div>
                <span>车牌：</span>
                <span>{{submitObj.plate}}</span>
              </div>
              <div>
                <span>同行人数：</span>
                <span>{{submitObj.accompany_total}}</span>
              </div>
              <div>
                <span>同行人：</span>

                <span v-if="submitObj.appointment_accompany&&submitObj.appointment_accompany.length>0">
                  <template v-for="item in submitObj.appointment_accompany">
                    {{item.name}},
                  </template>
                </span>
              </div>
              <div>
                <span>预约人：</span>
                <span>{{submitObj.user?submitObj.user.username:''}}</span>
              </div>
              <div>
                <span>状态：</span>
                <span>
                  <template v-for="item in book_status">
                    <el-tag :type="item.type" v-if="submitObj.status===item.id">{{item.value}}</el-tag>
                  </template>
                </span>
              </div>
              <div v-if="type==='show'">
                <span>审核意见：</span>
                <span>
                  {{submitObj.reason}}
                </span>
              </div>
            </div>
            <div v-if="type=='check'">
              <lx-header icon="" text="审核意见" style="margin-bottom: 10px; border: 0px;text-align: left;">
              </lx-header>
              <div>
                <el-input v-model="submitObj.reason" type="textarea" row="3"></el-input>
              </div>
              <div style="margin-top:15px">
                <el-button type="primary" style='margin:15px;' @click="submit(1)">审核通过</el-button>
                <el-button type="primary" style='margin:15px;' @click="submit(2)">驳回</el-button>
                <el-button type="primary" plain style='margin:15px;' @click="submit(3)">取消预约</el-button>
              </div>
            </div>

          </div>
        </div>
      </template>

      <template v-slot:footerContent>
        <div></div>
      </template>

    </xy-dialog>

  </div>
</template>

<script>
  import myMixins from "@/mixin/selectMixin.js";
  import {
    show,
    save
  } from "@/api/book/index.js"
  export default {
    mixins: [myMixins],
    components: {

    },
    data() {
      return {
        isShow: false,
        type: 'show',
        id: '',
        submitObj: {},
        form: {
          name: '',
        },
      }
    },
    created() {},
    methods: {
      submit(status) {
        this.submitObj.status = status
        save(this.submitObj).then(res => {
          this.$message({
            type: 'success',
            message: '审核成功'
          })
          this.isShow = false
          this.$emit('refresh')
        })
      },

      getDetail() {
        show({
          id: this.id,
          show_relation: ['user', 'appointmentAccompany', 'appointmentConfig']
        }).then(res => {
          this.submitObj = this.base.deepCopy(res, this.submitObj)
          console.log("this.submitObj", this.submitObj)
        })
      }
    },
    watch: {
      isShow(newVal) {
        if (newVal) {
          this.getDetail()
        } else {
          this.id = ''
          this.submitObj = {}
          this.$refs['dialog'].reset()
        }
      },
    }

  }
</script>

<style scoped lang="scss">
  ::v-deep .name {
    flex-basis: 100%;
  }

  .bookInfo {
    &>div {
      span {
        display: inline-block;
      }

      span:first-child {
        width: 20%;
        text-align: right;
      }

      span:last-child {
        width: 80%;
        text-align: left;
      }
    }
  }
</style>
