|
@@ -1,10 +1,25 @@
|
|
|
-import React, { useEffect, useMemo, useState } from "react";
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
-import { A2BarrageType, A2GoodsType, A2QuestionType } from "@/types";
|
|
|
+import {
|
|
|
+ A2BarrageType,
|
|
|
+ A2GoodsType,
|
|
|
+ A2QuestionType,
|
|
|
+ A2R_fSaveType,
|
|
|
+} from "@/types";
|
|
|
import classNames from "classnames";
|
|
|
import { envUrl } from "@/utils/env";
|
|
|
import Tab4S3 from "@/pages/A2Main/Tab4S3";
|
|
|
import Tab4S4 from "@/pages/A2Main/Tab4S4";
|
|
|
+import { A2_APIgetRandCode, A2_APIsaveBarrage } from "@/store/action/A2Main";
|
|
|
+import { Toast } from "antd-mobile";
|
|
|
+import { Button, Form, FormInstance, Input } from "antd";
|
|
|
+import TextArea from "antd/es/input/TextArea";
|
|
|
|
|
|
const topArrTemp = [
|
|
|
{
|
|
@@ -25,7 +40,7 @@ const topArrTemp = [
|
|
|
{
|
|
|
id: 2,
|
|
|
name: "留言",
|
|
|
- flag: true,
|
|
|
+ flag: false,
|
|
|
},
|
|
|
];
|
|
|
|
|
@@ -54,8 +69,11 @@ function Tab3InfoMtxt({
|
|
|
goodsId,
|
|
|
closeAudioFu,
|
|
|
}: Props) {
|
|
|
- // 页面的展开和收起-待完善
|
|
|
- const [pageShow, setPageShow] = useState(true);
|
|
|
+ // 表单的ref
|
|
|
+ const FormBoxRef = useRef<FormInstance>(null);
|
|
|
+
|
|
|
+ // 页面的展开和收起
|
|
|
+ const [pageShow, setPageShow] = useState(false);
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (!pageShow) {
|
|
@@ -71,13 +89,55 @@ function Tab3InfoMtxt({
|
|
|
// 顶部的数组
|
|
|
const topArr = useMemo(() => {
|
|
|
const arr = [...topArrTemp];
|
|
|
- // 判断 问答 和 知识 是否显示
|
|
|
- if (wdFlag) arr[1].flag = true;
|
|
|
- if (zsFlag) arr[2].flag = true;
|
|
|
+ // 判断 问答 和 知识 留言 是否显示
|
|
|
+ arr[1].flag = wdFlag;
|
|
|
+ arr[2].flag = zsFlag;
|
|
|
+ arr[3].flag = btnOkFlag || barrageList.length > 0;
|
|
|
+
|
|
|
return arr.filter((v) => v.flag);
|
|
|
- }, [wdFlag, zsFlag]);
|
|
|
+ }, [barrageList.length, btnOkFlag, wdFlag, zsFlag]);
|
|
|
|
|
|
// ------------------------留言 ----------------------------
|
|
|
+ const [codeImg, setCodeImg] = useState<any>("");
|
|
|
+
|
|
|
+ // 获取验证码函数
|
|
|
+ const getRandCodeFu = useCallback(async () => {
|
|
|
+ const res: any = await A2_APIgetRandCode();
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.readAsDataURL(res);
|
|
|
+ reader.onload = () => {
|
|
|
+ setCodeImg(reader.result);
|
|
|
+ };
|
|
|
+ // console.log(123, res);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getRandCodeFu();
|
|
|
+ }, [getRandCodeFu]);
|
|
|
+
|
|
|
+ // 没有通过校验
|
|
|
+ const onFinishFailed = useCallback(() => {}, []);
|
|
|
+
|
|
|
+ // 通过校验
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (value: A2R_fSaveType) => {
|
|
|
+ const obj = {
|
|
|
+ ...value,
|
|
|
+ goodsId,
|
|
|
+ };
|
|
|
+ const res = await A2_APIsaveBarrage(obj);
|
|
|
+ if (res.code === 0) {
|
|
|
+ Toast.show({
|
|
|
+ icon: "success",
|
|
|
+ content: "留言成功,等待审核",
|
|
|
+ });
|
|
|
+
|
|
|
+ // 初始化表单
|
|
|
+ FormBoxRef.current?.resetFields();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [goodsId]
|
|
|
+ );
|
|
|
|
|
|
return (
|
|
|
<div
|
|
@@ -155,6 +215,117 @@ function Tab3InfoMtxt({
|
|
|
{topAc === 4 ? (
|
|
|
<Tab4S4 type={info.tagType} closeFu={() => {}} isApp={true} />
|
|
|
) : null}
|
|
|
+
|
|
|
+ {/* --------------------留言-------------------- */}
|
|
|
+ {topAc === 2 ? (
|
|
|
+ <div className="tab3ITmain4">
|
|
|
+ {/* 上面的表单 */}
|
|
|
+ {btnOkFlag ? (
|
|
|
+ <div
|
|
|
+ className={classNames(
|
|
|
+ "t3IT4top",
|
|
|
+ barrageList.length <= 0 ? "t3IT4topOne" : ""
|
|
|
+ )}
|
|
|
+ >
|
|
|
+ <Form
|
|
|
+ ref={FormBoxRef}
|
|
|
+ labelCol={{ span: 0 }}
|
|
|
+ name="basic"
|
|
|
+ onFinish={onFinish}
|
|
|
+ onFinishFailed={onFinishFailed}
|
|
|
+ autoComplete="off"
|
|
|
+ >
|
|
|
+ <Form.Item
|
|
|
+ label="留言内容"
|
|
|
+ name="name"
|
|
|
+ rules={[
|
|
|
+ { required: true, message: "内容不能为空" },
|
|
|
+ {
|
|
|
+ validator: (rule, value) => {
|
|
|
+ if (value) {
|
|
|
+ const txt = value
|
|
|
+ .replaceAll(" ", "")
|
|
|
+ .replaceAll("\n", "");
|
|
|
+ return txt === ""
|
|
|
+ ? Promise.reject("内容不能为空")
|
|
|
+ : Promise.resolve();
|
|
|
+ } else return Promise.resolve();
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ <TextArea
|
|
|
+ rows={4}
|
|
|
+ placeholder="请输入内容"
|
|
|
+ showCount
|
|
|
+ maxLength={50}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item
|
|
|
+ label="您的昵称"
|
|
|
+ name="authorName"
|
|
|
+ rules={[{ required: true, message: "内容不能为空" }]}
|
|
|
+ getValueFromEvent={(e) =>
|
|
|
+ e.target.value.replace(/\s+/g, "")
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <Input maxLength={8} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item
|
|
|
+ className="t3IT4top_code"
|
|
|
+ label="验证码"
|
|
|
+ name="randCode"
|
|
|
+ rules={[{ required: true, message: "内容不能为空" }]}
|
|
|
+ getValueFromEvent={(e) =>
|
|
|
+ e.target.value.replace(/\s+/g, "")
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <Input maxLength={5} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ {/* 验证码图 */}
|
|
|
+ <div className="F_codeImg">
|
|
|
+ <img src={codeImg} alt="" onClick={() => getRandCodeFu()} />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="t3IT4top_tit">
|
|
|
+ 您的留言经审核并采纳后,才会在平台中公开展示
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <Form.Item className="t3IT4top_btn">
|
|
|
+ <Button type="primary" htmlType="submit">
|
|
|
+ 留言
|
|
|
+ </Button>
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ ) : null}
|
|
|
+
|
|
|
+ {/* 下面的留言列表 */}
|
|
|
+ {barrageList.length ? (
|
|
|
+ <div
|
|
|
+ className={classNames(
|
|
|
+ "t3ITfloo",
|
|
|
+ btnOkFlag ? "" : "t3ITflooAll"
|
|
|
+ )}
|
|
|
+ >
|
|
|
+ <div className="t3ITflooSon myscroll">
|
|
|
+ {barrageList.map((v) => (
|
|
|
+ <div className="t3ITlistRow" key={v.id}>
|
|
|
+ <div className="t3ITlist_Title">
|
|
|
+ <div className="t3ITlist_Title_l">{v.authorName}</div>
|
|
|
+ <div className="t3ITlist_Title_r">{v.createTime}</div>
|
|
|
+ </div>
|
|
|
+ <div className="t3ITlist_Txt">{v.name}</div>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ) : null}
|
|
|
+ </div>
|
|
|
+ ) : null}
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|