import * as WebBrowser from "expo-web-browser";
import * as React from "react";
import { Dimensions } from "react-native";
import { Button } from "@ui-kitten/components";
import { Div, Image, Text, Avatar, Input, Icon } from "react-native-magnus";
import { ScrollView } from "react-native-gesture-handler";
import { useFocusEffect } from "@react-navigation/native";
import { useModel } from "flooks";
import { useMount, useCreation, useRequest } from "ahooks";
import UpLoadImage from "../../components/UpLoadImage";
import OpenTime from "../../components/OpenTime";
import CommentCard from "../../components/Comment";
const { width } = Dimensions.get("window");
const img1 = require("../../assets/images/zan.png");
const img2 = require("../../assets/images/cai.png");
const AppraisalSortMap = new Map([
[
"ALL",
{
name: "全部",
},
],
[
"LATEST",
{
name: "最新",
},
],
[
"PRAISE",
{
name: "好评",
},
],
[
"BAD_REVIEW",
{
name: "差评",
isBad: true,
},
],
[
"HAVE_PIC",
{
name: "有图",
},
],
]);
const CommentItem = ({ info }) => {
const imgs = info.img ? info.img.split(",") : [];
const imageSize = imgs.length > 1 ? 80 : 167;
return (
{info.nickname}
{info.likes || 0}
{info.appraiseTime}
{info.goodsAppraise}
{imgs.map((item, index) => {
return (
);
})}
);
};
export default function LinksScreen({ navigation, route }) {
const { changeBackground } = useModel("barModel");
const { httpGet, httpPost } = useModel("httpModel");
const { success, loading, clearLoading } = useModel("loadingModel", true);
useFocusEffect(
React.useCallback(() => {
changeBackground("rgba(0,0,0,0)");
}, [])
);
const {
addClassification,
editGoodsMap,
saveClassByList,
removeGoodsClassMap,
sortClassification,
} = useModel("goodsModel");
const { GVDYKL, IQYCDU } = useModel("wordsModel");
const { params } = route;
const { goodsId } = params;
const [goodsInfo, setgoodsInfo] = React.useState({});
const [comments, setcomments] = React.useState([]);
const [appraisalSort, setappraisalSort] = React.useState("ALL");
useRequest(
() => {
return httpGet(`/appraisal/goods?goodsId=${goodsId}`)
.then(res => {
return Promise.resolve(res);
})
.catch(e => {
return Promise.resolve([]);
});
},
{
refreshDeps: [goodsId],
onSuccess: result => {
setcomments(result);
},
onError: e => {
setcomments([]);
},
}
);
useMount(() => {
if (goodsId) {
loading();
httpGet(`/goods/get/${goodsId}`, {}, true)
.then(res => {
setgoodsInfo(res);
setname(res.name);
setimg(res.img);
setinventory(res.inventory.toString());
setamount((res.amount || "").toString());
setdiscountAmount((res.discountAmount || "").toString());
setintroduction(res.introduction);
changeGoodsSpecification(sortClassification(res.specifications));
setpackingPrice((res.packingPrice || 0).toString());
changeWeek(res.week || "");
changeStartTime(res.startTime || "");
changeEndTime(res.endTime || "");
})
.finally(() => {
clearLoading();
});
}
});
React.useEffect(() => {
if (editGoodsMap.has(goodsId)) {
changeGoodsSpecification(editGoodsMap.get(goodsId));
}
}, [editGoodsMap.get(goodsId)]);
const { goodNum, badNum, monthSales, merchantId } = goodsInfo;
const [img, setimg] = React.useState();
const [name, setname] = React.useState("");
const [inventory, setinventory] = React.useState(0);
const [amount, setamount] = React.useState("");
const [discountAmount, setdiscountAmount] = React.useState();
const [packingPrice, setpackingPrice] = React.useState("0");
const [introduction, setintroduction] = React.useState("");
const [goodsSpecification, changeGoodsSpecification] = React.useState([]);
const [week, changeWeek] = React.useState("");
const [startTime, changeStartTime] = React.useState("08:00:00");
const [endTime, changeEndTime] = React.useState("18:00:00");
// 需要批量提交的规格
const postByList = useCreation(() => {
return goodsSpecification.filter(item => {
return !item.id || item.id < 0;
});
}, [goodsSpecification]);
return (
<>
{/* */}
份数
{goodsSpecification.map((item, index) => {
return (
{item.parent ? (
添加 {item.name}
¥{item.amount || 0}
) : (
分类名: {item.name}
{item.multiple ? IQYCDU : GVDYKL}
)}
);
})}
原价
优惠价
包装价格
供应时间
{
changeWeek(_week);
changeStartTime(_startTime);
changeEndTime(_endTime);
}}
week={week}
startTime={startTime}
endTime={endTime}
/>
商品评价
{comments.map(item => {
return
;
})}
{comments.length === 0 && (
暂无数据
)}
>
);
}