Commit d606e9ae by Lin

fix(customerPages):增强表单验证和按钮状态

- 更新提交按钮,确保在提交前处理表单验证。
- 引入一个新计算属性,用于检查必填表单项。
- 根据表单填写情况,为禁用按钮添加视觉反馈。
1 parent 2dce4367
...@@ -179,7 +179,7 @@ ...@@ -179,7 +179,7 @@
</template> </template>
</view> </view>
<view class="btns flex"> <view class="btns flex">
<view class="btn cancel" @click="submitCustomerProfileAPI">提交</view> <view :class="['btn', 'cancel', { disabled: isRequiredFormIncomplete }]" @click="handleSubmitClick">提交</view>
<template v-if="sceneType != 7"> <template v-if="sceneType != 7">
<view :class="['btn', { disabled: isStartReceptionDisabled }]" @click="startReception">开始接待</view> <view :class="['btn', { disabled: isStartReceptionDisabled }]" @click="startReception">开始接待</view>
</template> </template>
...@@ -380,7 +380,12 @@ export default { ...@@ -380,7 +380,12 @@ export default {
const { sceneType } = uni.$storage.get('userInfo') || {} const { sceneType } = uni.$storage.get('userInfo') || {}
return sceneType return sceneType
}, },
isRequiredFormIncomplete () {
const { customerForm, customerInfo } = this
return customerForm.some(e => e.required && !customerInfo[e.key])
},
isStartReceptionDisabled () { isStartReceptionDisabled () {
if (this.isRequiredFormIncomplete) return true
return [2, 3, 4].includes(Number(this.customerInfo.customerStatus)) return [2, 3, 4].includes(Number(this.customerInfo.customerStatus))
} }
}, },
...@@ -724,9 +729,26 @@ export default { ...@@ -724,9 +729,26 @@ export default {
animationDuration: 100 animationDuration: 100
}) })
}, },
handleSubmitClick () {
if (this.isRequiredFormIncomplete) {
uni.showToast({
title: '必填表单项不能为空',
icon: 'none'
})
return
}
this.submitCustomerProfileAPI()
},
async startReception () { async startReception () {
const { sceneType, customerInfo } = this const { sceneType, customerInfo } = this
if (sceneType == 7) return // 二手车无接待功能 if (sceneType == 7) return // 二手车无接待功能
if (this.isRequiredFormIncomplete) {
uni.showToast({
title: '必填表单项不能为空',
icon: 'none'
})
return
}
if (this.isStartReceptionDisabled) return if (this.isStartReceptionDisabled) return
const submitted = await this.submitCustomerProfileAPI({ fromReception: true }) const submitted = await this.submitCustomerProfileAPI({ fromReception: true })
if (!submitted) return if (!submitted) return
...@@ -1199,6 +1221,11 @@ export default { ...@@ -1199,6 +1221,11 @@ export default {
background: #dae9ff; background: #dae9ff;
color: #2c66f7; color: #2c66f7;
} }
.cancel.disabled {
background: rgba(218, 233, 255, 0.6);
color: rgba(44, 102, 247, 0.6);
background-image: none;
}
.disabled { .disabled {
background-image: linear-gradient(0deg, #2c66f799 0%, #48a6ff99 100%); background-image: linear-gradient(0deg, #2c66f799 0%, #48a6ff99 100%);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!