<style lang="less">
  @import './register.less';
</style>

<template>
  <div class="register">
    <div class="register-con">
      <div class="register-title">
        <div class="greet">欢迎注册</div>
        <div class="project-name">
          <img style="width: 32px;object-fit:scale-down;margin-right:8px" src="@/assets/images/logo-min.png" alt="">{{projectName}}
        </div>
      </div>
      <div class="form-con">
        <register-form
        :registercaptcha = "platform_register_captcha"
        @on-success-valid="handleSubmit"
        :member_type_options="dev_reg_level"
        ></register-form>
      </div>
    </div>
    <Modal
      :title="$t('tips')"
      :value="modalValue"
      width="400px"
      :closable="true"
      @on-ok="routerChange"
      @on-cancel="routerChange">
      <div>
        {{$t('cannot_register_tips')}}
      </div>
    </Modal>
  </div>
</template>

<script>
import registerForm from '_c/register-form'
import { mapActions } from 'vuex'
export default {
  components: {
    registerForm
  },
  data () {
    return {
      dev_reg_level: [],
      projectName: '',
      platform_register_captcha: false
    }
  },
  created () {
    this.getSiteData()
  },
  computed: {
    modalValue () {
      // return !this.$store.state.user.is_dev_register
      return false
    }
  },
  methods: {
    ...mapActions([
      'handleRegister',
      'GetPlatformData'
    ]),
    routerChange () {
      this.$router.push({ name: 'login' })
    },
    getSiteData () {
      this.GetPlatformData().then(res => {
        this.projectName = res.data.name
        this.platform_register_captcha = res.data.catpcha_switch.platform_register_captcha
        // this.platform_register_captcha = true
        this.dev_reg_level = res.data.dev_reg_level_list
      })
    },
    handleSubmit (params) {
      // params.password = md5(params.password)
      this.handleRegister(params).then((res) => {
        if (res.ret === 200) {
          this.$Message.success(this.$t('register_success_tips'))
          setTimeout(() => {
            this.$router.push({
              name: 'login'
            })
          }, 1000)
        } else this.$Message.warning(res.msg)
      })
    },
    handleOk () {
    }
  }
}
</script>

<style>

</style>
