<template>
  <div class="padding-20">
    <div class="search-box">
      <el-form ref="form"
               :inline="true"
               :model="searchForm"
               clearable
               class="mt-10">
        <el-form-item label="座位时间:">
          <el-date-picker
            v-model="searchForm.place_time"
            type="date"
            placeholder="选择座位时间"
            value-format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
        <el-form-item class="ml-10">
          <el-button
            icon="el-icon-search"
            type="primary"
            @click="searchSubmit">查询
          </el-button>
        </el-form-item>
        <el-form-item class="ml-10">
          <el-button
            icon="el-icon-plus"
            type="primary"
            v-permission="'business_place_set_add'"
            @click="add">临时加桌
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="tableData"
              stripe
              v-loading="tableLoading"
              fit
              class="marginT-10 order-table"
              border
              :max-height="vheight">
      <el-table-column label="ID" prop="id" width="80"></el-table-column>
      <el-table-column label="座位名称" prop="place_name"></el-table-column>
      <el-table-column label="说明" prop="place_desc"></el-table-column>
      <el-table-column label="预定方式">
        <template slot-scope="scope">
          <p>{{ ['整桌预定', '座位预定'][scope.row.place_pre_type] }}</p>
        </template>
      </el-table-column>
      <el-table-column label="总数量" prop="place_num" width="80"></el-table-column>
      <el-table-column label="已预定" prop="place_pre_num" width="80"></el-table-column>
      <el-table-column label="单桌人数" prop="place_user_max" width="80"></el-table-column>
      <el-table-column label="单价(元)" width="100">
        <template slot-scope="scope">
          <p>{{ scope.row.place_price | fen2Yuan }}</p>
        </template>
      </el-table-column>
      <el-table-column label="已预定" prop="place_pre_num" width="80"></el-table-column>
      <el-table-column label="日期" prop="place_time" width="140"></el-table-column>
      <el-table-column label="操作" width="120">
        <template slot-scope="scope">
          <el-button type="text" v-permission="'business_place_set_edit'" @click="edit(scope.row)">编辑</el-button>
          <el-button type="text" v-permission="'business_place_set_del'" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="marginT-20"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :hide-on-single-page="true"
      :current-page="page"
      :page-size="page_size"
      :page-sizes="[10, 20, 100, 200, 300, 400]"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount"/>
    <detail v-if="detailsDialog.show"
            v-model="detailsDialog.show"
            :exData="detailsDialog.exData"
            @success="init"></detail>
  </div>
</template>

<script>
import page from '@/mixin/page'
import detail from './details'

export default {
  mixins: [page],
  components: {
    detail,
  },
  data () {
    return {
      detailsDialog: {
        show: false,
        exData: {}
      },
      searchForm: {},
      tableData: [],
      tableUrl: '/v1/bar/place/list'
    }
  },
  methods: {
    add () {
      this.detailsDialog.exData = {}
      this.detailsDialog.show = true
    },
    edit (row) {
      this.detailsDialog.exData = row
      this.detailsDialog.show = true
    },
    del (row) {
      this.$confirm('确定要删除吗', '确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const data = await this.$fetch('/v1/bar/place/delete', { id: row.id }, 'get')
        if (data.code === 200) {
          this.$message.success('删除成功')
          this.init()
        }
      }).catch(() => {})
    }
  },
  mounted () {
    this.init()
  },
}
</script>

<style lang="scss" scoped>
</style>
