jyy-smart-canteen-h5/pages/advanceOrder/stopperSelection.vue

218 lines
5.2 KiB
Vue
Raw Permalink Normal View History

2025-05-27 10:30:44 +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">
<scroll-view style="width: 100%;height: 90vh;" scroll-y="true" @scrolltolower="onScrollTolower" scroll-with-animation="true">
<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.stallImgUrl" class="merchant-avatar" mode="aspectFill" ></image>
<view class="merchant-detail">
<view class="merchant-name">档口名称 {{ item.stallName }}</view>
<!-- <view class="merchant-name">菜谱名称 {{ item.recipeName }}</view> -->
<view class="merchant-stats">
<text>月销 {{ item.monthlySales }}</text>
<text class="business-hours">营业时间 {{ item.startBusinessTime }} - {{item.endBusinessTime}}</text>
</view>
</view>
</view>
2025-09-03 18:14:08 +08:00
<view class="status-box" :class="{ 'status-open': item.isOpen }">
{{ item.isOpen? '营业中' : '休息中' }}
2025-05-27 10:30:44 +08:00
</view>
</view>
</view>
</scroll-view>
</view>
</view>
</template>
<script>
import { getAdvanceOrderStallApi } from '@/api/advanceOrder/index.js'
export default {
data() {
return {
fontValue:uni.getStorageSync('fontSize') || 8,
orderDate:"",
areaId:"",
canteenId:"",
pageNum: 1,
pageSize: 10,
total: 0,
merchantList: []
}
},
2025-09-03 18:14:08 +08:00
onLoad() {
2025-05-27 10:30:44 +08:00
this.getAdvanceOrderStallList()
},
methods: {
// 翻页
onScrollTolower(){
// console.log(this.messageList.length)
// if(this.total>this.messageList.length){
// this.pageNum++
// this.getNoticeList()
// }
},
async getAdvanceOrderStallList() {
try {
let param = {
// pageNum: this.pageNum,
// pageSize: this.pageSize,
// areaId: this.areaId,
// canteenId: this.canteenId,
// key: 7,
// applyDate: '2025-04-18'
// "applyDate":"2024-11-11"
}
2025-09-03 18:14:08 +08:00
const res = await getAdvanceOrderStallApi()
console.log('?? ~ getList ~ res:', res)
res.rows.forEach(item=>{
if(item.businessState==2){//营业
item.stallList.forEach(sub=>{
sub.canteenId = item.canteenId
sub.canteenName = item.canteenName
this.merchantList.push(sub)
})
}
})
// this.merchantList = res.rows[0].stallList;
this.updateMerchantStatus()
2025-05-27 10:30:44 +08:00
} catch (error) {
console.log(error)
}
},
updateMerchantStatus() {
this.merchantList.forEach(merchant => {
2025-09-03 18:14:08 +08:00
merchant.isOpen = this.checkIfOpen(merchant.startBusinessTime,merchant.endBusinessTime)&&merchant.businessState==2;
console.log(merchant.isOpen)
2025-05-27 10:30:44 +08:00
});
},
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;
},
2025-09-03 18:14:08 +08:00
//跳转详情
2025-05-27 10:30:44 +08:00
goToMenu(item) {
2025-09-03 18:14:08 +08:00
if(item.isOpen){
if(item.recipeId){
uni.navigateTo({
url: `/pages/advanceOrder/index?params=${JSON.stringify(item)}`
})
}else{
uni.showToast({
title: '未配置菜谱',
icon: 'none'
})
}
2025-05-27 10:30:44 +08:00
}else{
uni.showToast({
2025-09-03 18:14:08 +08:00
title: '档口休息中!',
2025-05-27 10:30:44 +08:00
icon: 'none'
})
}
2025-09-03 18:14:08 +08:00
2025-05-27 10:30:44 +08:00
}
},
mounted() {
// this.updateMerchantStatus();
// 可以设置一个定时器,定期更新营业状态
// setInterval(this.updateMerchantStatus(), 5000); // 每分钟更新一次
}
}
</script>
<style lang="scss" scoped>
.page-container {
min-height: 100vh;
background-color: #f5f5f5;
padding: 40rpx;
}
.merchant-list {
.merchant-box {
margin-bottom: 20rpx;
&:last-child {
margin-bottom: 0;
}
}
.merchant-item {
background-color: #ffffff;
border-radius: 12rpx;
padding: 24rpx;
display: flex;
justify-content: space-between;
align-items: flex-start;
position: relative;
}
.merchant-info {
display: flex;
align-items: center;
flex: 1;
margin-right: 20rpx;
.merchant-avatar {
width: 88rpx;
height: 88rpx;
border-radius: 8rpx;
margin-right: 20rpx;
}
.merchant-detail {
flex: 1;
.merchant-name {
font-size: 30rpx;
color: #333333;
margin-bottom: 16rpx;
font-weight: 500;
}
.merchant-stats {
display: flex;
font-size: 24rpx;
color: #999999;
flex-direction: column;
align-items: flex-start;
.business-hours {
//margin-left: 24rpx;
}
}
}
}
.status-box {
width: 30rpx;
font-size: 24rpx;
color: #999999;
padding: 4rpx 4rpx;
background-color: #f5f5f5;
border-radius: 4rpx;
position: absolute;
top: 36rpx;
right: 24rpx;
&.status-open {
color: #ff6633;
background-color: #fff2ef;
}
}
}
</style>