| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- /* 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 moment from "moment";
- 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 } = useModel("loadingModel", true);
- const { mid, changeGuideStep } = useModel("userModel", true);
- const { addClassification, sortClassification } = useModel(
- "goodsModel",
- true
- );
- 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,
- } = useModel("wordsModel");
- const { showDialog } = useModel("dialogModel");
- const route = useRoute();
- const routeName = route.name;
- const [id, changeId] = React.useState("");
- 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");
- const [endTime, changeEndTime] = React.useState("22:00");
- const [introduction, changeIntroduction] = React.useState();
- const [defaultValue, ChangeDefaultValue] = React.useState("");
- const [goodsSpecification, changeGoodsSpecification] = React.useState([]);
- const [img, changeImg] = React.useState();
- 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());
- }
- changeWeek(res.week || "");
- changeStartTime(res.startTime || "");
- changeEndTime(res.endTime || "");
- changeIntroduction(res.introduction || "");
- // if (res.img && res.img.length) {
- changeImg(res.img);
- // }
- if (res.week) {
- ChangeDefaultValue([
- `${moment(res.startTime, "HH:mm:ss").format("HH:mm")}~${moment(
- res.endTime,
- "HH:mm:ss"
- ).format("HH:mm")}`,
- res.week,
- ]);
- }
- }
- useFocusEffect(
- React.useCallback(() => {
- changeBackground(theme["color-primary-500"]);
- const { params } = route;
- if (params) {
- if (params.id) {
- changeId(params.id);
- loading();
- httpGet(`/goods/get/${params.id}`).then(res => {
- getInfo(res);
- });
- httpGet(
- "/goodsSpecification/byGoodsId",
- {
- goodsId: params.id,
- },
- true
- ).then(res => {
- changeGoodsSpecification(sortClassification(res));
- });
- }
- } else {
- getInfo({});
- }
- }, [])
- );
- const specify = () => {
- return goodsSpecification.map(item => {
- return (
- <Layout key={item.id} style={styles.lay}>
- {item.parent ? (
- <Text category="h1">
- 添加
- {item.name}
- </Text>
- ) : (
- <Text category="c1">
- 分类名:
- {item.name}
- </Text>
- )}
- <Layout style={styles.money}>
- {item.parent ? (
- <Text category="h1">¥{item.amount}</Text>
- ) : (
- <Text category="c1">{item.multiple ? "多选" : "单选"}</Text>
- )}
- </Layout>
- </Layout>
- );
- });
- };
- const canNext = React.useMemo(() => {
- if (name && amount && inventory && week && startTime && endTime && img) {
- return true;
- }
- return false;
- }, [
- name,
- amount,
- discountAmount,
- inventory,
- week,
- startTime,
- endTime,
- introduction,
- img,
- ]);
- return (
- <>
- {routeName !== "AddGoods" ? (
- <GuideHeaderBar />
- ) : (
- <NavHeaderBar title={addGoods} />
- )}
- <ScrollPage>
- <Layout style={styles.container}>
- {routeName !== "AddGoods" && (
- <Card appearance="headFilled">
- <Text category="s1">{guide1_title1}</Text>
- <Text category="s1">{guideHome_title2}</Text>
- </Card>
- )}
- <Card appearance="formFilled">
- {/* 商品名称 */}
- <FormInput
- label={guide1_form_1}
- placeholder={guide1_pla_1}
- value={name}
- onChange={changeName}
- style={{ paddingVertical: 3 }}
- />
- {/* 商品价格 */}
- <FormInput
- label={guide1_form_2}
- placeholder={guide1_pla_2}
- value={amount}
- type="money"
- onChange={changeAmount}
- textAlign="right"
- />
- {/* 优惠价格 */}
- <FormInput
- label={guide1_form_3}
- placeholder={guide1_pla_3}
- value={discountAmount}
- type="money"
- onChange={changeDiscountAmount}
- textAlign="right"
- />
- {id !== 0 && (
- <>
- {/* 商品规格 */}
- <FormInput
- label="商品规格"
- type="url"
- changePath={() => {
- navigation.navigate("GoodsSpecification", {
- goodsId: id,
- });
- }}
- textAlign="right"
- />
- {specify()}
- </>
- )}
- {/* 每日供应数量 */}
- <FormInput
- label={guide1_form_4}
- placeholder={guide1_pla_4}
- value={inventory}
- type="amount"
- onChange={changeInventory}
- />
- {/* 供应时间 */}
- <FormInput
- label={guide1_form_5}
- type="openTime"
- defaultValue={defaultValue}
- onChange={(week, startTime, endTime) => {
- changeWeek(week);
- changeStartTime(startTime);
- changeEndTime(endTime);
- }}
- />
- <Layout>
- <Textarea
- containerStyle={styles.textareaContainer}
- style={styles.textarea}
- onChangeText={changeIntroduction}
- defaultValue={introduction}
- maxLength={50}
- placeholder={guide1_pla_5}
- placeholderTextColor="#B4B4B4"
- underlineColorAndroid="transparent"
- />
- </Layout>
- <FormInput
- type="img"
- value={img}
- textAlign="right"
- onChange={changeImg}
- />
- <Layout style={styles.layoutLeft} level="1">
- <Button
- status="primary"
- disabled={!canNext}
- onPress={() => {
- httpPost(
- "/goods/save",
- {
- id,
- name,
- amount,
- discountAmount,
- inventory,
- week,
- startTime,
- endTime,
- introduction,
- img,
- merchantId: mid,
- },
- { body: "json" },
- true
- ).then(res => {
- if (!id) {
- const { params } = route;
- const { classifyId } = params || {};
- if (classifyId) {
- addClassification(classifyId, res.id);
- }
- }
- success(`${id ? "修改" : "添加"}成功`);
- if (routeName !== "AddGoods") {
- changeGuideStep(2);
- } else {
- navigation.goBack();
- }
- });
- }}
- >
- {routeName !== "AddGoods" ? next : confirm}
- </Button>
- {routeName === "AddGoods" && id !== 0 && (
- <Button
- appearance="ghost"
- status="info"
- style={{ marginTop: 10 }}
- onPress={() => {
- showDialog({
- bodyText: removeTips,
- cancelable: true,
- confirmCallback: () => {
- httpPost(`/goods/del/${id}`, {}, {}, true).then(() => {
- success("删除成功");
- navigation.goBack();
- });
- },
- });
- }}
- >
- {delText}
- </Button>
- )}
- {routeName !== "AddGoods" && (
- <Button
- style={{ marginTop: 10 }}
- appearance="ghost"
- status="primary"
- onPress={() => {
- showDialog({
- bodyText: passTips,
- cancelable: true,
- confirmCallback: () => {
- changeGuideStep(2);
- },
- });
- }}
- >
- {pass}
- </Button>
- )}
- </Layout>
- </Card>
- {routeName !== "AddGoods" && <ConnectButton />}
- </Layout>
- </ScrollPage>
- </>
- );
- }
|