index.vue 1.99 KB
<!--
 * @Date: 2025-08-27 17:47:03
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2025-09-09 15:16:59
 * @FilePath: /lls_program/src/pages/RewardCategories/index.vue
 * @Description: 积分兑换分类
-->
<template>
  <view class="min-h-screen flex flex-col bg-white">
    <view class="flex-1 pb-20">
      <view class="p-4 space-y-4">
        <view v-for="(category, index) in categories" :key="category.id" class="rounded-lg overflow-hidden shadow-sm" @click="goToRewards(category)">
            <view class="relative" style="height: 380rpx;">
              <view class="absolute inset-0 flex flex-col justify-end p-4 text-white" style="background: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.6) 100%);">
                <h3 class="text-xl font-bold mb-1">{{ category.title }}</h3>
                <p class="text-sm text-white text-opacity-90">
                  {{ category.note }}
                </p>
              </view>
              <image mode="aspectFill" :src="category.background_url" :alt="category.title" class="w-full h-full object-cover" />
            </view>
        </view>
      </view>
    </view>
    <BottomNav />
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import Taro from '@tarojs/taro';
import BottomNav from '../../components/BottomNav.vue';
// 导入接口
import { getCouponHomeAPI } from '@/api/coupon';

const categories = ref([]);

const goToRewards = (category) => {
  if (!category.tips) {
    Taro.navigateTo({ url: '/pages/Rewards/index?id=' + category.id + '&category=' + category.id });
  } else {
    // 弹出确认提示框, 不用进行操作, 只是文本提示用户进行线下兑换
    Taro.showModal({
      title: '温馨提示',
      content: category.tips,
      showCancel: false
    }).then(res => {
      if (res.confirm) {
        // 点击了确认按钮
      }
    })
  }
};

onMounted(async () => {
  const { code, data } = await getCouponHomeAPI();
  if (code) {
    categories.value = data;
  }
})
</script>