You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

355 lines
9.1 KiB

4 years ago
<template>
<view>
<!-- 定位失败提示 -->
<view v-if="locationError" class="location-error">
<view class="location-error-content">
<text class="location-error-text">无法获取位置信息活动距离可能不准确</text>
<u-button size="mini" type="primary" @click="retryLocation" class="location-error-btn">重新定位</u-button>
</view>
</view>
4 years ago
<view class="listActivity">
4 years ago
<u-empty mode="list" text="暂无活动" marginTop="50" v-if="list.length==0&&!isloading"></u-empty>
<view class="activityBox" v-for="(item,index) in list" :key="index" @click="openInfo(item)">
2 years ago
<view :class="!item.isCanBook?'gray100':''"></view>
<view class="activityBox-top">
4 years ago
<image :src='item.cover_upload.url' style="width: 100%;height: 333rpx;"></image>
4 years ago
</view>
4 years ago
<view class="activityBox-content flex-col">
<view class="activityBox-row">
4 years ago
<text class="activityBox-title">{{isUnde(item.name)}}</text>
4 years ago
</view>
<view class="activityBox-row flex-row justify-between">
3 years ago
<view :class="item.type_name?'tag tag_green activityBox_btn':''">
3 years ago
<text>{{isUnde(item.type_name)}}</text>
3 years ago
</view>
3 years ago
<block v-if="item.orders_count==item.total&&item.orders_count!=0">
3 years ago
<view class="tag" v-if="item.isCanBook">
<text>已约满</text>
</view>
<view class="tag" v-else>
<text>{{item.rate_name}}</text>
</view>
</block>
<block v-else>
<view class="tag" :class="{activityBox_btn:item.isCanBook}">
3 years ago
<text>{{item.isCanBook?"立即报名":"已结束"}}</text>
3 years ago
</view>
3 years ago
</block>
4 years ago
</view>
3 years ago
<view class="activityBox-row" style="display: flex;">
3 years ago
<view style="display: inline-block;">
<text class="icon-shijian iconfont"></text>活动场次
</view>
<view style="display: flex;flex-direction: column;">
<block v-for="(k,index) in item.numbers">
<view v-if="index<2" class="tag tag_green activityBox_btn activityBox_time" style="margin-top: -5px;margin-bottom: 10px;">
<text style="margin-right:12rpx">
{{timeFormat(k.start_time,"MM月DD日")}}
</text>
<text>
{{getHm(k.start_time)}}-{{getHm(k.end_time)}}
</text>
</view>
3 years ago
</block>
3 years ago
</view>
4 years ago
3 years ago
<view v-if="item.numbers.length>2"
class="activityMore">
更多>>
3 years ago
</view>
4 years ago
</view>
<view class="activityBox-row">
<text class="icon-huodong iconfont"></text>
4 years ago
<text>活动地址{{isUnde(item.address)}}</text>
4 years ago
</view>
4 years ago
<view class="activityBox-row flex-row align-center" style="margin-bottom: 0rpx;"
@click.stop="tothere(item)">
4 years ago
<text class="icon-ditu-dibiao iconfont"></text>
4 years ago
<text>距离{{isUnde(item.distance)}}km</text>
4 years ago
<view class="tomap">
<text class="icon-daohang1 iconfont" style="margin-right: 0;"></text>
</view>
</view>
4 years ago
</view>
</view>
4 years ago
</view>
4 years ago
</view>
</template>
<script>
export default {
data() {
return {
4 years ago
showInfo: true,
4 years ago
list: [],
latitude: "",
longitude: "",
isloading: true,
locationError: false // 定位是否失败
4 years ago
}
4 years ago
},
onLoad() {
var that = this;
// 检测运行环境
const isH5 = typeof window !== 'undefined' && window.location
if (isH5) {
// H5环境使用浏览器定位API
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function(position) {
that.latitude = position.coords.latitude;
that.longitude = position.coords.longitude;
console.log('定位成功:', that.latitude, that.longitude);
that.loadActivity()
},
function(error) {
console.log('定位失败:', error);
that.locationError = true;
// 根据错误类型给出不同提示
switch(error.code) {
case error.PERMISSION_DENIED:
console.log('用户拒绝了定位权限');
break;
case error.POSITION_UNAVAILABLE:
console.log('位置信息不可用');
break;
case error.TIMEOUT:
console.log('定位超时');
break;
default:
console.log('定位失败,未知错误');
break;
}
// 定位失败时仍然加载活动列表
that.loadActivity()
},
{
enableHighAccuracy: true,
timeout: 15000, // 增加超时时间到15秒
maximumAge: 300000 // 缓存5分钟
}
);
} else {
console.log('浏览器不支持定位');
uni.showToast({
title: '浏览器不支持定位功能',
icon: 'none'
});
4 years ago
that.loadActivity()
}
} else {
// 小程序环境使用wx.getLocation
wx.getLocation({
success(res) {
console.log(res)
that.latitude = res.latitude;
that.longitude = res.longitude;
that.loadActivity()
},
fail(err) {
console.log('定位失败:', err);
that.loadActivity()
}
})
}
4 years ago
},
onShareAppMessage() {
return this.util.shareInfo
},
onShareTimeline(){
return this.util.shareInfo
4 years ago
},
methods: {
// 重新定位
retryLocation() {
this.locationError = false;
this.latitude = "";
this.longitude = "";
const isH5 = typeof window !== 'undefined' && window.location;
var that = this;
if (isH5 && navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function(position) {
that.latitude = position.coords.latitude;
that.longitude = position.coords.longitude;
console.log('重新定位成功:', that.latitude, that.longitude);
that.loadActivity();
},
function(error) {
console.log('重新定位失败:', error);
that.locationError = true;
uni.showToast({
title: '定位失败,请检查浏览器定位权限',
icon: 'none',
duration: 3000
});
},
{
enableHighAccuracy: true,
timeout: 15000,
maximumAge: 0 // 不使用缓存,重新获取
}
);
}
},
4 years ago
tothere(item) {
uni.openLocation({
latitude: parseFloat(item.latitude),
longitude: parseFloat(item.longitude),
name: item.name,
address: item.address
})
},
4 years ago
openInfo(obj) {
4 years ago
4 years ago
uni.navigateTo({
url: "info?id=" + obj.id
})
4 years ago
},
3 years ago
loadActivity() {
console.log("加载活动列表")
4 years ago
var that = this;
4 years ago
var nt = new Date();
4 years ago
that.isloading = true;
// 构建请求参数
var requestData = {
page_size: 100
};
// 如果有定位信息,添加到请求参数中
if (that.latitude && that.longitude) {
requestData.latitude = that.latitude;
requestData.longitude = that.longitude;
}
4 years ago
this.util.request({
api: '/api/mobile/activity/index',
data: requestData,
4 years ago
utilSuccess: function(res) {
4 years ago
for (var mod of res.data) {
mod.isCanBook = that.$moment(nt).isBefore(mod.end_plan);
}
4 years ago
that.list = res.data;
3 years ago
that.isloading = false;
4 years ago
},
utilFail: function(res) {
that.isloading = false;
4 years ago
}
4 years ago
})
4 years ago
},
isUnde(val) {
if (val) {
return val
} else {
return ""
}
},
getHm(val) {
4 years ago
if (val) {
3 years ago
return this.$moment(val).format("HH:mm")
4 years ago
} else return "";
3 years ago
},
timeFormat(val, format) {
return this.$moment(val).format(format)
4 years ago
}
4 years ago
}
}
</script>
<style>
4 years ago
@import url("@/static/css/activitybox.css");
4 years ago
page {
background-color: #f7f6f4;
}
.activityBox{
position: relative;
}
.activityBox-title {
font-size: 32rpx;
}
.activityBox-row{
font-size: 28rpx;
}
.activityBox-top{
font-size: 0;
}
.gray100{
width:100%;
height:333rpx;
position: absolute;
top:0;
left:0;
background-color: rgba(0,0,0,0.5);
z-index:999;
/* opacity: 50%;
filter: grayscale(100%);
opacity: 50%;
-webkit-filter: blackscale(100%);
filter: brightness(0.2); */
2 years ago
}
3 years ago
.activityBox_time {
3 years ago
/* height: 70rpx; */
3 years ago
vertical-align: middle;
display: inline-block;
margin: 4rpx;
background: #FCF6E3;
2 years ago
border: 2rpx solid #cf995a;
3 years ago
border-radius: 20rpx;
color: #4E4E4E;
3 years ago
margin-right: 10rpx;
3 years ago
}
.activityMore{
font-size: 26rpx;
font-family: PingFang SC;
font-weight: 400;
display: flex;
color: #cf995a;
flex-direction: column-reverse;
margin-left:10rpx
}
.location-error {
background-color: #fff3cd;
border: 1px solid #ffeaa7;
border-radius: 8rpx;
margin: 20rpx;
padding: 20rpx;
}
.location-error-content {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 28rpx;
color: #856404;
flex-wrap: wrap;
gap: 20rpx;
}
.location-error-text {
flex: 1;
min-width: 0;
word-wrap: break-word;
line-height: 1.4;
}
.location-error-btn {
flex-shrink: 0;
white-space: nowrap;
}
</style>