<template>
    <div class="login-container pt-5 pb-5">
      <v-form ref="form" v-model="valid" class="login-form">
        <v-text-field v-model="form.name" label="企业全称" placeholder="请输入企业全称" outlined :rules="[v=> !!v || '请输入企业全称']" dense></v-text-field>
        <v-text-field v-model="form.creditCode" label="统一信用编码" placeholder="请输入统一信用编码" outlined :rules="[checkCreditCode]" dense></v-text-field>
        <selectArea v-model="form.area"></selectArea>
        <v-text-field v-model="form.address" label="企业详细地址" placeholder="请输入企业详细地址" outlined :rules="[v=> !!v || '请输入企业地址']" dense></v-text-field>
        <v-text-field v-model="form.phone" label="企业联系手机" placeholder="请输入企业联系手机" outlined :rules="[checkPhone]" dense></v-text-field>
        <div class="default">
            <v-text-field label="手机验证码" v-model="form.code" placeholder="请输入验证码" outlined type="text" :rules="[v=> !!v || '请输入手机验证码']" dense></v-text-field>
            <v-btn class="getCode" v-if="codeShow" @click="sendCode" color="primary" small>获取验证码</v-btn>
            <v-btn class="getCode" v-else disabled small>重新获取{{count}}</v-btn>
        </div>
        <v-text-field v-model="form.email" label="企业邮箱" placeholder="请输入企业邮箱" outlined :rules="[checkEmail]" dense></v-text-field>
        <v-text-field v-model="form.username" label="登录用户名" placeholder="请输入登录用户名" outlined :rules="[v=> !!v || '请输入登录用户名']" dense></v-text-field>
        <v-text-field v-model="form.password" label="登录密码" placeholder="请输入登录密码" outlined :rules="[v=> !!v || '请输入登录密码']" dense></v-text-field>
        <v-btn :loading="loading" color="primary" class="submit-button" @click="handleRegister">提交申请</v-btn>
      </v-form>
    </div>
</template>

<script>
// import { companyRegister2 } from '@/api/user'
// import { isPhone, isEmail } from '@/utils/validate'
// import selectArea from '@/components/Area/index'
// import { code } from '@/mixin/code'
export default {
  name: 'registerPage',
  data () {
    return {
      valid: false,
      form: {},
      loading: false,
      snackbar: false,
      text: '',
      color: ''
    }
  },
  // watch: {
  //   'form.phone': function (n, o) {
  //     this.$set(this.form, 'username', n)
  //   }
  // },
  methods: {
    handleRegister () {
      // const verificationCode = this.$store.state.settings.verificationCode
      // if (this.$refs.form.validate()) {
      //   if (this.form.code === verificationCode) {
      //     const postForm = {
      //       user: { username: this.form.username, password: this.form.password, roleId: 2 },
      //       companyInfo: {
      //         name: this.form.name,
      //         creditCode: this.form.creditCode,
      //         address: this.form.area.province.areaName + this.form.area.city.areaName + this.form.area.area.areaName + this.form.address,
      //         phone: this.form.phone,
      //         email: this.form.email,
      //         type: 2
      //       },
      //       code: this.form.code
      //     }
      //     console.log('form', postForm)
      //     companyRegister2(postForm).then(res => {
      //       if (res.code === 200) {
      //         this.text = '提交成功请等待管理员审核'
      //         this.color = 'success'
      //         this.snackbar = true
      //         setTimeout(() => {
      //           this.$router.push({ path: '/login' })
      //         }, 800)
      //       }
      //     }).catch(e => {
      //       this.text = e.msg
      //       this.color = 'error'
      //       this.snackbar = true
      //     })
      //   } else {
      //     this.text = '验证码错误，请重新输入'
      //     this.color = 'warning'
      //     this.snackbar = true
      //   }
      // }
    },
    // 手机号验证
    checkPhone (val) {
      // if (!isPhone(val)) {
      //   return '请输入正确电话号码'
      // }
      // return true
    },
    // 邮箱验证
    checkEmail (val) {
      // if (!isEmail(val)) {
      //   return '请输入正确的企业邮箱'
      // }
      // return true
    },
    // 统一编码验证
    checkCreditCode (val) {
      // if (!(/^[^_IOZSVa-z\W]{2}\d{6}[^_IOZSVa-z\W]{10}$/g.test(val))) {
      //   return '请输入正确的统一信用编码'
      // }
      // return true
    },
    toHref (e) {
      // this.$router.push(e)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
