<template>
  <div class="main">
    <p class="recommend-history"><router-link to="/my/recommend">推荐记录</router-link></p>
    <card title="我要推荐">
      <v-form
        ref="form"
        className="recommend"
        :hasFieldBorder="true"
        :model="formModel"
        :fields="fields"
        @submit="onSubmit"
      >
        <input type="button" value="立即推荐" class="submit-button" @click="handleSubmit" />
      </v-form>
    </card>
  </div>
</template>

<script>
import Card from '@/components/Card'
import VForm from '@/components/Form'
import * as api from '@/api/index'

export default {
  components: { Card, VForm },
  data() {
    return {
      formModel: {},
      fields: [
        {
          fieldType: 'nativeSelect',
          name: 'project_id',
          label: '项目',
          required: true,
          placeholder: '请选择项目',
          rules: [{ required: true, message: '请选择项目' }],
          values: [
            { name: '1012', text: '数字领导力方向工商管理硕士' },
            // { name: '1000', text: '金融工商管理硕士' },
            { name: '1008', text: '酒店及旅游业工商管理硕士' },
            { name: '1001', text: '金融硕士' },
            { name: '1006', text: '应用心理学硕士' },
            { name: '1005', text: '教育学硕士' },
            { name: '1012', text: '工商管理硕士（MBA）' },
            { name: '1015', text: '餐饮管理方向MBA' },
            { name: '1016', text: '国际硕士1+1项目玛丽伍德大学' },
            { name: '1018', text: '国际硕士1+1项目纽约州立大学石溪分校' },
            { name: '1017', text: '全日制工商管理博士加州浸会大学' },
            { name: '1023', text: '在职工商管理博士加州浸会大学' }
            // { name: '1007', text: '中国未来金融领袖计划' }
          ],
          valueKey: 'name'
        },
        {
          name: 'name',
          label: '姓名',
          required: true,
          rules: [{ required: true, message: '请输入姓名' }]
        },
        {
          name: 'phone',
          label: '手机号',
          required: true,
          rules: [{ required: true, message: '请输入手机号' }]
        },
        {
          name: 'wechat',
          label: '微信号',
          required: true,
          rules: [{ required: true, message: '请输入微信号' }]
        },
        {
          name: 'company',
          label: '工作单位',
          required: true,
          rules: [{ required: true, message: '请输入工作单位' }]
        },
        {
          name: 'title',
          label: '职务',
          required: true,
          rules: [{ required: true, message: '请输入职务' }]
        },
        {
          type: 'textarea',
          name: 'comment',
          label: '推荐理由'
        }
      ]
    }
  },
  methods: {
    handleSubmit() {
      this.$refs.form.submit()
    },
    onSubmit(data) {
      data.channel = '19963'
      data.need_check_repeated = 1
      api.submitRecommend(data).then(() => {
        this.$dialog
          .alert({
            confirmButtonText: '确定',
            message: '推荐成功'
          })
          .then(() => {
            this.$router.push('/my/recommend')
          })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.recommend-history {
  padding-top: 20px;
  text-align: right;
  color: #5c5c5c;
}
.recommend {
  margin-left: -16px;
  margin-right: -16px;
}
.submit-button {
  width: 200px;
  margin: 40px auto;
}
</style>
