优化地址选择组件
This commit is contained in:
parent
edde094dc4
commit
783dd84263
@ -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({
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
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<number[]>([])
|
||||
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('请选择面料')
|
||||
} else {
|
||||
let ids = selectIds.current.join('-')
|
||||
goLink('/pages/order/index',{ids, sale_mode:selectIndex})
|
||||
}
|
||||
goLink('/pages/order/index',{ids:selectIds.current, sale_mode:selectIndex})
|
||||
|
||||
}
|
||||
|
||||
@ -248,7 +258,7 @@ export default ({show = false, onClose}: param) => {
|
||||
<View className={classnames('iconfont', 'icon-gouwuche', styles.miconfont)}></View>
|
||||
</View>
|
||||
<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>
|
||||
<View className={styles.goPay} onClick={() => orderDetail()}>
|
||||
|
@ -112,7 +112,6 @@ export default ()=>{
|
||||
}else{
|
||||
alert.error("请选择完整地址");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -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<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 (
|
||||
<View className={styles.order_main}>
|
||||
<OrderState state="预约中" desc="客服已接单,等待仓库配布出单..."/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user