Files
xdd-uniapp-new/pkg_product/views/healthList.vue
T
2023-09-20 21:49:33 +08:00

247 lines
7.4 KiB
Vue

<template>
<view class="pkg-product-list">
<view class="search-box flex jc-between ai-center">
<input type="text" v-model="keyword" placeholder="搜索商品" placeholder-style="color:#949494" @confirm="search">
<image class="icon" :src="webUrl+'/20220903142935869059.png'" mode="scaleToFill" @click="search"></image>
</view>
<swiper class="swiper-box" indicator-dots indicator-color="rgba(255,255,255,.3)" indicator-active-color="#fff"
autoplay circular v-if="bannerList.length>0">
<swiper-item v-for="(item,index) in bannerList" :key="index">
<image :src="item.pic" mode="scaleToFill" @click="$global.commonJump(item.uniappUrl)"/>
</swiper-item>
</swiper>
<swiper class="swiper-box" indicator-dots indicator-color="rgba(255,255,255,.3)" indicator-active-color="#fff"
autoplay circular v-else>
<swiper-item>
<view class="swiper-item uni-bg-blue">暂无内容</view>
</swiper-item>
</swiper>
<view class="tab-box flex jc-center ai-center" v-show="tabIndex===0">
<image class="active" src="/static/images/v6/btn_active_left.png" @click="changeTab(0)"/>
<image class="inactive" src="/static/images/v6/btn_right.png" @click="changeTab(1)"/>
</view>
<view class="tab-box flex jc-center ai-center" v-show="tabIndex===1">
<image class="inactive" src="/static/images/v6/btn_left.png" @click="changeTab(0)"/>
<image class="active" src="/static/images/v6/btn_active_right.png" @click="changeTab(1)"/>
</view>
<view class="body-box">
<view class="aside-box flex-0">
<view class="item flex jc-center ai-center" :class="index === asideIndex ? 'active' : ''"
v-for="(item, index) in asideList" :key="index" @click="asideTap(index)">
<text class="one-t">{{ item.label }}</text>
</view>
</view>
<view class="article-box">
<mescroll-body ref="mescrollRef" top="0" bottom="0" class='cotent-scroll' :up="upOption" :down="downOption"
@up="upCallback" @down="downCallback" @init="mescrollInit" @emptyclick="emptyClick">
<view class="list flex flex-wrap">
<view v-for="(item, index) in dataList" :key="index">
<view class="item item-store" @click="goStore(item.id)" v-if="tabIndex===0">
<image class="cover" :src="item.cover" mode="scaleToFill"/>
<view class="name one-t">{{ item.content }}</view>
<view class="price store flex ai-center" style="width: 100%;">
<image class="flex-0" :src="item.logo" mode="scaleToFill"/>
<view class="one-t">{{ item.name }}</view>
</view>
</view>
<view class="item" @click="goGoods(item.id)" v-else>
<image class="cover" :src="item.image" mode="scaleToFill"/>
<view class="name more-t">{{ item.storeName }}</view>
<view class="price">{{ item.price }}</view>
</view>
</view>
</view>
</mescroll-body>
</view>
</view>
</view>
</template>
<script>
import {fetchCity} from "@/api/wenwan";
import {wellnessFood, wellnessPlaceList} from "@/api/product";
import {getProducts} from "@/api/store";
import MescrollMixins from "@/mixins/mescroll-mixins";
import MescrollBody from "@/components/mescroll-uni/mescroll-body";
export default {
name: "healthList",
components: {
MescrollBody
},
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
tabIndex: 0,
keyword: "",
page: 1,
bannerList: [],
asideList: [],
asideIndex: 0,
dataList: [], // 列表数据
upOption: {
noMoreSize: 10, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
auto: true,
empty: {
tip: '暂无数据' // 提示
}
},
downOption: {
auto: false
}
}
},
mixins: [
MescrollMixins({
getPageData(mescroll) {
let that = this;
// 此时mescroll会携带page的参数:
let pageNum = mescroll.num; // 页码, 默认从1开始
let timer = setInterval(() => {
if (that.asideList.length > 0) {
clearInterval(timer);
let param = {
page: pageNum,
limit: 10,
keyword: that.keyword,
provinceId: that.asideList.length > 0 ? that.asideList[that.asideIndex].provinceId : ""
}
if (mescroll.num === 1) {
that.dataList = [];
}
if (that.tabIndex === 0) {
wellnessPlaceList(param).then(({data}) => {
that.dataList = that.dataList.concat(data);
mescroll.endSuccess(data.length);
});
} else {
param.isWellnessFood = 1;
getProducts(param).then(({data}) => {
that.dataList = that.dataList.concat(data);
mescroll.endSuccess(data.length);
});
}
}
}, 500)
}
})
],
onLoad() {
wellnessFood().then(({data}) => this.bannerList = data.banner);
fetchCity(4).then(({data}) => this.asideList = data.group);
},
methods: {
changeTab(index) {
if (this.asideList.length === 0) return;
if (index === this.tabIndex) return;
this.dataList = [];
this.tabIndex = index;
this.search();
},
search() {
if (this.asideList.length === 0) return;
//触发加载请求
this.mescroll.scrollTo(0, 0);
this.mescroll && this.mescroll.resetUpScroll(false);
},
asideTap(index) {
this.asideIndex = index;
this.search();
},
fetchData() {
let param = {
page: this.page,
limit: 10,
keyword: this.keyword,
provinceId: this.asideList.length > 0 ? this.asideList[this.asideIndex].provinceId : ""
}
if (this.tabIndex === 0) {
wellnessPlaceList(param).then(({data}) => {
for (let i = 0; i < data.length; i++) {
this.dataList.push(data[i]);
}
});
} else {
param.isWellnessFood = 1;
getProducts(param).then(({data}) => {
for (let i = 0; i < data.length; i++) {
this.dataList.push(data[i]);
}
});
}
},
goStore(id) {
uni.navigateTo({
url: "/pagesInn/inn/innHome?id=" + id
})
},
goGoods(id) {
uni.navigateTo({
url: "/pages/shop/GoodsCon/index?id=" + id
})
}
}
}
</script>
<style scoped lang="less">
@import "@/assets/css/product.less";
.pkg-product-list {
min-height: 100vh;
box-sizing: border-box;
padding-top: 16rpx;
background: #fff;
.tab-box {
margin: 0 32rpx;
.active {
width: 342rpx;
height: 96rpx;
}
.inactive {
width: 342rpx;
height: 80rpx;
border-radius: 10rpx;
box-shadow: 0 0 12px 0 rgba(0, 0, 0, .1);
}
}
.swiper-box {
margin: 20rpx auto 30rpx;
}
.body-box {
position: fixed;
top: 610rpx;
height: calc(100vh - 610rpx);
.store {
image {
width: 36rpx;
height: 36rpx;
border-radius: 50%;
vertical-align: middle;
margin-right: 20rpx;
}
view {
color: #333;
}
}
}
}
</style>