表单校验1.0

This commit is contained in:
WindowBird 2025-08-19 11:11:27 +08:00
parent deaa972edb
commit 05504a293d
2 changed files with 31 additions and 5 deletions

View File

@ -136,7 +136,10 @@ export default {
//
onAddressInput(e) {
this.$emit('address-input', e.detail.value)
const value = e.detail.value
this.addressValue = value
this.$emit('input', value)
this.$emit('address-input', value)
},
//
@ -242,6 +245,7 @@ export default {
}
this.addressValue = this.currentLocation.address
this.$emit('input', this.currentLocation.address)
this.$emit('use-location', this.currentLocation)
uni.showToast({

View File

@ -50,13 +50,18 @@
@location-error="onLocationError"
@use-location="onUseLocation"
@map-opened="onMapOpened"
@input="onAddressInput"
/>
<!-- 详细位置 -->
<view class="form-item">
<text class="field-label">详细位置</text>
<input v-model="formData.detailAddress" class="field-input" placeholder="例:6栋201室" />
<input
v-model="formData.detailAddress"
class="field-input"
placeholder="例:6栋201室"
@input="onDetailAddressInput"
/>
</view>
<!-- 租赁设备 -->
@ -149,18 +154,24 @@ export default {
const nameValid = this.formData.name.trim().length > 0
const phoneValid = this.formData.phone.trim().length > 0
const addressValid = this.formData.address.trim().length > 0
const detailAddressValid = this.formData.detailAddress.trim().length > 0
const equipmentSelected = !!this.formData.equipmentId
const packageSelected = !!this.formData.periodId
const amountValid = parseFloat(this.totalAmount) > 0
const canPayResult = nameValid && phoneValid && addressValid &&
const canPayResult = nameValid && phoneValid && addressValid && detailAddressValid &&
equipmentSelected && packageSelected && amountValid
//
console.log('🔍 canPay 实时检查:', {
nameValid,
phoneValid,
addressValid,
addressValid: addressValid,
addressValue: `"${this.formData.address}"`,
addressLength: this.formData.address.length,
detailAddressValid: detailAddressValid,
detailAddressValue: `"${this.formData.detailAddress}"`,
detailAddressLength: this.formData.detailAddress.length,
equipmentSelected,
packageSelected,
amountValid,
@ -181,6 +192,9 @@ export default {
'formData.address'() {
console.log('🔍 地址变化:', this.formData.address)
},
'formData.detailAddress'() {
console.log('🔍 详细位置变化:', this.formData.detailAddress)
},
'formData.equipmentId'() {
console.log('🔍 设备ID变化:', this.formData.equipmentId)
},
@ -218,6 +232,14 @@ export default {
methods: {
//
onAddressInput(value) {
console.log('🔍 地址输入变化:', value)
console.log('🔍 地址输入前 formData.address:', this.formData.address)
this.formData.address = value
console.log('🔍 地址输入后 formData.address:', this.formData.address)
},
//
onLocationSuccess(location) {
console.log('位置获取成功:', location)