import { RichText, View } from "@tarojs/components";
import react, { useEffect } from "react";
import { Collapse, CollapseItem, Toast } from "@antmjs/vantui";
import "./index.scss";
import { getTable } from "../../../../utils/index";
import moment from "moment";

const Version = () => {
  useEffect(() => {
    // 设置标题
    definePageConfig({
      navigationBarTitleText: "版本日志",
    });
  }, []);

  const [values, setValues] = react.useState([]);
  const [versionArr, setversionArr] = react.useState([]);

  useEffect(() => {
    getTabledata();
  });
  // 版本跟心日志
  const getTabledata = async () => {
    let paramsObj = {
      tableName: "version",
      okFun: (res: any) => {
        // console.log("res", res);
        setversionArr(res?.data ?? []);
      },
    };
    await getTable({ ...paramsObj });
    return [];
  };
  return (
    <View>
      <Collapse
        value={values}
        onChange={(e) => {
          console.log('e',e)
          setValues(e.detail);
        }}
        // onOpen={(e) => Toast.show(`打开${e.detail}`)}
        // onClose={(e) => Toast.show(`关闭${e.detail}`)}
      >
        {versionArr?.reverse()?.map((item: any, index: any) => {
          return (
            <CollapseItem
              title={moment(item?.date).format("YYYY-MM-DD")}
              // name={item?.name}
              name={String(index)}
            >
              {/* 富文本 */}
              <View onClick={() => {}} className="RichText">
                <RichText nodes={item?.content} />
              </View>
            </CollapseItem>
          );
        })}
      </Collapse>
      <Toast id="collapse-mess" />
    </View>
  );
};

export default Version;
