<template>
  <ie-page bg-color="#F6F8FA">
    <ie-navbar title="绑定会员卡" />
    <view class="h-20"></view>
    <view class="px-46 py-50 bg-white">
      <ie-input v-model="form.cardNo" type="number" :maxlength="8" placeholder="请输入会员卡号" />
      <ie-input custom-class="mt-28" type="text" :maxlength="6" v-model="form.password" placeholder="请输入会员卡密码" />
    </view>
    <ie-safe-toolbar :height="84" :shadow="false">
      <view class="px-46 pt-24">
        <ie-button type="primary" @click="handleSubmit">开始校验</ie-button>
      </view>
    </ie-safe-toolbar>
  </ie-page>
</template>

<script lang="ts" setup>
import { verifyCard } from '@/api/modules/user';
import { EnumBindScene } from '@/common/enum';
import { useTransferPage } from '@/hooks/useTransferPage';
import { useUserStore } from '@/store/userStore';
const { transferTo } = useTransferPage();
const userStore = useUserStore();
const form = ref({
  cardNo: '', // 60005001
  password: '', // 719615
});
const handleSubmit = async () => {
  const { cardNo, password } = form.value;
  if (!cardNo || cardNo.trim() === '') {
    uni.$ie.showToast('请输入会员卡号');
    return;
  }
  if (!password || password.trim() === '') {
    uni.$ie.showToast('请输入会员卡密码');
    return;
  }
  uni.$ie.showLoading();
  verifyCard(cardNo, password).then((res) => {
    uni.$ie.hideLoading();
    const submitInfo = {
      token: userStore.accessToken,
      scene: EnumBindScene.LOGIN_BIND,
      userInfo: userStore.userInfo,
      cardInfo: res.data,
      registerInfo: {
        username: form.value.cardNo,
        password: form.value.password,
      }
    };
    transferTo('/pagesSystem/pages/bind-profile/bind-profile', {
      data: submitInfo
    });
  }).catch(() => {
    uni.$ie.hideLoading();
  });

}
</script>

<style lang="scss" scoped></style>
