对接api3

This commit is contained in:
2022-05-09 10:03:33 +08:00
parent 4c46c6e22d
commit 883c24b7be
14 changed files with 294 additions and 203 deletions
@@ -7,41 +7,44 @@ import Counter from "../counter";
import Big from 'big.js'
import classnames from "classnames";
import styles from "./index.module.scss"
import { memo, useEffect, useState } from "react";
import { memo, useEffect, useRef, useState } from "react";
import {GetColorList} from "@/api/materialColor"
import { useRouter } from "@tarojs/taro";
type param = {
show?: true|false,
onClose?: () => void
onClose?: () => void,
title?: string,
productId?: number
}
export default memo(({show = false, onClose}: param) => {
export default memo(({show = false, onClose, title = '', productId = 0}: param) => {
const selectList = [
{step:1, digits:2, title:'剪板', unit:'米'},
{step:1, digits:2, title:'散剪', unit:'米'},
{step:1, digits:0, title:'大货', unit:'件'}
{id: 0, step:1, digits:0, title:'大货', unit:'件', eunit:'kg'},
{id: 1, step:1, digits:2, title:'剪板', unit:'米', eunit:'m'},
{id: 2, step:1, digits:2, title:'散剪', unit:'米', eunit:'m'},
]
const [selectIndex, setSelectIndex] = useState(0)
const selectProduct = (index:number) => {
setSelectIndex(index)
}
//获取面料颜色列表
const {fetchData:colorFetchData} = GetColorList()
const [list, setList] = useState<any[]>([])
const [loading, setLoading] = useState(false)
console.log('执行执行')
const condition = useRef({physical_warehouse:1, sale_mode:selectIndex, product_id:0})
const getColorList = async () => {
setLoading(() => true)
let {data} = await colorFetchData(condition.current)
setList([...data.list])
setLoading(() => false)
}
useEffect(() => {
if(!show) return
let lists:any[] = []
for(let i = 0; i < 20; i++) {
lists = [...lists, {
title:`${i}#薄荷绿`,
subtitle: '0770# 21S单面平纹(食毛)',
tag: '剪板',
count:0,
show: false,
}]
}
setList([...lists])
if(show) {
condition.current.product_id = productId
getColorList()
}
}, [show])
useEffect(() => {
@@ -62,7 +65,6 @@ export default memo(({show = false, onClose}: param) => {
setShowPopup(false)
}
//计算总数量和总米/件数
const [selectCount, setSelectCount] = useState({
sumCount: 0,
@@ -98,12 +100,17 @@ export default memo(({show = false, onClose}: param) => {
setSearchShow(true)
}
const addShopCart = () => {
}
return (
<View className={styles.shop_cart_main}>
<Popup showTitle={false} show={showPopup} onClose={() => closePopup()}>
<View className={styles.popup_con}>
<View className={styles.header}>0770# 21S单面平纹(食毛)</View>
<View className={styles.header}>{title}</View>
<View className={styles.search}>
<View className={styles.search_title}>下单类型:</View>
<View className={styles.search_list}>
@@ -119,9 +126,10 @@ export default memo(({show = false, onClose}: param) => {
<View className={styles.text} onClick={() => setSearchShow(false)}>取消</View>
</View>}
<View className={styles.colorNum}>
<View className={styles.title}>颜色分类 (13)</View>
<View className={styles.title}>颜色分类 (13) {list.length}</View>
<View className={classnames('iconfont icon-sousuo', styles.miconfont)} onClick={() => changeSearchShow()}></View>
</View>
<View className={styles.product_color_con}>
{list.length > 0&&<InfiniteScroll>
<View className={styles.color_con}>
@@ -156,7 +164,7 @@ export default memo(({show = false, onClose}: param) => {
<View className={styles.buy_btn}>
<View className={styles.buy_btn_con}>
<View className={styles.count}>当前已选{selectCount.kindCount}种,共{selectCount.sumCount}{selectList[selectIndex].unit}</View>
<View className={classnames(styles.add_cart, selectCount.kindCount&&styles.select_add_cart)}>加入购物车</View>
<View className={classnames(styles.add_cart, selectCount.kindCount&&styles.select_add_cart)} onClick={() => addShopCart()}>加入购物车</View>
</View>
</View>
</View>