文件
yjyf/yjyf-app/components/AppointTimeDrawer.vue
MiAn 53252d6d87 chore: 优化系统功能与界面体验
- 升级系统版本至1.0.100
- 新增订单详情页物流、资质等信息展示
- 优化师傅报价页收益计算与显示
- 新增企业资质管理模块
- 优化后台标签页管理与交互
- 修复标签解析与地址脱敏问题
- 优化预约时段选择逻辑
- 调整服务类型配置界面布局
2026-11-24 14:36:27 +08:00

295 行
6.5 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="drawer-mask" v-if="visible" @tap="close">
<view class="drawer-sheet" @tap.stop>
<!-- 1. 顶部日期选择条(1:1 复刻 frame_020:左大号日期 + 右日历图标「选择日期」) -->
<view class="date-header-row">
<text class="dh-date-val">{{ selectedDate }}</text>
<picker mode="date" :value="selectedDate" :start="todayStr" @change="onDateChange">
<view class="dh-picker-btn clickable-hover">
<image class="dh-cal-icon" src="/static/icons/calendar-orange.svg" mode="aspectFit" />
<text class="dh-cal-txt">选择日期</text>
</view>
</picker>
</view>
<!-- 2. 2x2 时段网格卡片(1:1 复刻 frame_020:上午/中午/下午/晚上 + 具体时间段) -->
<view class="slot-grid">
<view
class="slot-card clickable-hover"
v-for="item in computedSlots"
:key="item.name"
:class="{ active: selectedSlot === item.name && !item.disabled, disabled: item.disabled }"
@tap="selectSlot(item)"
>
<text class="slot-name">{{ item.name }}</text>
<text class="slot-range">{{ item.disabled ? '已过时段' : item.range }}</text>
</view>
</view>
<!-- 3. 底部说明区(1:1 复刻 frame_020) -->
<view class="explain-box">
<text class="exp-title">说明:</text>
<text class="exp-desc">期望上门时间仅供师傅参考,具体上门时间由师傅接单后和客户预约为准。</text>
</view>
<!-- 4. 底部通栏橙色确定按钮 -->
<view class="drawer-foot">
<view class="confirm-btn clickable-hover" @tap="handleConfirm">
<text class="cb-txt">确定</text>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, watch } from 'vue';
const props = defineProps({
visible: { type: Boolean, default: false },
date: { type: String, default: '' },
slot: { type: String, default: '' }
});
const emit = defineEmits(['update:visible', 'confirm']);
const slotList = [
{ name: '上午', range: '07:00~10:59', endHour: 11 },
{ name: '中午', range: '11:00~13:59', endHour: 14 },
{ name: '下午', range: '14:00~17:59', endHour: 18 },
{ name: '晚上', range: '18:00~20:59', endHour: 21 }
];
function formatDateStr(d) {
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
}
const now = new Date();
const todayStr = formatDateStr(now);
const tomorrow = new Date(now.getTime() + 86400000);
const tomorrowStr = formatDateStr(tomorrow);
const selectedDate = ref(todayStr);
const selectedSlot = ref('晚上');
const computedSlots = computed(() => {
const curNow = new Date();
const curToday = formatDateStr(curNow);
const curHour = curNow.getHours();
const isToday = selectedDate.value === curToday;
return slotList.map((item) => ({
...item,
disabled: isToday && curHour >= item.endHour
}));
});
function ensureValidSelection() {
const slots = computedSlots.value;
const firstAvailable = slots.find((s) => !s.disabled);
if (!firstAvailable) {
selectedDate.value = tomorrowStr;
selectedSlot.value = '上午';
return;
}
const currentHit = slots.find((s) => s.name === selectedSlot.value);
if (!currentHit || currentHit.disabled) {
selectedSlot.value = firstAvailable.name;
}
}
watch(() => props.visible, (v) => {
if (v) {
selectedDate.value = props.date || todayStr;
selectedSlot.value = props.slot || '晚上';
ensureValidSelection();
}
}, { immediate: true });
function onDateChange(e) {
if (e && e.detail && e.detail.value) {
selectedDate.value = e.detail.value;
ensureValidSelection();
}
}
function selectSlot(item) {
if (item.disabled) {
uni.showToast({ title: '今日该时段已过,请选择其他时段或明天', icon: 'none' });
return;
}
selectedSlot.value = item.name;
}
function close() {
emit('update:visible', false);
}
function handleConfirm() {
ensureValidSelection();
emit('confirm', {
date: selectedDate.value,
slot: selectedSlot.value,
display: `${selectedDate.value} ${selectedSlot.value}`
});
close();
}
</script>
<style scoped>
.drawer-mask {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.55);
z-index: 999;
display: flex;
flex-direction: column;
justify-content: flex-end;
animation: drawerFadeIn 0.2s ease-out;
}
@keyframes drawerFadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.drawer-sheet {
background: #FFFFFF;
border-radius: 28rpx 28rpx 0 0;
overflow: hidden;
padding: 0 0 calc(env(safe-area-inset-bottom));
box-sizing: border-box;
animation: drawerSlideUp 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes drawerSlideUp {
from { transform: translateY(100%); }
to { transform: translateY(0); }
}
.date-header-row {
display: flex;
align-items: center;
justify-content: space-between;
height: 108rpx;
padding: 0 36rpx;
border-bottom: 1rpx solid #F0F0F2;
}
.dh-date-val {
font-size: 38rpx;
font-weight: 700;
color: #1F1F1F;
}
.dh-picker-btn {
display: flex;
align-items: center;
gap: 10rpx;
}
.dh-cal-icon {
width: 34rpx;
height: 34rpx;
}
.dh-cal-txt {
font-size: 30rpx;
color: #1F1F1F;
}
.slot-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 28rpx;
padding: 40rpx 36rpx;
border-bottom: 1rpx solid #F0F0F2;
}
.slot-card {
height: 156rpx;
border-radius: 12rpx;
background: #F7F7F7;
border: 2rpx solid #E5E5E5;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12rpx;
transition: all 0.18s ease;
}
.slot-card.active {
background: #FFF7F0;
border-color: #F0710D;
}
.slot-card.disabled {
opacity: 0.45;
background: #F5F6F8;
border-color: #ECECEF;
}
.slot-name {
font-size: 32rpx;
font-weight: 500;
color: #1F1F1F;
line-height: 1;
}
.slot-card.active .slot-name {
color: #F0710D;
}
.slot-range {
font-size: 26rpx;
color: #666666;
line-height: 1;
}
.slot-card.active .slot-range {
color: #F0710D;
}
.explain-box {
padding: 36rpx 36rpx 80rpx;
display: flex;
flex-direction: column;
gap: 12rpx;
}
.exp-title {
font-size: 28rpx;
font-weight: 700;
color: #1F1F1F;
}
.exp-desc {
font-size: 28rpx;
color: #444444;
line-height: 1.5;
}
.drawer-foot {
padding: 0;
}
.confirm-btn {
height: 96rpx;
background: #F0710D;
display: flex;
align-items: center;
justify-content: center;
}
.cb-txt {
font-size: 32rpx;
font-weight: 600;
color: #FFFFFF;
line-height: 1;
}
.clickable-hover:active {
opacity: 0.85;
}
</style>