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

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);

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

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

function testClick() {
  jump({
    type: JumpType.MINI,
    url: '/subPackages/xmhMainProcess/mine/index',
    extra: {
      appId: 'wx4205ec55b793245e',
    }
  })
}
</script>

<template>
  <div class="page">
    <button type="primary" open-type="getPhoneNumber" @getphonenumber="getRealtimePhoneNumber">
      注册
    </button>
    <button @click="testClick">
      测试
    </button>
  </div>
  <RegisterLayer v-model="showRegisterLayer" @confirm="onRegisterConfirm"/>
</template>

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