<template>
  <div>
    <xy-dialog ref="dialog" :width="40" :is-show.sync="isShow" :type="'form'" title="预约次数调整" :form="form" :rules='rules'
      @submit="submit">
      <template v-slot:course_id>
        <div class="xy-table-item">
          <div class="xy-table-item-label" style="font-weight: bold">
            <span style="color: red;font-weight: bold;padding-right: 4px;">*</span>所属课程：
          </div>
          <div class="xy-table-item-content">
            <el-select style="width:100%" clearable v-model="form.course_id" placeholder="请选择课程">
              <el-option v-for="item in course_options" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </div>
        </div>
      </template>

      <template v-slot:total>
        <div class="xy-table-item">
          <div class="xy-table-item-label" style="font-weight: bold">
            <span style="color: red;font-weight: bold;padding-right: 4px;">*</span>可预约次数：
          </div>
          <div class="xy-table-item-content">
            <el-input type="number" style="width:100%" v-model="form.total"></el-input>
          </div>
        </div>
      </template>

    </xy-dialog>

  </div>
</template>

<script>
  import {
    update
  } from '@/api/book/count.js'
  export default {
    components: {

    },
    data() {
      return {
        isShow: false,
        form: {
          course_id: '',
          total: ''
        },
        course_options: [],
        rules: {
          course_id: [{
            required: true,
            message: '请选择课程'
          }],
          total: [{
            required: true,
            message: '请填可预约次数'
          }]
        }
      }
    },
    created() {},
    methods: {
      submit() {
        update({
          ...this.form
        }).then(res => {
          this.$message({
            type: 'success',
            message: '调整成功'
          })
          this.isShow = false
          this.$emit('refresh')
        })
      },

      setRow(row) {
        this.course_options = row
      }
    },
    watch: {
      isShow(newVal) {
        if (newVal) {

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

  }
</script>

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