123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- <template>
- <view class="discover-page base-container">
- <view class="discover-top">
- <view class="home-search">
- <view class="search-wrap">
- <up-search placeholder="搜索品种" v-model="typeSearch"></up-search>
- </view>
- </view>
- <view class="type-wrap">
- <up-scroll-list :indicator="typeList && typeList.length>5" indicatorColor="#FF770033" indicatorActiveColor="#FF7700" :indicatorWidth="30"
- :indicatorBarWidth="15">
- <view class="item-type" :class="{'active': activeType === 0}" @click="handleSelectType(0)">
- <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon.png`" alt="" />
- <view class="type-text">
- 全部
- </view>
- </view>
- <view class="item-type" v-for="(item, index) in typeList"
- :class="{'active': activeType === item.id}" :key="index" @click="handleSelectType(item.id)">
- <image class="type-img" :src="item.image" alt="" />
- <view class="type-text">
- {{item.name}}
- </view>
- </view>
- </up-scroll-list>
- </view>
- </view>
- <!-- 列表 -->
- <view class="discover-content">
- <view class="discover-filter">
- <view class="filter-item" :class="{'active': filterIndex === 0}" @click="selectFilter(0)">
- 综合
- </view>
- <view class="filter-item" :class="{'active': filterIndex === 1}" @click="selectFilter(1)">
- 价格
- <div class="filter-icon">
- <image v-show="filterIndex !== 1" style="width: 14px; height: 14px;padding-top: 2px;" :src="`${config.BASIC_IMG}home/filter-icon.png`" mode=""></image>
- <image v-show="filterIndex === 1 && orderType===true" style="width: 14px; height: 14px;padding-top: 2px;" :src="`${config.BASIC_IMG}home/filter-icon-1.png`" mode=""></image>
- <image v-show="filterIndex === 1 && orderType===false" style="width: 14px; height: 14px;padding-top: 2px;" :src="`${config.BASIC_IMG}home/filter-icon-2.png`" mode=""></image>
- </div>
- </view>
- <view class="filter-item" :class="{'active': filterIndex === 2}" @click="selectFilter(2)">
- 销量
- <div class="filter-icon">
- <image v-show="filterIndex !== 2" style="width: 14px; height: 14px;padding-top: 2px;" :src="`${config.BASIC_IMG}home/filter-icon.png`" mode=""></image>
- <image v-show="filterIndex === 2 && orderType===true" style="width: 14px; height: 14px;padding-top: 2px;" :src="`${config.BASIC_IMG}home/filter-icon-1.png`" mode=""></image>
- <image v-show="filterIndex === 2 && orderType===false" style="width: 14px; height: 14px;padding-top: 2px;" :src="`${config.BASIC_IMG}home/filter-icon-2.png`" mode=""></image>
- </div>
- </view>
- </view>
- <view class="discover-list">
- <view class="list-line">
- <view class="list-item" v-for="(item, index) in discoverData" :key="index">
- <image class="item-img" :src="item.img" mode="aspectFill"></image>
- <view class="item-desc">
- <view class="item-text">
- {{item.name}}
- </view>
- <view class="item-subtext">
- <text class="subtext-text">坏单包退</text>
- <text class="subtext-text">包邮</text>
- </view>
- <view class="info-price">
- <view class="price-text">
- <text class="price-unit">¥</text>{{item.price}}
- </view>
- <view class="info-sold">
- 已售{{item.salesVal}}
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
-
- <view class="no-data" v-if="!discoverData||!discoverData.length">
- 暂未上架商品,请耐心等候
- </view>
- </view>
- </view>
- </template>
- <script setup>
- import {
- onMounted,
- ref
- } from "vue";
- import config from "@/api/config.js"
- import HOME from "@/api/home.js"
- import { onShow } from "@dcloudio/uni-app"
- const typeSearch = ref(null)
- const filterIndex = ref(0)
- const activeType = ref(0)
- const orderType = ref(true)
- const discoverData = ref([])
- let sortObj = {
- 0: "id",
- 1: "price",
- 2: "salesVal"
- }
- function selectFilter(i) {
- if (filterIndex.value !== i) {
- orderType.value = false
- }
- filterIndex.value = i
- sort.value = sortObj[i]
- orderType.value = !orderType.value
- getGoodsList()
- }
-
- onShow(() => {
- const selectedType = uni.getStorageSync('selectedCategoryType');
- if (selectedType) {
- activeType.value = selectedType
- uni.setStorageSync('selectedCategoryType', 0);
- handleSelectType(selectedType||0)
- }
- })
- onMounted(() => {
- console.log('onMounted')
- getTypeList()
- getGoodsList()
- })
- const typeList = ref([])
- function getTypeList() {
- HOME.fetchTypeList().then(({
- data
- }) => {
- typeList.value = data
- })
- }
- const sort = ref("id")
- function getGoodsList(param) {
- let params = {...param, sort: sort.value}
- if (filterIndex.value !== 0) {
- params = {
- ...params,
- order: orderType.value ? "asc" : "desc"
- }
- }
- HOME.fetchGoodsList(params).then(({
- data
- }) => {
- discoverData.value = data
- })
- }
-
- function handleSelectType(id) {
- activeType.value = id
- let params = {}
- if (id) {
- params = {
- categoryId: id
- }
- }
- getGoodsList(params)
- }
- </script>
- <style lang="scss" scoped>
- .discover-page {
- padding: 0;
- background: #F2F3F5;
- height: 100vh;
- .discover-top {
- padding: 20rpx 24rpx;
- background: linear-gradient(#FFFFFF, #F2F3F5);
- .home-search {
- display: flex;
- align-items: center;
- width: 100%;
- border: 2rpx solid #FFD95E;
- border-radius: 40rpx;
- margin-bottom: 40rpx;
- .search-wrap {
- flex: 1;
- // padding-left: 22rpx;
- ::v-deep {
- .u-search {
- .u-search__content {
- background-color: transparent !important;
- .u-search__content__input {
- background-color: transparent !important;
- }
- }
- .u-search__action {
- text-align: center;
- line-height: 52rpx;
- border-radius: 40rpx;
- font-size: 28rpx;
- background-color: #FFD95E;
- margin: 6rpx 8rpx;
- width: 112rpx;
- height: 52rpx;
- }
- }
- }
- }
- .search-btn {
- text-align: center;
- line-height: 52rpx;
- border-radius: 40rpx;
- font-size: 28rpx;
- background-color: #FFD95E;
- margin: 6rpx 8rpx;
- width: 112rpx;
- height: 52rpx;
- }
- }
- .type-wrap {
- padding: 0 20rpx 0 20rpx;
- background-color: #fff;
- border-radius: 16rpx;
- height: 186rpx;
- box-sizing: border-box;
-
- // 覆盖 up-scroll-list 的默认样式,实现两端对齐
- :deep(.u-scroll-list__scroll-view__content) {
- display: flex;
- justify-content: space-between;
- align-items: center;
- width: 100%;
- min-width: 100%;
- }
- ::v-deep {
- .u-scroll-list__indicator {
- margin-top: 16rpx;
- }
- }
- .item-type {
- text-align: center;
- font-size: 24rpx;
- flex-shrink: 0;
- .type-img {
- width: 92rpx;
- height: 92rpx;
- }
- .type-text {
- line-height: 36rpx;
- }
- &.active {
- .type-text {
- background-color: #FFD95E;
- border-radius: 20rpx;
- }
- }
- }
- .item-type+.item-type {
- padding-left: 22rpx;
- }
- }
- }
- .discover-content {
- padding: 0rpx 24rpx 24rpx;
- height: calc(100% - 320rpx);
- overflow: auto;
- background: #F2F3F5;
- box-sizing: border-box;
- .no-data {
- text-align: center;
- color: rgba(0, 0, 0, 0.6);
- font-size: 28rpx;
- }
- .discover-filter {
- color: #A6A6A6;
- font-size: 28rpx;
- display: flex;
- align-items: center;
- .filter-item {
- padding: 12rpx 20rpx;
- display: flex;
- align-items: center;
- &.active {
- color: #000000;
- }
- .filter-icon {
- padding-left: 4rpx;
- }
- }
- }
- .discover-list {
- padding-top: 20rpx;
- .list-line {
- padding-bottom: 20rpx;
- display: flex;
- flex-wrap: wrap;
- .list-item {
- background-color: #FFFFFF;
- border-radius: 10rpx;
- width: calc(50% - 16rpx);
- margin-bottom: 20rpx;
- .item-img {
- width: 100%;
- height: 340rpx;
- object-fit: cover;
- border-radius: 10rpx 10rpx 0 0;
- }
- .item-desc {
- padding: 0 10rpx 10rpx;
- .item-text {
- width: calc(100% - 22rpx);
- overflow: hidden;
- text-overflow: ellipsis;
- color: #000000;
- font-size: 28rpx;
- line-height: 42rpx;
- font-weight: 600;
- white-space: nowrap;
- }
- .item-subtext {
- color: #AFAFAF;
- font-size: 24rpx;
- line-height: 36rpx;
- .subtext-text+.subtext-text {
- padding-left: 10rpx;
- }
- }
- .info-price {
- display: flex;
- align-items: baseline;
- justify-content: space-between;
- .price-text {
- color: #FF7700;
- font-size: 36rpx;
- .price-unit {
- font-size: 23rpx;
- }
- }
- .info-sold {
- font-size: 20rpx;
- color: #C4C4C4;
- }
- }
- }
- }
- .list-item:nth-child(2n) {
- margin-left: 20rpx;
- }
- }
- }
- }
- }
- </style>
|