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
+135
View File
@@ -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' })
}
}
})
+4
View File
@@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "访客预约"
}
+71
View File
@@ -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>
+114
View File
@@ -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;
}