Initial Commit
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
// appointment.js
|
||||
const { formatDate } = require('../../utils/util')
|
||||
const { appointmentDB } = require('../../utils/cloud')
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
form: {
|
||||
name: '',
|
||||
phone: '',
|
||||
company: '',
|
||||
reason: '',
|
||||
date: '',
|
||||
time: '',
|
||||
hostName: '',
|
||||
area: ''
|
||||
},
|
||||
areas: ['A区-生产车间', 'B区-办公楼', 'C区-仓储区', 'D区-研发中心', 'E区-综合区'],
|
||||
areaIndex: -1,
|
||||
today: '',
|
||||
submitting: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
if (!app.globalData.isLoggedIn) {
|
||||
wx.showToast({ title: '请先登录', icon: 'none' })
|
||||
setTimeout(() => {
|
||||
wx.navigateBack()
|
||||
}, 1500)
|
||||
return
|
||||
}
|
||||
const today = formatDate(new Date())
|
||||
this.setData({ today })
|
||||
},
|
||||
|
||||
onNameInput(e) {
|
||||
this.setData({ 'form.name': e.detail.value })
|
||||
},
|
||||
onPhoneInput(e) {
|
||||
this.setData({ 'form.phone': e.detail.value })
|
||||
},
|
||||
onCompanyInput(e) {
|
||||
this.setData({ 'form.company': e.detail.value })
|
||||
},
|
||||
onReasonInput(e) {
|
||||
this.setData({ 'form.reason': e.detail.value })
|
||||
},
|
||||
onHostNameInput(e) {
|
||||
this.setData({ 'form.hostName': e.detail.value })
|
||||
},
|
||||
|
||||
onAreaChange(e) {
|
||||
const index = Number(e.detail.value)
|
||||
this.setData({
|
||||
areaIndex: index,
|
||||
'form.area': this.data.areas[index]
|
||||
})
|
||||
},
|
||||
|
||||
onDateChange(e) {
|
||||
this.setData({ 'form.date': e.detail.value })
|
||||
},
|
||||
|
||||
onTimeChange(e) {
|
||||
this.setData({ 'form.time': e.detail.value })
|
||||
},
|
||||
|
||||
validateForm() {
|
||||
const { name, phone, company, reason, date, time, hostName, area } = this.data.form
|
||||
if (!name.trim()) {
|
||||
wx.showToast({ title: '请输入访客姓名', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!phone.trim() || phone.length !== 11) {
|
||||
wx.showToast({ title: '请输入正确的手机号', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!company.trim()) {
|
||||
wx.showToast({ title: '请输入所属公司', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!reason.trim()) {
|
||||
wx.showToast({ title: '请输入来访事由', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!date) {
|
||||
wx.showToast({ title: '请选择来访日期', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!time) {
|
||||
wx.showToast({ title: '请选择来访时间', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!hostName.trim()) {
|
||||
wx.showToast({ title: '请输入被访人姓名', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!area) {
|
||||
wx.showToast({ title: '请选择拜访区域', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
async onSubmit() {
|
||||
if (!this.validateForm()) return
|
||||
if (this.data.submitting) return
|
||||
|
||||
this.setData({ submitting: true })
|
||||
|
||||
try {
|
||||
// 写入云数据库
|
||||
await appointmentDB.create(this.data.form)
|
||||
|
||||
this.setData({ submitting: false })
|
||||
|
||||
wx.showModal({
|
||||
title: '提交成功',
|
||||
content: '您的预约已提交,请等待审核',
|
||||
showCancel: false,
|
||||
confirmText: '查看记录',
|
||||
confirmColor: '#1890ff',
|
||||
success: () => {
|
||||
wx.redirectTo({
|
||||
url: '/pages/records/records'
|
||||
})
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
this.setData({ submitting: false })
|
||||
console.error('提交预约失败', err)
|
||||
wx.showToast({ title: '提交失败,请重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "访客预约"
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<!--appointment.wxml-->
|
||||
<view class="page">
|
||||
<!-- 预约人信息 -->
|
||||
<view class="section">
|
||||
<view class="section-title">预约人信息</view>
|
||||
<view class="form-group">
|
||||
<text class="form-label">姓名</text>
|
||||
<input class="form-input" placeholder="请输入访客姓名" value="{{form.name}}" bindinput="onNameInput" />
|
||||
</view>
|
||||
<view class="form-group">
|
||||
<text class="form-label">手机号</text>
|
||||
<input class="form-input" type="number" maxlength="11" placeholder="请输入手机号" value="{{form.phone}}" bindinput="onPhoneInput" />
|
||||
</view>
|
||||
<view class="form-group">
|
||||
<text class="form-label">公司</text>
|
||||
<input class="form-input" placeholder="请输入所属公司" value="{{form.company}}" bindinput="onCompanyInput" />
|
||||
</view>
|
||||
<view class="form-group">
|
||||
<text class="form-label">来访事由</text>
|
||||
<input class="form-input" placeholder="请输入来访事由" value="{{form.reason}}" bindinput="onReasonInput" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 预约时间 -->
|
||||
<view class="section">
|
||||
<view class="section-title">预约时间</view>
|
||||
<view class="form-group">
|
||||
<text class="form-label">来访日期</text>
|
||||
<picker class="form-picker-wrap" mode="date" value="{{form.date}}" start="{{today}}" bindchange="onDateChange">
|
||||
<view class="form-picker">
|
||||
<text class="{{form.date ? 'picker-value' : 'picker-placeholder'}}">{{form.date || '请选择日期'}}</text>
|
||||
<text class="picker-arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="form-group">
|
||||
<text class="form-label">来访时间</text>
|
||||
<picker class="form-picker-wrap" mode="time" value="{{form.time}}" bindchange="onTimeChange">
|
||||
<view class="form-picker">
|
||||
<text class="{{form.time ? 'picker-value' : 'picker-placeholder'}}">{{form.time || '请选择时间'}}</text>
|
||||
<text class="picker-arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 被访人信息 -->
|
||||
<view class="section">
|
||||
<view class="section-title">被访人信息</view>
|
||||
<view class="form-group">
|
||||
<text class="form-label">被访人</text>
|
||||
<input class="form-input" placeholder="请输入被访人姓名" value="{{form.hostName}}" bindinput="onHostNameInput" />
|
||||
</view>
|
||||
<view class="form-group">
|
||||
<text class="form-label">拜访区域</text>
|
||||
<picker class="form-picker-wrap" range="{{areas}}" value="{{areaIndex}}" bindchange="onAreaChange">
|
||||
<view class="form-picker">
|
||||
<text class="{{areaIndex >= 0 ? 'picker-value' : 'picker-placeholder'}}">{{areaIndex >= 0 ? areas[areaIndex] : '请选择拜访区域'}}</text>
|
||||
<text class="picker-arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 提交按钮 -->
|
||||
<view class="submit-wrap">
|
||||
<button class="submit-btn" bindtap="onSubmit" disabled="{{submitting}}">
|
||||
{{submitting ? '提交中...' : '提交预约'}}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,114 @@
|
||||
/**appointment.wxss**/
|
||||
page {
|
||||
background-color: #f5f7fa;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.page {
|
||||
padding: 24rpx 32rpx 160rpx;
|
||||
}
|
||||
|
||||
.section {
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 32rpx;
|
||||
margin-bottom: 24rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: #1a1a1a;
|
||||
margin-bottom: 24rpx;
|
||||
padding-left: 16rpx;
|
||||
border-left: 6rpx solid #1890ff;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 88rpx;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.form-group:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
width: 160rpx;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #1a1a1a;
|
||||
height: 88rpx;
|
||||
}
|
||||
|
||||
.form-picker-wrap {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.form-picker {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 88rpx;
|
||||
}
|
||||
|
||||
.picker-value {
|
||||
font-size: 28rpx;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.picker-placeholder {
|
||||
font-size: 28rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.picker-arrow {
|
||||
font-size: 32rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.submit-wrap {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 20rpx 32rpx;
|
||||
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
|
||||
background: #fff;
|
||||
box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #1890ff;
|
||||
color: #fff;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
border-radius: 44rpx;
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.submit-btn::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.submit-btn[disabled] {
|
||||
background: #b3d9ff;
|
||||
color: #fff;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// index.js
|
||||
const { appointmentDB } = require('../../utils/cloud')
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
isLoggedIn: false,
|
||||
latestRecord: null
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
if (app.globalData.isLoggedIn) {
|
||||
this.onLoginReady()
|
||||
} else {
|
||||
app.loginReadyCallback = () => {
|
||||
this.onLoginReady()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (app.globalData.isLoggedIn) {
|
||||
this.loadLatestRecord()
|
||||
}
|
||||
},
|
||||
|
||||
onLoginReady() {
|
||||
this.setData({ isLoggedIn: true })
|
||||
this.loadLatestRecord()
|
||||
},
|
||||
|
||||
async loadLatestRecord() {
|
||||
if (!this.data.isLoggedIn) {
|
||||
this.setData({ latestRecord: null })
|
||||
return
|
||||
}
|
||||
try {
|
||||
const openid = app.globalData.userInfo.openid
|
||||
const record = await appointmentDB.getLatest(openid)
|
||||
if (record) {
|
||||
this.setData({ latestRecord: this.formatRecord(record) })
|
||||
} else {
|
||||
this.setData({ latestRecord: null })
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('加载最新预约失败', err)
|
||||
this.setData({ latestRecord: null })
|
||||
}
|
||||
},
|
||||
|
||||
formatRecord(record) {
|
||||
const date = record.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 { ...record, createTime: createTimeStr }
|
||||
},
|
||||
|
||||
goAppointment() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/appointment/appointment'
|
||||
})
|
||||
},
|
||||
|
||||
goRecords() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/records/records'
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "访客预约系统"
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<!--index.wxml-->
|
||||
<view class="page">
|
||||
<!-- loading 遮罩 -->
|
||||
<view class="loading-mask" wx:if="{{!isLoggedIn}}">
|
||||
<view class="loading-spinner"></view>
|
||||
<text class="loading-text">正在获取身份信息...</text>
|
||||
</view>
|
||||
|
||||
<view class="header">
|
||||
<view class="header-icon">🏢</view>
|
||||
<text class="header-title">访客预约系统</text>
|
||||
<text class="header-subtitle">协能工厂区域访问管理</text>
|
||||
</view>
|
||||
|
||||
<view class="action-list">
|
||||
<view class="action-card" bindtap="goAppointment">
|
||||
<view class="action-icon-wrap action-icon-blue">
|
||||
<text class="action-icon-text">📅</text>
|
||||
</view>
|
||||
<view class="action-info">
|
||||
<text class="action-title">访客预约</text>
|
||||
<text class="action-desc">选择预约时间和预约人,提交预约信息</text>
|
||||
</view>
|
||||
<text class="action-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="action-card" bindtap="goRecords">
|
||||
<view class="action-icon-wrap action-icon-green">
|
||||
<text class="action-icon-text">📋</text>
|
||||
</view>
|
||||
<view class="action-info">
|
||||
<text class="action-title">预约记录</text>
|
||||
<text class="action-desc">查看预约记录、进度及取消预约</text>
|
||||
</view>
|
||||
<text class="action-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<!-- 最新预约摘要 -->
|
||||
<view class="latest-card" wx:if="{{latestRecord}}">
|
||||
<view class="latest-header">
|
||||
<text class="latest-title">最新预约</text>
|
||||
<view class="status-tag status-{{latestRecord.status}}">{{latestRecord.statusText}}</view>
|
||||
</view>
|
||||
<view class="latest-body">
|
||||
<view class="latest-row">
|
||||
<text class="latest-label">访客</text>
|
||||
<text class="latest-value">{{latestRecord.name}}</text>
|
||||
</view>
|
||||
<view class="latest-row">
|
||||
<text class="latest-label">时间</text>
|
||||
<text class="latest-value">{{latestRecord.date}} {{latestRecord.time}}</text>
|
||||
</view>
|
||||
<view class="latest-row">
|
||||
<text class="latest-label">区域</text>
|
||||
<text class="latest-value">{{latestRecord.area}}</text>
|
||||
</view>
|
||||
<view class="latest-row">
|
||||
<text class="latest-label">被访人</text>
|
||||
<text class="latest-value">{{latestRecord.hostName}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="latest-footer" bindtap="goRecords">
|
||||
<text class="latest-link">查看全部记录 ›</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="footer">
|
||||
<text class="footer-text">协能工厂 · 访客管理</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,228 @@
|
||||
/**index.wxss**/
|
||||
page {
|
||||
background-color: #f5f7fa;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.page {
|
||||
padding: 40rpx 32rpx;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 60rpx 0 40rpx;
|
||||
}
|
||||
|
||||
.header-icon {
|
||||
font-size: 100rpx;
|
||||
margin-bottom: 24rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* loading 遮罩 */
|
||||
.loading-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: #f5f7fa;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
border: 6rpx solid #e0e0e0;
|
||||
border-top: 6rpx solid #1890ff;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.header-title {
|
||||
font-size: 44rpx;
|
||||
font-weight: 700;
|
||||
color: #1a1a1a;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.header-subtitle {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 功能卡片 */
|
||||
.action-list {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.action-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 36rpx 32rpx;
|
||||
margin-bottom: 24rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.action-card:active {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
.action-icon-wrap {
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
border-radius: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 28rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.action-icon-blue {
|
||||
background: rgba(24, 144, 255, 0.1);
|
||||
}
|
||||
|
||||
.action-icon-green {
|
||||
background: rgba(82, 196, 26, 0.1);
|
||||
}
|
||||
|
||||
.action-icon-text {
|
||||
font-size: 44rpx;
|
||||
}
|
||||
|
||||
.action-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.action-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #1a1a1a;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.action-desc {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.action-arrow {
|
||||
font-size: 40rpx;
|
||||
color: #ccc;
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
/* 最新预约卡片 */
|
||||
.latest-card {
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 28rpx 32rpx;
|
||||
margin-top: 8rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.latest-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20rpx;
|
||||
padding-bottom: 16rpx;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.latest-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.status-tag {
|
||||
font-size: 22rpx;
|
||||
padding: 4rpx 16rpx;
|
||||
border-radius: 16rpx;
|
||||
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;
|
||||
}
|
||||
|
||||
.latest-body {
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.latest-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 8rpx 0;
|
||||
}
|
||||
|
||||
.latest-label {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.latest-value {
|
||||
font-size: 24rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.latest-footer {
|
||||
padding-top: 16rpx;
|
||||
border-top: 1rpx solid #f0f0f0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.latest-link {
|
||||
font-size: 24rpx;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 120rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.footer-text {
|
||||
font-size: 24rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
@@ -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'
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "预约记录"
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user