Huanyuyuehui/pages/shop/index.vue

260 lines
7.2 KiB
Vue
Raw Normal View History

2024-03-24 15:23:25 +08:00
<template>
2024-03-25 16:25:29 +08:00
<view class="content" :style="viewColor">
2024-03-24 18:34:07 +08:00
<view class="top-tab" :style="`padding-top:`+navtop">
2024-03-28 11:10:52 +08:00
<view class="tab-location" @click="getLocation">
2024-03-28 17:54:55 +08:00
<view class="" style="max-width: 200px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
{{city}}
</view>
<view class="iconfont icon-dingwei" style="margin-left: 8rpx;"></view>
<view style="font-size: 14px;margin-left: 10px;font-weight: 500;" @click.stop="selectLocation">切换</view>
2024-03-24 15:23:25 +08:00
</view>
2024-03-24 17:43:25 +08:00
<view class="tab-sao iconfont icon-saoma" @tap='handleBorcode'></view>
2024-03-24 15:23:25 +08:00
</view>
<view class="content-map" >
2024-03-28 17:54:55 +08:00
<map class="map" :latitude="latitude" :longitude="longitude" :markers="[{'id':1,'latitude':latitude,'longitude':longitude,'iconPath':'/static/images/location.png',width:24,height:24 }]" :show-location="true"></map>
2024-03-24 15:23:25 +08:00
</view>
<view class="content-type">
2024-03-24 18:34:07 +08:00
<!-- <cover-image src="../annex/static/vipBg.png" style="position: absolute;
top: -20px;"></cover-image> -->
2024-03-26 14:48:11 +08:00
<view class="type-item" v-for="(item,index) in tabList" :key="index" @click="goShopSearch(item)">
2024-03-26 20:06:34 +08:00
<image class="type-item-img" :src="item.category_icon" mode=""></image>
2024-03-26 14:48:11 +08:00
<text class="type-item-text">{{item.category_name}}</text>
2024-03-24 15:23:25 +08:00
</view>
</view>
<view class="content-list">
<view class="list-tab">
2024-03-24 15:41:18 +08:00
<view :class="current==0?'action':''" @click="selectCurrent(0)">全部商家</view>
2024-03-26 14:48:11 +08:00
<view :class="current==1?'action':''" @click="selectCurrent(1,true)">附近商家</view>
2024-03-24 15:23:25 +08:00
</view>
2024-03-26 14:48:11 +08:00
<view class="list-container" v-if="shopList.length">
<view class="list-item" v-for="(item,index) in shopList" :key='index'>
<view class="list-item-left">
<image :src="item.mer_avatar" mode=""></image>
2024-03-24 17:43:00 +08:00
</view>
2024-03-26 14:48:11 +08:00
<view class="list-item-right" @click="navtoDetail(item)">
2024-03-24 15:23:25 +08:00
<view class="item-title">
2024-03-26 14:48:11 +08:00
{{item.mer_name}}
2024-03-24 15:23:25 +08:00
</view>
<view class="item-content">
<view class="right-center-left">
<view class="center-left-score">
2024-03-29 09:49:03 +08:00
<!-- <text class="iconfont icon-shitixing"></text>/ -->
<image src="@/static/images/xingxing.png" mode="" style="width: 12px;height: 12px;"></image>
2024-03-26 14:48:11 +08:00
<text>{{item.service_score}}</text>
2024-03-24 15:23:25 +08:00
</view>
2024-03-26 14:48:11 +08:00
<view class="center-left-time" v-if="item.config&&item.config.mer_take_time">营业时间:{{item.config.mer_take_time.join('-')}}</view>
2024-03-24 15:23:25 +08:00
</view>
<view class="right-center-right">
去选购
</view>
</view>
<view class="item-address">
2024-03-26 14:48:11 +08:00
<view class="address" v-if="item.mer_address">{{item.mer_address}}</view>
<view class="distance" v-if="item.distance">{{item.distance}}</view>
2024-03-24 15:23:25 +08:00
</view>
</view>
</view>
</view>
2024-03-25 10:42:01 +08:00
<view class="list-container" v-else>
<view class="list-fail">
<image :src="`${domain}/static/images/noCart.png`"></image>
<view>暂无商家去看看其他的吧</view>
</view>
</view>
2024-03-24 15:23:25 +08:00
</view>
2024-03-24 17:43:00 +08:00
<!--自定义底部tab栏-->
<customTab :newData="newData" :activeRouter="activeRouter"></customTab>
2024-03-24 15:23:25 +08:00
</view>
</template>
<script>
2024-03-25 10:42:01 +08:00
import { HTTP_REQUEST_URL } from '@/config/app';
2024-03-26 14:48:11 +08:00
import { getGeocoder } from '@/api/store.js';
2024-03-24 17:43:00 +08:00
import { getNavigation } from '@/api/public.js';
import customTab from '@/components/customTab';
2024-03-25 16:25:29 +08:00
import { mapGetters } from "vuex";
2024-03-26 14:48:11 +08:00
import {shopInit,shopNearby} from '@/api/shop.js'
2024-03-26 15:06:27 +08:00
import {getOrderOfflinePay} from '@/api/admin.js'
2024-03-28 11:10:52 +08:00
import prompt from '@/utils/prompt.js'
2024-03-24 15:23:25 +08:00
export default {
components:{
2024-03-24 17:43:00 +08:00
customTab,
2024-03-24 15:23:25 +08:00
},
data(){
return{
2024-03-25 10:42:01 +08:00
domain: HTTP_REQUEST_URL,
newData: {},
activeRouter: '',
2024-03-24 15:41:18 +08:00
tabList:[],
2024-03-26 14:48:11 +08:00
shopList:[],
2024-03-24 15:41:18 +08:00
current:0,
2024-03-24 18:34:07 +08:00
navtop:0,
2024-03-26 14:48:11 +08:00
addressInfo:[],
latitude: '',
longitude: '',
2024-03-28 17:54:55 +08:00
city:'请点击获取定位',
2024-03-24 15:23:25 +08:00
}
},
onLoad(){
2024-03-28 17:54:55 +08:00
// this.selfLocation();
2024-03-24 15:23:25 +08:00
},
2024-03-24 17:43:00 +08:00
onShow(){
2024-03-28 17:54:55 +08:00
uni.showTabBar({animation: false});
let location=uni.getStorageSync('locationCity');
if(location){
this.latitude=location.lat;
this.longitude=location.lon;
this.city=location.city;
}
this.init();
this.selfLocation();
2024-03-24 17:43:00 +08:00
this.getNav();
},
2024-03-25 16:25:29 +08:00
computed:{
...mapGetters(['viewColor'])
},
2024-03-24 17:43:00 +08:00
created(options) {
2024-03-24 18:34:07 +08:00
let statusBarHeight= uni.getSystemInfoSync().statusBarHeight+"px";
this.navtop=statusBarHeight;
2024-03-24 17:43:00 +08:00
let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
let curRoute = routes[routes.length - 1].route //获取当前页面路由
this.activeRouter = '/' + curRoute
},
2024-03-24 15:23:25 +08:00
methods:{
2024-03-28 11:10:52 +08:00
async getLocation(){
let self=this;
// #ifdef APP-PLUS
let res = await prompt.requestPermissions(['ACCESS_FINE_LOCATION'])
if(res!==1)return
else {
console.log('999: ',999);
}
// #endif
uni.getLocation({
type: 'gcj02',
2024-03-28 17:54:55 +08:00
geocode:true,
2024-03-28 11:10:52 +08:00
success: (res) => {
let latitude, longitude;
latitude = res.latitude.toString();
longitude = res.longitude.toString();
2024-03-28 17:54:55 +08:00
console.log('res: ',res);
let parems={
city:res.address.poiName,
lat:latitude,
lon:longitude
}
uni.setStorageSync('locationCity',parems);
2024-03-28 11:10:52 +08:00
self.latitude = res.latitude;
self.longitude = res.longitude;
2024-03-28 17:54:55 +08:00
self.city=res.address.poiName;
2024-03-28 11:10:52 +08:00
uni.hideLoading();
let data1={
mini:1,
type_id:4,
location:res.latitude+','+res.longitude
}
shopNearby(data1).then((r)=>{
if(r.data.list){
this.shopList=r.data.list;
}
})
},
fail: (res) => {
uni.hideLoading();
uni.showToast({
title: res.errMsg,
icon: 'none',
duration: 1000
});
}
});
},
selectLocation(){
uni.navigateTo({
url:'/pages/shop/location/index'
})
},
2024-03-26 14:48:11 +08:00
init(){
shopInit().then((res)=>{
if(res.data.lst){
this.tabList=res.data.lst;
}
if(res.data.list){
this.shopList=res.data.list;
}
console.log('res: ',res);
})
},
selfLocation() {
2024-03-28 17:54:55 +08:00
uni.hideLoading();
let data1={
mini:1,
type_id:4,
location:this.latitude+','+this.longitude
}
shopNearby(data1).then((r)=>{
if(r.data.list){
this.shopList=r.data.list;
2024-03-26 14:48:11 +08:00
}
2024-03-28 17:54:55 +08:00
})
2024-03-26 14:48:11 +08:00
},
goShopSearch(item){
uni.navigateTo({
2024-03-26 17:17:16 +08:00
url:'./search/index?id='+item.merchant_category_id
2024-03-26 14:48:11 +08:00
})
},
2024-03-24 17:43:00 +08:00
getNav(){
getNavigation().then(res => {
this.newData = res.data
if (this.newData.status && this.newData.status.status) {
uni.hideTabBar()
} else {
uni.showTabBar()
}
})
},
2024-03-24 17:43:25 +08:00
handleBorcode() {
// 从相机和相册扫码
// #ifdef APP-PLUS
uni.scanCode({
scanType:['qrCode'],
2024-03-26 15:06:27 +08:00
success: async (res)=> {
let result = JSON.parse(res.result)
let val = await getOrderOfflinePay(result.sn)
if(val.status == 200){
this.$util.Tips({
title: '支付成功',
icon: 'success'
});
setTimeout(()=>{
uni.navigateTo({
url:'/pages/users/order_list/index?status=-1'
})
},1000)
}
2024-03-24 17:43:25 +08:00
}
});
// #endif
2024-03-24 17:43:00 +08:00
},
2024-03-26 14:48:11 +08:00
selectCurrent(val,b){
if(b){
2024-03-28 17:54:55 +08:00
this.getLocation();
2024-03-26 14:48:11 +08:00
}
2024-03-28 17:54:55 +08:00
this.selfLocation();
2024-03-24 15:41:18 +08:00
this.current=val;
},
2024-03-26 14:48:11 +08:00
navtoDetail(item){
2024-03-24 15:41:18 +08:00
uni.navigateTo({
2024-03-26 14:48:11 +08:00
url:'/pages/shop_details/index?id='+item.mer_id
2024-03-24 15:41:18 +08:00
})
}
2024-03-24 15:23:25 +08:00
}
}
</script>
<style lang="less" scoped>
@import url("css/shop.css");
</style>