优化地址选择组件

This commit is contained in:
czm 2022-05-12 18:11:14 +08:00
parent 0066256009
commit 4d3135ed76
6 changed files with 55 additions and 21 deletions

View File

@ -10,6 +10,7 @@ import Qs from 'qs'
export const goLink = (path = '', params = {}, type:false|true = false) => { export const goLink = (path = '', params = {}, type:false|true = false) => {
if(path) { if(path) {
let params_str = Qs.stringify(params) let params_str = Qs.stringify(params)
console.log('params_str::',params_str)
path = params_str?path+'?'+params_str:path path = params_str?path+'?'+params_str:path
if(!type) { if(!type) {
Taro.navigateTo({ Taro.navigateTo({

View File

@ -8,7 +8,7 @@ import { GetAddressListApi } from "@/api/addressList";
import { alert } from "@/common/common"; 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 = { type Params = {
addressOnSelect?: (val:DefaultValueParm[]) => void, addressOnSelect?: (val:DefaultValueParm[]) => void,

View File

@ -20,9 +20,9 @@
.search{ .search{
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
padding: 0 20px; padding: 0 30px;
.search_item{ .search_item{
width: 148px; width: 200px;
height: 55px; height: 55px;
text-align: center; text-align: center;
line-height: 55px; line-height: 55px;

View File

@ -5,7 +5,7 @@ import MCheckbox from "@/components/checkbox";
import LoadingCard from "@/components/loadingCard"; import LoadingCard from "@/components/loadingCard";
import InfiniteScroll from "@/components/infiniteScroll"; import InfiniteScroll from "@/components/infiniteScroll";
import styles from "./index.module.scss" 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 Taro from "@tarojs/taro";
import { alert, goLink } from "@/common/common"; import { alert, goLink } from "@/common/common";
import {GetShoppingCartApi, DelShoppingCartApi} from "@/api/shopCart" import {GetShoppingCartApi, DelShoppingCartApi} from "@/api/shopCart"
@ -17,14 +17,14 @@ type param = {
} }
export default ({show = false, onClose}: param) => { export default ({show = false, onClose}: param) => {
const selectList = [ const selectList = [
{value:-1, title:'不限', unit:'', eunit:''}, // {value:-1, title:'不限', unit:'', eunit:''},
{value:0, title:'大货', unit:'件', eunit:'kg'}, {value:0, title:'大货', unit:'件', eunit:'kg'},
{value:1,title:'剪板', unit:'米', eunit:'m'}, {value:1,title:'剪板', unit:'米', eunit:'m'},
{value:2,title:'散剪', unit:'米', eunit:'kg'}, {value:2,title:'散剪', unit:'米', eunit:'kg'},
] ]
const [selectIndex, setSelectIndex] = useState(-1) const [selectIndex, setSelectIndex] = useState(0)
const selectProduct = (index:number) => { const selectProduct = (index:number) => {
setSelectIndex(index) setSelectIndex(index)
} }
@ -61,18 +61,16 @@ export default ({show = false, onClose}: param) => {
//初始化全部数据 //初始化全部数据
const initList = (color_list) => { const initList = (color_list) => {
if(selectIndex == -1) { color_list?.map(item => {
color_list?.map(item => { if(selectIndex == item.sale_mode) item.select = true
item.select = true })
})
}
} }
//显示是展示数据 //显示是展示数据
useEffect(() => { useEffect(() => {
if(!show) { if(!show) {
setList([]) setList([])
setSelectIndex(-1) setSelectIndex(0)
} else { } else {
getShoppingCart() getShoppingCart()
} }
@ -167,6 +165,7 @@ export default ({show = false, onClose}: param) => {
//获取面料选中的id //获取面料选中的id
const selectIds = useRef<number[]>([]) const selectIds = useRef<number[]>([])
const getSelectId = () => { const getSelectId = () => {
selectIds.current = []
list?.map(item => { list?.map(item => {
if(selectIndex == -1 || selectIndex == item.sale_mode) { if(selectIndex == -1 || selectIndex == item.sale_mode) {
item.select&&selectIds.current.push(item.id) 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' 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 = () => { const orderDetail = () => {
if(selectIndex == -1 ) { getSelectId()
console.log(selectIndex, selectIds.current) if(selectIds.current.length == 0) {
alert.error('请选择面料') alert.error('请选择面料')
} } else {
goLink('/pages/order/index',{ids:selectIds.current, sale_mode:selectIndex}) let ids = selectIds.current.join('-')
goLink('/pages/order/index',{ids, sale_mode:selectIndex})
}
} }
@ -248,7 +258,7 @@ export default ({show = false, onClose}: param) => {
<View className={classnames('iconfont', 'icon-gouwuche', styles.miconfont)}></View> <View className={classnames('iconfont', 'icon-gouwuche', styles.miconfont)}></View>
</View> </View>
<View className={styles.price_con}> <View className={styles.price_con}>
<View className={styles.price_real}><text></text>200</View> <View className={styles.price_real}><text></text>{estimatePrice}</View>
<View className={styles.price_forecast}></View> <View className={styles.price_forecast}></View>
</View> </View>
<View className={styles.goPay} onClick={() => orderDetail()}> <View className={styles.goPay} onClick={() => orderDetail()}>

View File

@ -101,7 +101,6 @@ export default ()=>{
}else{ }else{
alert.error("请选择完整地址"); alert.error("请选择完整地址");
} }
} }
return ( return (

View File

@ -1,9 +1,10 @@
import { SaleOrderPreViewApi } from "@/api/order";
import Popup from "@/components/popup"; import Popup from "@/components/popup";
import SearchInput from "@/components/searchInput"; import SearchInput from "@/components/searchInput";
import { Text, Textarea, View } from "@tarojs/components" import { Text, Textarea, View } from "@tarojs/components"
import Taro from "@tarojs/taro"; import Taro, { useRouter } from "@tarojs/taro";
import classnames from "classnames"; import classnames from "classnames";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useRef, useState } from "react";
import AddressInfo from "./components/addressInfo"; import AddressInfo from "./components/addressInfo";
import EstimatedAmount from "./components/estimatedAmount"; import EstimatedAmount from "./components/estimatedAmount";
import KindList from "./components/kindList"; 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<orderPreParam>({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 ( return (
<View className={styles.order_main}> <View className={styles.order_main}>
<OrderState state="预约中" desc="客服已接单,等待仓库配布出单..."/> <OrderState state="预约中" desc="客服已接单,等待仓库配布出单..."/>
@ -65,4 +89,4 @@ import styles from './index.module.scss'
<View className="common_safe_area_y"></View> <View className="common_safe_area_y"></View>
</View> </View>
) )
} }