From 783dd84263c7cdf3a4d7ba8670ee0439765c0758 Mon Sep 17 00:00:00 2001 From: czm <2192718639@qq.com> Date: Thu, 12 May 2022 18:11:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/common.ts | 1 + src/components/address/index.tsx | 2 +- src/components/shopCart/index.module.scss | 4 +-- src/components/shopCart/index.tsx | 38 ++++++++++++++--------- src/pages/addressAdd/index.tsx | 1 - src/pages/order/index.tsx | 30 ++++++++++++++++-- 6 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/common/common.ts b/src/common/common.ts index 5081eb8..080373b 100644 --- a/src/common/common.ts +++ b/src/common/common.ts @@ -10,6 +10,7 @@ import Qs from 'qs' export const goLink = (path = '', params = {}, type:false|true = false) => { if(path) { let params_str = Qs.stringify(params) + console.log('params_str::',params_str) path = params_str?path+'?'+params_str:path if(!type) { Taro.navigateTo({ diff --git a/src/components/address/index.tsx b/src/components/address/index.tsx index b3b9072..491ac06 100644 --- a/src/components/address/index.tsx +++ b/src/components/address/index.tsx @@ -8,7 +8,7 @@ import { GetAddressListApi } from "@/api/addressList"; import { alert } from "@/common/common"; -type DefaultValueParm = {name: string, id:string|number, level: number|string} +type DefaultValueParm = {name: string, id:string|number, level?: number|string} type Params = { addressOnSelect?: (val:DefaultValueParm[]) => void, diff --git a/src/components/shopCart/index.module.scss b/src/components/shopCart/index.module.scss index ca891ed..9af0c2e 100644 --- a/src/components/shopCart/index.module.scss +++ b/src/components/shopCart/index.module.scss @@ -20,9 +20,9 @@ .search{ display: flex; justify-content: space-between; - padding: 0 20px; + padding: 0 30px; .search_item{ - width: 148px; + width: 200px; height: 55px; text-align: center; line-height: 55px; diff --git a/src/components/shopCart/index.tsx b/src/components/shopCart/index.tsx index 9d9f7c5..dc900f4 100644 --- a/src/components/shopCart/index.tsx +++ b/src/components/shopCart/index.tsx @@ -5,7 +5,7 @@ import MCheckbox from "@/components/checkbox"; import LoadingCard from "@/components/loadingCard"; import InfiniteScroll from "@/components/infiniteScroll"; import styles from "./index.module.scss" -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import Taro from "@tarojs/taro"; import { alert, goLink } from "@/common/common"; import {GetShoppingCartApi, DelShoppingCartApi} from "@/api/shopCart" @@ -17,14 +17,14 @@ type param = { } export default ({show = false, onClose}: param) => { const selectList = [ - {value:-1, title:'不限', unit:'', eunit:''}, + // {value:-1, title:'不限', unit:'', eunit:''}, {value:0, title:'大货', unit:'件', eunit:'kg'}, {value:1,title:'剪板', unit:'米', eunit:'m'}, {value:2,title:'散剪', unit:'米', eunit:'kg'}, ] - const [selectIndex, setSelectIndex] = useState(-1) + const [selectIndex, setSelectIndex] = useState(0) const selectProduct = (index:number) => { setSelectIndex(index) } @@ -61,18 +61,16 @@ export default ({show = false, onClose}: param) => { //初始化全部数据 const initList = (color_list) => { - if(selectIndex == -1) { - color_list?.map(item => { - item.select = true - }) - } + color_list?.map(item => { + if(selectIndex == item.sale_mode) item.select = true + }) } //显示是展示数据 useEffect(() => { if(!show) { setList([]) - setSelectIndex(-1) + setSelectIndex(0) } else { getShoppingCart() } @@ -167,6 +165,7 @@ export default ({show = false, onClose}: param) => { //获取面料选中的id const selectIds = useRef([]) const getSelectId = () => { + selectIds.current = [] list?.map(item => { if(selectIndex == -1 || selectIndex == item.sale_mode) { item.select&&selectIds.current.push(item.id) @@ -185,13 +184,24 @@ export default ({show = false, onClose}: param) => { return item.sale_mode == 0? item.roll + '件': item.length + 'm' }, []) + //预估金额 + const estimatePrice = useMemo(() => { + let count = 0 + list.map(item => { + if(item.select) count += item.sale_price + }) + return Number(formatMillionYuan(count, 100).num) + },[list]) + //去结算 const orderDetail = () => { - if(selectIndex == -1 ) { - console.log(selectIndex, selectIds.current) + getSelectId() + if(selectIds.current.length == 0) { alert.error('请选择面料') - } - goLink('/pages/order/index',{ids:selectIds.current, sale_mode:selectIndex}) + } else { + let ids = selectIds.current.join('-') + goLink('/pages/order/index',{ids, sale_mode:selectIndex}) + } } @@ -248,7 +258,7 @@ export default ({show = false, onClose}: param) => { - 200 + {estimatePrice} 预估金额 orderDetail()}> diff --git a/src/pages/addressAdd/index.tsx b/src/pages/addressAdd/index.tsx index 63721ed..0399a4d 100644 --- a/src/pages/addressAdd/index.tsx +++ b/src/pages/addressAdd/index.tsx @@ -112,7 +112,6 @@ export default ()=>{ }else{ alert.error("请选择完整地址"); } - } return ( diff --git a/src/pages/order/index.tsx b/src/pages/order/index.tsx index bc303c0..c53952b 100644 --- a/src/pages/order/index.tsx +++ b/src/pages/order/index.tsx @@ -1,9 +1,10 @@ +import { SaleOrderPreViewApi } from "@/api/order"; import Popup from "@/components/popup"; import SearchInput from "@/components/searchInput"; import { Text, Textarea, View } from "@tarojs/components" -import Taro from "@tarojs/taro"; +import Taro, { useRouter } from "@tarojs/taro"; import classnames from "classnames"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import AddressInfo from "./components/addressInfo"; import EstimatedAmount from "./components/estimatedAmount"; import KindList from "./components/kindList"; @@ -25,6 +26,29 @@ import styles from './index.module.scss' } }) } + //获取购物车传过来的id + type orderPreParam = {shopping_cart_product_color_list:{shopping_cart_product_color_id:number}[], sale_mode:number} + const router = useRouter() + const idsAndSaleModel = useRef({shopping_cart_product_color_list:[], sale_mode:0}) + useEffect(() => { + idsAndSaleModel.current.sale_mode = Number(router.params.sale_mode) + router.params.ids?.split('-')?.map(item => { + return idsAndSaleModel.current.shopping_cart_product_color_list?.push({ + shopping_cart_product_color_id: Number(item) + }) + }) + getSaleOrderPreView() + }, []) + + //获取销售订单预览图 + const {fetchData} = SaleOrderPreViewApi() + const getSaleOrderPreView = async () => { + if(idsAndSaleModel.current.shopping_cart_product_color_list?.length > 0) { + let res = await fetchData(idsAndSaleModel.current) + console.log('res::', res) + } + } + return ( @@ -65,4 +89,4 @@ import styles from './index.module.scss' ) - } \ No newline at end of file + } From c403c2acb13c2a04a1bcd03c1ce75b21dea56df4 Mon Sep 17 00:00:00 2001 From: li tong bao <2903733959@qq.com> Date: Wed, 18 May 2022 18:38:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?--=E5=9C=B0=E5=9D=80=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AddressList/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/AddressList/index.tsx b/src/components/AddressList/index.tsx index ae48293..e412e63 100644 --- a/src/components/AddressList/index.tsx +++ b/src/components/AddressList/index.tsx @@ -110,10 +110,10 @@ const AddressList = memo((props:Params)=>{ ); }): - addButtonEnabled&&暂未添加地址 + 暂未添加地址 } - 添加收货地址 + {addButtonEnabled&&添加收货地址} ) })