<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: '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>