import { useEffect, useState } from 'react' import Taro from '@tarojs/taro' import { getUserQcode, setUserPhone } from '@/services/login' import { View, Image, Input, Text, Form } from '@tarojs/components' import CustomNav from '@/components/CustomNav' import ButtontWX from '@/components/ButtontWX' import checkedImg from '@/assets/lolginImages/checkedImg.png' import unselectedImg from '@/assets/lolginImages/unselectedImg.png' import { useModel } from '@/store' import './style.less' export default (props) => { const { isLoginVisible, loginType, tab } = props const { person, setPerson } = useModel('userData') const [countCenter, setCountCenter] = useState({ count: 60, toast: false, show_btn: false, code_ts: '获取验证码' }) const [checkImage, setCheckImage] = useState(false) const [InputPhoneValue, setInputPhoneValue] = useState('') const [InputCodeValue, setInputCodeValue] = useState('') const [myClosures, setMyClosure] = useState(false) useEffect(() => { if (isLoginVisible) { setMyClosure(isLoginVisible) } }, [isLoginVisible]) const myClosure = () => { setMyClosure(false) } const onInputPhone = (r) => { setInputPhoneValue(r?.detail?.value) console.log("🚀 ~ file: index.jsx ~ line 26 ~ InputCodeValue", InputPhoneValue) } const onInputCode = (r) => { setInputCodeValue(r?.detail?.value) } //获取验证码 const getCode = (r) => { if (InputPhoneValue === '' || !(/^1[3456789]\d{9}$/.test(InputPhoneValue))) { console.log('提示') Taro.showToast({ title: '手机号码有误', icon: 'none', duration: 2000 }) } else { getUserQcode({ phone: InputPhoneValue }).then(() => { Taro.showToast({ title: '验证码发送成功', icon: 'none', duration: 2000 }) }) let count = countCenter.count const timer = setInterval(() => { setCountCenter({ count: (count--), show_btn: true, code_ts: count + '秒后重发' }) if (count == 0) { setCountCenter({ show_btn: false, count: 60, code_ts: '获取验证码' }) clearInterval(timer) } }, 1000) } } const getUserLogin = () => { Taro.navigateTo({ url: `/pages/index/index?tab=${tab}` }); if (InputPhoneValue === '' || !(/^1[3456789]\d{9}$/.test(InputPhoneValue))) { console.log('提示') Taro.showToast({ title: '手机号或验证码有误', icon: 'none', duration: 2000 }) } else { if (!checkImage) { Taro.showToast({ title: '下方协议未勾选', icon: 'none', duration: 2000 }) } else { setUserPhone(person.personId, { captcha: InputCodeValue, phone: InputPhoneValue }).then((e) => { console.log('e', e); setPerson(e.person) // Taro.navigateTo({ url: path }); if (loginType) { Taro.navigateBack({ delta: 1 }) } else { myClosure() } }) // console.log('person', person); } } } return ( <> { isLoginVisible !== myClosures ? myClosures : isLoginVisible ? 您好! 欢迎进入农户端小程序! +86 { setCheckImage(!checkImage) }} /> 请认真查看文本协议/隐私政策,确认之后选择此项! : <> } ) }