优化地址选择组件
This commit is contained in:
@@ -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<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('请选择面料')
|
||||
}
|
||||
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) => {
|
||||
<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()}>
|
||||
|
||||
Reference in New Issue
Block a user