<template>
  <div>
    <xy-dialog ref="dialog" :width="70" :is-show.sync="isShow" :type="'form'" :title="type === 'add' ? '新增课程' : '编辑课程'"
      :form="form" :rules='rules' @submit="submit">
      <template v-slot:name>
        <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 v-model="form.name" placeholder="请输入课程类型" clearable style="width: 100%;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:status>
        <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 v-model="form.status" placeholder="请选择状态" style="width: 100%;">
              <el-option v-for="item in types_status" :key="item.id" :label="item.value" :value="item.id">
              </el-option>
            </el-select>
          </div>
        </div>
      </template>

      <template v-slot:wait_tip>
        <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 style="width: 100%;" v-model="form.wait_tip" placeholder="请输入待审核提示" clearable></el-input>
          </div>
        </div>
      </template>
      <template v-slot:pass_tip>
        <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 style="width: 100%;" v-model="form.pass_tip" placeholder="请输入通过提示" clearable></el-input>
          </div>
        </div>
      </template>
      <template v-slot:fault_tip>
        <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 style="width: 100%;" v-model="form.fault_tip" placeholder="请输入不通过提示" clearable></el-input>
          </div>
        </div>
      </template>
      <template v-slot:back_tip>
        <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 style="width: 100%;" v-model="form.back_tip" placeholder="请输入备选提示" clearable></el-input>
          </div>
        </div>
      </template>
      <template v-slot:year_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 style="width: 100%;" v-model="form.year_total" placeholder="请输入年预约次数" clearable></el-input>
          </div>
        </div>
      </template>


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

<script>
  import myMixins from "@/mixin/selectMixin.js";
  import {
    show,
    save
  } from "@/api/course/courseType.js"
  export default {
    mixins: [myMixins],
    components: {
    },
    data() {
      return {
        isShow: false,
        type: 'add',
        id: '',
        form: {
          name:'',
          status:1,
          wait_tip:"",
          pass_tip:"",
          fault_tip:'',
          back_tip:"",
          year_total:""
        },
        rules: {
          name: [{
            required: true,
            message: '请输入类型'
          }],
        },
      }
    },
    created() {},
    methods: {
      submit() {
        if (this.id) {
          this.form.id = this.id
        }

        save({
          ...this.form
        }).then(res => {
          this.$message({
            type: 'success',
            message: '保存课程类型成功'
          })
          this.isShow = false
          this.$emit('refresh')
          // this.active = 1

        })
      },
      getDetail() {
        show({
          id: this.id
        }).then(res => {
          this.form = this.base.requestToForm(res, this.form)
          this.form.status = res.status?res.status:0
        })
      },


    },
    watch: {
      isShow(newVal) {
        if (newVal) {
          if (this.type === 'editor') {
            this.getDetail()
          }
        } else {
          this.id = ''
          this.$refs['dialog'].reset()
        }
      },
    }

  }
</script>

<style scoped lang="scss">

</style>
