<template>
  <div>
    <xy-dialog ref="dialog" :width="80" :is-show.sync="isShow" :type="'form'" title="预约详情" :form="form">
      <template v-slot:show>
        <div class="xy-table-item">
          <div class="xy-table-item-label" style="font-weight: bold;display: none;">
            <span style="color: red;font-weight: bold;padding-right: 4px;"></span>
          </div>
          <div class="xy-table-item-content" style="width:100%">
            <div>预约人：{{select.user_name}}</div>
            <xy-table :list="list" :total="total" :isPage="false" :height="450" @pageIndexChange="pageIndexChange" @pageSizeChange="pageSizeChange"
              :table-item="table_item">
              <template v-slot:status>
                <el-table-column align='center' label="状态" width="120" header-align="center">
                  <template slot-scope="scope">
                    <div v-for="item in book_status">
                      <el-tag :type="item.type" v-if="scope.row.status===item.id">{{item.value}}</el-tag>
                    </div>
                  </template>
                </el-table-column>
              </template>
              <template v-slot:timerange>
                <el-table-column align='center' label="预约时段" width="120" header-align="center">
                  <template slot-scope="scope">
                    {{formateHH(scope.row.start_time)}}-{{formateHH(scope.row.end_time)}}
                  </template>
                </el-table-column>
              </template>
              <template v-slot:opr>
                <el-table-column align='center' label="预约操作" width="120" header-align="center">
                  <template slot-scope="scope">
                    <div v-if="scope.row.admin_id">系统预约</div>
                    <div v-else>本人预约</div>
                  </template>
                </el-table-column>
              </template>
              <template v-slot:btns>
                <div></div>
              </template>
            </xy-table>

          </div>
        </div>
      </template>
    </xy-dialog>
  </div>
</template>

<script>
  import {
    index
  } from "@/api/book/index.js"
  import myMixins from "@/mixin/selectMixin.js";

  export default {
    mixins: [myMixins],
    components: {

    },
    data() {
      return {
        isShow: false,
        select: {
          user_name: '',
          page: 1,
          page_size: 999,
        },
        form: {
          show: '',
        },
        list: [],
        total: 0,
        table_item: [{
          prop: 'date',
          label: '预约日期',
          align: 'left',
          width: 120,
        }, {
          prop: 'timerange',
          label: '预约时段',
          align: 'center',
          width: 120,
        }, {
          prop: 'content',
          label: '预约事项',
          align: 'center',
          width: 120,
        }, {
          prop: 'appointment_config.name',
          label: '预约场地',
          align: 'center',
          width: 120,
        }, {
          prop: 'plate',
          label: '车牌',
          align: 'center',
          // width: 180,
        }, {
          prop: 'accompany_total',
          label: '同行人数',
          align: 'center',
          width: 120,
        }, {
          prop: 'user.username',
          label: '预约人',
          align: 'center',
          width: 120,
        }, {
          prop: 'status',
          label: '状态',
          align: 'center',
          width: 120,
        }, {
          prop: 'opr',
          label: '预约操作',
          align: 'center',
          width: 120,
        }]
      }
    },
    created() {},
    methods: {


      setName(name) {
        this.select.user_name = name
        this.getList()
      },
      pageIndexChange(e) {
        this.select.page = e
        this.getList()
      },
      pageSizeChange(e) {
        this.select.page_size = e
        this.select.page = 1
        this.getList()
      },
      async getList() {
        const res = await index({
          page: this.select.page,
          page_size: this.select.page_size,
          user_name: this.select.user_name,
          show_relation: ['user', 'appointmentConfig'],
        })
        this.list = res.data
        this.total = res.total
      },
      formateHH(val) {
        if (val) {
          return this.$moment(val).format("HH:mm")
        } else {
          return ''
        }
      },
    },
    watch: {
      isShow(newVal) {
        if (newVal) {

        } else {
          this.row = {}
          this.$refs['dialog'].reset()
        }
      },
    }

  }
</script>

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