<template>
  <div id="applyForm">
    <el-row>
      <el-col :span="24" class="style">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-form-item label="申请人身份" prop="buyer">
            <el-radio-group v-model="form.buyer">
              <el-radio label="0">买家</el-radio>
              <el-radio label="1">卖家</el-radio>
            </el-radio-group>
          </el-form-item>
          <span v-if="form.buyer == '1'">
            <el-form-item label="选择产品" prop="goodsList">
              <el-select v-model="form.goodsList" placeholder="请选择选择产品">
                <el-option v-for="(item, index) in list" :key="index" :label="item.name" :value="item.id"> </el-option>
              </el-select>
            </el-form-item>
          </span>
          <el-form-item label="联系人" prop="contact">
            <el-input v-model="form.contact" placeholder="请输入联系人"></el-input>
          </el-form-item>
          <el-form-item label="联系电话" prop="contact_tel">
            <el-input v-model="form.contact_tel" placeholder="请输入联系电话"></el-input>
          </el-form-item>
          <el-form-item label="电子邮箱" prop="email">
            <el-input v-model="form.email" placeholder="请输入电子邮箱"></el-input>
          </el-form-item>
          <el-form-item label="单位名称" prop="company">
            <el-input v-model="form.company" placeholder="请输入单位名称"></el-input>
          </el-form-item>
          <el-row style="text-align:center">
            <el-button type="primary" @click="onSubmit('form')">立即申请</el-button>
            <el-button @click="restBtn('form')">取消</el-button>
          </el-row>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'applyForm',
  props: {
    form: null,
    list: null,
  },
  components: {},
  data: function() {
    return {
      rules: {
        buyer: [{ required: true, message: '请选择申请身份', trigger: 'blur' }],
        goodsList: [{ required: false, message: '请选择产品', trigger: 'blur' }],
        contact: [{ required: true, message: '请输入联系人', trigger: 'blur' }],
        contact_tel: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
        email: [{ required: false, message: '请输入电子邮箱', trigger: 'blur' }],
        company: [{ required: false, message: '请输入单位名称', trigger: 'blur' }],
      },
    };
  },
  created() {},
  methods: {
    onSubmit() {
      this.$emit('onSubmit', { data: this.form });
    },
    restBtn() {
      this.$emit('restBtn');
    },
  },
  computed: {
    ...mapState(['user']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped>
.style {
  padding: 0 10px;
}
</style>
