<template>
  <div class="section-form">
    <div class="section-form-inner">
      <div class="form-box">
        <h2>报名咨询CU教育学硕士</h2>
        <p>填写姓名 + 手机， 点击报名咨询</p>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
          <el-form-item prop="name">
            <el-input v-model="ruleForm.name" placeholder="姓名"></el-input>
          </el-form-item>
          <el-form-item prop="phone">
            <el-input v-model="ruleForm.phone" placeholder="手机"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" :loading="isLoading" @click="submit">报名咨询</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import cAction from '@action'

export default {
  name: 'leavex',
  props: {
    imgUrl: {},
    leavheight: {
      type: Number
    },
    imgUrlBg: {}
  },
  data() {
    var checkPhone = (rule, value, callback) => {
      var reg = /^1[345789]\d{9}$/
      if (!reg.test(value)) {
        callback(new Error('请输入11位手机号！'))
      } else {
        callback()
      }
    }
    return {
      ruleForm: {
        name: '',
        phone: '',
        channel: 19960,
        project_id: 1005
      },
      isLoading: false,
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        phone: [{ required: true, validator: checkPhone, trigger: 'blur' }]
      }
    }
  },
  methods: {
    submit() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.isLoading = true

          cAction.Infos.postInfo(this.ruleForm)
            .then(() => {
              this.$alert('提交成功', '信息', {
                confirmButtonText: '确定',
                type: 'success'
              })
              this.isLoading = false
            })
            .catch(e => {
              this.isLoading = false
              console.log(e)
            })
        } else {
          this.isLoading = false
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.section-form {
  position: relative;
  display: flex;
  justify-content: center;
  height: 554px;
  background: url(@/assets/images/major-set/mz.png) no-repeat center;
  background-repeat: no-repeat;
  background-size: 100%;
}
.section-form-inner {
  width: 70%;
  margin: 0 auto;
  h2 {
    font-size: 26px;
    font-family: SourceHanSansCN-Medium, SourceHanSansCN;
    font-weight: 500;
    color: #af1b40;
    line-height: 40px;
    letter-spacing: 5px;
    text-align: center;
  }
  p {
    margin-bottom: 30px;
    font-size: 20px;
    font-family: SourceHanSansCN-Regular, SourceHanSansCN;
    font-weight: 400;
    color: #777777;
    line-height: 30px;
    letter-spacing: 2px;
    text-align: center;
  }
  .form-box {
    width: 400px;
    padding: 40px;
    background-color: #fff;
    margin-top: 100px;
    white-space: nowrap;

    .el-input {
      width: 100%;
    }
    ::v-deep .el-input__inner {
      background: transparent;
      border: 0px;
      border-bottom: 1px solid #000;
      border-radius: 0px;
      padding: 0px;
      color: #333;
    }
    ::v-deep .el-button {
      margin-top: 20px;
      color: #fff;
      background-color: #af1b40;
      border: 1px solid #af1b40;
      width: 100%;
      height: 40px;
      border-radius: 0;
    }
  }
}
</style>
