表单校验
This commit is contained in:
parent
db29e572fe
commit
deaa972edb
|
|
@ -23,7 +23,11 @@
|
||||||
<!-- 姓名 -->
|
<!-- 姓名 -->
|
||||||
<view class="form-item">
|
<view class="form-item">
|
||||||
<text class="field-label">姓名</text>
|
<text class="field-label">姓名</text>
|
||||||
<input v-model="formData.name" class="field-input" placeholder="请输入姓名" />
|
<input
|
||||||
|
v-model="formData.name"
|
||||||
|
class="field-input"
|
||||||
|
placeholder="请输入姓名"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 手机号 -->
|
<!-- 手机号 -->
|
||||||
|
|
@ -46,6 +50,7 @@
|
||||||
@location-error="onLocationError"
|
@location-error="onLocationError"
|
||||||
@use-location="onUseLocation"
|
@use-location="onUseLocation"
|
||||||
@map-opened="onMapOpened"
|
@map-opened="onMapOpened"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 详细位置 -->
|
<!-- 详细位置 -->
|
||||||
|
|
@ -80,10 +85,10 @@
|
||||||
|
|
||||||
<!-- 支付区域 -->
|
<!-- 支付区域 -->
|
||||||
<view class="payment-section">
|
<view class="payment-section">
|
||||||
<button
|
<button
|
||||||
:class="['pay-button', { disabled: !canPay }]"
|
:class="['pay-button', { disabled: !canPay }]"
|
||||||
@click="handlePayment"
|
|
||||||
:disabled="!canPay"
|
:disabled="!canPay"
|
||||||
|
@click="handlePayment"
|
||||||
>
|
>
|
||||||
{{ canPay ? `立即支付 ¥${totalAmount}` : '请完善信息' }}
|
{{ canPay ? `立即支付 ¥${totalAmount}` : '请完善信息' }}
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -125,25 +130,65 @@
|
||||||
<script>
|
<script>
|
||||||
import commonEnum from '../../enum/commonEnum'
|
import commonEnum from '../../enum/commonEnum'
|
||||||
import MapLocation from '@/components/map-location/map-location.vue'
|
import MapLocation from '@/components/map-location/map-location.vue'
|
||||||
import { getDeviceTypes as fetchDeviceTypes, getPeriodPackages as fetchPeriodPackages } from '@/api/lease/lease.js'
|
import {
|
||||||
|
getDeviceTypes as fetchDeviceTypes,
|
||||||
|
getPeriodPackages as fetchPeriodPackages,
|
||||||
|
} from '@/api/lease/lease.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'LeasePage',
|
name: 'LeasePage',
|
||||||
components: {
|
components: {
|
||||||
MapLocation
|
MapLocation,
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
commonEnum() {
|
commonEnum() {
|
||||||
return commonEnum
|
return commonEnum
|
||||||
},
|
},
|
||||||
// 检查是否可以支付
|
// 检查是否可以支付 - 直接验证,不依赖formData默认值
|
||||||
canPay() {
|
canPay() {
|
||||||
return this.formData.name.trim() &&
|
const nameValid = this.formData.name.trim().length > 0
|
||||||
this.formData.phone.trim() &&
|
const phoneValid = this.formData.phone.trim().length > 0
|
||||||
this.formData.address.trim() &&
|
const addressValid = this.formData.address.trim().length > 0
|
||||||
this.formData.equipmentId &&
|
const equipmentSelected = !!this.formData.equipmentId
|
||||||
this.formData.periodId &&
|
const packageSelected = !!this.formData.periodId
|
||||||
parseFloat(this.totalAmount) > 0
|
const amountValid = parseFloat(this.totalAmount) > 0
|
||||||
|
|
||||||
|
const canPayResult = nameValid && phoneValid && addressValid &&
|
||||||
|
equipmentSelected && packageSelected && amountValid
|
||||||
|
|
||||||
|
// 实时调试信息
|
||||||
|
console.log('🔍 canPay 实时检查:', {
|
||||||
|
nameValid,
|
||||||
|
phoneValid,
|
||||||
|
addressValid,
|
||||||
|
equipmentSelected,
|
||||||
|
packageSelected,
|
||||||
|
amountValid,
|
||||||
|
canPay: canPayResult
|
||||||
|
})
|
||||||
|
|
||||||
|
return canPayResult
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
// 监控关键数据变化(可选,用于调试)
|
||||||
|
'formData.name'() {
|
||||||
|
console.log('🔍 姓名变化:', this.formData.name)
|
||||||
|
},
|
||||||
|
'formData.phone'() {
|
||||||
|
console.log('🔍 手机号变化:', this.formData.phone)
|
||||||
|
},
|
||||||
|
'formData.address'() {
|
||||||
|
console.log('🔍 地址变化:', this.formData.address)
|
||||||
|
},
|
||||||
|
'formData.equipmentId'() {
|
||||||
|
console.log('🔍 设备ID变化:', this.formData.equipmentId)
|
||||||
|
},
|
||||||
|
'formData.periodId'() {
|
||||||
|
console.log('🔍 套餐ID变化:', this.formData.periodId)
|
||||||
|
},
|
||||||
|
'totalAmount'() {
|
||||||
|
console.log('🔍 总金额变化:', this.totalAmount)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
|
@ -153,7 +198,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
formData: {
|
formData: {
|
||||||
name: '张珊珊',
|
name: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
address: '',
|
address: '',
|
||||||
detailAddress: '',
|
detailAddress: '',
|
||||||
|
|
@ -171,6 +216,8 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
|
|
||||||
// 地图组件事件处理
|
// 地图组件事件处理
|
||||||
onLocationSuccess(location) {
|
onLocationSuccess(location) {
|
||||||
console.log('位置获取成功:', location)
|
console.log('位置获取成功:', location)
|
||||||
|
|
@ -196,7 +243,7 @@ export default {
|
||||||
async getDeviceTypes() {
|
async getDeviceTypes() {
|
||||||
try {
|
try {
|
||||||
const response = await fetchDeviceTypes()
|
const response = await fetchDeviceTypes()
|
||||||
|
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
this.deviceTypes = response.data
|
this.deviceTypes = response.data
|
||||||
console.log('设备类型列表:', this.deviceTypes)
|
console.log('设备类型列表:', this.deviceTypes)
|
||||||
|
|
@ -243,7 +290,7 @@ export default {
|
||||||
|
|
||||||
// 构建设备类型选项列表
|
// 构建设备类型选项列表
|
||||||
const itemList = this.deviceTypes.map(item => item.name)
|
const itemList = this.deviceTypes.map(item => item.name)
|
||||||
|
|
||||||
uni.showActionSheet({
|
uni.showActionSheet({
|
||||||
itemList: itemList,
|
itemList: itemList,
|
||||||
success: res => {
|
success: res => {
|
||||||
|
|
@ -252,17 +299,17 @@ export default {
|
||||||
this.formData.equipment = selectedDevice.name
|
this.formData.equipment = selectedDevice.name
|
||||||
this.formData.equipmentId = selectedDevice.id
|
this.formData.equipmentId = selectedDevice.id
|
||||||
this.formData.equipmentSuitId = selectedDevice.suitId
|
this.formData.equipmentSuitId = selectedDevice.suitId
|
||||||
|
|
||||||
// 清空之前选择的套餐
|
// 清空之前选择的套餐
|
||||||
this.formData.period = ''
|
this.formData.period = ''
|
||||||
this.formData.periodId = ''
|
this.formData.periodId = ''
|
||||||
this.formData.equipmentSuitId=''
|
|
||||||
this.selectedPackage = null
|
this.selectedPackage = null
|
||||||
this.totalAmount = '0.00'
|
this.totalAmount = '0.00'
|
||||||
|
|
||||||
// 根据选中的设备类型获取租赁套餐
|
// 根据选中的设备类型获取租赁套餐
|
||||||
this.getPeriodPackages(selectedDevice.suitId)
|
this.getPeriodPackages(selectedDevice.suitId)
|
||||||
|
|
||||||
console.log('选中设备:', selectedDevice)
|
console.log('选中设备:', selectedDevice)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -288,7 +335,7 @@ export default {
|
||||||
|
|
||||||
// 构建套餐选项列表
|
// 构建套餐选项列表
|
||||||
const itemList = this.periodPackages.map(item => `${item.name} ¥${item.amount}`)
|
const itemList = this.periodPackages.map(item => `${item.name} ¥${item.amount}`)
|
||||||
|
|
||||||
uni.showActionSheet({
|
uni.showActionSheet({
|
||||||
itemList: itemList,
|
itemList: itemList,
|
||||||
success: res => {
|
success: res => {
|
||||||
|
|
@ -297,8 +344,8 @@ export default {
|
||||||
this.formData.period = selectedPackage.name
|
this.formData.period = selectedPackage.name
|
||||||
this.formData.periodId = selectedPackage.id
|
this.formData.periodId = selectedPackage.id
|
||||||
this.totalAmount = selectedPackage.amount.toFixed(2)
|
this.totalAmount = selectedPackage.amount.toFixed(2)
|
||||||
|
|
||||||
console.log('选中套餐:', selectedPackage)
|
console.log('选中套餐:', selectedPackage)
|
||||||
|
console.log('选中时长:', this.formData.periodId)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
@ -366,9 +413,9 @@ export default {
|
||||||
...this.formData,
|
...this.formData,
|
||||||
amount: this.totalAmount,
|
amount: this.totalAmount,
|
||||||
selectedDevice: this.selectedDevice,
|
selectedDevice: this.selectedDevice,
|
||||||
selectedPackage: this.selectedPackage
|
selectedPackage: this.selectedPackage,
|
||||||
})
|
})
|
||||||
|
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '支付成功',
|
title: '支付成功',
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
|
|
@ -484,8 +531,6 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 选择器
|
// 选择器
|
||||||
.selector {
|
.selector {
|
||||||
flex: 3;
|
flex: 3;
|
||||||
|
|
@ -505,7 +550,7 @@ export default {
|
||||||
.selector-text {
|
.selector-text {
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: #666;
|
color: #666;
|
||||||
|
|
||||||
&.placeholder {
|
&.placeholder {
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
@ -625,4 +670,3 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user