<script setup>
  import { ref } from 'vue'
  import { navigateTo } from '@/utils/router'
  import { onShow } from '@dcloudio/uni-app'
  import { getUserPayPwd } from '@/api/my-index'
  import { useAuthUser } from '@/composables/useAuthUser'
  import { useUI } from '@/utils/use-ui'
  import { formatNumberWithWan } from '../../../utils'

  const { integralData } = useAuthUser()
  const { showDialog } = useUI()

  const itemList = ref([])

  const getData = async () => {
    itemList.value = []
    const res = await getUserPayPwd()
    const isSetPayPwd = res?.data ? '修改支付密码' : '设置支付密码'

    itemList.value = [
      {
        title: '提现卡',
        key: '1',
        url: '/pages/my-index/wallet/bank-card/index'
      },
      {
        title: '积分记录',
        key: '2',
        url: '/pages/my-index/wallet/record'
      },
      {
        title: '提现记录',
        key: '5',
        url: '/pages/my-index/wallet/withdrawal-record'
      },
      {
        title: isSetPayPwd,
        key: '3',
        isType: !!res?.data,
        url: '/pages/my-index/wallet/edit-password'
      },
      {
        title: '实名认证',
        key: '4',
        url: '/pages/my-index/wallet/real-id'
      },
      // #ifdef H5
      {
        title: '邀请好友',
        key: '6',
        url: '/pages/my-index/wallet/invite'
      }
      // #endif
    ]
  }
  onShow(() => {
    getData()
  })
</script>

<template>
  <view class="wallet">
    <!-- 顶部样式 -->
    <view class="top-card">
      <view class="left-box">
        <text>我的资产</text>
        <text>{{ formatNumberWithWan(integralData) }}</text>
      </view>
      <view class="right-box">
        <button
          @click="showDialog('提示', '联系客服或者联系上级分享人', false)"
        >
          充值
        </button>
        <button @click="navigateTo('/pages/my-index/withdraw')">
          提现
        </button>
      </view>
    </view>

    <view
      v-for="(item, index) in itemList"
      :key="index"
      class="public-card"
      @click="
        item.url &&
          navigateTo(
            item.url,
            item.key === '3' ? { type: item.isType ? 1 : 0 } : null
          )
      "
    >
      <view class="left-box">
        <text>{{ item.title }}</text>
      </view>
      <view class="right-box">
        <uni-icons type="right" size="16" color="#999999"></uni-icons>
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
  @import '../styles/index.scss';
  .wallet {
    padding: 32rpx 24rpx;
  }

  .top-card {
    padding: 36rpx;
    margin-bottom: 48rpx;
    background: #ff4c54;
    border-radius: 32rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    font-family: PingFang SC, PingFang SC;
    font-style: normal;
    text-transform: none;
    &::after {
      width: 100%;
      height: 100%;
      right: 54rpx;
      content: '';
      position: absolute;
      background: url('/static/images/my-index/wallet-bg.png');
      background-size: 30%;
      background-position: center;
      background-repeat: no-repeat;
      z-index: 1;
      pointer-events: none;
    }
    .left-box {
      display: flex;
      flex-direction: column;
      text {
        font-weight: 500;
        font-size: 28rpx;
        color: #ffffff;
        margin-bottom: 8rpx;
        &:last-child {
          font-weight: bold;
          font-size: 64rpx;
          text-align: left;
        }
      }
    }
    .right-box {
      display: flex;
      align-items: center;
      button {
        width: 128rpx;
        height: 64rpx;
        line-height: 64rpx;
        border-radius: 100rpx 100rpx 100rpx 100rpx;
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 28rpx;
        color: #ffffff;
        text-align: center;
        font-style: normal;
        text-transform: none;
        background: transparent;
        border: 2rpx solid #ffffff;
        &::after {
          border: none;
        }
        &:last-child {
          margin-left: 16rpx;
          background: #ffffff;
          color: #eb1c26;
          border: none;
        }
      }
    }
  }
</style>
