<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:username>
        <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.username" placeholder="请输入姓名" clearable style="width: 100%;"></el-input>
          </div>
        </div>
      </template>

      <template v-slot:course>
        <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.course" placeholder="请选择就读班级" clearable style="width: 100%;">
              <el-option v-for="(item,index) in course_options" :key="index" :label="item.value" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </div>
      </template>
      <template v-slot:mobile>
        <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.mobile" placeholder="请输入联系方式" clearable style="width: 100%;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:company_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.company_name" placeholder="请输入公司名称" clearable style="width: 100%;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:company_position>
        <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.company_position" placeholder="请输入职务" clearable style="width: 100%;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:donate>
        <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.donate" placeholder="请输入" type="textarea" clearable style="width: 100%;"></el-input>
          </div>
        </div>
      </template>

    </xy-dialog>

  </div>
</template>

<script>
  import {
    save,
    show
  } from "@/api/system/baseForm.js"
  export default {
    components: {

    },
    data() {
      return {
        isShow: false,
        type: 'add',
        id: '',
        table_name: 'donates',
        course_options:[{
					label: '高研班｜第一期高级科创人才研修班',
					value: '高研班｜第一期高级科创人才研修班'
				}, {
					label: '高研班｜第二期高级科创人才研修班',
					value: '高研班｜第二期高级科创人才研修班'
				},{
					label: '高研班｜第三期高级科创人才研修班',
					value: '高研班｜第三期高级科创人才研修班'
				}, {
					label: '高研班｜第四期高级科创人才研修班',
					value: '高研班｜第四期高级科创人才研修班'
				},{
					label: '高研班｜第五期高级科创人才研修班',
					value: '高研班｜第五期高级科创人才研修班'
				}, {
					label: '高研班｜第六期高级科创人才研修班',
					value: '高研班｜第六期高级科创人才研修班'
				}, {
					label: '其他',
					value: '其他'
				}],
        form: {
          username: '',
          course: '',
          mobile: '',
          company_name: '',
          company_position: '',
          donate: ''
        },
        rules: {
          username: [{
            required: true,
            message: '请输入姓名'
          }],
          course: [{
            required: true,
            message: '请选择就读班级'
          }],
          mobile: [{
            required: true,
            message: '请输入联系方式'
          }],
          mobile: [{
            required: true,
            message: '请输入联系方式'
          }]
        }
      }
    },
    created() {},
    methods: {

      submit() {
        if (this.id) {
          this.form.id = this.id
        }
        if (this.type == 'add') {
          this.form.id = ''
        }
        console.log("this.form",this.form)
        save({
          table_name: this.table_name,
          ...this.form
        }).then(res => {
          this.$message({
            type: 'success',
            message: this.type === 'add' ? '新增成功' : '编辑成功'
          })
          this.isShow = false
          this.$emit('refresh')
        })
      },

      getDetail() {
        show({
          id: this.id,
          table_name: this.table_name,
        }).then(res => {
          this.form = this.base.requestToForm(res, this.form)
        })
      }
    },
    watch: {
      isShow(newVal) {
        if (newVal) {
          if (this.type === 'editor') {
            this.getDetail()
          }
        } else {
          this.id = ''
          this.type = "add"
          this.$refs['dialog'].reset()
        }
      },
    }

  }
</script>

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