import { useState } from "react"; import { Image, Label, View } from "@tarojs/components"; import Taro, { FC } from "@tarojs/taro"; import { AtButton, AtForm, AtInput, AtTextarea } from "taro-ui"; import BgImg from "../../images/feedback@2x-min.png"; import { handleValidate } from "../../../utils"; import { getBaseURL } from "@dage/service"; import { Rules } from "async-validator"; import { feedbackApi } from "../../../api"; import { FooterProtocol } from "../../../components/FooterProtocol"; import "./index.scss"; const DEFAULT_PARAMS = { name: "", phone: "", content: "", randCode: "", }; const formRules: Rules = { name: [{ required: true, message: "请输入称呼" }], phone: [{ required: true, message: "请输入联系方式" }], content: [{ required: true, message: "请输入反馈内容" }], randCode: [ { required: true, message: "请输入验证码" }, { validator: (_, value) => { return value.length === 5; }, message: "验证码输入有误", }, ], }; const FeedBackPage: FC = () => { const [checked, setChecked] = useState(false); const [params, setParams] = useState({ ...DEFAULT_PARAMS }); const [timestamp, setTimestamp] = useState(new Date().getTime()); const [loading, setLoading] = useState(false); const handleSubmit = async (event, readProtocol = false) => { if (!(await handleValidate(params, formRules))) return; if (!checked && !readProtocol) { Taro.showModal({ title: "提示", content: "是否已阅读并同意《用户服务协议》及《个人信息保护政策》", confirmText: "同意", success: (res) => { if (res.confirm) { setChecked(true); handleSubmit(undefined, true); } }, }); return; } try { setLoading(true); await feedbackApi(params); setParams({ ...DEFAULT_PARAMS }); setTimestamp(new Date().getTime()); Taro.showToast({ title: "提交成功", icon: "success", }); } finally { setLoading(false); } }; return ( setParams({ ...params, name: val as string, }) } /> setParams({ ...params, phone: val as string, }) } /> setParams({ ...params, content: val, }) } /> setParams({ ...params, randCode: val as string, }) } /> setTimestamp(new Date().getTime())} /> { Taro.navigateBack(); }} > 取消 提交 ); }; export default FeedBackPage;