<template>
  <CommonRoot>
    <FlexCol :gap="20" :padding="30">
      <Image src="https://mn.wenlvti.net/app_static/xiangyuan/images/bind-banner.jpg" width="100%" height="400" />
      <Button type="primary" @click="submit" :loading="loading">立即绑定</Button>
      <Button @click="doBack">稍后再说</Button>
    </FlexCol>
  </CommonRoot>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useLoadQuerys } from '@/common/composeabe/LoadQuerys';
import { toast } from '@/components/dialog/CommonRoot';
import { showError } from '@/common/composeabe/ErrorDisplay';
import { back, redirectTo } from '@/components/utils/PageAction';
import Button from '@/components/basic/Button.vue';
import FlexCol from '@/components/layout/FlexCol.vue';
import CommonRoot from '@/components/dialog/CommonRoot.vue';
import Image from '@/components/basic/Image.vue';
import InheritorContentApi from '@/api/collect/InheritorContent';
import { useAuthStore } from '@/store/auth';

/**
 *  账号绑定微信页面
 */

const { querys } = useLoadQuerys({
  nextPage: ''
});
const loading = ref(false);

const authStore = useAuthStore();
async function submit() {
  try {
    loading.value = true;
    const res = await uni.login({ provider: 'weixin' });
    await InheritorContentApi.bindWechat({ code: res.code });
    toast({ content: '绑定成功' });
    setTimeout(doBack, 800);
  } catch (e) {
    showError(e);
  } finally {
    loading.value = false;
  }
}
function doBack() {
  if (querys.value.nextPage) {
    redirectTo(querys.value.nextPage);
  } else {
    back();
  }
}
</script>
