<template>
  <div class="section-form">
    <div class="section-form-inner">
      <div class="form-box">
        <h2>玛丽伍德大学<br />领航数字时代EMBA</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: '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: 1012
      },
      isLoading: false,
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        phone: [{ required: true, validator: checkPhone, 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;
  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 {
      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: #faa634;
      border: 1px solid #faa634;
      width: 100%;
      height: 40px;
      border-radius: 0;
    }
  }
}
</style>
