Initial Commit

This commit is contained in:
chenglijuan
2026-04-18 22:15:11 +08:00
commit 9de2bdee2e
25 changed files with 1465 additions and 0 deletions
+105
View File
@@ -0,0 +1,105 @@
// records.js
const { appointmentDB } = require('../../utils/cloud')
const app = getApp()
Page({
data: {
records: [],
filteredRecords: [],
currentTab: 'all',
loading: true
},
onLoad() {
if (!app.globalData.isLoggedIn) {
wx.showToast({ title: '请先登录', icon: 'none' })
setTimeout(() => {
wx.navigateBack()
}, 1500)
return
}
this.loadRecords()
},
onShow() {
if (app.globalData.isLoggedIn) {
this.loadRecords()
}
},
async loadRecords() {
this.setData({ loading: true })
try {
const openid = app.globalData.userInfo.openid
const records = await appointmentDB.getList(openid)
// 格式化时间
const formatted = records.map(item => {
const date = item.createTime
let createTimeStr = ''
if (date) {
if (typeof date === 'object' && date.$date) {
createTimeStr = new Date(date.$date).toLocaleString('zh-CN')
} else {
createTimeStr = new Date(date).toLocaleString('zh-CN')
}
}
return { ...item, createTime: createTimeStr }
})
this.setData({ records: formatted, loading: false })
this.filterRecords()
} catch (err) {
console.error('加载预约记录失败', err)
this.setData({ records: [], loading: false })
this.filterRecords()
}
},
switchTab(e) {
const tab = e.currentTarget.dataset.tab
this.setData({ currentTab: tab })
this.filterRecords()
},
filterRecords() {
const { records, currentTab } = this.data
let filtered = records
if (currentTab !== 'all') {
filtered = records.filter(item => item.status === currentTab)
}
this.setData({ filteredRecords: filtered })
},
onCancel(e) {
const id = e.currentTarget.dataset.id
wx.showModal({
title: '确认取消',
content: '确定要取消该预约吗?',
confirmColor: '#ff4d4f',
success: async (res) => {
if (res.confirm) {
try {
const openid = app.globalData.userInfo.openid
const success = await appointmentDB.cancel(id, openid)
if (success) {
wx.showToast({ title: '已取消预约', icon: 'success' })
this.loadRecords()
} else {
wx.showToast({ title: '取消失败,无权限或状态不允许', icon: 'none' })
}
} catch (err) {
console.error('取消预约失败', err)
wx.showToast({ title: '操作失败', icon: 'none' })
}
}
}
})
},
goAppointment() {
wx.navigateTo({
url: '/pages/appointment/appointment'
})
}
})
+4
View File
@@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "预约记录"
}
+74
View File
@@ -0,0 +1,74 @@
<!--records.wxml-->
<view class="page">
<!-- 状态筛选 -->
<view class="tabs">
<view class="tab {{currentTab === 'all' ? 'tab-active' : ''}}" bindtap="switchTab" data-tab="all">
全部
</view>
<view class="tab {{currentTab === 'pending' ? 'tab-active' : ''}}" bindtap="switchTab" data-tab="pending">
待审核
</view>
<view class="tab {{currentTab === 'approved' ? 'tab-active' : ''}}" bindtap="switchTab" data-tab="approved">
已通过
</view>
<view class="tab {{currentTab === 'rejected' ? 'tab-active' : ''}}" bindtap="switchTab" data-tab="rejected">
已拒绝
</view>
</view>
<!-- 记录列表 -->
<view class="record-list" wx:if="{{!loading && filteredRecords.length > 0}}">
<view class="record-card" wx:for="{{filteredRecords}}" wx:key="_id">
<view class="record-header">
<text class="record-id">{{item.id}}</text>
<view class="status-tag status-{{item.status}}">
{{item.statusText}}
</view>
</view>
<view class="record-body">
<view class="record-row">
<text class="record-label">访客姓名</text>
<text class="record-value">{{item.name}}</text>
</view>
<view class="record-row">
<text class="record-label">手机号码</text>
<text class="record-value">{{item.phone}}</text>
</view>
<view class="record-row">
<text class="record-label">来访事由</text>
<text class="record-value">{{item.reason}}</text>
</view>
<view class="record-row">
<text class="record-label">预约时间</text>
<text class="record-value">{{item.date}} {{item.time}}</text>
</view>
<view class="record-row">
<text class="record-label">拜访区域</text>
<text class="record-value">{{item.area}}</text>
</view>
<view class="record-row">
<text class="record-label">被访人</text>
<text class="record-value">{{item.hostName}}</text>
</view>
</view>
<view class="record-footer" wx:if="{{item.status === 'pending'}}">
<view class="cancel-btn" bindtap="onCancel" data-id="{{item._id}}">取消预约</view>
</view>
</view>
</view>
<!-- 加载中 -->
<view class="empty" wx:if="{{loading}}">
<text class="empty-icon">⏳</text>
<text class="empty-text">加载中...</text>
</view>
<!-- 空状态 -->
<view class="empty" wx:if="{{!loading && filteredRecords.length === 0}}">
<text class="empty-icon">📭</text>
<text class="empty-text">暂无预约记录</text>
<view class="empty-btn" bindtap="goAppointment">去预约</view>
</view>
</view>
+174
View File
@@ -0,0 +1,174 @@
/**records.wxss**/
page {
background-color: #f5f7fa;
min-height: 100vh;
}
.page {
padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
}
/* 筛选标签 */
.tabs {
display: flex;
background: #fff;
padding: 16rpx 32rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
position: sticky;
top: 0;
z-index: 10;
}
.tab {
flex: 1;
text-align: center;
font-size: 28rpx;
color: #666;
padding: 16rpx 0;
position: relative;
}
.tab-active {
color: #1890ff;
font-weight: 600;
}
.tab-active::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 48rpx;
height: 6rpx;
background: #1890ff;
border-radius: 3rpx;
}
/* 记录列表 */
.record-list {
padding: 24rpx 32rpx;
}
.record-card {
background: #fff;
border-radius: 20rpx;
padding: 32rpx;
margin-bottom: 24rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
}
.record-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24rpx;
padding-bottom: 20rpx;
border-bottom: 1rpx solid #f0f0f0;
}
.record-id {
font-size: 24rpx;
color: #999;
}
.status-tag {
font-size: 24rpx;
padding: 6rpx 20rpx;
border-radius: 20rpx;
font-weight: 500;
}
.status-pending {
background: rgba(250, 173, 20, 0.1);
color: #faad14;
}
.status-approved {
background: rgba(82, 196, 26, 0.1);
color: #52c41a;
}
.status-rejected {
background: rgba(255, 77, 79, 0.1);
color: #ff4d4f;
}
.status-cancelled {
background: rgba(0, 0, 0, 0.04);
color: #999;
}
.record-body {
margin-bottom: 8rpx;
}
.record-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12rpx 0;
}
.record-label {
font-size: 26rpx;
color: #999;
flex-shrink: 0;
}
.record-value {
font-size: 26rpx;
color: #333;
text-align: right;
margin-left: 32rpx;
}
.record-footer {
padding-top: 20rpx;
border-top: 1rpx solid #f0f0f0;
display: flex;
justify-content: flex-end;
}
.cancel-btn {
font-size: 26rpx;
color: #ff4d4f;
padding: 12rpx 32rpx;
border: 1rpx solid #ff4d4f;
border-radius: 32rpx;
}
.cancel-btn:active {
background: #fff1f0;
}
/* 空状态 */
.empty {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 200rpx;
}
.empty-icon {
font-size: 120rpx;
margin-bottom: 32rpx;
}
.empty-text {
font-size: 28rpx;
color: #999;
margin-bottom: 48rpx;
}
.empty-btn {
font-size: 28rpx;
color: #fff;
background: #1890ff;
padding: 20rpx 64rpx;
border-radius: 40rpx;
}
.empty-btn:active {
background: #096dd9;
}