From 072e818279de56d7819386d00abaa283db22b9ce Mon Sep 17 00:00:00 2001 From: li tong bao <2903733959@qq.com> Date: Wed, 18 May 2022 18:18:24 +0800 Subject: [PATCH 1/4] =?UTF-8?q?--=E5=9C=B0=E5=9D=80=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=A2=9E=E5=8A=A0=E7=84=A6=E7=82=B9=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E3=80=81=E6=98=AF=E5=90=A6=E6=98=BE=E7=A4=BA=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8C=89=E9=92=AE=E3=80=81=E9=BB=98=E8=AE=A4=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=80=BC=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AddressList/index.tsx | 35 +++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/components/AddressList/index.tsx b/src/components/AddressList/index.tsx index e60a20f..8d30912 100644 --- a/src/components/AddressList/index.tsx +++ b/src/components/AddressList/index.tsx @@ -7,15 +7,29 @@ import {addressListApi} from "@/api/addressManager" interface Params{ refresherEnabled?: boolean,//是否开启刷新 onSelect?: (item:any,index:number)=>void,//列表选择 - + addButtonEnabled?: boolean, //是否显示添加按钮 + focusBorderEnabled?: boolean, //焦点显示蓝色边框 + id?: number, //默认选择值 } // 地址列表 const AddressList = memo((props:Params)=>{ + const {addButtonEnabled=true,focusBorderEnabled=false} = props; const {fetchData, state} = addressListApi() // 获取数据 - const getData = ()=>{ - fetchData(); + const getData = async ()=>{ + const result = await fetchData(); + if(props.id){ + setFocusId(props.id as any); + }else{ + result.data.list?.every(item=>{ + if(item.is_default){ + setFocusId(item.id); + return false; + } + return true; + }) + } } useEffect(()=>{ getData(); @@ -25,10 +39,19 @@ const AddressList = memo((props:Params)=>{ const [refreshState, setRefreshState] = useState(false); const handleRefresh = async ()=>{ setRefreshState(true); - await fetchData(); + await getData(); setRefreshState(false); } const data = Array.from({length:15}); + // 焦点 + const [focusId, setFocusId] = useState(); + // 列表选择 + const handleSelect = (item: any, index: number)=>{ + props.onSelect&&props.onSelect(item,index); + if(focusBorderEnabled){ + setFocusId(item?.id); + } + } return ( @@ -39,7 +62,7 @@ const AddressList = memo((props:Params)=>{ // data.length>0? // data.map((item,index)=>{ return( - props.onSelect&&props.onSelect(item,index)} className={`address-list ${item.is_default&&'address-active'}`}> + handleSelect(item,index)} className={`address-list ${focusId==item.id&&'address-active'}`}> {item.name} { @@ -62,7 +85,7 @@ const AddressList = memo((props:Params)=>{ ); }): - 暂未添加地址 + addButtonEnabled&&暂未添加地址 } 添加收货地址 From edde094dc40e7dce2914171ca822c957b547d3a6 Mon Sep 17 00:00:00 2001 From: li tong bao <2903733959@qq.com> Date: Wed, 18 May 2022 18:22:17 +0800 Subject: [PATCH 2/4] =?UTF-8?q?--=E5=9C=B0=E5=9D=80=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/addressManager.ts | 22 +++++++++++ src/common/constant.js | 2 +- src/components/AddressList/index.scss | 3 ++ src/components/AddressList/index.tsx | 33 +++++++++++++++-- src/pages/addressAdd/index.tsx | 53 ++++++++++++++++----------- 5 files changed, 87 insertions(+), 26 deletions(-) diff --git a/src/api/addressManager.ts b/src/api/addressManager.ts index 376ba04..ffa3dcd 100644 --- a/src/api/addressManager.ts +++ b/src/api/addressManager.ts @@ -32,3 +32,25 @@ import { useRequest } from "@/use/useHttp" method: "get", }) } + +/** + * 地址编辑 + * @returns + */ + export const addressEditApi = () => { + return useRequest({ + url: `/v1/mall/address`, + method: "put", + }) +} + +/** + * 地址删除 + * @returns + */ + export const addressDeleteApi = () => { + return useRequest({ + url: `/v1/mall/address`, + method: "delete", + }) +} diff --git a/src/common/constant.js b/src/common/constant.js index 7c65e86..b856a54 100644 --- a/src/common/constant.js +++ b/src/common/constant.js @@ -8,7 +8,7 @@ export const BASE_URL = `http://192.168.1.30:40001/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.165:40001/lymarket` // 王霞 +// export const BASE_URL = `http://192.168.1.4:40001/lymarket` // 王霞 // export const BASE_URL = `http://192.168.1.224:50002/lymarket` // 添 // CDN diff --git a/src/components/AddressList/index.scss b/src/components/AddressList/index.scss index 6089a65..5f8cd5b 100644 --- a/src/components/AddressList/index.scss +++ b/src/components/AddressList/index.scss @@ -22,6 +22,9 @@ border: 1px solid #68b4ff; box-shadow: 0px 0px 10px 0px rgba(0,122,255,0.27); } + .address-list:first-child{ + margin-top: 0; + } .address-list:last-child{ margin-bottom: 300px; } diff --git a/src/components/AddressList/index.tsx b/src/components/AddressList/index.tsx index 8d30912..ae48293 100644 --- a/src/components/AddressList/index.tsx +++ b/src/components/AddressList/index.tsx @@ -2,7 +2,9 @@ import { Button, Navigator, ScrollView, Text, View } from "@tarojs/components" import { memo, useEffect, useState } from "react" import "./index.scss" -import {addressListApi} from "@/api/addressManager" +import {addressListApi,addressDeleteApi} from "@/api/addressManager" +import { alert } from "@/common/common" +import Taro, { showModal } from "@tarojs/taro" interface Params{ refresherEnabled?: boolean,//是否开启刷新 @@ -33,8 +35,12 @@ const AddressList = memo((props:Params)=>{ } useEffect(()=>{ getData(); + // 监听刷新 + Taro.eventCenter.on("addressList:refresh", getData); + return ()=>{ + Taro.eventCenter.off("addressList:refresh", getData); + } },[]) - // 处理刷新 const [refreshState, setRefreshState] = useState(false); const handleRefresh = async ()=>{ @@ -52,6 +58,25 @@ const AddressList = memo((props:Params)=>{ setFocusId(item?.id); } } + // 删除地址 + const {fetchData: deleteFetch} = addressDeleteApi() + const handleDelete = (item:any)=>{ + showModal(({ + title: "提示", + content: "是否删除地址?", + async success(ev){ + if(ev.confirm){ + const result = await deleteFetch({id:item.id}); + if(result.success){ + alert.success("删除成功"); + getData(); + }else{ + alert.success(result.msg); + } + } + } + })) + } return ( @@ -62,7 +87,7 @@ const AddressList = memo((props:Params)=>{ // data.length>0? // data.map((item,index)=>{ return( - handleSelect(item,index)} className={`address-list ${focusId==item.id&&'address-active'}`}> + handleDelete(item)} onClick={()=>handleSelect(item,index)} className={`address-list ${focusId==item.id&&'address-active'}`}> {item.name} { @@ -75,7 +100,7 @@ const AddressList = memo((props:Params)=>{ {/* **省**市**区**街道****仓库 */} {item.province_name+item.city_name+item.district_name} {item.address_detail} { - item.is_default&&{item.phone} + item.is_default&&{item.phone.replace(item.phone.substring(3,7), "****")} } diff --git a/src/pages/addressAdd/index.tsx b/src/pages/addressAdd/index.tsx index caf683f..63721ed 100644 --- a/src/pages/addressAdd/index.tsx +++ b/src/pages/addressAdd/index.tsx @@ -6,7 +6,7 @@ import { Button, Input, Text, Textarea, View } from "@tarojs/components" import Taro, { setNavigationBarTitle, useRouter } from "@tarojs/taro" import { useEffect, useState } from "react" import "./index.scss" -import {addressAddApi, addressDetailApi} from "@/api/addressManager" +import {addressAddApi, addressDetailApi,addressEditApi} from "@/api/addressManager" export default ()=>{ const [showSiteModal, setShowSiteModal] = useState(false); @@ -15,7 +15,7 @@ export default ()=>{ if(type=="add"){ setNavigationBarTitle({title:"新增收货地址"}) }else{ - // initalFormData(); + initalFormData(); setNavigationBarTitle({title:"编辑收货地址"}) } },[]) @@ -23,19 +23,24 @@ export default ()=>{ const {fetchData: getFromData} = addressDetailApi() const initalFormData = async ()=>{ const detail = await getFromData({id}); - const siteArray = [] - // setFormData({ - // name: detail.data.name, - // phone: detail.data.phone, - // site: detail.data., - // siteArray: [], - // district_id: detail.data.district_id, - // address_detail: detail.data.address_detail, - // is_default: false - // }) + const { province_id,province_name,city_id,city_name,district_id,district_name } = detail.data; + const siteArray = [{id: province_id, name: province_name}]; + city_id&&siteArray.push({id: city_id, name: city_name}); + district_id&&siteArray.push({id: district_id, name: district_name}); + setFormData({ + name: detail.data.name, + phone: detail.data.phone, + site: siteArray.map(item=>item.name).join(" "), + siteArray: siteArray as any, + district_id: detail.data.district_id, + address_detail: detail.data.address_detail, + is_default: detail.data.is_default, + id: detail.data.id, + }) } - const {fetchData, state} = addressAddApi() + const {fetchData} = addressAddApi() + const {fetchData: editFetch} = addressEditApi() // 保存 const [formData, setFormData] = useState({ name: "", @@ -44,7 +49,8 @@ export default ()=>{ siteArray: [], district_id:"", address_detail: "", - is_default: false + is_default: false, + id: 0 }) const rules = { name: [{ @@ -62,20 +68,27 @@ export default ()=>{ } const handleSave = ()=>{ retrieval(formData, rules).then(async ()=>{ - const result = await fetchData({ + const result = type=="add"?await fetchData({ name: formData.name, phone:formData.phone, - site:formData.site, district_id:formData.district_id, address_detail: formData.address_detail, is_default: formData.is_default + }):await editFetch({ + name: formData.name, + phone:formData.phone, + district_id:formData.district_id, + address_detail: formData.address_detail, + is_default: formData.is_default, + id: formData.id }); if(result.success){ - alert.success("保存成功") + Taro.eventCenter.trigger("addressList:refresh"); + Taro.navigateBack(); + alert.success("保存成功"); }else{ alert.error(result.msg); } - // Taro.navigateBack(); }).catch((message)=>{ alert.none(message) }) @@ -89,8 +102,6 @@ export default ()=>{ },[formData]) // 设置选择地址 const handleSetSite = (ev:any)=>{ - console.log(ev); - if(ev.length>=3){ setFormData({ ...formData, @@ -123,7 +134,7 @@ export default ()=>{ -
setShowSiteModal(false)} show={showSiteModal}/> +
setShowSiteModal(false)} show={showSiteModal}/> ) } From 783dd84263c7cdf3a4d7ba8670ee0439765c0758 Mon Sep 17 00:00:00 2001 From: czm <2192718639@qq.com> Date: Thu, 12 May 2022 18:11:14 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/common.ts | 1 + src/components/address/index.tsx | 2 +- src/components/shopCart/index.module.scss | 4 +-- src/components/shopCart/index.tsx | 38 ++++++++++++++--------- src/pages/addressAdd/index.tsx | 1 - src/pages/order/index.tsx | 30 ++++++++++++++++-- 6 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/common/common.ts b/src/common/common.ts index 5081eb8..080373b 100644 --- a/src/common/common.ts +++ b/src/common/common.ts @@ -10,6 +10,7 @@ import Qs from 'qs' export const goLink = (path = '', params = {}, type:false|true = false) => { if(path) { let params_str = Qs.stringify(params) + console.log('params_str::',params_str) path = params_str?path+'?'+params_str:path if(!type) { Taro.navigateTo({ diff --git a/src/components/address/index.tsx b/src/components/address/index.tsx index b3b9072..491ac06 100644 --- a/src/components/address/index.tsx +++ b/src/components/address/index.tsx @@ -8,7 +8,7 @@ import { GetAddressListApi } from "@/api/addressList"; import { alert } from "@/common/common"; -type DefaultValueParm = {name: string, id:string|number, level: number|string} +type DefaultValueParm = {name: string, id:string|number, level?: number|string} type Params = { addressOnSelect?: (val:DefaultValueParm[]) => void, diff --git a/src/components/shopCart/index.module.scss b/src/components/shopCart/index.module.scss index ca891ed..9af0c2e 100644 --- a/src/components/shopCart/index.module.scss +++ b/src/components/shopCart/index.module.scss @@ -20,9 +20,9 @@ .search{ display: flex; justify-content: space-between; - padding: 0 20px; + padding: 0 30px; .search_item{ - width: 148px; + width: 200px; height: 55px; text-align: center; line-height: 55px; diff --git a/src/components/shopCart/index.tsx b/src/components/shopCart/index.tsx index 9d9f7c5..dc900f4 100644 --- a/src/components/shopCart/index.tsx +++ b/src/components/shopCart/index.tsx @@ -5,7 +5,7 @@ import MCheckbox from "@/components/checkbox"; import LoadingCard from "@/components/loadingCard"; import InfiniteScroll from "@/components/infiniteScroll"; import styles from "./index.module.scss" -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import Taro from "@tarojs/taro"; import { alert, goLink } from "@/common/common"; import {GetShoppingCartApi, DelShoppingCartApi} from "@/api/shopCart" @@ -17,14 +17,14 @@ type param = { } export default ({show = false, onClose}: param) => { const selectList = [ - {value:-1, title:'不限', unit:'', eunit:''}, + // {value:-1, title:'不限', unit:'', eunit:''}, {value:0, title:'大货', unit:'件', eunit:'kg'}, {value:1,title:'剪板', unit:'米', eunit:'m'}, {value:2,title:'散剪', unit:'米', eunit:'kg'}, ] - const [selectIndex, setSelectIndex] = useState(-1) + const [selectIndex, setSelectIndex] = useState(0) const selectProduct = (index:number) => { setSelectIndex(index) } @@ -61,18 +61,16 @@ export default ({show = false, onClose}: param) => { //初始化全部数据 const initList = (color_list) => { - if(selectIndex == -1) { - color_list?.map(item => { - item.select = true - }) - } + color_list?.map(item => { + if(selectIndex == item.sale_mode) item.select = true + }) } //显示是展示数据 useEffect(() => { if(!show) { setList([]) - setSelectIndex(-1) + setSelectIndex(0) } else { getShoppingCart() } @@ -167,6 +165,7 @@ export default ({show = false, onClose}: param) => { //获取面料选中的id const selectIds = useRef([]) const getSelectId = () => { + selectIds.current = [] list?.map(item => { if(selectIndex == -1 || selectIndex == item.sale_mode) { item.select&&selectIds.current.push(item.id) @@ -185,13 +184,24 @@ export default ({show = false, onClose}: param) => { return item.sale_mode == 0? item.roll + '件': item.length + 'm' }, []) + //预估金额 + const estimatePrice = useMemo(() => { + let count = 0 + list.map(item => { + if(item.select) count += item.sale_price + }) + return Number(formatMillionYuan(count, 100).num) + },[list]) + //去结算 const orderDetail = () => { - if(selectIndex == -1 ) { - console.log(selectIndex, selectIds.current) + getSelectId() + if(selectIds.current.length == 0) { alert.error('请选择面料') - } - goLink('/pages/order/index',{ids:selectIds.current, sale_mode:selectIndex}) + } else { + let ids = selectIds.current.join('-') + goLink('/pages/order/index',{ids, sale_mode:selectIndex}) + } } @@ -248,7 +258,7 @@ export default ({show = false, onClose}: param) => { - 200 + {estimatePrice} 预估金额 orderDetail()}> diff --git a/src/pages/addressAdd/index.tsx b/src/pages/addressAdd/index.tsx index 63721ed..0399a4d 100644 --- a/src/pages/addressAdd/index.tsx +++ b/src/pages/addressAdd/index.tsx @@ -112,7 +112,6 @@ export default ()=>{ }else{ alert.error("请选择完整地址"); } - } return ( diff --git a/src/pages/order/index.tsx b/src/pages/order/index.tsx index bc303c0..c53952b 100644 --- a/src/pages/order/index.tsx +++ b/src/pages/order/index.tsx @@ -1,9 +1,10 @@ +import { SaleOrderPreViewApi } from "@/api/order"; import Popup from "@/components/popup"; import SearchInput from "@/components/searchInput"; import { Text, Textarea, View } from "@tarojs/components" -import Taro from "@tarojs/taro"; +import Taro, { useRouter } from "@tarojs/taro"; import classnames from "classnames"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import AddressInfo from "./components/addressInfo"; import EstimatedAmount from "./components/estimatedAmount"; import KindList from "./components/kindList"; @@ -25,6 +26,29 @@ import styles from './index.module.scss' } }) } + //获取购物车传过来的id + type orderPreParam = {shopping_cart_product_color_list:{shopping_cart_product_color_id:number}[], sale_mode:number} + const router = useRouter() + const idsAndSaleModel = useRef({shopping_cart_product_color_list:[], sale_mode:0}) + useEffect(() => { + idsAndSaleModel.current.sale_mode = Number(router.params.sale_mode) + router.params.ids?.split('-')?.map(item => { + return idsAndSaleModel.current.shopping_cart_product_color_list?.push({ + shopping_cart_product_color_id: Number(item) + }) + }) + getSaleOrderPreView() + }, []) + + //获取销售订单预览图 + const {fetchData} = SaleOrderPreViewApi() + const getSaleOrderPreView = async () => { + if(idsAndSaleModel.current.shopping_cart_product_color_list?.length > 0) { + let res = await fetchData(idsAndSaleModel.current) + console.log('res::', res) + } + } + return ( @@ -65,4 +89,4 @@ import styles from './index.module.scss' ) - } \ No newline at end of file + } From c403c2acb13c2a04a1bcd03c1ce75b21dea56df4 Mon Sep 17 00:00:00 2001 From: li tong bao <2903733959@qq.com> Date: Wed, 18 May 2022 18:38:51 +0800 Subject: [PATCH 4/4] =?UTF-8?q?--=E5=9C=B0=E5=9D=80=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AddressList/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/AddressList/index.tsx b/src/components/AddressList/index.tsx index ae48293..e412e63 100644 --- a/src/components/AddressList/index.tsx +++ b/src/components/AddressList/index.tsx @@ -110,10 +110,10 @@ const AddressList = memo((props:Params)=>{ ); }): - addButtonEnabled&&暂未添加地址 + 暂未添加地址 } - 添加收货地址 + {addButtonEnabled&&添加收货地址} ) })