<template>
  <div id="company">
    <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="institution_code">
                <el-input v-model="form.institution_code" 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="companytype">
                <el-input v-model="form.companytype" placeholder="请输入注册类型"></el-input>
              </el-form-item>
              <el-form-item label="注册时间" prop="companydate">
                <el-date-picker v-model="form.companydate" placeholder="请选择" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"> </el-date-picker>
              </el-form-item>
              <el-form-item label="注册资金" prop="companycapital">
                <el-input v-model="form.companycapital" placeholder="请输入注册资金"></el-input>
              </el-form-item>
              <el-form-item label="企业法人" prop="companyperson">
                <el-input v-model="form.companyperson" placeholder="请输入企业法人"></el-input>
              </el-form-item>
              <el-form-item label="企业总收入" prop="sndqyzsr">
                <el-input v-model="form.sndqyzsr" placeholder="请输入上年度企业总收入"></el-input>
              </el-form-item>
              <el-form-item label="研发费用" prop="sndyffy">
                <el-input v-model="form.sndyffy" placeholder="请输入上年度研发费用"></el-input>
              </el-form-item>
              <el-form-item label="企业总人数" prop="companytotal">
                <el-input v-model="form.companytotal" placeholder="请输入企业总人数"></el-input>
              </el-form-item>
              <el-form-item label="研发人数" prop="zjzyfrs">
                <el-input v-model="form.zjzyfrs" placeholder="请输入专&兼职研发人数"></el-input>
              </el-form-item>
              <el-form-item label="企业简介" prop="companybrief">
                <el-input
                  v-model="form.companybrief"
                  placeholder="请输入企业简介"
                  type="textarea"
                  maxlength="300"
                  :autosize="{ minRows: 4, maxRows: 6 }"
                  show-word-limit
                ></el-input>
              </el-form-item>
              <el-form-item label="主要产品" prop="mainproduct">
                <el-input
                  v-model="form.mainproduct"
                  placeholder="请输入主要产品"
                  type="textarea"
                  maxlength="300"
                  :autosize="{ minRows: 4, maxRows: 6 }"
                  show-word-limit
                ></el-input>
              </el-form-item>
              <el-form-item label="资质&荣誉" prop="qualifications">
                <el-input
                  v-model="form.qualifications"
                  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: organization } = createNamespacedHelpers('organization');
export default {
  name: 'company',
  props: {},
  components: {},
  data: function () {
    return {
      form: {},
      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' }],
        institution_code: [{ required: true, message: '请输入机构代码', trigger: 'blur' }],
      },
    };
  },
  created() {},
  methods: {
    ...organization(['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>
