Просмотр исходного кода

版本07.08.3(商家举报,购物车订单价格对接)

panhui 5 лет назад
Родитель
Сommit
e455de8267

+ 50 - 18
screens/Detail/Cart.jsx

@@ -1,6 +1,8 @@
 import * as WebBrowser from 'expo-web-browser';
 import * as React from 'react';
 import { StyleSheet, View, Image } from 'react-native';
+import { Div, Text } from 'react-native-magnus';
+
 import { Flex } from '@ant-design/react-native';
 import { Modal, TouchableRipple, Badge } from 'react-native-paper';
 import { ScrollView } from 'react-native-gesture-handler';
@@ -9,9 +11,9 @@ import { useCreation, useRequest } from '@umijs/hooks';
 import { useNavigation, useFocusEffect } from '@react-navigation/native';
 import useModel from 'flooks';
 import Detail from './model';
+import MapModel from '../Map/model';
 
 import Icon from '../../components/SvgIcon';
-import Text from '../../components/Text';
 import Button from '../../components/Button';
 import Plus from '../../components/Plus';
 
@@ -30,7 +32,8 @@ export default function Cart() {
     clearCart,
     setCartMap,
     changeNum,
-  } = useModel(Detail, ['id', 'merchantInfo']);
+    cartMoneyInfo,
+  } = useModel(Detail, ['id', 'merchantInfo', 'cartMoneyInfo']);
 
   useFocusEffect(
     React.useCallback(() => {
@@ -42,7 +45,7 @@ export default function Cart() {
 
   const [cartList, setcartList] = React.useState([]);
 
-  const { deliveryAmount, startingAmount } = merchantInfo;
+  const { startingAmount } = merchantInfo;
 
   const [showList, setshowList] = React.useState(false);
 
@@ -83,11 +86,31 @@ export default function Cart() {
     setCartMap(cartMap);
   }, [cartMap]);
 
+  const {
+    deliveryAmount,
+    goodsTotal,
+    fullReduction,
+    packingPrice,
+    reducedAmount,
+  } = cartMoneyInfo;
+
+  // 钱
+
   const price = useCreation(() => {
-    return cartList.reduce((total, item) => {
-      return accAdd(total, accMul(item.num, item.goodsRealPrice));
-    }, 0);
-  }, [num]);
+    if (goodsTotal) {
+      return (goodsTotal - reducedAmount).toFixed(2);
+    } else {
+      return 0;
+    }
+  }, [goodsTotal, reducedAmount]);
+
+  const total = useCreation(() => {
+    if (goodsTotal) {
+      return (goodsTotal + packingPrice - fullReduction).toFixed(2);
+    } else {
+      return 0;
+    }
+  }, [goodsTotal, fullReduction, packingPrice]);
 
   const canSubmit = useCreation(() => {
     if (price >= startingAmount && num > 0) {
@@ -154,17 +177,26 @@ export default function Cart() {
               </TouchableRipple>
 
               <Flex.Item style={styles.center}>
-                <Text
-                  size="s1"
-                  style={{
-                    lineHeight: 18,
-                    marginVertical: 0,
-                  }}
-                  color={num === 0 ? '#B4B4B4' : '#fff'}
-                >
-                  {num === 0 ? '未选购商品' : `¥${price}`}
-                </Text>
-                <Text size="c2" type="info">
+                <Div row alignItems="center" h={18}>
+                  <Text
+                    fontSize="xl"
+                    lineHeight={18}
+                    color={num === 0 ? 'gray300' : 'white'}
+                  >
+                    {num === 0 ? '未选购商品' : `¥${price}`}
+                  </Text>
+                  <Text
+                    fontSize="sm"
+                    color="gray300"
+                    lineHeight={18}
+                    textDecorLine="line-through"
+                    textDecorColor="gray300"
+                    ml={5}
+                  >
+                    ¥{total}
+                  </Text>
+                </Div>
+                <Text fontSize="xs" color="gray300">
                   另需配送费¥{deliveryAmount || 0}
                 </Text>
               </Flex.Item>

+ 5 - 3
screens/Detail/ReportBusinessScreen.jsx

@@ -40,8 +40,10 @@ const reasomsMap = new Map([
 ]);
 
 export default function ReportBusinessScreen({ navigation }) {
-  const { merchantInfo } = useModel(DetailModel, ['merchantInfo']);
-  const { complaintSave } = useModel(Order, []);
+  const { merchantInfo, complaintSave } = useModel(DetailModel, [
+    'merchantInfo',
+  ]);
+  const { id } = useModel(User, ['id']);
   const { logo, showName, mid } = merchantInfo;
 
   const [type, settype] = React.useState('商家资质问题(缺少相关从业资质)');
@@ -83,7 +85,7 @@ export default function ReportBusinessScreen({ navigation }) {
     const img = [...imgList].filter((item) => {
       return item;
     });
-    complaintSave('', 'MERCHANT', type, content, img.join(',')).then(() => {
+    complaintSave(id, mid, type, content, img.join(',')).then(() => {
       navigation.goBack();
     });
   }

+ 33 - 13
screens/Detail/SubmitScreen.jsx

@@ -46,13 +46,27 @@ export default function SubmitScreen() {
     remark,
     payMethod,
     cartRefreash,
-  } = useModel(Detail, ['merchantInfo', 'remark', 'payMethod']);
+    cartMoneyInfo,
+  } = useModel(Detail, [
+    'merchantInfo',
+    'remark',
+    'payMethod',
+    'cartMoneyInfo',
+  ]);
   const { chooseAddressId } = useModel(AddressModel, ['chooseAddressId']);
   const { submitOrder } = useModel(Order, []);
   const route = useRoute();
   const navigation = useNavigation();
   const { params } = route;
 
+  const {
+    deliveryAmount,
+    fullReduction,
+    packingPrice,
+    firstBuy,
+    realAmount,
+  } = cartMoneyInfo;
+
   const { banner, preparationTime, showName } = merchantInfo;
 
   const [cartList, setcartList] = React.useState([]);
@@ -69,12 +83,6 @@ export default function SubmitScreen() {
     },
   });
 
-  const price = useCreation(() => {
-    return cartList.reduce((total, item) => {
-      return accAdd(total, accMul(item.num, item.goodsRealPrice));
-    }, 0);
-  }, [cartList]);
-
   const time = useCreation(() => {
     return new Time().addTime(preparationTime / 60, 'HH:mm');
   }, [preparationTime]);
@@ -162,27 +170,39 @@ export default function SubmitScreen() {
             </Text>
             <Div flex={1} />
             <Text fontSize="xs" color="gray300" textAlign="left">
-              ¥00.00
+              ¥{packingPrice}
             </Text>
           </Div>
           <Div row mt={10}>
             <Text fontSize="xs" color="gray300" textAlign="left">
-              叮咚快递
+              配送费
             </Text>
             <Div flex={1} />
             <Text fontSize="xs" color="gray300" textAlign="left">
-              ¥00.00
+              ¥{deliveryAmount}
             </Text>
           </Div>
           <Div row mt={10}>
             <Text fontSize="xs" color="gray300" textAlign="left">
-              叮咚快递
+              满减
             </Text>
             <Div flex={1} />
             <Text fontSize="xs" color="red500" textAlign="left">
-              -¥00.00
+              -¥{fullReduction}
             </Text>
           </Div>
+          {firstBuy !== 0 && (
+            <Div row mt={10}>
+              <Text fontSize="xs" color="gray300" textAlign="left">
+                首单
+              </Text>
+              <Div flex={1} />
+              <Text fontSize="xs" color="red500" textAlign="left">
+                -¥{firstBuy}
+              </Text>
+            </Div>
+          )}
+
           <Div h={1} bg="gray200" mt={5} />
           <Button
             block
@@ -210,7 +230,7 @@ export default function SubmitScreen() {
               小计
             </Text>
             <Text fontSize="xl" ml={20} textAlign="left">
-              ¥{price}
+              ¥{realAmount}
             </Text>
           </Div>
         </Div>

+ 47 - 1
screens/Detail/model.js

@@ -16,6 +16,7 @@ const DetailModel = (now) => ({
   payMethod: 'ALI_PAY',
   remark: '',
   tablewareNum: 1,
+  cartMoneyInfo: {},
   init(id) {
     now({ id: 0, merchantInfo: {}, goodsList: [] });
 
@@ -61,7 +62,7 @@ const DetailModel = (now) => ({
       });
   },
   getCart() {
-    const { id } = now();
+    const { id, calculatePrice } = now();
     now({ cartList: [] });
     if (!id) {
       return Promise.resolve([]);
@@ -74,6 +75,7 @@ const DetailModel = (now) => ({
       })
       .then((res) => {
         now({ remark: '' });
+        calculatePrice(res);
         return Promise.resolve(res);
       });
   },
@@ -216,6 +218,50 @@ const DetailModel = (now) => ({
       now({ remark: '', tablewareNum: 1 });
     }
   },
+  calculatePrice(cartList) {
+    const { chooseInfo } = now(MapModel);
+    if (cartList.length > 0 && chooseInfo.location) {
+      const ids = cartList.map((item) => {
+        return item.shoppingCartId;
+      });
+
+      request
+        .get(`/shoppingCart/calculatePrice`, {
+          params: {
+            cartId: ids[0],
+            longitude: chooseInfo.location.lng,
+            latitude: chooseInfo.location.lat,
+          },
+        })
+        .then((res) => {
+          now({ cartMoneyInfo: res });
+        });
+    } else {
+      now({ cartMoneyInfo: {} });
+    }
+  },
+  // 投诉
+  complaintSave(userId, merchantId, type, content, img) {
+    const { loading, warnning, success } = now(Toast);
+    loading();
+    return request
+      .post(`/merchantComplaint/save`, {
+        data: {
+          userId,
+          merchantId,
+          type,
+          content,
+          img,
+        },
+      })
+      .then(() => {
+        success('提交成功');
+        return Promise.resolve();
+      })
+      .catch((e) => {
+        warnning(e.error);
+      });
+  },
 });
 
 export default DetailModel;

+ 4 - 1
screens/Main/Home/HomeHeader.js

@@ -93,7 +93,10 @@ export default function Header() {
             }}
             title={local ? TchangeToChinese : TchangeToth}
           />
-          <Menu.Item onPress={() => {}} title="版本07.08.2(新增用户选址)" />
+          <Menu.Item
+            onPress={() => {}}
+            title="版本07.08.3(商家举报,购物车订单价格对接)"
+          />
         </Menu>
       </Appbar.Header>
     </>

+ 1 - 0
screens/Order/model.js

@@ -84,6 +84,7 @@ const OrderModel = (now) => ({
       })
       .catch((e) => {
         warnning(e.error);
+        return Promise.reject();
       });
   },
 });