<!-- 账号注册 accountReg  -->
<template>
  <view>
    <!-- 标题栏 -->
    <view class="head-box ss-m-b-60 ss-flex-col">
      <view class="head-title ss-m-r-40">注册</view>
      <view class="head-subtitle">注册后即可登录使用更多功能</view>
    </view>
	
    <!-- 表单项 -->
    <uni-forms
      ref="accountRegRef"
      v-model="state.model"
      :rules="state.rules"
      validateTrigger="bind"
    >
      <uni-forms-item name="phone">
        <uni-easyinput placeholder="请输入手机号" v-model="state.model.phone" :inputBorder="false" :maxlength="11"></uni-easyinput>
      </uni-forms-item>

      <uni-forms-item name="password">
        <uni-easyinput
          type="password"
          placeholder="请输入密码"
          v-model="state.model.password"
          :inputBorder="false"
        >
        </uni-easyinput>
      </uni-forms-item>
	  <uni-forms-item name="password1">
	    <uni-easyinput
	      type="password"
	      placeholder="请再次输入密码"
	      v-model="state.model.password1"
	      :inputBorder="false"
	    >
	    </uni-easyinput>
	  </uni-forms-item>
    </uni-forms>
	<view class="submit_btn reg_btn" @tap="accountRegSubmit">注册</view>
  </view>
</template>

<script setup>
  import { ref, reactive, unref } from 'vue';
  import sheep from '@/common';
  import { phone, mobile, password } from '@/common/validate/form';
  import { closeAuthModal } from '@/common/hooks/useModal';
import AuthUtil from '@/common/api/member/auth';
import $store from '@/common/store';
  const accountRegRef = ref(null);

  const emits = defineEmits(['onConfirm']);

  const props = defineProps({
    agreeStatus: {
      type: [Boolean, null],
      default: null,
    },
  });

  // 数据
  const state = reactive({
    model: {
	  clientType: 0,
      //mobile: '', // 账号
	  phone: '',
      password: '', // 密码
	  password1: ''
    },
    rules: {
      //mobile,
	  phone,
      password,
    },
  });

  // 账号注册
  async function accountRegSubmit() {
    // 表单验证
    const validate = await unref(accountRegRef).validate().catch((error) => {
        console.log('error: ', error);
    })
    if (!validate) return;
	if(state.model.password1!==state.model.password){
		sheep.$helper.toast('两次密码输入不一致')
		return
	}
	if(!props.agreeStatus){
		sheep.$helper.toast('请选择同意协议')
		return
	}
	// 提交数据
	const { code, data } = await AuthUtil.phonePswRegister(state.model)
	if (code === 1) {
		//closeAuthModal()
		const modal = $store('modal')
		modal.$patch((state) => {
		  state.loginType = 'accountLogin'
		})
	}
  }
</script>

<style lang="scss" scoped>
  @import '../index.scss';
</style>
