shop_uniapp/pages/local_life/local_life.vue

460 lines
11 KiB
Vue

<template>
<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
:up="upOption">
<view class="index">
<u-sticky offset-top="0" h5-nav-height="0" bg-color="transparent">
<view class="index-bg">
<u-navbar title-color="#fff" :is-fixed="false" :border-bottom="false"
:background="{ background: 'transparent', }" :is-back="false">
<view class="flex row city">
<u-icon name="map" size="28" color="#FFFFFF" style="margin-top: 6rpx;"></u-icon>
<router-link class="m-l-16 flex white row-center" to="/bundle_b/pages/city/city">
<text class="m-r-6">{{ cityInfo.name || '选择' }}</text>
<u-icon name="arrow-down" size="24" color="#FFFFFF"></u-icon>
</router-link>
</view>
<view class="flex-1 m-t-30 flex">
<u-search wrap-bg-color="transparent" :hideRight="true" :show-action="true" action-text="取消"
:action-style="{color: '#fff'}" :animation="true" @focus="hideRight=false"
@blur="hideRight=true" @custom="handleCancel" placeholder="搜索商家或商品名称" height="64"
@search="search" v-model="keyword"></u-search>
</view>
</u-navbar>
</view>
</u-sticky>
<view v-if="appConfig.show_local_notice">
<u-notice-bar mode="horizontal" :list="[appConfig.local_notice]"></u-notice-bar>
</view>
<view class="m-t-20">
<ad-swipers :pid="7" height="312rpx" radius="20rpx" padding="0 30rpx"></ad-swipers>
</view>
<view>
<view class="nav bg-white m-t-20" v-if="navList.length != ''">
<swiper :style="'height:' + navSwiperH + 'rpx;'" @change="swiperChange">
<swiper-item v-for="(items, index) in navList" :key="index">
<view class="flex flex-wrap">
<view v-for="(item, index2) in items" :key="index2" class="nav-item m-t-30"
@tap="menuJump(item)">
<view class="flex-col col-center">
<image class="nav-icon m-b-15" :src="item.image"></image>
<view class="name xs">{{item.name}}</view>
</view>
</view>
</view>
</swiper-item>
</swiper>
<view class="dots" v-if="navList.length > 1">
<view v-for="(item, index) in navList" :key="index"
:class="'dot ' + (index == currentSwiper ? 'active' : '')"></view>
</view>
</view>
</view>
<view class="filter">
<view :class="'flex ' + (active == 1 ? 'active': '')" @tap="sortChange(1)">
<view class="mr-0">价格</view>
<view class="flex col-center">
<view class="arrow-icon flex-col col-center row-center">
<u-icon name="arrow-up-fill"
:color="moneySort == 'asc' ? colorConfig.primary : colorConfig.normal"></u-icon>
<u-icon name="arrow-down-fill"
:color="moneySort == 'desc' ? colorConfig.primary : colorConfig.normal"></u-icon>
</view>
</view>
</view>
<view :class="'flex ' + (active == 2 ? 'active': '')" @tap="sortChange(2)">
<view class="mr-0">距离</view>
<view class="flex col-center">
<view class="arrow-icon flex-col col-center row-center">
<u-icon name="arrow-up-fill"
:color="distanceSort == 'asc' ? colorConfig.primary : colorConfig.normal"></u-icon>
<u-icon name="arrow-down-fill"
:color="distanceSort == 'desc' ? colorConfig.primary : colorConfig.normal"></u-icon>
</view>
</view>
</view>
</view>
<view>
<u-waterfall v-model="list" ref="uWaterfall">
<template v-slot:left="{leftList}">
<view class="demo-warter" v-for="(item, index) in leftList" :key="index"
@click="toPage(item.id, item.lstore_id)">
<view class="goods-image">
<u-lazy-load border-radius="10rpx 10rpx 0 0" :image="item.url"
:index="index"></u-lazy-load>
<view class="distance">
{{item.distance}}
</view>
</view>
<view class="m-t-20"> {{item.title}} </view>
<view class="m-t-20">
<price-format :first-size="36" :second-size="24" color="#FF2C3C"
:price="item.price" />
<text v-if="item.original_price" class="original-price m-l-10">¥{{item.original_price}}</text>
</view>
</view>
</template>
<template v-slot:right="{rightList}">
<view class="demo-warter" v-for="(item, index) in rightList" :key="index"
@click="toPage(item.id, item.lstore_id)">
<view class="goods-image">
<u-lazy-load border-radius="10rpx 10rpx 0 0" :image="item.url"
:index="index"></u-lazy-load>
<view class="distance">
{{item.distance}}
</view>
</view>
<view class="m-t-20"> {{item.title}} </view>
<view class="m-t-20">
<price-format :first-size="36" :second-size="24" color="#FF2C3C"
:price="item.price" />
<text v-if="item.original_price" class="original-price m-l-10">¥{{item.original_price}}</text>
</view>
</view>
</template>
</u-waterfall>
</view>
</view>
<tabbar></tabbar>
</mescroll-body>
</template>
<script>
import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins";
import {
mapGetters,
mapActions,
mapMutations
} from 'vuex'
import {
arraySlice,
menuJump
} from '@/utils/tools'
import {
getLocalHome,
getLocalList
} from '@/api/store.js'
import {
sortType,
} from '@/utils/type';
export default {
mixins: [MescrollMixin],
data() {
return {
loadStatus: 'loadmore',
enable: true,
navSwiperH: '',
currentSwiper: 0,
active: 0,
moneySort: sortType.NONE,
distanceSort: sortType.NONE,
navList: [],
downOption: {
auto: false,
},
upOption: {
toTop: {
bottom: '300rpx'
},
auto: false,
empty: {
fixed: true,
icon: `${this.$aliOSS}uniapp/order_null.png`,
tip: '暂无数据',
top: '60%'
}
},
list: [],
width: '346rpx',
keyword: ''
}
},
async onLoad(options) {
try {
if (!options?.refresh) {
this.keyword = ''
this.reLocationFunc()
this.mescroll.resetUpScroll()
}
} catch (e) {}
this.getLocal()
},
onShow(options) {
this.getCartNum()
},
onHide() {
// #ifdef H5
this.enable = false
// #endif
},
methods: {
...mapActions(['initLocationFunc', 'getCartNum']),
...mapMutations(['setCityInfo']),
handleCancel() {
this.keyword = '';
this.mescroll.resetUpScroll()
},
async getLocal() {
const {
data
} = await getLocalHome()
this.navList = [data]
if (this.navList[0].length == 0) {
this.navSwiperH = 0
return
}
if (this.navList[0].length <= 5) {
this.navSwiperH = 200
} else {
this.navSwiperH = 374
}
},
// 位置
async reLocationFunc() {
await this.initLocationFunc();
},
swiperChange(e) {
this.currentSwiper = e.detail.current
},
menuJump(item) {
menuJump(item)
},
// 下拉刷新
downCallback() {
this.getLocal()
this.mescroll.resetUpScroll()
},
upCallback(page) {
const pageNum = page.num;
const pageSize = page.size;
const {
moneySort,
distanceSort,
keyword
} = this
if (this.cityInfo && this.cityInfo.gcj02_lng) {
getLocalList({
page_size: pageSize,
page_no: pageNum,
type: 'all',
c_name: this.cityInfo.name,
longitude: this.cityInfo.gcj02_lng ?? 0,
latitude: this.cityInfo.gcj02_lat ?? 0,
money_sort: moneySort,
distance_sort: distanceSort,
keyword
}).then(({
data
}) => {
if (page.num == 1) this.list = [];
const curPageData = data.list;
const curPageLen = curPageData.length;
const hasNext = !!data.more;
this.list = this.list.concat(JSON.parse(JSON.stringify(curPageData)));
this.mescroll.endSuccess(curPageLen, hasNext);
}).catch(() => {
this.mescroll.endErr()
})
}
},
search() {
this.$refs.uWaterfall.clear()
this.mescroll.resetUpScroll()
},
// 排序
sortChange(i) {
const {
moneySort,
distanceSort
} = this
this.active = parseInt(i)
switch (i) {
case 1:
if (moneySort == sortType.DESC || moneySort == sortType.NONE) {
this.moneySort = sortType.ASC
} else if (moneySort == sortType.ASC) {
this.moneySort = sortType.DESC
}
this.distanceSort = sortType.NONE
break;
case 2:
if (distanceSort == sortType.DESC || distanceSort == sortType.NONE) {
this.distanceSort = sortType.ASC
} else if (distanceSort == sortType.ASC) {
this.distanceSort = sortType.DESC
}
this.moneySort = sortType.NONE
break;
}
this.search()
},
toPage(id, lstore_id) {
this.$Router.push({
path: '/bundle_b/pages/local_shop/local_shop_buy',
query: {
id,
lstore_id
}
})
}
},
computed: {
...mapGetters(['sysInfo', 'cityInfo', 'userInfo', 'appConfig']),
},
watch: {
cityInfo: {
handler(val) {
this.$refs.uWaterfall.clear()
this.keyword = ''
this.mescroll.resetUpScroll()
}
},
list(val) {
this.goodsList = val
}
}
}
</script>
<style lang="scss">
page {
padding: 0;
}
.demo-warter {
border-radius: 20rpx;
margin: 20rpx 10rpx;
background-color: #ffffff;
padding: 20rpx;
position: relative;
}
.index {
min-height: calc(100vh - var(--window-bottom));
.index-bg {
position: relative;
background-image: url('#{$aliOSS-path}uploads/images/2024010413223852d897379.jpg');
padding-top: 40rpx;
padding-bottom: 14rpx;
}
.u-navbar {
::v-deep .u-search {
padding: 0 30rpx;
}
}
.city {
flex: 0 0 auto;
position: absolute;
top: 0;
bottom: 100rpx;
left: 40rpx;
}
.nav {
position: relative;
border-radius: 20rpx;
.nav-item {
width: 20%;
.nav-icon {
width: 60rpx;
height: 60rpx;
}
}
.dots {
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: 20rpx;
display: flex;
.dot {
width: 10rpx;
height: 6rpx;
border-radius: 6rpx;
margin-right: 10rpx;
background-color: rgba(255, 44, 60, 0.4);
&.active {
width: 20rpx;
background-color: $-color-primary;
}
}
}
}
.filter {
display: flex;
align-items: center;
padding: 30rpx;
.arrow-icon {
transform: scale(0.5);
}
view {
margin-right: 20rpx;
}
.mr-0 {
margin-right: 0;
}
.active {
color: $-color-primary;
}
}
}
.search {
color: #fff;
margin-right: 20rpx;
}
.goods-image {
position: relative;
.distance {
position: absolute;
bottom: 0;
left: 0;
color: #fff;
font-size: 24rpx;
background-color: rgba(0, 0, 0, 0.8);
padding: 4rpx 10rpx;
border-radius: 0 10rpx 10rpx 0;
}
}
.original-price {
font-size: 24rpx;
color: #999;
text-decoration: line-through;
}
</style>