Dining_Hall/pages/passenger/canteenList.vue

215 lines
5.6 KiB
Vue
Raw Normal View History

2025-06-10 15:12:17 +08:00
<template>
<page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
<view class="page-container">
<view class="merchant-list">
<view
class="merchant-box"
v-for="(item, index) in merchantList"
:key="index"
>
<view class="merchant-item" @click="goToMenu(item)">
<view class="merchant-info">
<image
:src="item.imgUrl"
class="merchant-avatar"
mode="aspectFill"
></image>
<view class="merchant-detail">
2025-06-10 16:58:02 +08:00
<view class="merchant-name">
<text>{{ item.canteenName }}</text>
<view class="status-box" :class="{ 'status-open': item.isOpen }">
{{ item.isOpen ? '营业中' : '休息中' }}
</view>
</view>
2025-06-10 15:12:17 +08:00
<view class="merchant-stats">
2025-06-10 16:58:02 +08:00
<view style="margin-bottom: 5px;display: flex;align-items: center;">
<view style="color:#000;">拥挤程度</view>
<view class="gl" v-if="item.personRate<=66" :class="{ 'gl-green': item.personRate>0 }"></view>
<view class="gl" v-else :class="{ 'gl-red': item.personRate>0 }"></view>
<view class="gl" v-if="item.personRate<=66" :class="{ 'gl-green': item.personRate>33 }"></view>
<view class="gl" v-else :class="{ 'gl-red': item.personRate>33 }"></view>
<view class="gl" v-if="item.personRate<=66"></view>
<view class="gl" v-else :class="{ 'gl-red':item.personRate>66 }"></view>
<view v-if="item.personRate<=66&&item.personRate>=0" style="color:#00aa00;">畅通</view>
<view v-if="item.personRate>66" style="color:#ff6633;">拥挤</view>
</view>
<view>
<text style="color:#000;">营业时间</text>
<text class="business-hours">{{ item.startBusinessTime }} - {{item.endBusinessTime}}</text>
</view>
2025-06-10 15:12:17 +08:00
</view>
</view>
</view>
2025-06-10 16:58:02 +08:00
2025-06-10 15:12:17 +08:00
</view>
</view>
</view>
</view>
</template>
<script>
import { queryNowPresentNumApi } from '@/api/passenger/index.js'
export default {
data() {
return {
fontValue:uni.getStorageSync('fontSize') || 8,
2025-06-10 16:58:02 +08:00
merchantList: [{"presentNum":9,"capacity":400,"businessState":2,"canteenName":"sbd工业园食堂","canteenId":"378928314946949120","startBusinessTime":"00:00:00","endBusinessTime":"23:59:59","imgUrl":null,"personRate":3}]
2025-06-10 15:12:17 +08:00
}
},
2025-06-10 16:58:02 +08:00
onLoad() {
2025-06-10 15:12:17 +08:00
this.queryNowPresentNum()
},
methods: {
async queryNowPresentNum() {
try {
let param = {
"custId":uni.getStorageSync('custId')
}
2025-06-10 16:58:02 +08:00
const res = await queryNowPresentNumApi(param)
2025-06-10 15:12:17 +08:00
this.merchantList = res.data;
2025-06-10 16:58:02 +08:00
this.merchantList.forEach(item=>{
item.personRate = Number(((item.presentNum/item.capacity)*100).toFixed(2))
})
console.log('?? ~ getList ~ res:', this.merchantList)
2025-06-10 15:12:17 +08:00
this.updateMerchantStatus()
} catch (error) {
console.log(error)
}
},
updateMerchantStatus() {
this.merchantList.forEach(merchant => {
merchant.isOpen = this.checkIfOpen(merchant.startBusinessTime,merchant.endBusinessTime);
});
},
checkIfOpen(start,end) {
// console.log(start)
// console.log(end)
// 这是一个简单的判断逻辑
// const [start, end] = businessHours.split('-');
const now = new Date();
const currentTime = now.getHours() * 60 + now.getMinutes();
const [startHour, startMinute, startSecond] = start.split(':').map(Number);
const [endHour, endMinute, endSecond] = end.split(':').map(Number);
const startTime = startHour * 60 + startMinute;
const endTime = endHour * 60 + endMinute;
return currentTime >= startTime && currentTime <= endTime;
},
goToMenu(item) {
uni.navigateTo({
url: `/pages/passenger/flowDetail?params=${JSON.stringify(item)}`
})
}
2025-06-10 16:58:02 +08:00
},
2025-06-10 15:12:17 +08:00
mounted() {
// this.updateMerchantStatus();
// 可以设置一个定时器,定期更新营业状态
// setInterval(this.updateMerchantStatus(), 5000); // 每分钟更新一次
}
}
</script>
<style lang="scss" scoped>
.page-container {
2025-06-17 16:19:23 +08:00
height: 96vh;
overflow-y: auto;
2025-06-10 15:12:17 +08:00
background-color: #f5f5f5;
padding: 20rpx;
}
.merchant-list {
.merchant-box {
margin-bottom: 20rpx;
&:last-child {
margin-bottom: 0;
}
}
.merchant-item {
background-color: #ffffff;
border-radius: 12rpx;
padding: 20rpx;
display: flex;
justify-content: space-between;
align-items: flex-start;
width: 100%;
position: relative;
}
.merchant-info {
width: 90%;
display: flex;
align-items: center;
.merchant-avatar {
2025-06-10 16:58:02 +08:00
width: 100rpx;
height: 100rpx;
2025-06-10 15:12:17 +08:00
border-radius: 8rpx;
margin-right: 20rpx;
}
.merchant-detail {
width: 80%;
.merchant-name {
width: 100%;
font-size: 26rpx;
color: #333333;
margin-bottom: 16rpx;
font-weight: 500;
2025-06-10 16:58:02 +08:00
display: flex;
2025-06-10 15:12:17 +08:00
}
.merchant-stats {
display: flex;
font-size: 24rpx;
color: #999999;
flex-direction: column;
align-items: flex-start;
.business-hours {
//margin-left: 24rpx;
}
}
}
}
.status-box {
font-size: 22rpx;
color: #999999;
2025-06-10 16:58:02 +08:00
padding: 4rpx 8rpx;
margin-left: 10px;
2025-06-10 15:12:17 +08:00
background-color: #f5f5f5;
border-radius: 4rpx;
2025-06-10 16:58:02 +08:00
// position: absolute;
// top: 36rpx;
// right: 24rpx;
2025-06-10 15:12:17 +08:00
&.status-open {
color: #ff6633;
background-color: #fff2ef;
}
}
2025-06-10 16:58:02 +08:00
.gl{
height: 5px;
width:50px;
background-color: #ccc;
margin-right: 4px;
border-radius:4px;
&.gl-red{
background-color: #ff6633;
}
&.gl-green{
background-color: #00aa00;
}
}
2025-06-10 15:12:17 +08:00
}
</style>