From e6d61585ddb297a31cef12527f99830085ebc4c6 Mon Sep 17 00:00:00 2001 From: chenglijuan Date: Thu, 7 May 2026 18:36:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=89=E6=A0=87=E7=A6=BB=E5=BC=80=E6=97=B6?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=BF=85=E5=A1=AB=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/plate-input/plate-input.wxss | 11 +++--- pages/appointment/appointment.js | 41 +++++++++++++++++++-- pages/appointment/appointment.wxml | 47 ++++++++++++++++--------- pages/appointment/appointment.wxss | 15 ++++++++ 4 files changed, 90 insertions(+), 24 deletions(-) diff --git a/components/plate-input/plate-input.wxss b/components/plate-input/plate-input.wxss index 49a92a1..75efef6 100644 --- a/components/plate-input/plate-input.wxss +++ b/components/plate-input/plate-input.wxss @@ -2,9 +2,9 @@ .plate-container { flex: 1; - position: relative; display: flex; align-items: center; + overflow: hidden; } /* 车牌格子区域 */ @@ -17,6 +17,8 @@ padding: 8rpx 16rpx; height: 72rpx; flex: 1; + min-width: 0; + overflow: hidden; } .plate-cell { @@ -72,14 +74,11 @@ /* 清除按钮 */ .plate-clear { - position: absolute; - right: -60rpx; - top: 50%; - transform: translateY(-50%); + flex-shrink: 0; font-size: 24rpx; color: #ff4d4f; padding: 8rpx 12rpx; - flex-shrink: 0; + margin-left: 12rpx; } /* 弹窗遮罩 */ diff --git a/pages/appointment/appointment.js b/pages/appointment/appointment.js index a5a760c..cf039ab 100644 --- a/pages/appointment/appointment.js +++ b/pages/appointment/appointment.js @@ -29,7 +29,8 @@ Page({ today: '', timeStart: '', timeEnd: '', - submitting: false + submitting: false, + fieldErrors: {} }, onLoad() { @@ -87,15 +88,19 @@ Page({ onNameInput(e) { this.setData({ 'form.name': e.detail.value }) + this._clearFieldError('name') }, onPhoneInput(e) { this.setData({ 'form.phone': e.detail.value }) + this._clearFieldError('phone') }, onCompanyInput(e) { this.setData({ 'form.company': e.detail.value }) + this._clearFieldError('company') }, onReasonInput(e) { this.setData({ 'form.reason': e.detail.value }) + this._clearFieldError('reason') }, onHostNameInput(e) { this.setData({ 'form.hostName': e.detail.value }) @@ -104,6 +109,33 @@ Page({ this.setData({ 'form.plateNumber': e.detail.value }) }, + onNameBlur() { + if (!this.data.form.name.trim()) { + this.setData({ 'fieldErrors.name': '姓名不能为空' }) + } + }, + onPhoneBlur() { + if (!this.data.form.phone.trim()) { + this.setData({ 'fieldErrors.phone': '手机号不能为空' }) + } + }, + onCompanyBlur() { + if (!this.data.form.company.trim()) { + this.setData({ 'fieldErrors.company': '公司不能为空' }) + } + }, + onReasonBlur() { + if (!this.data.form.reason.trim()) { + this.setData({ 'fieldErrors.reason': '来访事由不能为空' }) + } + }, + + _clearFieldError(field) { + if (this.data.fieldErrors[field]) { + this.setData({ ['fieldErrors.' + field]: '' }) + } + }, + onAreaChange(e) { const index = Number(e.detail.value) const department = this.data.departments[index] @@ -173,7 +205,12 @@ Page({ _updateTimeRange() { const { timeStart, timeEnd } = this.data if (timeStart && timeEnd) { - this.setData({ 'form.time': timeStart + '-' + timeEnd }) + if (timeEnd <= timeStart) { + this.setData({ 'form.time': '', 'fieldErrors.timeRange': '结束时间必须晚于开始时间' }) + wx.showToast({ title: '结束时间必须晚于开始时间', icon: 'none' }) + return + } + this.setData({ 'form.time': timeStart + '-' + timeEnd, 'fieldErrors.timeRange': '' }) } else { this.setData({ 'form.time': '' }) } diff --git a/pages/appointment/appointment.wxml b/pages/appointment/appointment.wxml index 22bf1aa..63224f4 100644 --- a/pages/appointment/appointment.wxml +++ b/pages/appointment/appointment.wxml @@ -5,19 +5,31 @@ 预约人信息 姓名* - + + + {{fieldErrors.name}} + 手机号* - + + + {{fieldErrors.phone}} + 公司* - + + + {{fieldErrors.company}} + 来访事由* - + + + {{fieldErrors.reason}} + 车牌号 @@ -39,18 +51,21 @@ 来访时段* - - - - {{timeStart || '开始时间'}} - - - - - - {{timeEnd || '结束时间'}} - - + + + + + {{timeStart || '开始时间'}} + + + + + + {{timeEnd || '结束时间'}} + + + + {{fieldErrors.timeRange}} diff --git a/pages/appointment/appointment.wxss b/pages/appointment/appointment.wxss index dfeb1cc..19e4373 100644 --- a/pages/appointment/appointment.wxss +++ b/pages/appointment/appointment.wxss @@ -41,6 +41,11 @@ page { flex-wrap: wrap; } +.form-field-wrap { + flex: 1; + min-width: 0; +} + .time-range { flex: 1; display: flex; @@ -158,3 +163,13 @@ page { color: #94aec5; box-shadow: none; } + +.form-input-error { + color: #ff4d4f; +} + +.form-error { + font-size: 22rpx; + color: #ff4d4f; + padding-top: 4rpx; +}