mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2026-08-07 03:14:59 +08:00
- 将多个组件转换为 `<script setup>` 语法,提升可读性和性能 - 优化状态管理和事件处理逻辑,简化代码结构 - 更新样式和布局以适应新组件结构 - 添加新功能和修复已知问题,提升用户体验
173 lines
3.6 KiB
Vue
173 lines
3.6 KiB
Vue
<template>
|
|
<view class="wrapper">
|
|
<u-navbar
|
|
:border="false"
|
|
:fixed="true"
|
|
:placeholder="true"
|
|
left-icon="arrow-left"
|
|
:auto-back="false"
|
|
@left-click="back"
|
|
>
|
|
<template #center>
|
|
<view v-if="search" class="search-wrap">
|
|
<u-search
|
|
@search="searchFun()"
|
|
@custom="searchFun()"
|
|
v-model="params.goodsName"
|
|
></u-search>
|
|
</view>
|
|
<text v-else class="nav-title">{{ title }}</text>
|
|
</template>
|
|
<template #right>
|
|
<view class="nav-right" @click="searchFlag()">
|
|
<text v-if="search">取消</text>
|
|
<u-icon v-else size="22" name="search"></u-icon>
|
|
</view>
|
|
</template>
|
|
</u-navbar>
|
|
<!-- 顶部栏 -->
|
|
<view class="header-wraper">
|
|
<image class="header-banner" mode="aspectFit" src="/static/join-buy.png"></image>
|
|
</view>
|
|
<!-- 商品栏 -->
|
|
<div class="swiper">
|
|
<goodsTemplate v-if="goodsList.length" :res="goodsList" />
|
|
|
|
<u-empty v-else style="margin-top:20%" text="暂无拼团活动" mode="data"></u-empty>
|
|
</div>
|
|
|
|
</view>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, watch } from 'vue'
|
|
import { onLoad, onReachBottom, onNavigationBarButtonTap } from '@dcloudio/uni-app'
|
|
import * as API_Promotions from '@/api/promotions'
|
|
import goodsTemplate from '@/components/m-goods-list/promotion.vue'
|
|
|
|
const is_empty = ref(false)
|
|
const search = ref(false)
|
|
const title = ref('拼团活动')
|
|
const popupFlag = ref(false)
|
|
|
|
const params = ref({
|
|
pageNumber: 1,
|
|
pageSize: 10,
|
|
categoryPath: '',
|
|
goodsName: '',
|
|
})
|
|
|
|
const goodsList = ref<any[]>([])
|
|
|
|
watch(search, (val) => {
|
|
if (!val && !title.value) {
|
|
title.value = '拼团活动'
|
|
}
|
|
})
|
|
|
|
onReachBottom(() => {
|
|
loadMore()
|
|
})
|
|
|
|
onNavigationBarButtonTap(() => {
|
|
popupFlag.value = !popupFlag.value
|
|
})
|
|
|
|
onLoad(async () => {
|
|
GET_AssembleGoods()
|
|
})
|
|
|
|
function back() {
|
|
if (search.value) {
|
|
search.value = false
|
|
params.value.goodsName = ''
|
|
goodsList.value = []
|
|
params.value.pageNumber = 1
|
|
GET_AssembleGoods()
|
|
return
|
|
}
|
|
const pages = getCurrentPages()
|
|
if (pages.length > 1) {
|
|
uni.navigateBack()
|
|
} else {
|
|
uni.switchTab({
|
|
url: '/pages/tabbar/home/index',
|
|
})
|
|
}
|
|
}
|
|
|
|
function loadMore() {
|
|
params.value.pageNumber++
|
|
GET_AssembleGoods()
|
|
}
|
|
|
|
function searchFlag() {
|
|
search.value = !search.value
|
|
}
|
|
|
|
function toHref(goods: any) {
|
|
uni.navigateTo({
|
|
url: `/pages/product/goods?id=${goods.skuId}&goodsId=${goods.goodsId}`,
|
|
})
|
|
}
|
|
|
|
function searchFun() {
|
|
goodsList.value = []
|
|
GET_AssembleGoods()
|
|
}
|
|
|
|
function GET_AssembleGoods() {
|
|
const requestParams = JSON.parse(JSON.stringify(params.value))
|
|
if (requestParams.category_id === 0) delete requestParams.category_id
|
|
|
|
API_Promotions.getAssembleList(requestParams)
|
|
.then((response) => {
|
|
const data = response.data.result.records
|
|
|
|
if (!data || !data.length) {
|
|
is_empty.value = true
|
|
} else {
|
|
is_empty.value = false
|
|
goodsList.value.push(...(data || []))
|
|
}
|
|
})
|
|
.catch(() => {})
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.search-wrap {
|
|
width: 100%;
|
|
padding: 0 20rpx;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.nav-title {
|
|
font-size: 32rpx;
|
|
color: #303133;
|
|
}
|
|
|
|
.nav-right {
|
|
margin-right: 24rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
font-size: 28rpx;
|
|
color: #303133;
|
|
}
|
|
|
|
.header-wraper {
|
|
background: url('/static/bg.png') no-repeat center center;
|
|
background-size: cover;
|
|
height: 200rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
|
|
.header-banner {
|
|
width: 188rpx;
|
|
height: 60rpx;
|
|
display: block;
|
|
}
|
|
}
|
|
</style>
|