This commit is contained in:
wangxiaoxian 2026-05-09 17:01:20 +08:00
parent 166480323c
commit a8de74cfd4
2 changed files with 55 additions and 36 deletions

View File

@ -23,30 +23,23 @@
<input type="text" v-model="form.name" placeholder="请输入租客姓名" class="item-input"/>
</view>
<view class="form-item">
<text class="item-label required">手机号</text>
<text class="item-label">手机号</text>
<input type="number" v-model="form.phone" placeholder="请输入手机号" class="item-input" maxlength="11"/>
</view>
<view class="form-item">
<text class="item-label">身份证号</text>
<input type="text" v-model="form.idCard" placeholder="请输入身份证号" class="item-input" maxlength="18"/>
</view>
<view class="form-item">
<text class="item-label">紧急联系人</text>
<input type="text" v-model="form.emergencyContact" placeholder="请输入紧急联系人" class="item-input"/>
</view>
<view class="form-item">
<text class="item-label">紧急电话</text>
<input type="number" v-model="form.emergencyPhone" placeholder="请输入紧急联系电话" class="item-input" maxlength="11"/>
</view>
</view>
</view>
<view class="form-section">
<view class="section-title">备注信息</view>
<view class="form-card">
<view class="form-item">
<textarea v-model="form.remark" placeholder="请输入备注信息(选填)" class="remark-input" maxlength="200"/>
<text class="word-count">{{form.remark.length}}/200</text>
<view class="form-item" v-if="isEdit">
<text class="item-label">状态</text>
<view class="status-options">
<view class="status-option" :class="{ active: form.status === 'active' }" @click="form.status = 'active'">
<text>正常</text>
</view>
<view class="status-option" :class="{ active: form.status === 'inactive' }" @click="form.status = 'inactive'">
<text>停用</text>
</view>
</view>
</view>
</view>
</view>
@ -72,9 +65,7 @@
name: '',
phone: '',
idCard: '',
emergencyContact: '',
emergencyPhone: '',
remark: ''
status: 'active'
}
}
},
@ -95,9 +86,7 @@
name: data.name || '',
phone: data.phone || '',
idCard: data.idCard || '',
emergencyContact: data.emergencyContact || '',
emergencyPhone: data.emergencyPhone || '',
remark: data.remark || ''
status: data.status || 'active'
}
} catch (error) {
uni.showToast({ title: '加载失败', icon: 'none' })
@ -105,15 +94,34 @@
uni.hideLoading()
}
},
validateForm() {
const { name, phone, idCard } = this.form
if (!name || !name.trim()) {
uni.showToast({ title: '请输入租客姓名', icon: 'none' })
return false
}
if (name.trim().length < 2 || name.trim().length > 50) {
uni.showToast({ title: '姓名长度应在2-50个字符', icon: 'none' })
return false
}
if (phone && phone.trim()) {
const phonePattern = /^1[3-9]\d{9}$/
if (!phonePattern.test(phone.trim())) {
uni.showToast({ title: '请输入正确的手机号', icon: 'none' })
return false
}
}
if (idCard && idCard.trim()) {
const idCardPattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
if (!idCardPattern.test(idCard.trim())) {
uni.showToast({ title: '请输入正确的身份证号', icon: 'none' })
return false
}
}
return true
},
async save() {
if (!this.form.name.trim()) {
uni.showToast({ title: '请输入姓名', icon: 'none' })
return
}
if (!this.form.phone.trim()) {
uni.showToast({ title: '请输入手机号', icon: 'none' })
return
}
if (!this.validateForm()) return
try {
uni.showLoading({ title: '保存中...' })
if (this.isEdit) {
@ -172,8 +180,9 @@
.item-label { width: 180rpx; font-size: 30rpx; color: #1E293B; font-weight: 500; }
.item-label.required::after { content: '*'; color: #EF4444; margin-left: 8rpx; }
.item-input { flex: 1; font-size: 30rpx; color: #1E293B; text-align: right; }
.remark-input { width: 100%; height: 200rpx; font-size: 30rpx; color: #1E293B; line-height: 1.6; }
.word-count { position: absolute; right: 32rpx; bottom: 24rpx; font-size: 24rpx; color: #94A3B8; }
.delete-section { margin-top: 48rpx; }
.delete-btn { width: 100%; height: 96rpx; background: #FEE2E2; color: #EF4444; font-size: 32rpx; font-weight: 600; border-radius: 16rpx; border: none; display: flex; align-items: center; justify-content: center; }
.status-options { display: flex; gap: 24rpx; }
.status-option { padding: 16rpx 32rpx; border-radius: 12rpx; background: #F1F5F9; font-size: 28rpx; color: #64748B; }
.status-option.active { background: #DBEAFE; color: #2563EB; }
</style>

View File

@ -59,7 +59,8 @@
data() {
return {
renterId: null,
renter: null
renter: null,
isLoading: false
}
},
onLoad(options) {
@ -69,20 +70,29 @@
}
},
onShow() {
if (this.renterId) {
// onLoad
if (this.renterId && this.renter) {
this.loadData()
}
},
methods: {
async loadData() {
if (this.isLoading) return
this.isLoading = true
try {
uni.showLoading({ title: '加载中...' })
const res = await renterApi.getDetail(this.renterId)
this.renter = res.data
} catch (error) {
//
if (error?.message === '重复请求') {
console.log('重复请求被拦截')
return
}
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
uni.hideLoading()
this.isLoading = false
}
},
editRenter() {