<template>
  <div id="expert">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-form :model="form" :rules="rules" ref="form" label-width="100px">
            <el-col :span="24" class="title"> 基本信息 </el-col>
            <el-col :span="24" class="info">
              <el-form-item label="姓名" prop="name">
                <el-input v-model="form.name" placeholder="请输入姓名"></el-input>
              </el-form-item>
              <el-form-item label="手机号" prop="phone">
                <el-input v-model="form.phone" placeholder="请输入手机号"></el-input>
              </el-form-item>
              <el-form-item label="登录密码" prop="passwd">
                <el-input v-model="form.passwd" placeholder="请输入登录密码" show-password></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="addr">
                <el-input v-model="form.addr" placeholder="请输入联系地址"></el-input>
              </el-form-item>
              <el-form-item label="办公电话" prop="office_phone">
                <el-input v-model="form.office_phone" placeholder="请输入办公电话"></el-input>
              </el-form-item>
              <el-form-item label="所属行业" prop="profession">
                <el-input v-model="form.profession" placeholder="请输入所属行业"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" class="title"> 详细信息 </el-col>
            <el-col :span="24" class="info">
              <el-form-item label="头像图片" prop="img_path">
                <e-upload url="/files/cysci/expert_imgpath/upload" :limit="1" v-model="form.image"></e-upload>
              </el-form-item>
              <el-form-item label="qq&微信" prop="qqwx">
                <el-input v-model="form.qqwx" placeholder="请输入qq&微信"></el-input>
              </el-form-item>
              <el-form-item label="出生日期" prop="birthDate">
                <el-date-picker v-model="form.birthDate" placeholder="请选择" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"> </el-date-picker>
              </el-form-item>
              <el-form-item label="毕业院校" prop="school">
                <el-input v-model="form.school" placeholder="请输入毕业院校"></el-input>
              </el-form-item>
              <el-form-item label="最高学历" prop="education">
                <el-input v-model="form.education" placeholder="请输入最高学历"></el-input>
              </el-form-item>
              <el-form-item label="职务职称" prop="zwzc">
                <el-input v-model="form.zwzc" placeholder="请输入职务职称"></el-input>
              </el-form-item>
              <el-form-item label="擅长领域" prop="expertise">
                <el-input v-model="form.expertise" 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-form-item label="工作经历" prop="workexperience">
                <el-input
                  v-model="form.workexperience"
                  placeholder="请输入工作经历"
                  type="textarea"
                  maxlength="300"
                  :autosize="{ minRows: 4, maxRows: 6 }"
                  show-word-limit
                ></el-input>
              </el-form-item>
              <el-form-item label="科研综述" prop="scientific">
                <el-input
                  v-model="form.scientific"
                  placeholder="请输入科研综述"
                  type="textarea"
                  maxlength="300"
                  :autosize="{ minRows: 4, maxRows: 6 }"
                  show-word-limit
                ></el-input>
              </el-form-item>
              <el-form-item label="承担项目" prop="undertakingproject">
                <el-input
                  v-model="form.undertakingproject"
                  placeholder="请输入承担项目"
                  type="textarea"
                  maxlength="300"
                  :autosize="{ minRows: 4, maxRows: 6 }"
                  show-word-limit
                ></el-input>
              </el-form-item>
              <el-form-item label="科技奖励" prop="scienceaward">
                <el-input
                  v-model="form.scienceaward"
                  placeholder="请输入科技奖励"
                  type="textarea"
                  maxlength="300"
                  :autosize="{ minRows: 4, maxRows: 6 }"
                  show-word-limit
                ></el-input>
              </el-form-item>
              <el-form-item label="社会任职" prop="social">
                <el-input
                  v-model="form.social"
                  placeholder="请输入社会任职"
                  type="textarea"
                  maxlength="300"
                  :autosize="{ minRows: 4, maxRows: 6 }"
                  show-word-limit
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" class="btn">
              <el-button type="primary" size="mini">取消注册</el-button>
              <el-button type="primary" size="mini" @click="onSubmit('form')">提交注册</el-button>
            </el-col>
          </el-form>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: mapExpert } = createNamespacedHelpers('expert');
export default {
  name: 'expert',
  props: {},
  components: {},
  data: function () {
    return {
      form: {
        image: [],
        status: '0',
      },
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        phone: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { max: 11, message: '不得超过11' },
        ],
        passwd: [{ required: true, message: '请输入登录密码', trigger: 'blur' }],
        email: [{ required: true, message: '请输入电子邮箱', trigger: 'blur' }],
        addr: [{ required: true, message: '请输入联系地址', trigger: 'blur' }],
        office_phone: [{ required: true, message: '请输入办公电话', trigger: 'blur' }],
        profession: [{ required: true, message: '请输入所属行业', trigger: 'blur' }],
      },
    };
  },
  created() {},
  methods: {
    ...mapExpert(['create']),
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          let data = this.form;
          data.status = '0';
          let res = await this.create(data);
          if (this.$checkRes(res)) {
            this.$message({
              message: '账号注册成功',
              type: 'success',
            });
            this.$router.push({ path: '/service/index' });
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    .title {
      font-size: 16px;
      font-weight: bold;
      border-bottom: 1px dashed #ccc;
      padding: 0 0 10px 0;
      margin: 0 0 10px 0;
    }
    .info {
      border: 1px solid #ccc;
      border-radius: 5px;
      padding: 10px;
      margin: 0 0 10px 0;
    }
    .btn {
      text-align: center;
      margin: 0 0 10px 0;
    }
  }
}
</style>
