<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 { useTransferPage } from '@/hooks/useTransferPage';
const { transferTo } = useTransferPage();
const form = ref({
  cardNo: '',
  password: ''
});
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(() => {
    uni.$ie.hideLoading();
    transferTo('/pagesSystem/pages/user-profile/user-profile', {
      data: {
        cardNo,
        password,
        type: 'card',
        scene: 'phone_improve'
      }
    });
  }).catch(() => {
    uni.$ie.hideLoading();
  });

}
</script>

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