diff --git a/src/api/shopCart.ts b/src/api/shopCart.ts index 87e0d32..291ab60 100644 --- a/src/api/shopCart.ts +++ b/src/api/shopCart.ts @@ -31,4 +31,15 @@ export const DelShoppingCartApi = () => { url: `/v1/mall/shoppingCart/productColor`, method: "delete", }) +} + +/** + * 修改购物车数量 + * @returns +*/ +export const UpdateShoppingCartApi = () => { + return useRequest({ + url: `/v1/mall/shoppingCart/productColor`, + method: "put", + }) } \ No newline at end of file diff --git a/src/app.config.ts b/src/app.config.ts index 27b804e..e735150 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -171,6 +171,12 @@ export default { pages: [ "index", ] + }, + { + root: "pages/collection", + pages: [ + "index", + ] } ] } diff --git a/src/common/constant.js b/src/common/constant.js index 8e897bc..42b4b0b 100644 --- a/src/common/constant.js +++ b/src/common/constant.js @@ -6,11 +6,11 @@ // export const BASE_URL = `http://192.168.1.165:40001/lymarket` // 王霞 // export const BASE_URL = `https://test.zzfzyc.com/lymarket` // 测试环境 // export const BASE_URL = `http://192.168.1.30:40001/lymarket` // 发 -export const BASE_URL = `http://192.168.1.30:50001/lymarket` // 发 +// export const BASE_URL = `http://192.168.1.30:50001/lymarket` // 发 // export const BASE_URL = `https://dev.zzfzyc.com/lymarket` // 开发环境 // export const BASE_URL = `https://www.zzfzyc.com/lymarket` // 正式环境 // export const BASE_URL = `http://192.168.1.5:40001/lymarket` // 王霞 -// export const BASE_URL = `http://192.168.1.224:50002/lymarket` // 添 +export const BASE_URL = `http://192.168.1.224:50002/lymarket` // 添 // export const BASE_URL = `http://192.168.1.15:50001/lymarket` // 杰 // CDN diff --git a/src/components/counter/index.tsx b/src/components/counter/index.tsx index 37c1e59..9ff7d87 100644 --- a/src/components/counter/index.tsx +++ b/src/components/counter/index.tsx @@ -11,12 +11,14 @@ type params = { onChange?:(val:number) => void, onBlue?:(val:number) => void, //失去焦点触发 onClickBtn?:(val:number) => void, - unit?: string + unit?: string, + disable?: true|false, //是否禁用 } -export default ({minNum = 0, maxNum = 10000, step=1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = ''}: params) => { +export default ({minNum = 0, maxNum = 10000, step=1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = '', disable = false}: params) => { const [value, setValue] = useState({count:defaultNum}) const onPlus = () => { + if(disable) return false let {count} = value let num_res = Big(count).add(step).toNumber() num_res = num_res >= maxNum?maxNum:num_res @@ -26,6 +28,7 @@ export default ({minNum = 0, maxNum = 10000, step=1, digits = 0, defaultNum = 0, onClickBtn?.(parseFloat(num_res)) } const minus = () => { + if(disable) return false let {count} = value let num_res = Big(count).minus(step).toNumber() num_res = num_res < minNum?minNum:num_res @@ -102,6 +105,7 @@ export default ({minNum = 0, maxNum = 10000, step=1, digits = 0, defaultNum = 0, onInput={onInputEven} onBlur={onBluerEven} type='digit' + disabled={disable} /> {unit} diff --git a/src/components/orderBtns/index.tsx b/src/components/orderBtns/index.tsx index c1f23b2..871f2a2 100644 --- a/src/components/orderBtns/index.tsx +++ b/src/components/orderBtns/index.tsx @@ -6,6 +6,7 @@ import Taro from "@tarojs/taro" import {useRef, memo, useState, useMemo } from "react" import classnames from "classnames"; import styles from './index.module.scss' +import { AddShoppingCartApi } from "@/api/shopCart" type Param = { orderInfo: { @@ -180,6 +181,7 @@ export default memo(({orderInfo, onClick}:Param) => { }) } + //显示更多按钮 const [showMore, setShowMore] = useState(false) const styleTop = useMemo(() => { diff --git a/src/components/shopCart/index.module.scss b/src/components/shopCart/index.module.scss index 43de2c1..008bf06 100644 --- a/src/components/shopCart/index.module.scss +++ b/src/components/shopCart/index.module.scss @@ -17,6 +17,11 @@ margin-right: 10px; } } + .count_all{ + font-size: 22px; + color: #ABABAB; + padding: 30px 20px; + } .search{ display: flex; justify-content: space-between; @@ -104,6 +109,15 @@ flex-direction: column; justify-content: space-between; align-items: flex-end; + .btn_count{ + width: 235px; + height: 64px; + background-color: #ECF5FF; + border-radius: 40px 0px 16px 0px; + padding: 0 20px; + display: flex; + align-items: center; + } .price{ font-size: $font_size; font-weight: 700; diff --git a/src/components/shopCart/index.tsx b/src/components/shopCart/index.tsx index d76c056..497e587 100644 --- a/src/components/shopCart/index.tsx +++ b/src/components/shopCart/index.tsx @@ -8,7 +8,7 @@ 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} from "@/api/shopCart" +import {GetShoppingCartApi, DelShoppingCartApi, UpdateShoppingCartApi} from "@/api/shopCart" import { formatHashTag, formatImgUrl, formatPriceDiv } from "@/common/fotmat"; import { setParam } from "@/common/system"; import { debounce } from "@/common/util"; @@ -189,14 +189,24 @@ export default ({show = false, onClose}: param) => { return item.sale_mode == 0? '条':'米' }, []) - //预估金额 + //预估金额和总条数 const estimatePrice = useMemo(() => { - let count = 0 + let estimate_amount = 0 + let product_list = new Set() //面料 + let color_count = 0 //颜色数量 + let all_count = 0 //总数量 list.map(item => { - if(item.select) count += item.estimate_amount + if(item.select) { + estimate_amount += item.estimate_amount + product_list.add(item.product_id) + color_count++ + all_count += item.sale_mode == 0?item.roll: (item.length) + } }) - return Number(formatPriceDiv(count)) + let all_count_text = selectIndex == 0?all_count + '条': (all_count/100) + '米' + return {price: Number(formatPriceDiv(estimate_amount)), countText: `已选${product_list.size}种面料,${color_count}个颜色,共${all_count_text}`, color_count} },[list]) + //去结算 const orderDetail = debounce(() => { @@ -205,18 +215,27 @@ export default ({show = false, onClose}: param) => { alert.error('请选择面料') } else { let ids = selectIds.current.join('-') - setParam({ids, sale_mode:selectIndex}) + setParam({ids, sale_mode:selectIndex}) //临时存储 closePopup() goLink('/pages/order/comfirm') } }, 500) - //计数组件 - const getInputValue = (num, item) => { - item.count = parseFloat(num) - setList([...list]) + //计数组件-当后端修改完成才修改前端显示 + const {fetchData: fetchDataUpdateShoppingCart} = UpdateShoppingCartApi() + const [UpdateShoppingCartLoading, setUpdateShoppingCartLoading] = useState(false) + const getInputValue = 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) { + item.count = parseFloat(num) + setList([...list]) + } + } - return ( @@ -229,6 +248,7 @@ export default ({show = false, onClose}: param) => { 删除所选 + {estimatePrice.countText} {selectList.map((item) => { return selectProduct(item.value)} className={classnames(styles.search_item, (selectIndex==item.value)&&styles.search_item_select)}>{item.title} @@ -254,16 +274,19 @@ export default ({show = false, onClose}: param) => { {formatPirce(item.sale_price)}/{selectList[selectIndex].eunit} {/* ×{formatCount(item)} */} - getInputValue(e, item)} - defaultNum={item.count} - step={selectList[selectIndex].step} - digits={selectList[selectIndex].digits} - onClickBtn={(e) => getInputValue(e, item)} - unit={formatUnit(item)} - minNum={selectList[selectIndex].minNum} - maxNum={selectList[selectIndex].maxNum} - /> + + getInputValue(e, item)} + defaultNum={item.count} + 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} + /> + })} @@ -281,11 +304,11 @@ export default ({show = false, onClose}: param) => { - {estimatePrice} + {estimatePrice.price} 预估金额 orderDetail()}> - 去结算 + 去结算({estimatePrice.color_count}) diff --git a/src/pages/collection/index.config.ts b/src/pages/collection/index.config.ts new file mode 100644 index 0000000..a316ea6 --- /dev/null +++ b/src/pages/collection/index.config.ts @@ -0,0 +1,4 @@ +export default { + navigationBarTitleText: '我的收藏', + enableShareAppMessage: true, +} diff --git a/src/pages/collection/index.module.scss b/src/pages/collection/index.module.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/collection/index.tsx b/src/pages/collection/index.tsx new file mode 100644 index 0000000..67a9d9f --- /dev/null +++ b/src/pages/collection/index.tsx @@ -0,0 +1,12 @@ +import Search from "@/components/search" +import { View } from "@tarojs/components" +import styles from './index.module.scss' +export default () => { + return ( + + + console.log(e)} placeholder="请输入面料关键词" placeIcon="out" showBtn={true} /> + + + ) + } \ No newline at end of file diff --git a/src/pages/details/components/orderCount/index.tsx b/src/pages/details/components/orderCount/index.tsx index ea454ec..78166e7 100644 --- a/src/pages/details/components/orderCount/index.tsx +++ b/src/pages/details/components/orderCount/index.tsx @@ -296,7 +296,7 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param) // } void, //选择地址 - defaultValue?: AddressInfoParam|null, //默认值 disabled?: false|true, //true禁用后只用于展示 onChangeShipmentMode?: (val: number) => void, //返回收货方式 status?: 1|2, //1确认订单时使用, 2订单流程 @@ -35,7 +34,7 @@ type Param = { } } -export default memo(forwardRef(({onSelect, onChangeShipmentMode, orderInfo, status = 2}: Param, ref) => { +export default memo(forwardRef(({onSelect, onChangeShipmentMode, orderInfo, status = 2, disabled = false}: Param, ref) => { const [addressInfo, setAddressInfo] = useState() @@ -46,6 +45,7 @@ export default memo(forwardRef(({onSelect, onChangeShipmentMode, orderInfo, stat } }, [orderInfo]) + //地址格式 const formatAddress = useMemo(() => { if(addressInfo?.province_name) { @@ -58,7 +58,7 @@ export default memo(forwardRef(({onSelect, onChangeShipmentMode, orderInfo, stat //打开地址列表 const [showAddressList, setShowAddressList] = useState(false) const changeShow = () => { - if(receivingStatus == 2 && !logisticsShow) + if(receivingStatus == 2 && !logisticsShow && !disabledSelect) setShowAddressList(() => true) } @@ -72,6 +72,7 @@ export default memo(forwardRef(({onSelect, onChangeShipmentMode, orderInfo, stat const {fetchData: shipmentModeFetchData} = EditSaleOrderShipmentModeApi() const onReceivingStatus = (value, e) => { e.stopPropagation() + if(!disabledSelect) return false changeReceivingStatus(value) } const changeReceivingStatus = debounce(async (value) => { @@ -123,9 +124,21 @@ export default memo(forwardRef(({onSelect, onChangeShipmentMode, orderInfo, stat SaleOrderStatusAlreadyReceipt, SaleOrderStatusComplete, SaleOrderStatusRefund, - SaleOrderStatusCancel + SaleOrderStatusCancel, } = ORDER_STATUS + //禁用 + const disabledSelect = useMemo(() => { + let statusList = [ + SaleOrderStatusWaitingReceipt.value, + SaleOrderStatusAlreadyReceipt.value, + SaleOrderStatusComplete.value, + SaleOrderStatusRefund.value, + SaleOrderStatusCancel.value, + ] + return (statusList.includes(orderInfo?.status!)||disabled) + }, [orderInfo, disabled]) + //根据订单状态判断是否显示物流 const logisticsShowList = [SaleOrderStatusWaitingReceipt.value, SaleOrderStatusAlreadyReceipt.value, SaleOrderStatusComplete.value, SaleOrderStatusRefund.value, SaleOrderStatusCancel.value] const logisticsShow = useMemo(() => { diff --git a/src/pages/order/index.tsx b/src/pages/order/index.tsx index e1e3b45..e706a52 100644 --- a/src/pages/order/index.tsx +++ b/src/pages/order/index.tsx @@ -4,12 +4,14 @@ import { CancelOrderApi } from "@/api/order"; import { GetOrderPayApi } from "@/api/orderPay"; +import { AddShoppingCartApi } from "@/api/shopCart"; import { alert, goLink } from "@/common/common"; import { ORDER_STATUS } from "@/common/enum"; import { formatDateTime, formatPriceDiv } from "@/common/fotmat"; import OrderBtns from "@/components/orderBtns"; import Popup from "@/components/popup"; import SearchInput from "@/components/searchInput"; +import ShopCart from "@/components/shopCart"; import { Text, Textarea, View } from "@tarojs/components" import Taro, { useDidShow, usePullDownRefresh, useRouter } from "@tarojs/taro"; import classnames from "classnames"; @@ -97,7 +99,8 @@ import styles from './index.module.scss' name: orderDetail?.target_user_name, phone: orderDetail?.target_user_phone, shipment_mode: orderDetail?.shipment_mode, - id: orderDetail?.id + id: orderDetail?.id, + sale_mode: orderDetail?.sale_mode, } }, [orderDetail]) @@ -152,6 +155,9 @@ import styles from './index.module.scss' toPay() } else if(val == 3) { setRefundShow(true) + } else if(val == 7) { + //再购 + addShopCart() } }, [orderDetail]) @@ -199,6 +205,40 @@ import styles from './index.module.scss' setRefundShow(false) }, []) + + + //添加购物车 + const [showCart, setShowCart] = useState(false) + const {fetchData:addFetchData} = AddShoppingCartApi() + const addShopCart = async () => { + let color_list:{product_color_id: number, roll?: number, length?: number}[] = [] + orderDetail?.product_list.map(pitem => { + pitem?.product_colors.map(citem => { + if(orderDetail?.sale_mode == 0) { + return color_list.push({product_color_id: citem.id, roll: citem.roll}) + } else { + return color_list.push({product_color_id: citem.id, length: citem.length}) + } + }) + }) + const state = await addFetchData({ + sale_mode: orderDetail?.sale_mode, + color_list + }) + if(state.success) { + Taro.showToast({ + title:'已加入购物车' + }) + setShowCart(true) + } else { + Taro.showToast({ + icon:'none', + title: state.msg + }) + } + + } + return ( @@ -238,6 +278,7 @@ import styles from './index.module.scss' + setShowCart(false)}/> ) diff --git a/src/pages/salesAfter/components/addressInfoDetail/index.tsx b/src/pages/salesAfter/components/addressInfoDetail/index.tsx index d8e8b70..db4d5f3 100644 --- a/src/pages/salesAfter/components/addressInfoDetail/index.tsx +++ b/src/pages/salesAfter/components/addressInfoDetail/index.tsx @@ -25,7 +25,7 @@ export default memo(({return_address = '', return_phone = '', onLogistics, stage //是否显示地址 const showAddress = useMemo(() => { return stage != ReturnStageApplying.value - }, []) + }, [stage]) //上传物流 const upLogistics = useMemo(() => { diff --git a/src/use/useHttp.ts b/src/use/useHttp.ts index 2663ab8..2f38afc 100644 --- a/src/use/useHttp.ts +++ b/src/use/useHttp.ts @@ -110,7 +110,7 @@ export const useRequest = (options:option = { success: false, // 请求是否成功 data: {}, msg: '', - loading: true, + loading: false, error: null, query: {}, filter: null, @@ -127,7 +127,7 @@ export const useRequest = (options:option = { const {login} = useLoginRequest() useEffect(() => { - console.log('变化::', state.loading) + console.log('变化1::', state.loading) }, [state.loading]) // 请求函数 const fetchData = async (sub_options?:any) => {