<script setup>
import {ref} from "vue";
import RegisterLayer from "../../components/RegisterLayer.vue";
import {useUserStore} from "../../stores/user";

const userStore = useUserStore();
const showRegisterLayer = ref(false);

function onRegisterConfirm(data) {
  console.log('注册确认:', data);
  showRegisterLayer.value = false;

  uni.navigateBack({
    delta: 1
  })
}

async function getRealtimePhoneNumber(e) {
  console.log("获取手机号码", e);

  uni.navigateBack({
    delta: 1
  })
  return

  if (e.detail.errMsg !== "getPhoneNumber:ok") {
    uni.showToast({
      title: "请授权使用手机号",
      icon: "none",
    });
    return;
  }

  await userStore.phoneCallback(e.detail, () => {
    showRegisterLayer.value = true;
  });
}
</script>

<template>
  <button type="primary" class="phone-button" open-type="getPhoneNumber" @getphonenumber="getRealtimePhoneNumber">
    注册
  </button>
  <RegisterLayer v-model="showRegisterLayer" @confirm="onRegisterConfirm"/>
</template>

<style scoped>
.phone-button {
  margin-top: 100px;
  width: 90%;
}
</style>