<template>
  <div>
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px"
        label-position="left">
        <el-col :span="24">
          <el-form-item label="课题名称" prop="topic_name">
            <el-input v-model="formData.topic_name" placeholder="请输入课题名称" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label-width="120px" label="项目申报计划" prop="field103" required>
            <el-upload ref="field103" :file-list="field103fileList" :action="field103Action"
              :before-upload="field103BeforeUpload" accept=".doc,.docx">
              <el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="23">
          <el-form-item label-width="120px" label="项目成员添加" prop="field107">
            <el-select v-model="formData.field107" placeholder="请选择项目成员添加" clearable :style="{width: '100%'}">
              <el-option v-for="(item, index) in field107Options" :key="index" :label="item.label"
                :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="提交" prop="field105">
            <el-button type="primary" icon="el-icon-search" size="medium"> 主要按钮 </el-button>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" @click="submitForm">提交</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        topic_name: undefined,
        field103: null,
        field107: undefined,
        field105: undefined,
      },
      rules: {
        topic_name: [{
          required: true,
          message: '请输入课题名称',
          trigger: 'blur'
        }],
        field107: [{
          required: true,
          message: '请选择项目成员添加',
          trigger: 'change'
        }],
      },
      field103Action: 'https://jsonplaceholder.typicode.com/posts/',
      field103fileList: [],
      field107Options: [{
        "label": "选项一",
        "value": 1
      }, {
        "label": "选项二",
        "value": 2
      }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
    field103BeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 2
      if (!isRightSize) {
        this.$message.error('文件大小超过 2MB')
      }
      let isAccept = new RegExp('.doc,.docx').test(file.type)
      if (!isAccept) {
        this.$message.error('应该选择.doc,.docx类型的文件')
      }
      return isRightSize && isAccept
    },
  }
}

</script>
<style>
.el-upload__tip {
  line-height: 1.2;
}

</style>
