shop_app/pages/special/index.vue

377 lines
9.2 KiB
Vue

<!-- 普通专题推荐位 -->
<template>
<view class="whole" v-if="loading" :style="{background: pageInfo.background_color || '#F5F5F5'}">
<view class="banner" v-if="pageInfo.image">
<image :src="pageInfo.image + '?x-oss-process=image/format,webp'" :webp="true" mode="widthFix" class="img"></image>
</view>
<view :style="{background: pageInfo.nav_bg_color || '#f3f3f3'}" class="tabsBox" v-if="actionList.length">
<up-tabs
:current="activeIndex"
keyName="name"
:list="actionList"
:lineColor="pageInfo.nav_text_color"
:inactiveStyle="{ color: pageInfo.nav_text_color }"
:activeStyle="{ color: pageInfo.nav_text_color }"
@click="changeTabs">
</up-tabs>
</view>
<view class="goodbox" v-if="goodsList.length !== 0" :class="pageInfo.show_type === 2 ? 'two' : pageInfo.show_type === 3 ? 'three' : ''">
<view class="item" v-for="(item, index) in goodsList" :key="item.id" @click="toGroups(item.pivot.path)">
<div class="imgbox">
<image :src="item.pivot.image + '?x-oss-process=image/format,webp'" :webp="true" mode="aspectFill" class="img"></image>
<view class="out" v-if="item.sold_status === 2">
<img src="https://ct-upimg.yx090.com/ju8hn6/shop/image/2024/01/16/Cr6cRRhhqYNhScigxIyumyV9hXXMI3vKvsE1jgt0.png" class="out_img" />
</view>
<view class="out" v-else-if="item.sold_status === 0">
<img src="https://ct-upimg.yx090.com/ju8hn6/shop/image/2024/08/21/QBhUheeYWSJ3OGM27fkAufJAlFSA8GBhWjpY5oNy.png" class="out_img" />
</view>
<view class="out" v-else-if="item.total_stock === 0">
<img src="https://ct-upimg.yx090.com/ju8hn6/shop/image/2024/08/21/pMTv6QiZZEpSqkJmk7hMcbEzIuNzMyp7YVBbe42H.png" class="out_img" />
</view>
</div>
<view class="box">
<view class="tit">
<view class="kuajing" v-if="item.has_cross_border">跨境包税</view>
<view class="kuajing" v-else-if="item.overseas_direct_mail">海外直邮</view>{{item.pivot.title}}
</view>
<view class="ation" v-if="!item.has_cross_border">
<template v-if="item.red_amount * 1 != 0">
<text class="quan" v-if="item.red_type == 2">新人再减{{item.red_amount * 1}}元</text>
<text class="quan" v-else="item.red_type == 0">券{{item.red_amount * 1}}元</text>
</template>
<template v-if="item.pivot && item.pivot.actives_title">
<text class="man" v-for="(itm, i) in item.pivot.actives_title" :key="i">{{itm}}</text>
</template>
</view>
<view class="bot">
<view class="text" v-if="item.pivot.path_type === 0">
<text class="prefix"></text>
<text class="txt1" v-if="parseFloat(item.pivot.min_price) == parseFloat(item.pivot.max_price)">{{item.pivot.min_price}}</text>
<text class="txt1" v-else>{{item.pivot.min_price * 1}}~{{item.pivot.max_price}}</text>
</view>
<view class="text" v-else>
<text class="prefix"></text>
<text class="txt1" v-if="parseFloat(item.min_price) == parseFloat(item.max_price)">{{item.min_price}}</text>
<text class="txt1" v-else>{{item.min_price * 1}}~{{item.max_price}}</text>
</view>
<view class="icon"><up-icon name="shopping-cart" :color="Color" size="24" /></view>
</view>
</view>
</view>
<view class="bottom" v-if="page >= last_page" :style="{color: modifyTextColor(pageInfo.background_color)}">
没有更多了
</view>
</view>
<view v-else class="empty">
<up-empty mode="data" icon="https://ct-upimg.yx090.com/g.ii090/images/sprite/empty/data.png" text="暂无数据"></up-empty>
</view>
<!-- 返回顶部 -->
<div @click="handleTop" v-if="showTop" class="top">
<up-icon name="arrow-upward" color="#000" size="24" />
</div>
</view>
</template>
<script>
import { ref, reactive, toRefs } from 'vue'
import { get, post } from '@/api/request.js'
import { modifyTextColor } from '@/utils/index.js'
import { Style } from '@/utils/list.js'
export default {
setup() {
const data = reactive({
activeIndex: 0,
id: '',
page: 1,
last_page: 0,
goodsList: [],
loading: false,
showTop: false,
pageInfo: {},
Color: '',
priceColor: '',
actionList: [],
actionId: 0
})
async function getPageInfo() {
await get('/api/app/showcase/' + data.id).then((res) => {
data.pageInfo = res.data
data.actionList = res.data.actives || []
if(data.actionList.length != 0) {
data.actionList.unshift({id: 0, name: '全部'})
}
})
}
async function getFetchList() {
uni.showLoading({
mask: true,
title: '加载中'
})
await get('/api/app/showcase/goods/' + data.id, { page: data.page, pageSize: 24, active_id: data.actionId }).then((res) => {
data.last_page = res.meta.last_page
data.goodsList = data.goodsList.concat(res.data)
uni.hideLoading()
})
}
const handleTop = () => {
uni.pageScrollTo({
scrollTop: 0,
duration: 300
})
}
const toGroups = (path) => {
uni.navigateTo({
url: path + '&source_id=' + data.id + '&source_type=exclusive'
})
}
const changeTabs = (event) => {
if (event.id == data.actionId) {
return
}
data.actionId = event.id
data.activeIndex = event.index
data.page = 1
data.goodsList = []
getFetchList()
}
return {
modifyTextColor,
...toRefs(data),
getFetchList,
handleTop,
toGroups,
getPageInfo,
changeTabs
}
},
onReachBottom() {
if (this.page < this.last_page) {
this.page ++
this.getFetchList()
}
},
onPageScroll(e) {
if (e.scrollTop > 300) {
this.showTop = true
} else {
this.showTop = false
}
},
async onLoad(options) {
this.id = options.id
// await this.$onLaunched
await this.getPageInfo()
await this.getFetchList()
this.title = options.title || this.pageInfo.title
this.Color = uni.getStorageSync('theme_color')
this.bgColor = Style[uni.getStorageSync('theme_index') * 1].bgColor
this.priceColor = Style[uni.getStorageSync('theme_index') * 1].priceColor
uni.setNavigationBarTitle({
title: this.title
})
this.loading = true
}
}
</script>
<style lang="scss" scoped>
.whole{
min-height: 100vh;
.banner{
width: 100%;
.img{
width: 100%;
}
}
.tabsBox{
position: sticky;
top: -1px;
z-index: 1;
}
}
.goodbox{
padding: 24rpx;
display: flex;
flex-wrap: wrap;
.item{
margin: 0 0 24rpx 0;
display: flex;
align-items: center;
justify-content: space-between;
background: #fff;
padding: 24rpx;
box-sizing: border-box;
border-radius: 10rpx;
width: 100%;
.imgbox{
position: relative;
.out{
position: absolute;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
top: 0;
left: 0;
.out_img{
width: 100rpx;
height: 100rpx;
}
}
}
.img{
width: 200rpx;
height: 200rpx;
border-radius: 10rpx;
}
.box{
display: flex;
height: 200rpx;
width: calc(100% - 220rpx);
flex-direction: column;
justify-content: space-between;
.tit{
font-size: 28rpx;
color: #2C2C2C;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
line-height: 40rpx;
}
.ation{
font-size: 22rpx;
text{
margin: 0 8rpx 8rpx 0;
border-radius: 6rpx;
padding: 6rpx 10rpx;
line-height: 1;
color: v-bind('Color');
display: inline-block;
}
.quan{
border: 1px solid v-bind('Color');
}
.man{
background-color: v-bind('bgColor');
border: 1px solid v-bind('bgColor');
}
}
.bot{
display: flex;
align-items: center;
justify-content: space-between;
}
.text{
color: v-bind('priceColor');
.prefix{
font-size: 24rpx;
}
text{
font-size: 34rpx;
}
}
}
}
&.two{
.item{
width: calc(50% - 14rpx);
display: block;
margin: 0 24rpx 24rpx 0;
&:nth-child(2n+2){
margin: 0 0 24rpx 0;
}
.img{
width: 100%;
height: 292rpx;
}
.box{
width: 100%;
height: auto;
.tit{
height: 80rpx;
margin: 10rpx 0;
}
.txt1{
font-size: 28rpx;
}
}
.imgbox{
.out{
.out_img{
width: 150rpx;
height: 150rpx;
}
}
}
}
}
&.three{
.item{
width: calc(33.3% - 18rpx);
display: block;
padding: 18rpx;
margin: 0 24rpx 24rpx 0;
&:nth-child(3n+3){
margin: 0 0 24rpx 0;
}
.img{
width: 100%;
height: 184rpx;
}
.box{
width: 100%;
height: auto;
.tit{
height: 80rpx;
margin: 10rpx 0;
}
.txt1{
font-size: 26rpx;
}
.icon{
display: none;
}
}
}
}
}
.empty{
width: 100%;
height: calc(100vh - 100rpx);
position: relative;
z-index: 1;
color: #fff;
}
.top {
position: fixed;
bottom: 15%;
right: 5%;
background: #fff;
width: 80rpx;
height: 80rpx;
line-height: 107rpx;
border-radius: 50%;
text-align: center;
box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.2);
z-index: 10;
}
.bottom {
text-align: center;
font-size: 24rpx;
color: #333;
margin: auto;
line-height: 80rpx;
width: 100%;
}
</style>