<template>
  <div class="section-form">
    <div class="section-form-inner">
      <div class="form-box">
        <h2>
          报名咨询玛丽伍德大学<br />
          EMBA与MBA项目
        </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 prop="project_id">
            <el-select v-model="ruleForm.project_id" placeholder="选择您想报名的项目">
              <el-option label="数字时代领航人才EMBA" :value="1012"></el-option>
              <el-option label="综合管理方向MBA" :value="1026"></el-option>
            </el-select>
          </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: 'FormBox',
  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: window.localStorage.getItem('channel_num') || 19960,
        project_id: ''
      },
      isLoading: false,
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        phone: [{ required: true, validator: checkPhone, trigger: 'blur' }],
        project_id: [{ required: true, message: '请选择项目', trigger: 'blur' }]
      }
    }
  },
  methods: {
    submit() {
      this.$refs.ruleForm.validate().then(() => {
        this.isLoading = true
        cAction.Infos.postInfo(this.ruleForm)
          .then(() => {
            this.$alert('提交成功', '信息', { confirmButtonText: '确定', type: 'success' })
            this.isLoading = false
          })
          .catch(() => {
            this.isLoading = false
          })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.section-form {
  position: relative;
  display: flex;
  justify-content: center;
  // height: 554px;
  padding-bottom: 50px;
  background: url(https://webapp-pub.oss-cn-beijing.aliyuncs.com/project/new-marywood/form_bg.png) no-repeat center;
  background-repeat: no-repeat;
  background-size: cover;
}
.section-form-inner {
  width: 70%;
  margin: 0 auto;
  h2 {
    font-size: 26px;
    font-family: SourceHanSansCN-Medium, SourceHanSansCN;
    font-weight: 500;
    color: #1a5632;
    line-height: 40px;
    letter-spacing: 5px;
    text-align: center;
  }
  p {
    margin-top: 10px;
    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;

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