<template>
  <div>

    <div>
      <div ref="lxHeader">
        <lx-header icon="md-apps" :text="$route.meta.title" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content">
            <div class="searchwrap" style="display: flex;align-items: center;">
              <div>
                <el-input v-model="select.name" placeholder="请输入场地名称"></el-input>
              </div>
              <div>
                <el-button type="primary" size="small" @click="getList">查询</el-button>
              </div>
              <div>
                <el-button type="primary" size="small" @click="editAppointment('add')">新增</el-button>
              </div>

            </div>
          </div>

        </lx-header>
      </div>
    </div>

    <div>
      <xy-table :list="list" :total="total" @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 types_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:btns>
          <el-table-column align='center' label="操作" width="180" header-align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="editAppointment('editor',scope.row.id)">编辑</el-button>
              <el-popconfirm style="margin:0 10px" @confirm="deleteList(scope.row.id)" title="确定删除吗？">
                <el-button type="danger" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </template>
      </xy-table>
    </div>

    <addAppointment ref="addAppointment" @refresh="getList"></addAppointment>
  </div>
</template>

<script>
  import myMixins from "@/mixin/selectMixin.js";
  import addAppointment from './components/addAppointment.vue';
  import {
    index,
    destroy
  } from "@/api/book/appointment.js"
  export default {
    mixins: [myMixins],
    components: {
      addAppointment
    },
    data() {
      return {
        select: {
          name: '',
          page: 1,
          page_size: 10,
        },
        list: [],
        total: 0,
        table_item: [{
          prop: 'no',
          label: '编号',
          align: 'center',
          width: 120,
        },{
          prop: 'name',
          label: '场地名称',
          align: 'left',
          width: 120,
        }, {
          prop: 'content',
          label: '场地简介',
          align: 'center'
        }, {
          prop: 'total',
          label: '场地容纳人数',
          align: 'center',
          width: 120,
        }, {
          prop: 'status',
          label: '状态',
          align: 'center',
          width: 120,
        }]

      }
    },
    created() {
      this.getList()

    },
    methods: {
      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,
          filter: [{
            key: 'name',
            op: 'like',
            value: this.select.name
          }]
        })
        this.list = res.data
        this.total = res.total
      },

      editAppointment(type, id) {
        if (id) {
          this.$refs.addAppointment.id = id
        }

        this.$refs.addAppointment.type = type
        this.$refs.addAppointment.isShow = true
      },
      deleteList(id) {
        var that = this;
        destroy({
          id: id,
        }).then(response => {
          this.$Message.success('删除成功');
          this.getList()
        }).catch(error => {
          console.log(error)
          reject(error)
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .searchwrap {
    display: flex;
    align-items: center;

    &>div {
      display: flex;
      align-items: center;
      margin-right: 10px;

      span {
        min-width: 70px;
      }
    }
  }
</style>
