/* eslint-disable react/jsx-one-expression-per-line */
/* eslint-disable no-shadow */
/* eslint-disable camelcase */
import * as WebBrowser from "expo-web-browser";
import * as React from "react";
import { StyleSheet } from "react-native";
import { Layout, Text, useTheme, Button, Card } from "@ui-kitten/components";
import { useModel } from "flooks";
import { useFocusEffect, useRoute } from "@react-navigation/native";
import { useCreation, useUnmount, useMount } from "@umijs/hooks";
import Textarea from "react-native-textarea";
import ScrollPage from "../components/ScrollPage";
import FormInput from "../components/FormInput";
import ConnectButton from "../components/ConnectButton";
import GuideHeaderBar from "../components/GuideHeaderBar";
import NavHeaderBar from "../components/NavHeaderBar";
const styles = StyleSheet.create({
container: {
flex: 1,
paddingBottom: 33,
},
tabContent: {
backgroundColor: "#fff",
marginTop: 20,
},
img: {
width: 100,
height: 100,
alignSelf: "center",
},
img2: {
width: 97,
height: 21,
alignSelf: "center",
marginTop: 2,
},
text: {
marginTop: 16,
},
layoutLeft: {
// flexDirection: "row",
paddingVertical: 10,
justifyContent: "center",
alignItems: "center",
},
form: {
paddingHorizontal: 26,
paddingVertical: 20,
},
textareaContainer: {
backgroundColor: "#F0F0F0",
height: 100,
borderRadius: 4,
},
textarea: {
textAlignVertical: "top", // hack android
fontSize: 13,
color: "#333",
paddingHorizontal: 14,
paddingVertical: 10,
height: 100,
},
lay: {
flexDirection: "row",
marginLeft: 120,
marginBottom: 10,
},
money: {
marginLeft: 10,
},
});
export default function Guide1Screen({ navigation }) {
const theme = useTheme();
const { changeBackground } = useModel("barModel");
const { httpGet, httpPost } = useModel("httpModel", true);
const { success, loading, clearLoading } = useModel("loadingModel", true);
const { mid, userInfo, changeGuideStep } = useModel("userModel", true);
const {
addClassification,
editGoodsMap,
saveClassByList,
removeGoodsClassMap,
sortClassification,
} = useModel("goodsModel");
const {
guide1_title1,
guideHome_title2,
guide1_form_1,
guide1_pla_1,
guide1_form_2,
guide1_pla_2,
guide1_form_3,
guide1_pla_3,
guide1_form_4,
guide1_pla_4,
guide1_form_5,
guide1_pla_5,
next,
pass,
passTips,
confirm,
addGoods,
delText,
removeTips,
GVDYKL,
IQYCDU,
} = useModel("wordsModel");
const { showDialog } = useModel("dialogModel");
const route = useRoute();
const [routeName, setRouteName] = React.useState("");
const [id, changeId] = React.useState("NEW");
const [name, changeName] = React.useState("");
const [amount, changeAmount] = React.useState("");
const [discountAmount, changeDiscountAmount] = React.useState("");
const [inventory, changeInventory] = React.useState(0);
const [week, changeWeek] = React.useState("");
const [startTime, changeStartTime] = React.useState("08:00:00");
const [endTime, changeEndTime] = React.useState("18:00:00");
const [introduction, changeIntroduction] = React.useState();
const [goodsSpecification, changeGoodsSpecification] = React.useState([]);
const [packingPrice, setPackingPrice] = React.useState();
const [img, changeImg] = React.useState();
// 需要批量提交的规格
const postByList = useCreation(() => {
return goodsSpecification.filter(item => {
return !item.id || item.id < 0;
});
}, [goodsSpecification]);
function getInfo(res) {
changeName(res.name || "");
if (res.discountAmount) {
changeDiscountAmount(res.discountAmount.toString());
}
if (res.amount) {
changeAmount(res.amount.toString());
}
if (res.inventory) {
changeInventory(res.inventory.toString());
}
if (res.packingPrice) {
setPackingPrice(res.packingPrice.toString());
}
changeWeek(res.week || "");
changeStartTime(res.startTime || "");
changeEndTime(res.endTime || "");
changeIntroduction(res.introduction || "");
// if (res.img && res.img.length) {
changeImg(res.img);
//
}
useMount(() => {
const { params, name } = route;
setRouteName(name);
if (params) {
if (params.id) {
changeId(params.id);
loading();
httpGet(`/goods/get/${params.id}`, {}, true)
.then(res => {
getInfo(res);
changeGoodsSpecification(sortClassification(res.specifications));
})
.finally(() => {
clearLoading();
});
}
} else if (mid) {
console.log(userInfo);
changeWeek(userInfo.week || "");
changeStartTime(userInfo.startTime || "");
changeEndTime(userInfo.endTime || "");
}
});
useUnmount(() => {
removeGoodsClassMap();
});
React.useEffect(() => {
if (editGoodsMap.has(id)) {
changeGoodsSpecification(editGoodsMap.get(id));
}
}, [editGoodsMap.get(id)]);
useFocusEffect(
React.useCallback(() => {
changeBackground(theme["color-primary-500"]);
}, [])
);
const specify = () => {
return goodsSpecification.map((item, index) => {
return (
{item.parent ? (
添加
{item.name}
) : (
分类名:
{item.name}
)}
{item.parent ? (
¥{item.amount}
) : (
{item.multiple ? IQYCDU : GVDYKL}
)}
);
});
};
const canNext = React.useMemo(() => {
if (
name &&
amount &&
inventory &&
week &&
startTime &&
endTime &&
img &&
packingPrice
) {
return true;
}
return false;
}, [
name,
amount,
discountAmount,
inventory,
week,
startTime,
endTime,
introduction,
img,
]);
return (
<>
{routeName !== "AddGoods" ? (
) : (
)}
{routeName !== "AddGoods" && (
{guide1_title1}
{guideHome_title2}
)}
{/* 商品名称 */}
{/* 商品价格 */}
{/* 优惠价格 */}
{/* 包装价格 */}
{/* 商品规格 */}
{
navigation.navigate("GoodsSpecification", {
goodsId: id,
});
}}
textAlign="right"
/>
{specify()}
{/* 每日供应数量 */}
{/* 供应时间 */}
{
changeWeek(week);
changeStartTime(startTime);
changeEndTime(endTime);
}}
/>
{routeName === "AddGoods" && id !== "NEW" && (
)}
{routeName !== "AddGoods" && (
)}
{routeName !== "AddGoods" && }
>
);
}