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 + }