jiuyiUniapp/jiuyi2/pages/shop/gift.vue

161 lines
2.9 KiB
Vue
Raw Normal View History

2025-04-08 21:54:02 +08:00
<script setup>
// 礼包专区
import {
ref,
reactive,
getCurrentInstance,
} from 'vue'
import {
onReachBottom,
onPullDownRefresh,
onShow,
onLoad,
onReady,
} from '@dcloudio/uni-app';
// 工具库
import util from '@/common/js/util.js'
//
import api from '@/api/index.js'
// 商品列表
import productList from '@/components/shop/productList/productList'
2025-04-12 09:00:09 +08:00
const {
proxy
} = getCurrentInstance()
2025-04-08 21:54:02 +08:00
// tab
const tab = reactive([{
name: '礼包专区',
},
{
name: '超值礼包',
},
{
name: '大礼包',
},
{
name: '小礼包',
},
])
// 下标
const tabIndex = ref(0)
2025-04-12 09:00:09 +08:00
onReady(() => {
// 获取礼包分类
getGiftCate().then(rs => {
// 分类
proxy.$refs.product.listPrototype.categoryId = tab[tabIndex.value].id
proxy.$refs.product.getList()
})
})
onReachBottom(() => {
// 重载列表
proxy.$refs.product.getMoreList()
})
onPullDownRefresh(() => {
// 重载列表
proxy.$refs.product.refreshList()
})
// 获取礼包分类
function getGiftCate() {
return new Promise(resolve => {
api.shop.getCategory({
query: {
categoryCode: 'GIFT_PACK',
},
}).then(rs => {
if (rs.code === 200) {
tab.length = 0
tab.push(...rs.data)
resolve(tab)
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
})
})
}
2025-04-08 21:54:02 +08:00
// 切换tab
function handleTab(index) {
if (tabIndex.value === index) return
tabIndex.value = index
2025-04-12 09:00:09 +08:00
// 分类
proxy.$refs.product.listPrototype.categoryId = tab[tabIndex.value].id
// 重载列表
proxy.$refs.product.refreshList()
2025-04-08 21:54:02 +08:00
}
</script>
<template>
<view class="app">
<!-- 公告 -->
2025-04-14 09:01:03 +08:00
<!-- <swiper class="notice c333 f28" vertical="true">
2025-04-08 21:54:02 +08:00
<swiper-item class="item bsb rows plr20" v-for="(item, index) in 2" :key="index">
<image class="icon" src="/static/notice.png" mode="aspectFit" />
<view class="f1 mlr20">九亿商城上线啦~</view>
</swiper-item>
2025-04-14 09:01:03 +08:00
</swiper> -->
2025-04-08 21:54:02 +08:00
<!-- 礼包专区 -->
<view class="tab bfff">
2025-04-12 09:00:09 +08:00
<view class="item ver ptb20" v-for="(item,index) in tab" :key="index" @click="handleTab(index)"
2025-04-08 21:54:02 +08:00
:class="{'active': index === tabIndex}">
2025-04-12 09:00:09 +08:00
<view class="">
<image class="icon" :src="item.icon" mode="aspectFill" />
</view>
2025-04-08 21:54:02 +08:00
<view class="line"></view>
</view>
</view>
<!-- 商品卡片组 加载更多 -->
<view class="product oh ptb30 plr30">
<productList ref="product" />
</view>
</view>
</template>
<style lang="scss" scoped>
// 公告
.notice {
height: 80rpx;
background-color: #e8e8e8;
.icon {
width: 84rpx;
height: 36rpx;
}
}
// 导航
.tab {
display: grid;
grid-template-columns: repeat(4, 1fr);
//
.item {
2025-04-12 09:00:09 +08:00
.icon {
width: 160rpx;
height: 40rpx;
}
2025-04-08 21:54:02 +08:00
.line {
width: 40rpx;
height: 6rpx;
background-color: #DD4B5B;
opacity: 0;
transition: .3s;
}
&.active {
.line {
opacity: 1;
}
}
}
}
</style>