diff --git a/config/index.js b/config/index.js index 09a4522..67d84a9 100644 --- a/config/index.js +++ b/config/index.js @@ -10,6 +10,8 @@ const CURRENT_VERSION = `Version: ${JSON.stringify(process.env.CODE_BRANCH || ve '', ) +console.log('process::', process) + const config = { projectName: 'EShop', date: '2022-4-6', diff --git a/src/components/addCollection/index.tsx b/src/components/addCollection/index.tsx index dfa0fe5..d06fdb4 100644 --- a/src/components/addCollection/index.tsx +++ b/src/components/addCollection/index.tsx @@ -1,53 +1,58 @@ -import Popup from "@/components/popup"; -import { Input, ScrollView, Text, View } from "@tarojs/components"; -import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"; -import classnames from "classnames"; -import styles from './index.module.scss' -import TextareaEnhance from "@/components/textareaEnhance"; -import { CreateFavoriteApi, FavoriteListApi } from "@/api/favorite"; -import { alert, goLink } from "@/common/common"; -import { getFilterData } from "@/common/util"; +import Popup from '@/components/popup' +import { Input, ScrollView, Text, View } from '@tarojs/components' +import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react' +import classnames from 'classnames' +import styles from './index.module.scss' +import TextareaEnhance from '@/components/textareaEnhance' +import { CreateFavoriteApi, FavoriteListApi } from '@/api/favorite' +import { alert, goLink } from '@/common/common' +import { getFilterData } from '@/common/util' //原因选择 type ReasonInfoParam = { - show?: boolean, //显示 - onClose?: () => void, //关闭 - onAdd?: (val: any) => void + show?: boolean //显示 + onClose?: () => void //关闭 + onAdd?: (val: any) => void } -export default memo(({show = false, onClose, onAdd}: ReasonInfoParam) => { - //获取列表 - const [list, setList] = useState([]) - const {fetchData: fetchDataList} = FavoriteListApi() - const getFavoriteList = async () => { - let res = await fetchDataList(getFilterData()) - setList(() => res.data.list) - } - useEffect(() => { - if(show) getFavoriteList() - }, [show]) +export default memo(({ show = false, onClose, onAdd }: ReasonInfoParam) => { + //获取列表 + const [list, setList] = useState([]) + const { fetchData: fetchDataList } = FavoriteListApi() + const getFavoriteList = async () => { + let res = await fetchDataList(getFilterData()) + setList(() => res.data.list) + } + useEffect(() => { + if (show) getFavoriteList() + }, [show]) - const onCreate = () => { - onClose?.() - goLink('/pages/collection/index') - } + const onCreate = () => { + onClose?.() + goLink('/pages/collection/index') + } - return ( - - - - 选择收藏夹 - - - 新建 - - - - {list?.map((item: any) => onAdd?.(item)} className={styles.collection_item}> - {item.name}({item.product_color_list?.length||0}) - {item.remark} - )} - + return ( + + + + 选择收藏夹 + + + 新建 + + + + {list?.map((item: any) => ( + onAdd?.(item)} className={styles.collection_item}> + + {item.name} + ({item.product_color_list?.length || 0}) + + {item.remark} - - ) -}) \ No newline at end of file + ))} + + + + ) +}) diff --git a/src/components/shopCart/index.tsx b/src/components/shopCart/index.tsx index 67c8f61..e4f245b 100644 --- a/src/components/shopCart/index.tsx +++ b/src/components/shopCart/index.tsx @@ -1,380 +1,406 @@ -import {Image, ScrollView, View } from "@tarojs/components" -import Popup from "@/components/popup" -import classnames from "classnames"; -import MCheckbox from "@/components/checkbox"; -import LoadingCard from "@/components/loadingCard"; -import InfiniteScroll from "@/components/infiniteScroll"; -import styles from "./index.module.scss" -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import Taro from "@tarojs/taro"; -import { alert, goLink } from "@/common/common"; -import {GetShoppingCartApi, DelShoppingCartApi, UpdateShoppingCartApi} from "@/api/shopCart" -import { formatHashTag, formatImgUrl, formatPriceDiv } from "@/common/fotmat"; -import { setParam } from "@/common/system"; -import { debounce, throttle } from "@/common/util"; -import Counter from "../counter"; -import { ApplyOrderAccessApi, GetAdminUserInfoApi, SubscriptionMessageApi } from "@/api/user"; -import useCommonData from "@/use/useCommonData"; -import BindSalesmanPopup from "../bindSalesmanPopup"; -import LabAndImgShow from "../LabAndImgShow"; -import LabAndImg from "../LabAndImg"; +import { Image, ScrollView, View } from '@tarojs/components' +import Popup from '@/components/popup' +import classnames from 'classnames' +import MCheckbox from '@/components/checkbox' +import LoadingCard from '@/components/loadingCard' +import InfiniteScroll from '@/components/infiniteScroll' +import styles from './index.module.scss' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import Taro from '@tarojs/taro' +import { alert, goLink } from '@/common/common' +import { GetShoppingCartApi, DelShoppingCartApi, UpdateShoppingCartApi } from '@/api/shopCart' +import { formatHashTag, formatImgUrl, formatPriceDiv } from '@/common/fotmat' +import { setParam } from '@/common/system' +import { debounce, throttle } from '@/common/util' +import Counter from '../counter' +import { ApplyOrderAccessApi, GetAdminUserInfoApi, SubscriptionMessageApi } from '@/api/user' +import useCommonData from '@/use/useCommonData' +import BindSalesmanPopup from '../bindSalesmanPopup' +import LabAndImgShow from '../LabAndImgShow' +import LabAndImg from '../LabAndImg' type param = { - show?: true|false, - onClose?: () => void, - intoStatus?: 'again'|'shop', - default_sale_mode?: number, //面料类型(0:大货, 1:剪版,2:散剪 + show?: true | false + onClose?: () => void + intoStatus?: 'again' | 'shop' + default_sale_mode?: number //面料类型(0:大货, 1:剪版,2:散剪 } -export default ({show = false, onClose, intoStatus='shop', default_sale_mode}: param) => { - const selectList = [ - {value:0, title:'大货', unit:'条', eunit:'kg', step:1, digits:0, minNum:1, maxNum:100000, defaultNum:1}, - {value:1,title:'剪板', unit:'米', eunit:'m', step:1, digits:2, minNum:0.5, maxNum:9.99, defaultNum:1}, - {value:2,title:'散剪', unit:'米', eunit:'kg', step:1, digits:2, minNum:5, maxNum:100000, defaultNum:10}, - ] +export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode }: param) => { + const selectList = [ + { value: 0, title: '大货', unit: '条', eunit: 'kg', step: 1, digits: 0, minNum: 1, maxNum: 100000, defaultNum: 1 }, + { value: 1, title: '剪板', unit: '米', eunit: 'm', step: 1, digits: 2, minNum: 0.5, maxNum: 9.99, defaultNum: 1 }, + { value: 2, title: '散剪', unit: '米', eunit: 'kg', step: 1, digits: 2, minNum: 5, maxNum: 100000, defaultNum: 10 }, + ] - //切换面料类型 - const [selectIndex, setSelectIndex] = useState(default_sale_mode||0) - const selectProduct = (index:number) => { - setSelectIndex(index) - } - useEffect(() => { - setSelectIndex(() => default_sale_mode!) - }, [default_sale_mode]) + //切换面料类型 + const [selectIndex, setSelectIndex] = useState(default_sale_mode || 0) + const selectProduct = (index: number) => { + setSelectIndex(index) + } + useEffect(() => { + setSelectIndex(() => default_sale_mode!) + }, [default_sale_mode]) - useEffect(() => { - resetList() - setSelectStatus(true) - }, [selectIndex]) + useEffect(() => { + resetList() + setSelectStatus(true) + }, [selectIndex]) - //获取购物车数据数量 - const {setShopCount} = useCommonData() + //获取购物车数据数量 + const { setShopCount } = useCommonData() - //重置勾选数据 - const resetList = () => { - list?.map(item => { - if(selectIndex == item.sale_mode || selectIndex == -1) { - checkboxData[item.id] = true - } else { - checkboxData[item.id] = false - } - }) - setCheckboxData(() => ({...checkboxData})) - } - - //获取数据 - const [list, setList] = useState([]) - const [loading, setLoading] = useState(false) - const {fetchData} = GetShoppingCartApi() - const getShoppingCart = async () => { - const {data} = await fetchData() - let color_list = data.color_list||[] - setShopCount(color_list.length) - initList(color_list) - setList(color_list) - setLoading(false) - } - - //初始化全部数据默认勾选 - const [checkboxData, setCheckboxData] = useState<{[index:number]:true|false}>({}) - const initStatus = useRef(false) - const initList = (color_list) => { - if(initStatus.current) { - color_list?.map(item => { - if(selectIndex == item.sale_mode) checkboxData[item.id] = true - }) - initStatus.current = false - } - setCheckboxData(() => checkboxData) - } - - //显示是展示数据 - useEffect(() => { - if(!show) { - setList([]) - setSelectIndex(default_sale_mode||0) - } else { - setLoading(true) - initStatus.current = true - getShoppingCart() - setShowBindSalesman(() => false) - } - }, [show]) - - useEffect(() => { - return () => { - setList([]) - } - }, []) - - const [showPopup, setShowPopup] = useState(false) - useEffect(() => { - setShowPopup(show) - }, [show]) - - //全选反选 - const [selectStatus, setSelectStatus] = useState(false) - const selectAll = () => { - list.map(item => { - if(selectIndex == item.sale_mode || selectIndex == -1) - checkboxData[item.id] = !selectStatus - }) - setSelectStatus(!selectStatus) - setCheckboxData(() => ({...checkboxData})) - } - - //checkbox选中回调 - const selectCallBack = (item) => { + //重置勾选数据 + const resetList = () => { + list?.map((item) => { + if (selectIndex == item.sale_mode || selectIndex == -1) { checkboxData[item.id] = true - checkSelect() - setCheckboxData(() => ({...checkboxData})) - } - - //checkbox选中判断是否全部选中,全部选中后是全选,否则反选 - const checkSelect = () => { - let list_count = 0 - let select_count = 0 - list?.map(item => { - if(selectIndex == -1 || selectIndex == item.sale_mode) { - list_count ++ - if(checkboxData[item.id]) select_count++ - } - }) - setSelectStatus(select_count == list_count) - } - - //checkbox关闭回调 - const colseCallBack = (item) => { + } else { checkboxData[item.id] = false - checkSelect() - setCheckboxData(() => ({...checkboxData})) + } + }) + setCheckboxData(() => ({ ...checkboxData })) + } + + //获取数据 + const [list, setList] = useState([]) + const [loading, setLoading] = useState(false) + const { fetchData } = GetShoppingCartApi() + const getShoppingCart = async () => { + const { data } = await fetchData() + let color_list = data.color_list || [] + setShopCount(color_list.length) + initList(color_list) + setList(color_list) + setLoading(false) + } + + //初始化全部数据默认勾选 + const [checkboxData, setCheckboxData] = useState<{ [index: number]: true | false }>({}) + const initStatus = useRef(false) + const initList = (color_list) => { + if (initStatus.current) { + color_list?.map((item) => { + if (selectIndex == item.sale_mode) checkboxData[item.id] = true + }) + initStatus.current = false } + setCheckboxData(() => checkboxData) + } - //popup关闭 - const closePopup = () => { - onClose?.() - setShowPopup(false) + //显示是展示数据 + useEffect(() => { + if (!show) { + setList([]) + setSelectIndex(default_sale_mode || 0) + } else { + setLoading(true) + initStatus.current = true + getShoppingCart() + setShowBindSalesman(() => false) } + }, [show]) - - - //删除购物车内容 - const {fetchData:delShopFetchData} = DelShoppingCartApi() - const delSelect = () => { - getSelectId() - if(selectIds.current.length <= 0) return alert.none('请选择要删除的面料!') - Taro.showModal({ - content: '删除所选商品?', - success: async function (res) { - if (res.confirm) { - const res = await delShopFetchData({id:selectIds.current}) - if(res.success) { - getShoppingCart() - Taro.showToast({ - title: '成功', - icon: 'success', - }) - - } else { - Taro.showToast({ - title: res.msg, - icon: 'none', - }) - } - - } else if (res.cancel) { - console.log('用户点击取消') - } - } - }) + useEffect(() => { + return () => { + setList([]) } + }, []) - //获取面料选中的id - const selectIds = useRef([]) - const getSelectId = () => { - selectIds.current = [] - list?.map(item => { - if(selectIndex == -1 || selectIndex == item.sale_mode) { - checkboxData[item.id]&&selectIds.current.push(item.id) - } - }) - } + const [showPopup, setShowPopup] = useState(false) + useEffect(() => { + setShowPopup(show) + }, [show]) - //格式化金额 - const formatPirce = useCallback((price) => { - return Number(formatPriceDiv(price)) - }, []) + //全选反选 + const [selectStatus, setSelectStatus] = useState(false) + const selectAll = () => { + list.map((item) => { + if (selectIndex == item.sale_mode || selectIndex == -1) checkboxData[item.id] = !selectStatus + }) + setSelectStatus(!selectStatus) + setCheckboxData(() => ({ ...checkboxData })) + } - //格式化数量 - const formatCount = useCallback((item) => { - return item.sale_mode == 0? item.roll : (item.length/100) - }, []) + //checkbox选中回调 + const selectCallBack = (item) => { + checkboxData[item.id] = true + checkSelect() + setCheckboxData(() => ({ ...checkboxData })) + } - //格式化单位 - const formatUnit = useCallback((item) => { - return item.sale_mode == 0? '条':'米' - }, []) + //checkbox选中判断是否全部选中,全部选中后是全选,否则反选 + const checkSelect = () => { + let list_count = 0 + let select_count = 0 + list?.map((item) => { + if (selectIndex == -1 || selectIndex == item.sale_mode) { + list_count++ + if (checkboxData[item.id]) select_count++ + } + }) + setSelectStatus(select_count == list_count) + } - //预估金额和总条数 - const estimatePrice = useMemo(() => { - let estimate_amount = 0 - let product_list = new Set() //面料 - let color_count = 0 //颜色数量 - let all_count = 0 //总数量 - list.map(item => { - if(checkboxData[item.id]) { - estimate_amount += item.estimate_amount - product_list.add(item.product_id) - color_count++ - all_count += item.sale_mode == 0?item.roll: (item.length) - } - }) - let all_count_text = selectIndex == 0?all_count + ' 条': (all_count/100) + ' 米' - return {price: Number(formatPriceDiv(estimate_amount)).toFixed(2), countText: `已选 ${product_list.size} 种面料,${color_count} 个颜色,共 ${all_count_text}`, color_count} - },[list, checkboxData]) - + //checkbox关闭回调 + const colseCallBack = (item) => { + checkboxData[item.id] = false + checkSelect() + setCheckboxData(() => ({ ...checkboxData })) + } - //去结算 - const {fetchData: useFetchData} = GetAdminUserInfoApi() - const {fetchData: applyOrderAccessFetchData} = ApplyOrderAccessApi() - const orderDetail = throttle( async () => { - let res = await useFetchData() - if(res.data.order_access_status !== 3) { - if(res.data.order_access_status == 1) applyOrderAccessFetchData() - setShowBindSalesman(() => true) - onClose?.() - return false - } - getSelectId() - if(selectIds.current.length == 0) { - alert.error('请选择面料') - } else { - let ids = selectIds.current.join('-') - setParam({ids, sale_mode:selectIndex}) //临时存储 - closePopup() - if(intoStatus == "again") { - goLink('/pages/order/comfirm', {}, 'redirectTo') - } else { - goLink('/pages/order/comfirm') - } - } - }, 500) + //popup关闭 + const closePopup = () => { + onClose?.() + setShowPopup(false) + } - - //计数组件-当后端修改完成才修改前端显示 - const {fetchData: fetchDataUpdateShoppingCart} = UpdateShoppingCartApi() - const [UpdateShoppingCartLoading, setUpdateShoppingCartLoading] = useState(false) - const getInputValue = debounce(async (num, item) => { - let roll = item.sale_mode == 0?parseFloat(num):0 - let length = item.sale_mode != 0?(parseFloat(num)*100):0 - setUpdateShoppingCartLoading(() => true) - let res = await fetchDataUpdateShoppingCart({id: item.id, roll, length}) - setUpdateShoppingCartLoading(() => false) - if(res.success) { + //删除购物车内容 + const { fetchData: delShopFetchData } = DelShoppingCartApi() + const delSelect = () => { + getSelectId() + if (selectIds.current.length <= 0) return alert.none('请选择要删除的面料!') + Taro.showModal({ + content: '删除所选商品?', + success: async function (res) { + if (res.confirm) { + const res = await delShopFetchData({ id: selectIds.current }) + if (res.success) { getShoppingCart() + Taro.showToast({ + title: '成功', + icon: 'success', + }) + } else { + Taro.showToast({ + title: res.msg, + icon: 'none', + }) + } + } else if (res.cancel) { + console.log('用户点击取消') } - }, 300) + }, + }) + } - //绑定业务员和电话号码 - const [showBindSalesman, setShowBindSalesman] = useState(false) + //获取面料选中的id + const selectIds = useRef([]) + const getSelectId = () => { + selectIds.current = [] + list?.map((item) => { + if (selectIndex == -1 || selectIndex == item.sale_mode) { + checkboxData[item.id] && selectIds.current.push(item.id) + } + }) + } - //显示图片弹窗 - const [showLabImage, setShowLabImage] = useState(false) - const [labImageValue, setLabImageValue] = useState() - const getLabAndImg = useCallback((val) => { - setShowLabImage(() => true) - setLabImageValue(val) - }, []) - const closeLabImgShow = useCallback(() => { - setShowLabImage(() => false) - }, []) + //格式化金额 + const formatPirce = useCallback((price) => { + return Number(formatPriceDiv(price)) + }, []) - return ( - - closePopup()} > - - - {!selectStatus?'全选':'反选'} - - - 删除所选 - - - {estimatePrice.countText} - - {selectList.map((item) => { - return selectProduct(item.value)} className={classnames(styles.search_item, (selectIndex==item.value)&&styles.search_item_select)}>{item.title} - })} - - - {loading&&} - {!loading&&list?.length > 0&& - - {list?.map((item, index) => { - return - - selectCallBack(item)} onClose={() => colseCallBack(item)}/> - - - - - - - {formatHashTag(item.product_code, item.product_name)} - {formatPirce(item.sale_price)}/{selectList[item.sale_mode].eunit} - - - - {item.product_color_code +' ' + item.product_color_name} - {item.sale_mode_name} - - - getInputValue(e, item)} - defaultNum={formatCount(item)} - step={selectList[selectIndex].step} - digits={selectList[selectIndex].digits} - onClickBtn={(e) => getInputValue(e, item)} - unit={formatUnit(item)} - minNum={selectList[selectIndex].minNum} - maxNum={selectList[selectIndex].maxNum} - disable={UpdateShoppingCartLoading} - /> - - - - - })} - - } - {!loading&&list?.length == 0 && - 暂未选择商品 - 去选购 - } - - - - - - - - - {estimatePrice.price} - 预估金额 - - orderDetail()}> - 去结算({estimatePrice.color_count}) - - - + //格式化数量 + const formatCount = useCallback((item) => { + return item.sale_mode == 0 ? item.roll : item.length / 100 + }, []) + + //格式化单位 + const formatUnit = useCallback((item) => { + return item.sale_mode == 0 ? '条' : '米' + }, []) + + //预估金额和总条数 + const estimatePrice = useMemo(() => { + let estimate_amount = 0 + let product_list = new Set() //面料 + let color_count = 0 //颜色数量 + let all_count = 0 //总数量 + list.map((item) => { + if (checkboxData[item.id]) { + estimate_amount += item.estimate_amount + product_list.add(item.product_id) + color_count++ + all_count += item.sale_mode == 0 ? item.roll : item.length + } + }) + let all_count_text = selectIndex == 0 ? all_count + ' 条' : all_count / 100 + ' 米' + return { + price: Number(formatPriceDiv(estimate_amount)).toFixed(2), + countText: `已选 ${product_list.size} 种面料,${color_count} 个颜色,共 ${all_count_text}`, + color_count, + } + }, [list, checkboxData]) + + //去结算 + const { fetchData: useFetchData } = GetAdminUserInfoApi() + const { fetchData: applyOrderAccessFetchData } = ApplyOrderAccessApi() + const orderDetail = throttle(async () => { + let res = await useFetchData() + if (res.data.order_access_status !== 3) { + if (res.data.order_access_status == 1) applyOrderAccessFetchData() + setShowBindSalesman(() => true) + onClose?.() + return false + } + getSelectId() + if (selectIds.current.length == 0) { + alert.error('请选择面料') + } else { + let ids = selectIds.current.join('-') + setParam({ ids, sale_mode: selectIndex }) //临时存储 + closePopup() + if (intoStatus == 'again') { + goLink('/pages/order/comfirm', {}, 'redirectTo') + } else { + goLink('/pages/order/comfirm') + } + } + }, 500) + + //计数组件-当后端修改完成才修改前端显示 + const { fetchData: fetchDataUpdateShoppingCart } = UpdateShoppingCartApi() + const [UpdateShoppingCartLoading, setUpdateShoppingCartLoading] = useState(false) + const getInputValue = debounce(async (num, item) => { + let roll = item.sale_mode == 0 ? parseFloat(num) : 0 + let length = item.sale_mode != 0 ? parseFloat(num) * 100 : 0 + setUpdateShoppingCartLoading(() => true) + let res = await fetchDataUpdateShoppingCart({ id: item.id, roll, length }) + setUpdateShoppingCartLoading(() => false) + if (res.success) { + getShoppingCart() + } + }, 300) + + //绑定业务员和电话号码 + const [showBindSalesman, setShowBindSalesman] = useState(false) + + //显示图片弹窗 + const [showLabImage, setShowLabImage] = useState(false) + const [labImageValue, setLabImageValue] = useState() + const getLabAndImg = useCallback((val) => { + setShowLabImage(() => true) + setLabImageValue(val) + }, []) + const closeLabImgShow = useCallback(() => { + setShowLabImage(() => false) + }, []) + + return ( + + closePopup()}> + + + {!selectStatus ? '全选' : '反选'} + + + 删除所选 + + + {estimatePrice.countText} + + {selectList.map((item) => { + return ( + selectProduct(item.value)} + className={classnames(styles.search_item, selectIndex == item.value && styles.search_item_select)}> + {item.title} - - - setShowBindSalesman(false)}/> - - - + ) + })} + + + {loading && } + {!loading && list?.length > 0 && ( + + + {list?.map((item) => { + return ( + + + selectCallBack(item)} + onClose={() => colseCallBack(item)} + /> + + + + + + + {formatHashTag(item.product_code, item.product_name)} + + + {formatPirce(item.sale_price)} + /{selectList[item.sale_mode].eunit} + + + + + {item.product_color_code + ' ' + item.product_color_name} + {item.sale_mode_name} + + + getInputValue(e, item)} + defaultNum={formatCount(item)} + step={selectList[selectIndex].step} + digits={selectList[selectIndex].digits} + onClickBtn={(e) => getInputValue(e, item)} + unit={formatUnit(item)} + minNum={selectList[selectIndex].minNum} + maxNum={selectList[selectIndex].maxNum} + disable={UpdateShoppingCartLoading} + /> + + + + + ) + })} + + + )} + {!loading && list?.length == 0 && ( + + 暂未选择商品 + 去选购 + + )} + + + + + + + + + + {estimatePrice.price} + + 预估金额 + + orderDetail()}> + 去结算({estimatePrice.color_count}) + + - ) + + + setShowBindSalesman(false)} /> + + + + + + ) } - diff --git a/src/pages/details/components/orderCount/index.tsx b/src/pages/details/components/orderCount/index.tsx index 0268bde..e46a12f 100644 --- a/src/pages/details/components/orderCount/index.tsx +++ b/src/pages/details/components/orderCount/index.tsx @@ -1,306 +1,333 @@ -import {View, Text } from "@tarojs/components" -import Popup from "@/components/popup" -import LoadingCard from "@/components/loadingCard"; -import Search from "@/components/search"; -import Counter from "../counter"; +import { View, Text } from '@tarojs/components' +import Popup from '@/components/popup' +import LoadingCard from '@/components/loadingCard' +import Search from '@/components/search' +import Counter from '../counter' import Big from 'big.js' -import classnames from "classnames"; -import styles from "./index.module.scss" -import { memo, useCallback, useEffect, useRef, useState } from "react"; -import { useSelector } from "@/reducers/hooks" -import {GetColorList} from "@/api/materialColor" -import {AddShoppingCartApi} from "@/api/shopCart" -import Taro, { useRouter } from "@tarojs/taro"; -import UseLogin from "@/use/useLogin" -import { formatHashTag, formatPriceDiv } from "@/common/fotmat"; -import { getFilterData } from "@/common/util"; -import LabAndImg from "@/components/LabAndImg"; +import classnames from 'classnames' +import styles from './index.module.scss' +import { memo, useCallback, useEffect, useRef, useState } from 'react' +import { useSelector } from '@/reducers/hooks' +import { GetColorList } from '@/api/materialColor' +import { AddShoppingCartApi } from '@/api/shopCart' +import Taro, { useRouter } from '@tarojs/taro' +import UseLogin from '@/use/useLogin' +import { formatHashTag, formatPriceDiv } from '@/common/fotmat' +import { getFilterData } from '@/common/util' +import LabAndImg from '@/components/LabAndImg' import VirtualList from '@tarojs/components/virtual-list' -import useCommonData from "@/use/useCommonData"; -import LabAndImgShow from "@/components/LabAndImgShow"; - - +import useCommonData from '@/use/useCommonData' +import LabAndImgShow from '@/components/LabAndImgShow' type param = { - show?: true|false, - onClose?: () => void, - title?: string, - productId?: number + show?: true | false + onClose?: () => void + title?: string + productId?: number } -export default memo(({show = false, onClose, title = '', productId = 0}: param) => { - const {adminUserInfo} = useSelector(state => state.userInfo) +export default memo(({ show = false, onClose, title = '', productId = 0 }: param) => { + const { adminUserInfo } = useSelector((state) => state.userInfo) - const [selectList, _] = useState([ - {id: 0, step:1, digits:0, maxNum:100000, defaultNum:1, title:'大货', unit:'条', eunit:'kg', priceField:'bulk_price'}, - {id: 1, step:1, digits:2, maxNum:9.99, defaultNum:1, title:'剪板', unit:'米', eunit:'m', priceField:'length_cut_price'}, - {id: 2, step:1, digits:2, minNum:10, maxNum:100000, defaultNum:10, title:'散剪', unit:'米', eunit:'kg', priceField:'weight_cut_price'}, - ]) - const [selectIndex, setSelectIndex] = useState(0) - const selectProduct = (index:number) => { - setSelectIndex(() => index) + const [selectList, _] = useState([ + { id: 0, step: 1, digits: 0, maxNum: 100000, defaultNum: 1, title: '大货', unit: '条', eunit: 'kg', priceField: 'bulk_price' }, + { id: 1, step: 1, digits: 2, maxNum: 9.99, defaultNum: 1, title: '剪板', unit: '米', eunit: 'm', priceField: 'length_cut_price' }, + { id: 2, step: 1, digits: 2, minNum: 10, maxNum: 100000, defaultNum: 10, title: '散剪', unit: '米', eunit: 'kg', priceField: 'weight_cut_price' }, + ]) + const [selectIndex, setSelectIndex] = useState(0) + const selectProduct = (index: number) => { + setSelectIndex(() => index) + } + + //重置数据 + useEffect(() => { + const newList = initList(list) + setList([...newList]) + condition.current.code_or_name = null + setSearchShow(false) + }, [selectIndex]) + + //获取面料颜色列表 + const { fetchData: colorFetchData, state: colorState } = GetColorList() + const [list, setList] = useState([]) + const condition = useRef({ physical_warehouse: adminUserInfo?.physical_warehouse, sale_mode: selectIndex, product_id: 0, code_or_name: null }) + const getColorList = async () => { + let { data } = await colorFetchData(getFilterData(condition.current)) + let lists = initList(data.list) + setList(() => [...lists]) + } + const [showPopup, setShowPopup] = useState(false) + + //显示获取 + useEffect(() => { + if (show) { + setSelectIndex(0) + condition.current.code_or_name = null + setSearchShow(false) + condition.current.product_id = productId + getColorList() } + setShowPopup(show) + }, [show]) - //重置数据 - useEffect(() => { - const newList = initList(list) - setList([...newList]) - condition.current.code_or_name = null - setSearchShow(false) - }, [selectIndex]) - - //获取面料颜色列表 - const {fetchData:colorFetchData, state: colorState} = GetColorList() - const [list, setList] = useState([]) - const condition = useRef({physical_warehouse:adminUserInfo?.physical_warehouse, sale_mode:selectIndex, product_id:0, code_or_name:null}) - const getColorList = async () => { - let {data} = await colorFetchData(getFilterData(condition.current)) - let lists = initList(data.list) - setList(() => [...lists]) - } - const [showPopup, setShowPopup] = useState(false) - - - //显示获取 - useEffect(() => { - if(show) { - setSelectIndex(0) - condition.current.code_or_name = null - setSearchShow(false) - condition.current.product_id = productId - getColorList() - } - setShowPopup(show) - }, [show]) - - //初始化列表数据 - const initList = useCallback((list) => { - const newList = list.map(item => { - item.count = 0 - item.show = false - return item - }) - return newList - }, []) - - //卸载数据 - useEffect(() => { - return () => { - setList([]) - } - }, []) - - //popup关闭 - const closePopup = () => { - onClose?.() - setShowPopup(false) - setList([]) - } - - //计算总数量和总米/件数 - const [selectCount, setSelectCount] = useState<{sumCount:number, kindCount:number, color_list:any[]}>({ - sumCount: 0, - kindCount: 0, - color_list: [] + //初始化列表数据 + const initList = useCallback((list) => { + const newList = list.map((item) => { + item.count = 0 + item.show = false + return item }) - useEffect(() => { - let sumCount = 0, kindCount = 0, color_list:any[] = [] - let color_list_info = {} - list.map(item => { - if(item.count > 0) { - sumCount = Big(sumCount).add(item.count).toNumber() - kindCount ++ - color_list_info = selectIndex == 0? {product_color_id:item.id, roll:item.count}:{product_color_id:item.id, length:(item.count*100)} - color_list.push(color_list_info) - - } - }) - setSelectCount({...selectCount, sumCount, kindCount, color_list}) - }, [list]) + return newList + }, []) - //计数组件 - const getInputValue = useCallback((num, item) => { - item.count = parseFloat(num) - if(num == 0) item.show = false - setList(() => [...list]) - }, [list]) - - - const onAdd = (item) => { - item.show = true - item.count = selectList[selectIndex].defaultNum - setList((list) => [...list]) + //卸载数据 + useEffect(() => { + return () => { + setList([]) } + }, []) - //搜索显示与隐藏 - const [searchShow, setSearchShow] = useState(false) - const changeSearchShow = () => { - setSearchShow(true) - } + //popup关闭 + const closePopup = () => { + onClose?.() + setShowPopup(false) + setList([]) + } - //添加购物车 - const {getShopCount} = useCommonData() - const {getSelfUserInfo} = UseLogin() - const {fetchData:addFetchData} = AddShoppingCartApi() - const addShopCart = async () => { - try { - await getSelfUserInfo() - } catch(msg) { - Taro.showToast({ - icon:'none', - title:'授权失败,请求完善授权' - }) - return false - } - if(selectCount.sumCount == 0) { - Taro.showToast({ - icon:'none', - title:'请选择面料颜色!' - }) - return false - } - - const state = await addFetchData({ - "sale_mode": selectIndex, - color_list: selectCount.color_list - }) - if(state.success) { - Taro.showToast({ - title:'添加成功' - }) - getShopCount() - onClose?.() - } else { - Taro.showToast({ - icon:'none', - title: state.msg - }) - } - - } - - //筛选数据 - const searchInput = useCallback((e) => { - condition.current.code_or_name = e - getColorList() - }, []) - - //清空搜索内容 - const searchRef = useRef(null) - const clearSearch = () => { - searchRef.current.clearInput() - setSearchShow(false) - } - - //格式化金额 - const formatPrice = useCallback((item) => { - const price = Number(formatPriceDiv(item[selectList[selectIndex].priceField])) - return ¥{price} /{selectList[selectIndex].eunit} - }, [selectIndex]) - - //显示图片弹窗 - const [showLabImage, setShowLabImage] = useState(false) - const [labImageValue, setLabImageValue] = useState() - const getLabAndImg = useCallback((val) => { - setShowLabImage(() => true) - setLabImageValue(val) - }, []) - const closeLabImgShow = useCallback(() => { - setShowLabImage(() => false) - }, []) - - //虚拟滚动 - const Rows = memo(({id, index, style, data}:any) => { - let item = data[index] - return ( - <> - {item&& - - - - - {formatHashTag(item.code, item.name)} - - {formatPrice(item)} - - - - {!item.show&& onAdd(item)}>添加 - || - - } - - || - } - - ) + //计算总数量和总米/件数 + const [selectCount, setSelectCount] = useState<{ sumCount: number; kindCount: number; color_list: any[] }>({ + sumCount: 0, + kindCount: 0, + color_list: [], + }) + useEffect(() => { + let sumCount = 0, + kindCount = 0, + color_list: any[] = [] + let color_list_info = {} + list.map((item) => { + if (item.count > 0) { + sumCount = Big(sumCount).add(item.count).toNumber() + kindCount++ + color_list_info = selectIndex == 0 ? { product_color_id: item.id, roll: item.count } : { product_color_id: item.id, length: item.count * 100 } + color_list.push(color_list_info) + } }) + setSelectCount({ ...selectCount, sumCount, kindCount, color_list }) + }, [list]) - return ( - - closePopup()} > - - {title} - - 下单类型: - - {selectList.map((item, index) => { - return selectProduct(index)} className={classnames(styles.search_item, (selectIndex==index)&&styles.search_item_select)}>{item.title} - })} - - - {searchShow&& - - - - clearSearch()}>取消 - } - - 颜色分类 ({list.length}) - {!searchShow&& changeSearchShow()}>} - - - - {(list.length <= 0 && colorState.loading)&&} - {(list.length > 0&& !colorState.loading)&& - - - {Rows} - - - } - {(list.length <= 0 && !colorState.loading)&&暂无此商品} - - - - 当前已选{selectCount.kindCount}种,共{selectCount.sumCount}{selectList[selectIndex].unit} - addShopCart()}>加入购物车 - - - - - - - - + //计数组件 + const getInputValue = useCallback( + (num, item) => { + item.count = parseFloat(num) + if (num == 0) item.show = false + setList(() => [...list]) + }, + [list], + ) + + const onAdd = (item) => { + item.show = true + item.count = selectList[selectIndex].defaultNum + setList((list) => [...list]) + } + + //搜索显示与隐藏 + const [searchShow, setSearchShow] = useState(false) + const changeSearchShow = () => { + setSearchShow(true) + } + + //添加购物车 + const { getShopCount } = useCommonData() + const { getSelfUserInfo } = UseLogin() + const { fetchData: addFetchData } = AddShoppingCartApi() + const addShopCart = async () => { + try { + await getSelfUserInfo() + } catch (msg) { + Taro.showToast({ + icon: 'none', + title: '授权失败,请求完善授权', + }) + return false + } + if (selectCount.sumCount == 0) { + Taro.showToast({ + icon: 'none', + title: '请选择面料颜色!', + }) + return false + } + + const state = await addFetchData({ + sale_mode: selectIndex, + color_list: selectCount.color_list, + }) + if (state.success) { + Taro.showToast({ + title: '添加成功', + }) + getShopCount() + onClose?.() + } else { + Taro.showToast({ + icon: 'none', + title: state.msg, + }) + } + } + + //筛选数据 + const searchInput = useCallback((e) => { + condition.current.code_or_name = e + getColorList() + }, []) + + //清空搜索内容 + const searchRef = useRef(null) + const clearSearch = () => { + searchRef.current.clearInput() + setSearchShow(false) + } + + //格式化金额 + const formatPrice = useCallback( + (item) => { + const price = Number(formatPriceDiv(item[selectList[selectIndex].priceField])) + return ( + + ¥ + {price} + /{selectList[selectIndex].eunit} - ) -}) + ) + }, + [selectIndex], + ) + //显示图片弹窗 + const [showLabImage, setShowLabImage] = useState(false) + const [labImageValue, setLabImageValue] = useState() + const getLabAndImg = useCallback((val) => { + setShowLabImage(() => true) + setLabImageValue(val) + }, []) + const closeLabImgShow = useCallback(() => { + setShowLabImage(() => false) + }, []) + + //虚拟滚动 + const Rows = memo(({ id, index, style, data }: any) => { + let item = data[index] + return ( + <> + {(item && ( + + + + + + {formatHashTag(item.code, item.name)} + {formatPrice(item)} + + + {(!item.show && ( + onAdd(item)}> + 添加 + + )) || ( + + + + )} + + + )) || } + + ) + }) + + return ( + + closePopup()}> + + {title} + + 下单类型: + + {selectList.map((item, index) => { + return ( + selectProduct(index)} + className={classnames(styles.search_item, selectIndex == index && styles.search_item_select)}> + {item.title} + + ) + })} + + + {searchShow && ( + + + + + clearSearch()}> + 取消 + + + )} + + 颜色分类 ({list.length}) + {!searchShow && changeSearchShow()}>} + + + + {list.length <= 0 && colorState.loading && } + {list.length > 0 && !colorState.loading && ( + + + {Rows} + + + + )} + {list.length <= 0 && !colorState.loading && 暂无此商品} + + + + + 当前已选{selectCount.kindCount}种,共{selectCount.sumCount} + {selectList[selectIndex].unit} + + addShopCart()}> + 加入购物车 + + + + + + + + + + + ) +}) diff --git a/src/pages/details/index.tsx b/src/pages/details/index.tsx index da0c483..22cb3eb 100644 --- a/src/pages/details/index.tsx +++ b/src/pages/details/index.tsx @@ -1,57 +1,56 @@ - import { Button, RichText, Text, View } from '@tarojs/components' -import Taro, { useDidShow, usePullDownRefresh, useRouter } from '@tarojs/taro'; -import classnames from "classnames"; -import DesSwiper from './components/swiper'; -import OrderCount from './components/orderCount'; -import ShopCart from '@/components/shopCart'; -import styles from './index.module.scss' -import { useCallback, useEffect, useMemo, useState } from 'react'; -import {formatHashTag} from '@/common/fotmat' -import {GetProductDetailApi} from '@/api/material' -import useLogin from '@/use/useLogin'; -import { AnalysisShortCodeApi, GetShortCodeApi } from '@/api/share'; -import { SHARE_SCENE } from '@/common/enum'; -import useUserInfo from '@/use/useUserInfo'; -import LabAndImg from '@/components/LabAndImg'; -import { alert } from '@/common/common'; -import AddCollection from '@/components/addCollection'; -import { AddFavoriteApi, DelFavoriteProductApi } from '@/api/favorite'; -import useCommonData from '@/use/useCommonData'; -import { IMG_CND_Prefix } from '@/common/constant'; +import Taro, { useDidShow, usePullDownRefresh, useRouter } from '@tarojs/taro' +import classnames from 'classnames' +import DesSwiper from './components/swiper' +import OrderCount from './components/orderCount' +import ShopCart from '@/components/shopCart' +import styles from './index.module.scss' +import { useCallback, useEffect, useMemo, useState } from 'react' +import { formatHashTag } from '@/common/fotmat' +import { GetProductDetailApi } from '@/api/material' +import useLogin from '@/use/useLogin' +import { AnalysisShortCodeApi, GetShortCodeApi } from '@/api/share' +import { SHARE_SCENE } from '@/common/enum' +import useUserInfo from '@/use/useUserInfo' +import LabAndImg from '@/components/LabAndImg' +import { alert } from '@/common/common' +import AddCollection from '@/components/addCollection' +import { AddFavoriteApi, DelFavoriteProductApi } from '@/api/favorite' +import useCommonData from '@/use/useCommonData' +import { IMG_CND_Prefix } from '@/common/constant' -type item = {title:string, img:string, url:string, id:number} +type item = { title: string; img: string; url: string; id: number } type Params = { list?: item[] - swiperOnClick?: (val: item) => void, + swiperOnClick?: (val: item) => void style?: Object } -export default (props:Params) => { - const {getPhoneNumber, userInfo} = useLogin() +export default (props: Params) => { + const { getPhoneNumber, userInfo } = useLogin() //获取参数(有两种参数:1.商品id, 2.页面分享) const router = useRouter() - const [params, setParams] = useState({id: '', share: null}) + const [params, setParams] = useState({ id: '', share: null }) //判断是否是分享过来的参数 - const judgeParam = async () => { - if(router.params.id) { - setParams({...params, id:router.params.id}) - }else if(router.params.share) { + const judgeParam = async () => { + if (router.params.id) { + setParams({ ...params, id: router.params.id }) + } else if (router.params.share) { analysisShortCode() } } //解析短码参数 - const {fetchData: fetchDataAnalysisShortCode} = AnalysisShortCodeApi() + const { fetchData: fetchDataAnalysisShortCode } = AnalysisShortCodeApi() const analysisShortCode = async () => { - let res = await fetchDataAnalysisShortCode({md5_key: router.params.share}) - setParams({id: res.data.product_id, share: res.data}) + let res = await fetchDataAnalysisShortCode({ md5_key: router.params.share }) + setParams({ id: res.data.product_id, share: res.data }) } //获取购物车数据数量 - const {getShopCount, commonData} = useCommonData() + const { getShopCount, commonData } = useCommonData() useDidShow(() => { judgeParam() @@ -60,32 +59,31 @@ export default (props:Params) => { }) useEffect(() => { - if(params.id) { + if (params.id) { getProductDetail() } }, [params]) - + //获取数据 const [productInfo, setProductInfo] = useState({}) - const {fetchData} = GetProductDetailApi() + const { fetchData } = GetProductDetailApi() const getProductDetail = async () => { - let {data} = await fetchData({id: params.id}) + let { data } = await fetchData({ id: params.id }) setProductInfo(data) Taro.stopPullDownRefresh() } useEffect(() => { - if(productInfo.code) { + if (productInfo.code) { getShortCode() setCollectStatus(() => productInfo.is_favorite) } }, [productInfo]) - //面料名称 const productName = useMemo(() => { return formatHashTag(productInfo.code, productInfo.name) - },[productInfo]) + }, [productInfo]) const [showCart, setShowCart] = useState(false) const [showOrderCount, setShowOrderCount] = useState(false) @@ -94,65 +92,72 @@ export default (props:Params) => { // ` const html = `` - const {setSortCode, userInfo : userObj } = useUserInfo() + const { setSortCode, userInfo: userObj } = useUserInfo() //详情页获取分享短码 - const {ShareDetail} = SHARE_SCENE - const {fetchData: fetchDataShortCode} = GetShortCodeApi() + const { ShareDetail } = SHARE_SCENE + const { fetchData: fetchDataShortCode } = GetShortCodeApi() const getShortCode = async () => { - const {data: resDetail} = await fetchDataShortCode({"share_user_id": userObj.adminUserInfo.user_id, type:ShareDetail.value, product_id: parseInt(params.id)}) - const img = IMG_CND_Prefix + (productInfo.texture_url?productInfo.texture_url.split(',')[0]:'/mall/share_img_01.png') - setSortCode({... userObj.sort_code, shareShortDetail: {title: productName as string, code: resDetail.md5_key, img:img}}) + const { data: resDetail } = await fetchDataShortCode({ + share_user_id: userObj.adminUserInfo.user_id, + type: ShareDetail.value, + product_id: parseInt(params.id), + }) + const img = IMG_CND_Prefix + (productInfo.texture_url ? productInfo.texture_url.split(',')[0] : '/mall/share_img_01.png') + setSortCode({ ...userObj.sort_code, shareShortDetail: { title: productName as string, code: resDetail.md5_key, img: img } }) } //授权手机号和下单 - const placeOrder = async (status = 'to_phone',e:any = {}) => { - if(!productInfo.id) return false - if(status == 'to_phone') { - if(!e.detail.code) return alert.error('请授权手机号') + const placeOrder = async (status = 'to_phone', e: any = {}) => { + if (!productInfo.id) return false + if (status == 'to_phone') { + if (!e.detail.code) return alert.error('请授权手机号') try { await getPhoneNumber(e.detail.code) - } catch(msg) { + } catch (msg) { Taro.showToast({ - icon:"none", - title: msg + icon: 'none', + title: msg, }) return false } - } + } setShowOrderCount(true) } //收藏功能 const [collectStatus, setCollectStatus] = useState(false) const [collectionShow, setCollectionShow] = useState(false) - const {fetchData: addFavoritefetchData} = AddFavoriteApi() + const { fetchData: addFavoritefetchData } = AddFavoriteApi() const openCollection = () => { - if(productInfo.is_favorite) { + if (productInfo.is_favorite) { delFavoriteProduct() } else { setCollectionShow(true) } } - const onAdd = useCallback(async (val) => { - let res = await addFavoritefetchData({favorite_id: val.id, product_id: Number(params.id)}) - if(res.success) { - alert.success('添加成功') - setCollectStatus(true) - getProductDetail() - } else { - alert.none(res.msg) - } - - setCollectionShow(false) - }, [params]) + const onAdd = useCallback( + async (val) => { + let res = await addFavoritefetchData({ favorite_id: val.id, product_id: Number(params.id) }) + if (res.success) { + alert.success('添加成功') + setCollectStatus(true) + getProductDetail() + } else { + alert.none(res.msg) + } + + setCollectionShow(false) + }, + [params], + ) const closeCollection = useCallback(() => { setCollectionShow(false) }, []) //取消收藏 - const {fetchData: delFavoriteProductFetchData} = DelFavoriteProductApi() + const { fetchData: delFavoriteProductFetchData } = DelFavoriteProductApi() const delFavoriteProduct = async () => { - let res = await delFavoriteProductFetchData({favorite_id: productInfo.favorite_id, product_id:[productInfo.id]}) - if(res.success) { + let res = await delFavoriteProductFetchData({ favorite_id: productInfo.favorite_id, product_id: [productInfo.id] }) + if (res.success) { setCollectStatus(false) getProductDetail() alert.none('已取消收藏') @@ -163,67 +168,85 @@ export default (props:Params) => { usePullDownRefresh(() => { getProductDetail() }) - + return ( - + - {productInfo.code&&{productName}} + {productInfo.code && {productName}} {productInfo.describe} 分享 - + - + 收藏 详情参数 - 编号:{productInfo.code} - 幅宽:{productInfo.width} - 克重:{productInfo.weight_density} - 成分:{productInfo.component} + + 编号:{productInfo.code} + + + 幅宽:{productInfo.width} + + + 克重:{productInfo.weight_density} + + + 成分:{productInfo.component} + 色号 ({productInfo?.product_color_list?.length}) - - {productInfo?.product_color_list?.map(item => { - return - - - - {item.code} + + {productInfo?.product_color_list?.map((item) => { + return ( + + + - })} - + {item.code} + + ) + })} + - + - setShowCart(true)}> + setShowCart(true)}> 购物车 - {(commonData.shopCount > 0)&&{commonData.shopCount > 99?'99+':commonData.shopCount}} + {commonData.shopCount > 0 && {commonData.shopCount > 99 ? '99+' : commonData.shopCount}} - { - (!userInfo.adminUserInfo?.is_authorize_phone)&& - - 选购商品 - - || placeOrder('to_order')}>选购商品 - } + {(!userInfo.adminUserInfo?.is_authorize_phone && ( + + + 选购商品 + + )) || ( + placeOrder('to_order')}> + 选购商品 + + )} - setShowOrderCount(false)} title={productName} productId={productInfo.id}/> - setShowCart(false)}/> - + setShowOrderCount(false)} title={productName} productId={productInfo.id} /> + setShowCart(false)} /> + ) diff --git a/src/pages/order/orderList/components/orderStatusList/index.tsx b/src/pages/order/orderList/components/orderStatusList/index.tsx index 1257330..b2e1e89 100644 --- a/src/pages/order/orderList/components/orderStatusList/index.tsx +++ b/src/pages/order/orderList/components/orderStatusList/index.tsx @@ -1,47 +1,54 @@ -import { ScrollView, View } from "@tarojs/components" -import { memo, useEffect, useState } from "react" -import styles from './index.module.scss' -import classnames from "classnames"; +import { ScrollView, View } from '@tarojs/components' +import { memo, useEffect, useState } from 'react' +import styles from './index.module.scss' +import classnames from 'classnames' type Param = { - list: {id: number, name: string}[], - defaultId?: number|null, - onSelect?: (val: number) => void + list: { id: number; name: string }[] + defaultId?: number | null + onSelect?: (val: number) => void } -export default memo(({list = [], defaultId = null, onSelect}: Param) => { - const [selectInfo, setSelectInfo] = useState({ - selected: -1, //当前选中的id - tabId: '', //需要滚动到的id - }) - useEffect(() => { - if(defaultId) { - console.log('defaultId:::', defaultId) - const index = list?.findIndex(item => { - return item.id == defaultId - }) - if(index !== -1) { - const num = index > 0?( index - 1) : 0 - setSelectInfo((e) => ({...e, tabId:list[num].id.toString()})) - } - } - setSelectInfo((e) => ({...e, selected: defaultId||-1})) - }, [defaultId]) - const clickEvent = ({item, index}: {item:any, index:number}) => { - const num = index > 0?( index - 1) : 0 - setSelectInfo((e) => ({...e, tabId:list[num].id.toString(), selected: item.id})) - onSelect?.(item.id) +export default memo(({ list = [], defaultId = null, onSelect }: Param) => { + const [selectInfo, setSelectInfo] = useState({ + selected: -1, //当前选中的id + tabId: '', //需要滚动到的id + }) + useEffect(() => { + if (defaultId) { + console.log('defaultId:::', defaultId) + const index = list?.findIndex((item) => { + return item.id == defaultId + }) + if (index !== -1) { + const num = index > 0 ? index - 1 : 0 + setSelectInfo((e) => ({ ...e, tabId: list[num].id.toString() })) + } } + setSelectInfo((e) => ({ ...e, selected: defaultId || -1 })) + }, [defaultId]) + const clickEvent = ({ item, index }: { item: any; index: number }) => { + const num = index > 0 ? index - 1 : 0 + setSelectInfo((e) => ({ ...e, tabId: list[num].id.toString(), selected: item.id })) + onSelect?.(item.id) + } - return ( - - - - {list.map((item, index) => { - return clickEvent({item, index})} className={classnames(styles.order_status_item, (selectInfo.selected==item.id)&&styles.selected)}>{item.name} - })} - - + return ( + + + + {list.map((item, index) => { + return ( + clickEvent({ item, index })} + className={classnames(styles.order_status_item, selectInfo.selected == item.id && styles.selected)}> + {item.name} + + ) + })} - ) + + + ) }) - diff --git a/src/pages/searchList/hightSearchList.tsx b/src/pages/searchList/hightSearchList.tsx index 07650f3..0ba64ce 100644 --- a/src/pages/searchList/hightSearchList.tsx +++ b/src/pages/searchList/hightSearchList.tsx @@ -1,220 +1,221 @@ -import { Image, ScrollView, Text, View } from "@tarojs/components" -import classnames from "classnames"; -import Filter from "@/components/filter"; +import { Image, ScrollView, Text, View } from '@tarojs/components' +import classnames from 'classnames' +import Filter from '@/components/filter' import InfiniteScroll from '@/components/infiniteScroll' -import SortBtn from "@/components/sortBtn"; -import SearchInput from "@/components/searchInput"; -import LinkBlueTooth from "@/components/bluetooth/LinkBlueTooth"; -import {useBluetooth} from "@/use/contextBlueTooth" -import {toRgb} from '@/common/bluetooth/color/colorSpace' -import styles from './hightSearchList.module.scss' -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import Taro, { useDidShow, usePullDownRefresh, useReady } from "@tarojs/taro"; -import {GetLabProductApi} from "@/api/material" -import { dataLoadingStatus, getFilterData } from "@/common/util"; -import { formatHashTag, formatImgUrl } from "@/common/fotmat"; -import useLogin from "@/use/useLogin"; -import { goLink } from "@/common/common"; -import SelectData, {ListProps} from "./components/selectData"; -import LabAndImg from "@/components/LabAndImg"; +import SortBtn from '@/components/sortBtn' +import SearchInput from '@/components/searchInput' +import LinkBlueTooth from '@/components/bluetooth/LinkBlueTooth' +import { useBluetooth } from '@/use/contextBlueTooth' +import { toRgb } from '@/common/bluetooth/color/colorSpace' +import styles from './hightSearchList.module.scss' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import Taro, { useDidShow, usePullDownRefresh, useReady } from '@tarojs/taro' +import { GetLabProductApi } from '@/api/material' +import { dataLoadingStatus, getFilterData } from '@/common/util' +import { formatHashTag, formatImgUrl } from '@/common/fotmat' +import useLogin from '@/use/useLogin' +import { goLink } from '@/common/common' +import SelectData, { ListProps } from './components/selectData' +import LabAndImg from '@/components/LabAndImg' export default () => { - useLogin() + useLogin() - const firstOpen = useRef(true) - const [showFilter, setShowFilter] = useState(false) - //搜索参数 - const [searchField, setSearchField] = useState({ - l: '', - a: '', - b: '', - page : 1, - size : 10, - width: '', - weight_density: '', - product_kind_id: '', - component: '', - abstract_sort_key: '' + const firstOpen = useRef(true) + const [showFilter, setShowFilter] = useState(false) + //搜索参数 + const [searchField, setSearchField] = useState({ + l: '', + a: '', + b: '', + page: 1, + size: 10, + width: '', + weight_density: '', + product_kind_id: '', + component: '', + abstract_sort_key: '', + }) + + //获取面料列表 + const [materialList, setMaterialList] = useState<{ list: any[]; total: number }>({ list: [], total: 0 }) + const { fetchData: materialFetchData, state: materialState } = GetLabProductApi() + const getProductList = async () => { + let { data } = await materialFetchData(getFilterData(searchField)) + setMaterialList({ list: data.list, total: data.total }) + Taro.stopPullDownRefresh() + firstOpen.current = false + } + + //监听筛选条件变化 + useEffect(() => { + getProductList() + }, [searchField]) + + //上拉加载数据 + const pageNum = useRef({ size: searchField.size, page: searchField.page }) + const getScrolltolower = () => { + if (materialList.list.length < materialList.total) { + pageNum.current.page++ + const size = pageNum.current.size * pageNum.current.page + setSearchField({ ...searchField, size }) + } + } + + //数据加载状态 + const statusMore = useMemo(() => { + return dataLoadingStatus({ list: materialList.list, total: materialList.total, status: materialState.loading }) + }, [materialList, materialState]) + + const { state: colorState, measureAndGetLab } = useBluetooth() + const getLab = () => { + if (colorState.connected) { + measureAndGetLab() + } else { + Taro.showToast({ + title: '请链接设备', + icon: 'none', + }) + } + } + + //监听lab数据变化 + const [blueToothColor, setBlueToothColor] = useState('') + useEffect(() => { + if (colorState.deviceLab && !firstOpen.current) { + const rgb = toRgb([colorState.deviceLab.L, colorState.deviceLab.a, colorState.deviceLab.b]) + setBlueToothColor(`rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`) + setSearchField({ ...searchField, l: rgb[0], a: rgb[1], b: rgb[2], size: 10, page: 1 }) + setMaterialList(() => ({ list: [], total: 0 })) + pageNum.current = { size: 10, page: 1 } + } + }, [colorState.deviceLab]) + + const goLinkPage = (item) => { + goLink('/pages/details/index', { id: item.product_id }) + } + + //获取筛选条件 + const getFiltr = (e) => { + pageNum.current.page = 1 + setMaterialList(() => ({ list: [], total: 0 })) + const { data } = e + setSearchField({ + ...searchField, + width: data?.width, + weight_density: data?.weight, + size: 10, + component: data?.element, + product_kind_id: data?.seriesId, }) + formatSelectList(e) + } - //获取面料列表 - const [materialList, setMaterialList] = useState<{list:any[], total:number}>({list:[], total:0}) - const {fetchData: materialFetchData, state: materialState} = GetLabProductApi() - const getProductList = async () => { - let {data} = await materialFetchData(getFilterData(searchField)) - setMaterialList({list:data.list, total:data.total}) - Taro.stopPullDownRefresh() - firstOpen.current = false + //筛选条件格式化 + const [selectList, setSelectList] = useState() + const formatSelectList = (val = { data: {}, field: {} }) => { + let data: ListProps[] = [] + for (let key in val.data) { + if (key !== 'seriesId' && val.data[key] != '') { + data.push({ title: val.field[key], value: val.data[key] }) + } } + setSelectList([...data]) + } - //监听筛选条件变化 - useEffect(() => { - getProductList() - }, [searchField]) + //页面下拉刷新 + usePullDownRefresh(() => { + setSearchField({ ...searchField, size: 10 }) + }) - //上拉加载数据 - const pageNum = useRef({size: searchField.size, page: searchField.page}) - const getScrolltolower = () => { - if(materialList.list.length < materialList.total) { - pageNum.current.page++ - const size = pageNum.current.size * pageNum.current.page - setSearchField({...searchField, size }) - } + //排序 + type sortParam = 'none' | 'top' | 'bottom' + const sortComprehensiveRef = useRef(null) + const sortCollectionRef = useRef(null) + const [sortStatus, setSortStatus] = useState<{ comprehensive: sortParam; collection: sortParam }>({ + comprehensive: 'none', + collection: 'none', + }) + const changeSort = (val) => { + setMaterialList(() => ({ list: [], total: 0 })) + if (val == 1) { + const { status, value } = sortComprehensiveRef.current.changeSort() + setSortStatus((e) => ({ ...e, comprehensive: status, collection: 'none' })) + setSearchField((e) => ({ ...e, abstract_sort_key: value, size: 10, page: 1 })) + } else { + const { status, value } = sortCollectionRef.current.changeSort() + setSortStatus((e) => ({ ...e, collection: status, comprehensive: 'none' })) + setSearchField((e) => ({ ...e, abstract_sort_key: value, size: 10, page: 1 })) } + pageNum.current = { size: 10, page: 1 } + } - //数据加载状态 - const statusMore = useMemo(() => { - return dataLoadingStatus({list:materialList.list, total: materialList.total, status: materialState.loading}) - }, [materialList, materialState]) - - const {state: colorState, measureAndGetLab} = useBluetooth() - const getLab = () => { - if(colorState.connected) { - measureAndGetLab() - } else { - Taro.showToast({ - title: '请链接设备', - icon: 'none' - }) - } - } - - //监听lab数据变化 - const [blueToothColor, setBlueToothColor] = useState('') - useEffect(() => { - if(colorState.deviceLab && !firstOpen.current) { - const rgb = toRgb([colorState.deviceLab.L, colorState.deviceLab.a, colorState.deviceLab.b]) - setBlueToothColor(`rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`) - setSearchField({...searchField, l:rgb[0], a:rgb[1], b:rgb[2], size:10, page:1}) - setMaterialList(() => ({list:[], total:0})) - pageNum.current = {size: 10, page: 1} - } - }, [colorState.deviceLab]) - - const goLinkPage = (item) => { - goLink('/pages/details/index',{id:item.product_id}) - } - - //获取筛选条件 - const getFiltr = (e) => { - pageNum.current.page = 1 - setMaterialList(() => ({list:[], total:0})) - const {data} = e - setSearchField({ - ...searchField, - width: data?.width, - weight_density: data?.weight, - size: 10, - component: data?.element, - product_kind_id: data?.seriesId - }) - formatSelectList(e) - } - - //筛选条件格式化 - const [selectList , setSelectList] = useState() - const formatSelectList = (val = {data:{}, field:{}}) => { - let data:ListProps[] = [] - for(let key in val.data) { - if(key !== 'seriesId'&& val.data[key] != '') { - data.push({title:val.field[key], value:val.data[key]}) - } - } - setSelectList([...data]) - } - - //页面下拉刷新 - usePullDownRefresh(() => { - setSearchField({...searchField ,size : 10}) - }) - - //排序 - type sortParam = 'none'|'top'|'bottom' - const sortComprehensiveRef = useRef(null) - const sortCollectionRef = useRef(null) - const [sortStatus, setSortStatus] = useState<{comprehensive:sortParam, collection:sortParam}>({ - comprehensive: 'none', - collection: 'none' - }) - const changeSort = (val) => { - setMaterialList(() => ({list:[], total:0})) - if(val == 1) { - const {status, value} = sortComprehensiveRef.current.changeSort() - setSortStatus((e) => ({...e, comprehensive: status, collection: 'none'})) - setSearchField((e) => ({...e, abstract_sort_key: value, size:10, page:1})) - } else { - const {status, value} = sortCollectionRef.current.changeSort() - setSortStatus((e) => ({...e, collection: status, comprehensive: 'none'})) - setSearchField((e) => ({...e, abstract_sort_key: value, size:10, page:1})) - } - pageNum.current = {size: 10, page: 1} - } - - const labAndImgObj = useCallback((item) => { - const img = item?item.texture_url.split(',')[0]:'' - return {lab:item.lab,rgb:item.rgb,texture_url:img} - }, [materialList]) - return ( - - - - - - getLab()}> - {blueToothColor&&|| - 请取色 - } - - - + const labAndImgObj = useCallback( + (item) => { + const img = item ? item.texture_url.split(',')[0] : '' + return { lab: item.lab, rgb: item.rgb, texture_url: img } + }, + [materialList], + ) + return ( + + + + + + getLab()}> + {(blueToothColor && ) || ( + 请取色 + )} - - - changeSort(1)}> - 综合 - - - changeSort(2)}> - 收藏 - - - - - - - - - setShowFilter(true)}> - 筛选 - - - - - - 搜索结果 ({materialList.total}条记录) - - - - {materialList.list.map(item => { - return goLinkPage(item)}> - - - {(item.product_color_code)} - - - {formatHashTag(item.product_code, item.product_name)} - {item.product_kind_name} - - - })} - - - - - getFiltr(e)} onClose={() => setShowFilter(false)}/> + - ) -} \ No newline at end of file + + + + changeSort(1)}> + 综合 + + + changeSort(2)}> + 收藏 + + + + + + + + setShowFilter(true)}> + 筛选 + + + + + + 搜索结果 ({materialList.total}条记录) + + + + {materialList.list.map((item) => { + return ( + goLinkPage(item)}> + + + {item.product_color_code} + + + {formatHashTag(item.product_code, item.product_name)} + {item.product_kind_name} + + + ) + })} + + + + + getFiltr(e)} onClose={() => setShowFilter(false)} /> + + ) +} diff --git a/src/pages/searchList/search.tsx b/src/pages/searchList/search.tsx index c255911..a37cbbc 100644 --- a/src/pages/searchList/search.tsx +++ b/src/pages/searchList/search.tsx @@ -1,36 +1,35 @@ - import { Text, View } from '@tarojs/components' import Search from '@/components/search' -import { alert, goLink } from '@/common/common'; -import classnames from "classnames"; -import styles from './search.module.scss' -import { useEffect, useRef, useState } from 'react'; -import {GetHotSearchApi, GetSearchHistoryApi, AddSearchHistoryApi} from "@/api/search" -import { SCENE } from '@/common/constant'; -import useLogin from '@/use/useLogin'; -import Taro, { useDidShow, useShareAppMessage } from '@tarojs/taro'; +import { alert, goLink } from '@/common/common' +import classnames from 'classnames' +import styles from './search.module.scss' +import { useEffect, useRef, useState } from 'react' +import { GetHotSearchApi, GetSearchHistoryApi, AddSearchHistoryApi } from '@/api/search' +import { SCENE } from '@/common/constant' +import useLogin from '@/use/useLogin' +import Taro, { useDidShow, useShareAppMessage } from '@tarojs/taro' -type searchDataParam = {'search_key':''} +type searchDataParam = { search_key: '' } export default () => { useLogin() - const [searchData, setSearchData] = useState<{hotField: searchDataParam[], historyField: searchDataParam[]}>({ + const [searchData, setSearchData] = useState<{ hotField: searchDataParam[]; historyField: searchDataParam[] }>({ hotField: [], - historyField: [] + historyField: [], }) //获取热门搜索数据 - const {fetchData:hotFetchData} = GetHotSearchApi() + const { fetchData: hotFetchData } = GetHotSearchApi() const getHotSearch = async () => { - let {data} = await hotFetchData({page:1, size:10}) - setSearchData((val) => ({...val, hotField: data.list})) + let { data } = await hotFetchData({ page: 1, size: 10 }) + setSearchData((val) => ({ ...val, hotField: data.list })) } //获取历史搜索数据 - const {fetchData:HistoryFetchData} = GetSearchHistoryApi() + const { fetchData: HistoryFetchData } = GetSearchHistoryApi() const getSearchHistory = async () => { - let {data} = await HistoryFetchData({page:1, size:10}) - setSearchData((val) => ({...val, historyField: data.list})) + let { data } = await HistoryFetchData({ page: 1, size: 10 }) + setSearchData((val) => ({ ...val, historyField: data.list })) } useDidShow(() => { @@ -39,53 +38,65 @@ export default () => { }) //添加搜索关键字 - const addSearchField = useRef({key: '', screen: SCENE.SearchScene}) - const {fetchData:addFetchData} = AddSearchHistoryApi() + const addSearchField = useRef({ key: '', screen: SCENE.SearchScene }) + const { fetchData: addFetchData } = AddSearchHistoryApi() const addSearchHistory = async () => { await addFetchData(addSearchField.current) // goLink('/pages/searchList/searchList', {key: addSearchField.current.key}) - } //搜索事件, status = true 添加搜索, status = false 直接跳转 const searchEvent = (e, status = true) => { - if(e == "") { + if (e == '') { alert.error('请输入关键词') return false - } + } addSearchField.current.key = e - status&&addSearchHistory() + status && addSearchHistory() Taro.navigateTo({ - url: `/pages/searchList/searchList?key=${addSearchField.current.key}` + url: `/pages/searchList/searchList?key=${addSearchField.current.key}`, }) } - return ( - searchEvent(e)}/> + searchEvent(e)} /> - goLink('/pages/searchList/hightSearchList')}>高级搜索 - {searchData?.hotField.length > 0 && - - 热门面料 + goLink('/pages/searchList/hightSearchList')}> + 高级搜索 + + {searchData?.hotField.length > 0 && ( + + + 热门面料 + + + {searchData.hotField.map((item) => { + return ( + searchEvent(item.search_key, false)}> + {item.search_key} + + ) + })} + - - {searchData.hotField.map((item, index) => { - return searchEvent(item.search_key, false)}>{item.search_key} - })} + )} + {searchData?.historyField.length > 0 && ( + + + 历史搜索 + {/* */} + + + {searchData?.historyField?.map((item) => ( + searchEvent(item.search_key, false)}> + {item.search_key} + + ))} + - } - {searchData?.historyField.length > 0 && - - 历史搜索 - {/* */} - - - {searchData?.historyField?.map((item, index) => searchEvent(item.search_key, false)}>{item.search_key})} - - } + )} ) } diff --git a/src/pages/searchList/searchList.tsx b/src/pages/searchList/searchList.tsx index 15d232d..d9c39f6 100644 --- a/src/pages/searchList/searchList.tsx +++ b/src/pages/searchList/searchList.tsx @@ -1,198 +1,199 @@ -import { Image, ScrollView, Text, View } from "@tarojs/components" -import classnames from "classnames"; +import { Image, ScrollView, Text, View } from '@tarojs/components' +import classnames from 'classnames' import Search from '@/components/search' -import Filter from "@/components/filter"; +import Filter from '@/components/filter' import InfiniteScroll from '@/components/infiniteScroll' -import SortBtn from "@/components/sortBtn"; -import SelectData, {ListProps} from "./components/selectData"; -import { goLink } from "@/common/common"; -import styles from './searchList.module.scss' -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import {GetProductListApi} from "@/api/material" -import Taro, { useDidShow, usePullDownRefresh, useRouter } from "@tarojs/taro"; -import { formatHashTag, formatImgUrl } from "@/common/fotmat"; -import { dataLoadingStatus, getFilterData } from "@/common/util"; -import useLogin from "@/use/useLogin"; -import LabAndImg from "@/components/LabAndImg"; +import SortBtn from '@/components/sortBtn' +import SelectData, { ListProps } from './components/selectData' +import { goLink } from '@/common/common' +import styles from './searchList.module.scss' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { GetProductListApi } from '@/api/material' +import Taro, { useDidShow, usePullDownRefresh, useRouter } from '@tarojs/taro' +import { formatHashTag, formatImgUrl } from '@/common/fotmat' +import { dataLoadingStatus, getFilterData } from '@/common/util' +import useLogin from '@/use/useLogin' +import LabAndImg from '@/components/LabAndImg' export default () => { - useLogin() + useLogin() - const [showFilter, setShowFilter] = useState(false) - const router = useRouter() + const [showFilter, setShowFilter] = useState(false) + const router = useRouter() - //搜索参数 - const [searchField, setSearchField] = useState({ - code_or_name: router.params.key, - page : 1, - size : 10, - width: '', - weight_density: '', - product_kind_id: '', - component: '', - abstract_sort_key: '' + //搜索参数 + const [searchField, setSearchField] = useState({ + code_or_name: router.params.key, + page: 1, + size: 10, + width: '', + weight_density: '', + product_kind_id: '', + component: '', + abstract_sort_key: '', + }) + + //获取面料列表 + const [materialList, setMaterialList] = useState<{ list: any[]; total: number }>({ list: [], total: 0 }) + const { fetchData: materialFetchData, state: materialState } = GetProductListApi() + const getProductList = async () => { + let { data } = await materialFetchData(getFilterData(searchField)) + setMaterialList({ list: data.list, total: data.total }) + Taro.stopPullDownRefresh() + } + + //监听筛选条件变化 + useEffect(() => { + getProductList() + }, [searchField]) + + //上拉加载数据 + const pageNum = useRef({ size: searchField.size, page: searchField.page }) + const getScrolltolower = () => { + if (materialList.list.length < materialList.total) { + pageNum.current.page++ + const size = pageNum.current.size * pageNum.current.page + setSearchField({ ...searchField, size }) + } + } + + //数据加载状态 + const statusMore = useMemo(() => { + return dataLoadingStatus({ list: materialList.list, total: materialList.total, status: materialState.loading }) + }, [materialList, materialState]) + + //输入了搜索关键字 + const getSearchData = useCallback((e) => { + pageNum.current.page = 1 + setMaterialList(() => ({ list: [], total: 0 })) + setSearchField((val) => ({ ...val, code_or_name: e, size: 10 })) + pageNum.current = { size: 10, page: 1 } + }, []) + + const goLinkPage = (item) => { + goLink('/pages/details/index', { id: item.id }) + } + + //页面下拉刷新 + usePullDownRefresh(() => { + setSearchField({ ...searchField, size: 10 }) + }) + + //获取筛选条件 + const getFiltr = (e) => { + pageNum.current.page = 1 + setMaterialList(() => ({ list: [], total: 0 })) + const { data } = e + setSearchField({ + ...searchField, + width: data?.width, + weight_density: data?.weight, + size: 10, + component: data?.element, + product_kind_id: data?.seriesId, }) - - //获取面料列表 - const [materialList, setMaterialList] = useState<{list:any[], total:number}>({list:[], total:0}) - const {fetchData: materialFetchData, state: materialState} = GetProductListApi() - const getProductList = async () => { - let {data} = await materialFetchData(getFilterData(searchField)) - setMaterialList({list:data.list, total:data.total}) - Taro.stopPullDownRefresh() + formatSelectList(e) + } + + //筛选条件格式化 + const [selectList, setSelectList] = useState() + const formatSelectList = (val = { data: {}, field: {} }) => { + let data: ListProps[] = [] + for (let key in val.data) { + if (key !== 'seriesId' && val.data[key] != '') { + data.push({ title: val.field[key], value: val.data[key] }) + } } + setSelectList([...data]) + } - //监听筛选条件变化 - useEffect(() => { - getProductList() - }, [searchField]) - - - //上拉加载数据 - const pageNum = useRef({size: searchField.size, page: searchField.page}) - const getScrolltolower = () => { - if(materialList.list.length < materialList.total) { - pageNum.current.page++ - const size = pageNum.current.size * pageNum.current.page - setSearchField({...searchField, size }) - } + //排序 + type sortParam = 'none' | 'top' | 'bottom' + const sortComprehensiveRef = useRef(null) + const sortCollectionRef = useRef(null) + const [sortStatus, setSortStatus] = useState<{ comprehensive: sortParam; collection: sortParam }>({ + comprehensive: 'none', + collection: 'none', + }) + const changeSort = (val) => { + if (val == 1) { + const { status, value } = sortComprehensiveRef.current.changeSort() + setSortStatus((e) => ({ ...e, comprehensive: status, collection: 'none' })) + setSearchField((e) => ({ ...e, abstract_sort_key: value, size: 10, page: 1 })) + } else { + const { status, value } = sortCollectionRef.current.changeSort() + setSortStatus((e) => ({ ...e, collection: status, comprehensive: 'none' })) + setSearchField((e) => ({ ...e, abstract_sort_key: value, size: 10, page: 1 })) } + pageNum.current = { size: 10, page: 1 } + } - //数据加载状态 - const statusMore = useMemo(() => { - return dataLoadingStatus({list:materialList.list, total: materialList.total, status: materialState.loading}) - }, [materialList, materialState]) - - //输入了搜索关键字 - const getSearchData = useCallback((e) => { - pageNum.current.page = 1 - setMaterialList(() => ({list:[], total:0})) - setSearchField((val) => ({...val, code_or_name:e, size:10})) - pageNum.current = {size: 10, page: 1} - }, []) - - const goLinkPage = (item) => { - goLink('/pages/details/index',{id:item.id}) - } - - //页面下拉刷新 - usePullDownRefresh(() => { - setSearchField({...searchField ,size : 10}) - }) - - //获取筛选条件 - const getFiltr = (e) => { - pageNum.current.page = 1 - setMaterialList(() => ({list:[], total:0})) - const {data} = e - setSearchField({ - ...searchField, - width: data?.width, - weight_density: data?.weight, - size: 10, - component: data?.element, - product_kind_id: data?.seriesId - }) - formatSelectList(e) - } - - //筛选条件格式化 - const [selectList , setSelectList] = useState() - const formatSelectList = (val = {data:{}, field:{}}) => { - let data:ListProps[] = [] - for(let key in val.data) { - if(key !== 'seriesId'&& val.data[key] != '') { - data.push({title:val.field[key], value:val.data[key]}) - } - } - setSelectList([...data]) - } - - //排序 - type sortParam = 'none'|'top'|'bottom' - const sortComprehensiveRef = useRef(null) - const sortCollectionRef = useRef(null) - const [sortStatus, setSortStatus] = useState<{comprehensive:sortParam, collection:sortParam}>({ - comprehensive: 'none', - collection: 'none' - }) - const changeSort = (val) => { - if(val == 1) { - const {status, value} = sortComprehensiveRef.current.changeSort() - setSortStatus((e) => ({...e, comprehensive: status, collection: 'none'})) - setSearchField((e) => ({...e, abstract_sort_key: value, size:10, page:1})) - } else { - const {status, value} = sortCollectionRef.current.changeSort() - setSortStatus((e) => ({...e, collection: status, comprehensive: 'none'})) - setSearchField((e) => ({...e, abstract_sort_key: value, size:10, page:1})) - } - pageNum.current = {size: 10, page: 1} - } - - const labAndImgObj = useCallback((item) => { - const img = item?item.texture_url.split(',')[0]:'' - return {lab:item.lab,rgb:item.rgb,texture_url:img} - }, [materialList]) - return ( - - - - - - - changeSort(1)}> - 综合 - - - changeSort(2)}> - 收藏 - - - goLink('/pages/searchList/hightSearchList')}> - 高级搜索 - - - - - - - - - setShowFilter(true)}> - 筛选 - - - - - - 搜索结果 ({materialList.total}条记录) - - - - {materialList.list.map(item => { - return goLinkPage(item)}> - - - {(item.product_color_count)}色 - - - {formatHashTag(item.code, item.name)} - - {item.width} - {item.weight_density} - - {item.component} - - - })} - - - - - setShowFilter(false)} onFiltr={(e) => getFiltr(e)} /> + const labAndImgObj = useCallback( + (item) => { + const img = item ? item.texture_url.split(',')[0] : '' + return { lab: item.lab, rgb: item.rgb, texture_url: img } + }, + [materialList], + ) + return ( + + + + + + + changeSort(1)}> + 综合 + + + changeSort(2)}> + 收藏 + + + goLink('/pages/searchList/hightSearchList')}> + 高级搜索 + + - ) -} \ No newline at end of file + + + + + + setShowFilter(true)}> + 筛选 + + + + + + 搜索结果 ({materialList.total}条记录) + + + + {materialList.list.map((item) => { + return ( + goLinkPage(item)}> + + + {item.product_color_count}色 + + + {formatHashTag(item.code, item.name)} + + {item.width} + {item.weight_density} + + {item.component} + + + ) + })} + + + + + setShowFilter(false)} onFiltr={(e) => getFiltr(e)} /> + + ) +} diff --git a/src/pages/user/index.tsx b/src/pages/user/index.tsx index 6fd935c..2bd2283 100644 --- a/src/pages/user/index.tsx +++ b/src/pages/user/index.tsx @@ -1,223 +1,211 @@ -import { View, Image, Text, Navigator, Button } from "@tarojs/components" -import { memo, useEffect, useState } from "react" +import { View, Image, Text, Navigator, Button } from '@tarojs/components' +import { memo, useEffect, useState } from 'react' import styles from './index.module.scss' -import classnames from "classnames"; -import { useSelector } from "@/reducers/hooks"; -import { alert, goLink } from "@/common/common"; +import classnames from 'classnames' +import { useSelector } from '@/reducers/hooks' +import { alert, goLink } from '@/common/common' import useLogin from '@/use/useLogin' import { BASE_URL } from '@/common/constant' -import Taro, { useShareAppMessage } from "@tarojs/taro"; -import { userassets, userorderStatistics } from "@/api/mine" -import { formatPriceDiv } from "@/common/fotmat" -import { useDidShow, } from '@tarojs/taro' -import { GetAdminUserInfoApi } from "@/api/user"; - +import Taro, { useShareAppMessage } from '@tarojs/taro' +import { userassets, userorderStatistics } from '@/api/mine' +import { formatPriceDiv } from '@/common/fotmat' +import { useDidShow } from '@tarojs/taro' +import { GetAdminUserInfoApi } from '@/api/user' export default () => { + // 用户信息 + const { getSelfUserInfo, getAdminUserInfo } = useLogin() + const { adminUserInfo } = useSelector((state) => state.userInfo) - // 用户信息 - const { getSelfUserInfo, getAdminUserInfo } = useLogin(); - const { adminUserInfo } = useSelector(state => state.userInfo); + const [current_version, setCurrent_version] = useState(CURRENT_VERSION) + const [current_githash, setCurrent_githash] = useState(CURRENT_GITHASH) + const [current_env, setCurrent_env] = useState(CURRENT_ENV) - const [current_version,setCurrent_version] = useState(CURRENT_VERSION) - const [current_githash,setCurrent_githash] = useState(CURRENT_GITHASH) - const [current_env,setCurrent_env] = useState(CURRENT_ENV) + const handleAuth = async () => { + console.log('授权面版') + getSelfUserInfo() + .then() + .catch(() => { + alert.none('授权失败,请授权后再使用') + }) + } + const { fetchData: Apiassets, state } = userassets() + const { fetchData: ApigetTotal, state: stateData } = userorderStatistics() - //分享 - useShareAppMessage(res => { - if (res.from !== 'button') { - // 来自页面内转发按钮 - console.log('点击个德') - } - return { - title: '转发啦', - path: '/page/user?id=123' - } - }) - - const handleAuth = async () => { - console.log('授权面版') - getSelfUserInfo().then().catch(() => { - alert.none("授权失败,请授权后再使用"); - }); - } - const { fetchData: Apiassets, state } = userassets() - const { fetchData: ApigetTotal, state: stateData } = userorderStatistics() - - useDidShow(() => { - ApigetTotal() - getAdminUserInfo() - Apiassets() - }) - const checkGo = () => { - if (adminUserInfo?.authentication_status === 0 || adminUserInfo?.authentication_status === 1 || adminUserInfo?.authentication_status === 2 || adminUserInfo?.authentication_status === 3) { - Taro.showModal({ - title: '提示', - content: '你还未认证,认证后解锁更多功能', - cancelText: '稍后认证', - confirmText: '去认证', - success: function (res) { - if (res.confirm) { - Taro.navigateTo({ url: '/pages/certification/index' }) - } else if (res.cancel) { - console.log('用户点击取消') - } - } - }) - } else { - Taro.navigateTo({ - url: "/pages/creditLine/index" - }) - } - } - return ( - -
- checkGo()} userInfo={adminUserInfo}/> -
- {/* {(adminUserInfo as any)?.authentication_status==1&&} */} - {/* 测试暂时添加 */} - {current_version} - {current_env === 'development' &&{BASE_URL}} - {!adminUserInfo?.is_authorize_name && } - - ) + useDidShow(() => { + ApigetTotal() + getAdminUserInfo() + Apiassets() + }) + const checkGo = () => { + if ( + adminUserInfo?.authentication_status === 0 || + adminUserInfo?.authentication_status === 1 || + adminUserInfo?.authentication_status === 2 || + adminUserInfo?.authentication_status === 3 + ) { + Taro.showModal({ + title: '提示', + content: '你还未认证,认证后解锁更多功能', + cancelText: '稍后认证', + confirmText: '去认证', + success: function (res) { + if (res.confirm) { + Taro.navigateTo({ url: '/pages/certification/index' }) + } else if (res.cancel) { + console.log('用户点击取消') + } + }, + }) + } else { + Taro.navigateTo({ + url: '/pages/creditLine/index', + }) + } + } + return ( + +
+ checkGo()} userInfo={adminUserInfo} /> +
+ {/* {(adminUserInfo as any)?.authentication_status==1&&} */} + {/* 测试暂时添加 */} + {current_version} + {current_env === 'development' && {BASE_URL}} + {!adminUserInfo?.is_authorize_name && } + + ) } // 提示弹窗 const Modal = memo((props: any) => { - const { data } = props; - const [modalShow, setModalShow] = useState(true); - const handleouter = () => { - } - return ( - <> - {modalShow && - - e.stopPropagation()}> - 首次登录提醒 - - To: 万丰园纺织科技 - 尊敬的老朋友,欢迎你使用小程序商城;由于您是我们长期合作的伙伴,你的组织已自动为你生成,关联后可查看历史订单哟。 - 信息错误请联系客服 - - - - setModalShow(false)}>我知道 - - - - } - - ) + const { data } = props + const [modalShow, setModalShow] = useState(true) + const handleouter = () => {} + return ( + <> + {modalShow && ( + + e.stopPropagation()}> + 首次登录提醒 + + To: 万丰园纺织科技 + + 尊敬的老朋友,欢迎你使用小程序商城;由于您是我们长期合作的伙伴,你的组织已自动为你生成,关联后可查看历史订单哟。 + + 信息错误请联系客服 + + + + setModalShow(false)}>我知道 + + + + )} + + ) }) // 头部 | 订单 const Header = memo((props: any) => { - const { data } = props; - console.log(props, 'propsprops') - let menu = [{ text: "待配布", icon: "icon-daipeibu", url: "/pages/order/orderList/index?status=0" }, { text: "待付款", icon: "icon-daifukuan", url: "/pages/order/orderList/index?status=1" }, - { text: "待发货", icon: "icon-daifahuo", url: "/pages/order/orderList/index?status=2" }, { text: "待收货", icon: "icon-yifahuo", url: "/pages/order/orderList/index?status=3" }, - { text: "退款/售后", icon: "icon-a-tuikuanshouhou", url: "/pages/salesAfter/salesAfterList/index" }]; - const { getPhoneNumber } = useLogin(); - const mGetPhoneNumber = (ev) => { - if (ev.detail?.code) { - getPhoneNumber(ev.detail.code); - } else { - alert.none("绑定失败!"); - } - } - const navTo = () => { - Taro.navigateTo({ - // url: '/pages/certification/index' - url: '/pages/userEdit/index' - }) - } - return ( - - - - - - - - - - {/* {state.data.user_name} */} - {data?.user_name} - - - {data?.phone ? data?.phone?.replace(data?.phone?.substring(3, 7), "****") : } - - - - - - - - - - - - {((data?.authentication_status == 0 || data?.authentication_status == 1) && data?.order_access_status == 3) && - navTo()}> - - - 未认证 - - - 暂未加入或注册组织 - - - - - } - {(data?.authentication_status == 3 && data?.order_access_status == 3) && - navTo()}> - - - 认证失败 - - - 暂未加入或注册组织 - - - - - } - {(data?.authentication_status == 2 && data?.order_access_status == 3) && - navTo()}> - - - 认证中 - - - {data?.company_name || '暂未加入或注册组织'} - - - - - } - {(data?.authentication_status == 4 && data?.order_access_status == 3) && - navTo()}> - - - - - - 已认证 - - - {data?.company_name} - - - - - } - {/* + const { data } = props + console.log(props, 'propsprops') + let menu = [ + { text: '待配布', icon: 'icon-daipeibu', url: '/pages/order/orderList/index?status=0' }, + { text: '待付款', icon: 'icon-daifukuan', url: '/pages/order/orderList/index?status=1' }, + { text: '待发货', icon: 'icon-daifahuo', url: '/pages/order/orderList/index?status=2' }, + { text: '待收货', icon: 'icon-yifahuo', url: '/pages/order/orderList/index?status=3' }, + { text: '退款/售后', icon: 'icon-a-tuikuanshouhou', url: '/pages/salesAfter/salesAfterList/index' }, + ] + const { getPhoneNumber } = useLogin() + const mGetPhoneNumber = (ev) => { + if (ev.detail?.code) { + getPhoneNumber(ev.detail.code) + } else { + alert.none('绑定失败!') + } + } + const navTo = () => { + Taro.navigateTo({ + // url: '/pages/certification/index', + url: '/pages/userEdit/index', + }) + } + return ( + + + + + + + + + + {/* {state.data.user_name} */} + {data?.user_name} + + + {data?.phone ? ( + data?.phone?.replace(data?.phone?.substring(3, 7), '****') + ) : ( + + )} + + + + + + + + + + + + {(data?.authentication_status == 0 || data?.authentication_status == 1) && data?.order_access_status == 3 && ( + navTo()}> + + 未认证 + {data?.company_name || '暂未加入或注册组织'} + + + + )} + {data?.authentication_status == 3 && data?.order_access_status == 3 && ( + navTo()}> + + 认证失败 + {data?.company_name || '暂未加入或注册组织'} + + + + )} + {data?.authentication_status == 2 && data?.order_access_status == 3 && ( + navTo()}> + + 认证中 + {data?.company_name || '暂未加入或注册组织'} + + + + )} + {data?.authentication_status == 4 && data?.order_access_status == 3 && ( + navTo()}> + + + + + + 已认证 + + {data?.company_name} + + + + )} + {/* 1 {data?.authentication_status==1&&"未认证"} @@ -230,137 +218,131 @@ const Header = memo((props: any) => { {data?.authentication_status==3&&重新认证 } {data?.authentication_status==4&&认证通过,可以下单啦 } */} - {/* + {/* {data?.authentication_status==1&&"暂未加入或注册组织"} {data?.authentication_status==2&&data?.company_name} {data?.authentication_status==3&&data?.company_name} {data?.authentication_status==4&&data?.company_name} */} - - - - 订单 - goLink('/pages/order/orderList/index')}>全部 - - - { - menu.map((item, index) => { - return ( - - - {item.text} - { - index == 0 && props.MenuData.data.wait_match !== 0 && - - {props.MenuData.data.wait_match > 99 ? '99+' : props.MenuData.data.wait_match} - - } - { - index == 1 && props.MenuData.data.wait_pay !== 0 && - - {props.MenuData.data.wait_pay > 99 ? '99+' : props.MenuData.data.wait_pay} - - } - { - index == 2 && props.MenuData.data.wait_shipped !== 0 && - - {props.MenuData.data.wait_shipped > 99 ? '99+' : props.MenuData.data.wait_shipped} - - } - { - index == 3 && props.MenuData.data.already_shipped !== 0 && - - {props.MenuData.data.already_shipped > 99 ? '99+' : props.MenuData.data.already_shipped} - - } - { - index == 4 && props.MenuData.data.after_return !== 0 && - - {props.MenuData.data.after_return > 99 ? '99+' : props.MenuData.data.after_return} - - } - - - ) - }) - } - - - - - ) + + + + 订单 + goLink('/pages/order/orderList/index')}> + 全部 + + + + {menu.map((item, index) => { + return ( + + + {item.text} + {index == 0 && props.MenuData.data.wait_match !== 0 && ( + + {props.MenuData.data.wait_match > 99 ? '99+' : props.MenuData.data.wait_match} + + )} + {index == 1 && props.MenuData.data.wait_pay !== 0 && ( + + {props.MenuData.data.wait_pay > 99 ? '99+' : props.MenuData.data.wait_pay} + + )} + {index == 2 && props.MenuData.data.wait_shipped !== 0 && ( + + {props.MenuData.data.wait_shipped > 99 ? '99+' : props.MenuData.data.wait_shipped} + + )} + {index == 3 && props.MenuData.data.already_shipped !== 0 && ( + + {props.MenuData.data.already_shipped > 99 ? '99+' : props.MenuData.data.already_shipped} + + )} + {index == 4 && props.MenuData.data.after_return !== 0 && ( + + {props.MenuData.data.after_return > 99 ? '99+' : props.MenuData.data.after_return} + + )} + + ) + })} + + + + + ) }) // 我的资产 const Assets = (props: any) => { - return ( - <> - {(props?.userInfo?.order_access_status == 3) && - 我的资产 - - - - ¥ - {formatPriceDiv(props.data.data.wallet_money || 0, 100, true)} - {/* {props.wallet_money || 0} */} - - 预存款 - - {/* + return ( + <> + {(props?.userInfo?.order_access_status == 3 && ( + + 我的资产 + + + + ¥ + {formatPriceDiv(props.data.data.wallet_money || 0, 100, true)} + {/* {props.wallet_money || 0} */} + + 预存款 + + {/* {props.data.data.coupon_count || 0} 优惠券 */} - props.checkShow()}> - - ¥ - {formatPriceDiv(props.data.data.credit_line || 0, 100, true)} - {/* .-00 */} - - 授信额度 - - - ||} - - ) -}; + props.checkShow()}> + + ¥ + {formatPriceDiv(props.data.data.credit_line || 0, 100, true)} + {/* .-00 */} + + 授信额度 + + + + )) || } + + ) +} // 功能 const Main = memo(() => { - let menu = [ - { text: "我的客服", icon: "icon-wodekefu", type: 'customer', label:'(0757) 8270 6695'}, - { text: "地址管理", icon: "icon-daohang", url: "/pages/addressManager/index", type: 'url' }, - { text: "码单管理", icon: "icon-a-yuanmadanmadanguanli", url: "/pages/weightList/index", type: 'url' }, - { text: "我的收藏", icon: "icon-shoucang", url: "/pages/collection/index", type: 'url' }, - { text: "颜色对比", icon: "icon-yanseduibi", url: "/pages/sampleComparison/index", type: 'url' }, - // { text: "分享推广", icon: "icon-fenxiang" }, - { text: "邀请码", icon: "icon-yaoqingma", url: "/pages/bindSalesman/index", type: 'url' }, - ] - const navigation = (item) => { - if(item.type === 'url') goLink(item.url) - } - return ( - - - { - menu.map((item, index) => { - return ( - navigation(item)} key={index} className={styles['card-main-list-content-item']}> - - - {item.text} - - {item.label} - - - - {item.type === 'customer' && } - - ) - }) - } - - - ) -}) \ No newline at end of file + let menu = [ + { text: '我的客服', icon: 'icon-wodekefu', type: 'customer', label: '(0757) 8270 6695' }, + { text: '地址管理', icon: 'icon-daohang', url: '/pages/addressManager/index', type: 'url' }, + { text: '码单管理', icon: 'icon-a-yuanmadanmadanguanli', url: '/pages/weightList/index', type: 'url' }, + { text: '我的收藏', icon: 'icon-shoucang', url: '/pages/collection/index', type: 'url' }, + { text: '颜色对比', icon: 'icon-yanseduibi', url: '/pages/sampleComparison/index', type: 'url' }, + // { text: "分享推广", icon: "icon-fenxiang" }, + { text: '邀请码', icon: 'icon-yaoqingma', url: '/pages/bindSalesman/index', type: 'url' }, + ] + const navigation = (item) => { + if (item.type === 'url') goLink(item.url) + } + return ( + + + {menu.map((item, index) => { + return ( + navigation(item)} key={index} className={styles['card-main-list-content-item']}> + + + {item.text} + + {item.label} + + + + {item.type === 'customer' && } + + ) + })} + + + ) +})