This commit is contained in:
li tong bao
2022-05-18 18:22:37 +08:00
6 changed files with 55 additions and 21 deletions
+1 -1
View File
@@ -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,
+2 -2
View File
@@ -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;
+24 -14
View File
@@ -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()}>