<template>
  <div class="welcome">
    <div class="top">
      <div class="pic">
        <img src="../../../assets/images/my_pay_01.png" />
      </div>
      <h1>欢迎您</h1>
      <p class="t1">
        报名私人财富风险管理顾问证书项目，请在填写以下内容后，使用微信支付本项目的学费，共计<span>3980</span>元。
      </p>
    </div>
    <div class="form">
      <el-form :model="ruleForm" :rules="rules" label-width="90px" ref="ruleForm">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-select v-model="ruleForm.gender" style="width: 100%">
            <el-option value="1" label="男"></el-option>
            <el-option value="2" label="女"></el-option>
            <el-option value="0" label="未知"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="公司" prop="company">
          <el-input v-model="ruleForm.company"></el-input>
        </el-form-item>
        <el-form-item label="从业年限" prop="working_years">
          <el-select v-model="ruleForm.working_years" style="width: 100%">
            <el-option value="1年"></el-option>
            <el-option value="2年"></el-option>
            <el-option value="3年"></el-option>
            <el-option value="4年"></el-option>
            <el-option value="5年"></el-option>
            <el-option value="6年"></el-option>
            <el-option value="7年"></el-option>
            <el-option value="8年"></el-option>
            <el-option value="9年"></el-option>
            <el-option value="10年"></el-option>
            <el-option value="10年以上"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="ruleForm.phone" :maxlength="11"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="ruleForm.email"></el-input>
        </el-form-item>
        <div class="buttons">
          <el-button type="primary" class="button-submit" @click="handleSubmit">提交</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import * as api from '@/api/my'
export default {
  data() {
    const user = window.G.UserInfo || {}
    return {
      material: {},
      progress: {},
      ruleForm: {
        name: '',
        phone: user.mobile,
        email: '',
        gender: '',
        company: '',
        working_years: ''
      },
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        phone: [{ required: true, pattern: /^1[3-9]\d{9}$/, message: '请输入手机号', trigger: 'blur' }],
        email: [{ type: 'email', message: '请输入邮箱', trigger: 'blur' }],
        gender: [{ required: true, message: '请选择性别', trigger: 'change' }],
        company: [{ required: true, message: '请输入公司名称', trigger: 'blur' }],
        working_years: [{ required: true, message: '请选择从业年限', trigger: 'change' }]
      }
    }
  },
  methods: {
    handleSubmit() {
      this.$refs.ruleForm.validate().then(this.handleSubmitRequest)
    },
    handleSubmitRequest() {
      const params = Object.assign({}, this.ruleForm, { project_id: webConf.others.projectId, channel: '19960' })
      api.submitApply(params).then(response => {
        if (parseInt(response.error) === 0) {
          this.$emit('update', response.data)
        } else {
          this.$message({ type: 'error', message: response.message })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.welcome {
  margin: 0 auto;
  padding: 20px 0;
}
.top {
  padding: 40px 0;
  .pic {
    text-align: center;
  }
  h1 {
    padding: 20px 0;
    font-size: 24px;
    font-weight: 500;
    color: #222;
    line-height: 1;
    text-align: center;
  }
}
.t1 {
  font-size: 14px;
  color: #262626;
  line-height: 20px;
  text-align: center;
  span {
    color: #ffa448;
  }
}
.buttons {
  text-align: center;
}
.button-submit {
  width: 100px;
  margin: 0 auto;
}
.form {
  max-width: 350px;
  margin: 0 auto;
}
</style>
