<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="contacts">
                <el-input v-model="form.contacts" 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="address">
                <el-input v-model="form.address" 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"> 111 </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: mapMechanism } = createNamespacedHelpers('mechanism');
export default {
  name: 'company',
  props: {},
  components: {},
  data: function () {
    return {
      form: {},
      rules: {
        name: [{ required: true, message: '请输入机构名称', trigger: 'blur' }],
        contacts: [{ 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' }],
        address: [{ required: true, message: '请输入联系地址', trigger: 'blur' }],
        profession: [{ required: true, message: '请输入所属行业', trigger: 'blur' }],
      },
    };
  },
  created() {},
  methods: {
    ...mapMechanism(['create']),
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          let data = this.form;
          data.status = '0';
          console.log(data);
          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>
