import { Button, Checkbox, CheckboxGroup, Input, Radio, RadioGroup, Text, Textarea, View } from '@tarojs/components' import Taro from '@tarojs/taro' import { useState } from 'react' import './index.scss' type ServiceType = 'new' | 'update' type ApplicationForm = { serviceType: ServiceType storeName: string storeAddress: string contactName: string contactPhone: string description: string } type FormErrors = Partial> const INITIAL_FORM: ApplicationForm = { serviceType: 'new', storeName: '', storeAddress: '', contactName: '', contactPhone: '', description: '', } const PHONE_PATTERN = /^1[3-9]\d{9}$/ const validateForm = (form: ApplicationForm, agreed: boolean) => { const errors: FormErrors = {} if (!form.storeName.trim()) errors.storeName = '请输入门店名称' if (!form.storeAddress.trim()) errors.storeAddress = '请输入门店地址' if (!form.contactName.trim()) errors.contactName = '请输入联系人姓名' if (!form.contactPhone.trim()) { errors.contactPhone = '请输入联系电话' } else if (!PHONE_PATTERN.test(form.contactPhone.trim())) { errors.contactPhone = '请输入正确的手机号码' } if (!form.description.trim()) errors.description = '请描述需要办理的内容' if (!agreed) errors.agreement = '请阅读并同意隐私政策和服务说明' return errors } export default function Landing () { const [form, setForm] = useState(INITIAL_FORM) const [agreed, setAgreed] = useState(false) const [errors, setErrors] = useState({}) const updateField = (field: K, value: ApplicationForm[K]) => { setForm((current) => ({ ...current, [field]: value })) setErrors((current) => ({ ...current, [field]: undefined })) } const showPolicy = (type: 'privacy' | 'service') => { const isPrivacy = type === 'privacy' Taro.showModal({ title: isPrivacy ? '隐私政策' : '服务说明', content: isPrivacy ? '您填写的信息仅用于本次门店标注服务的联系与确认,我们将妥善保护您的个人信息。' : '提交申请后,工作人员将在服务时间内联系您核对资料。具体办理结果以实际审核情况为准。', showCancel: false, confirmText: '我知道了', }) } const handleSubmit = () => { const validationErrors = validateForm(form, agreed) const firstError = Object.values(validationErrors)[0] setErrors(validationErrors) if (firstError) { Taro.showToast({ title: firstError, icon: 'none' }) return } Taro.showModal({ title: '提交成功', content: '您的申请已提交,工作人员将在服务时间内联系您确认。', showCancel: false, confirmText: '我知道了', }) } return ( 门店企业标注,在线提交 提供门店新增标注、信息修改等企业服务,提交资料后由工作人员联系确认。 第三方企业服务,非地图平台官方服务 办理类型 updateField('serviceType', event.detail.value as ServiceType)} > 新增标注 信息修改 门店名称 updateField('storeName', event.detail.value)} /> {errors.storeName && {errors.storeName}} 门店地址 updateField('storeAddress', event.detail.value)} /> {errors.storeAddress && {errors.storeAddress}} 联系人 updateField('contactName', event.detail.value)} /> {errors.contactName && {errors.contactName}} 联系电话 updateField('contactPhone', event.detail.value)} /> {errors.contactPhone && {errors.contactPhone}} 补充说明