<route lang="json5" type="page">
{
  layout: 'default',
  needLogin: true,
  style: {
    navigationStyle: 'custom',
  },
}
</route>

<script lang="ts" setup>
// 必须导入需要用到的页面生命周期（即使在当前页面上没有直接使用到）
// eslint-disable-next-line unused-imports/no-unused-imports
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
import { getConfigByCode } from '@/api/common'
import { myUsers } from '@/api/mine'
import { t } from '@/locale'
import { goBack, toPage } from '@/utils/page'

defineOptions({
  name: 'ReferEarn', // 邀请赚钱
})

// z-paging
const paging = ref(null)
// 类似mixins，如果是页面滚动务必要写这一行，并传入当前ref绑定的paging，注意此处是paging，而非paging.value
useZPaging(paging)
const changeNavbarThreshold = 50 // 滚动到这个高度时改变导航栏颜色

const navBgColor = ref('transparent')
onPageScroll((e) => {
  // 根据滚动高度改变导航栏背景色
  if (e.scrollTop > changeNavbarThreshold) {
    navBgColor.value = '#ffffff'
  }
  else {
    navBgColor.value = 'transparent'
  }
})
// 搜索结果
const dataList = ref([])
async function queryList(pageNo: number, pageSize: number) {
  try {
    const res = await myUsers({
      page: pageNo,
      size: pageSize,
      type: 1,
    })
    paging.value.complete(res.data.list)
  }
  catch {
    paging.value.complete(false)
  }
}
const invitedAmount = ref<any>(0)
async function getConfig() {
  try {
    const res = await getConfigByCode({ code: 'invited_amount' })
    console.log(res)
    if (res.code === '200') {
      invitedAmount.value = res.data.valueInfo
    }
  }
  catch {

  }
}
onLoad(() => {
  getConfig()
})
</script>

<template>
  <wd-navbar :custom-style="`background: ${navBgColor}`" safe-area-inset-top :bordered="false" fixed>
    <template #left>
      <wd-icon name="thin-arrow-left" :color="navBgColor === '#ffffff' ? '#000000' : '#ffffff'" size="32rpx" @click="() => goBack()" />
    </template>
    <template #title>
      <view class="font-bold text-32rpx!" :style="{ color: navBgColor === '#ffffff' ? '#000000' : '#ffffff' }">
        {{ $t('referEarn.title') }}
      </view>
    </template>
  </wd-navbar>
  <z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList">
    <view class="relative mb-40rpx">
      <!-- 邀请图 -->
      <image src="/static/images/refer-earn-bg.png" class="w-full" mode="widthFix" />
      <view class="absolute bottom-166rpx left-1/2 w-326rpx transform text-center -translate-x-1/2">
        <view class="px-14rpx text-36rpx text-white">
          <view>{{ $t('referEarn.inviteFriends') }}</view>
          <view class="mb-26rpx">
            {{ $t('referEarn.earnCash') }}
            <text class="text-[var(--wot-color-theme)]">
              ৳{{ invitedAmount }}
            </text>
          </view>
        </view>
        <view class="rounded-full bg-#F9CD96 py-14rpx text-34rpx text-[var(--wot-color-theme)] font-bold shadow-[0_2rpx_8rpx_0_rgba(249,205,150,0.5)]" @click="toPage({ url: '/pages/mine/share' })">
          {{ $t('referEarn.shareNow') }}
        </view>
      </view>
    </view>
    <view class="px-24rpx">
      <view class="mb-28rpx text-center text-32rpx text-[var(--wot-color-theme)]">
        {{ $t('referEarn.howToShare') }}
      </view>
      <view class="mb-40rpx flex items-center justify-between text-center">
        <view class="shadow='0rpx 2rpx 8rpx 0rpx rgba(249,205,150,0.5)' flex flex-1 flex-col items-center rounded-16rpx bg-#F9CD96/60 px-12rpx py-30rpx">
          <view class="mb-10rpx text-48rpx text-[var(--wot-color-theme)]">
            1
          </view>
          <view class="text-24rpx text-#8F3301 font-bold">
            {{ $t('referEarn.step1') }}
          </view>
        </view>
        <wd-icon name="caret-right-small" size="32rpx" color="#D8D8D8" class="mx-16rpx" />
        <view class="shadow='0rpx 2rpx 8rpx 0rpx rgba(249,205,150,0.5)' flex flex-1 flex-col items-center rounded-16rpx bg-#F9CD96/60 px-12rpx py-30rpx">
          <view class="mb-10rpx text-48rpx text-[var(--wot-color-theme)]">
            2
          </view>
          <view class="text-24rpx text-#8F3301 font-bold">
            {{ $t('referEarn.step2') }}
          </view>
        </view>
        <wd-icon name="caret-right-small" size="32rpx" color="#D8D8D8" class="mx-16rpx" />
        <view class="shadow='0rpx 2rpx 8rpx 0rpx rgba(249,205,150,0.5)' flex flex-1 flex-col items-center rounded-16rpx bg-#F9CD96/60 px-12rpx py-30rpx">
          <view class="mb-10rpx text-48rpx text-[var(--wot-color-theme)]">
            3
          </view>
          <view class="text-24rpx text-#8F3301 font-bold">
            {{ t('referEarn.step3', [invitedAmount]) }}
          </view>
        </view>
      </view>
      <view>
        <view class="mb-18rpx text-32rpx">
          {{ $t('referEarn.invitedFriends') }}
        </view>
        <view v-if="dataList.length" class="rounded-16rpx bg-white px-24rpx py-8rpx">
          <view
            v-for="(item, index) in dataList"
            :key="index"
            class="flex items-center justify-between py-18rpx"
            :class="{ 'border-b-1 border-b-solid border-#e8e8e8': index !== dataList.length - 1 }"
          >
            <view class="flex items-center">
              <wd-img width="80rpx" height="80rpx" round :src="item.headPic" />
              <view class="ml-20rpx text-28rpx font-bold">
                {{ item.name }}
              </view>
            </view>
            <view class="text-24rpx">
              {{ item.createTime }}
            </view>
          </view>
        </view>
      </view>
    </view>
  </z-paging>
</template>

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