对接购物车列表
This commit is contained in:
parent
f3c818f549
commit
d0f069937b
@ -21,3 +21,14 @@ export const AddShoppingCartApi = () => {
|
|||||||
method: "post",
|
method: "post",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除购物车面料颜色
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const DelShoppingCartApi = () => {
|
||||||
|
return useRequest({
|
||||||
|
url: `/v1/mall/shoppingCart/productColor`,
|
||||||
|
method: "delete",
|
||||||
|
})
|
||||||
|
}
|
@ -9,7 +9,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://dev.zzfzyc.com/lymarket` // 开发环境
|
||||||
// export const BASE_URL = `https://www.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.165:40001/lymarket` // 王霞
|
||||||
// export const BASE_URL = `http://192.168.1.224:50001/lymarket` // 添
|
// export const BASE_URL = `http://192.168.1.224:50002/lymarket` // 添
|
||||||
|
|
||||||
// CDN
|
// CDN
|
||||||
// 生成密钥
|
// 生成密钥
|
||||||
@ -17,7 +17,7 @@ export const GET_UPLOAD_SIGN = `/upyun/getsign` // 请求签名 url
|
|||||||
export const UPLOAD_CDN_URL = `https://v0.api.upyun.com/`
|
export const UPLOAD_CDN_URL = `https://v0.api.upyun.com/`
|
||||||
|
|
||||||
// 前缀
|
// 前缀
|
||||||
export const IMG_CND_Prefix = "http://test.cdn.zzfzyc.com/"
|
export const IMG_CND_Prefix = "http://test.cdn.zzfzyc.com"
|
||||||
|
|
||||||
|
|
||||||
// 上传图片视频
|
// 上传图片视频
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { IMG_CND_Prefix } from "./constant";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除井号
|
* 移除井号
|
||||||
* @param {String} val code 编码
|
* @param {String} val code 编码
|
||||||
@ -133,3 +135,12 @@ export const toDecimal2 = (x) => {
|
|||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化图片路径
|
||||||
|
* @param {*} url
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const formatImgUrl = (url) => {
|
||||||
|
return IMG_CND_Prefix + url
|
||||||
|
}
|
@ -1,26 +1,30 @@
|
|||||||
.checkbox_main{
|
.checkbox_main{
|
||||||
width: 40px;
|
width: 50px;
|
||||||
height: 40px;
|
height: 50px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
.checkbox_item{
|
.checkbox_item{
|
||||||
width: 30px;
|
width: 40px;
|
||||||
height: 30px;
|
height: 40px;
|
||||||
border: 1px solid #707070;
|
border: 1px solid #707070;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
}
|
}
|
||||||
|
.no_checkbox_item{
|
||||||
|
border:0;
|
||||||
|
background-color: #DDDDDD;
|
||||||
|
}
|
||||||
.checkbox_item_select{
|
.checkbox_item_select{
|
||||||
background-color: $color_main;
|
background-color: $color_main;
|
||||||
border: 0;
|
border: 0;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
width: 30px;
|
width: 40px;
|
||||||
height: 30px;
|
height: 40px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: 30px;
|
line-height: 40px;
|
||||||
.miconfont{
|
.miconfont{
|
||||||
font-size: 26px;
|
font-size: 26px;
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,15 @@ import { useEffect, useState } from "react";
|
|||||||
import styles from "./index.module.scss"
|
import styles from "./index.module.scss"
|
||||||
|
|
||||||
type params = {
|
type params = {
|
||||||
onSelect?: () => void,
|
onSelect?: () => void, //选择触发
|
||||||
onClose?: () => void,
|
onClose?: () => void, //取消触发
|
||||||
status?: false|true
|
status?: false|true //是否选中
|
||||||
|
disabled?: false|true //是否禁用
|
||||||
}
|
}
|
||||||
export default ({onSelect, onClose, status = false}: params) => {
|
export default ({onSelect, onClose, status = false, disabled = false}: params) => {
|
||||||
const [selected, SetSelected] = useState(false)
|
const [selected, SetSelected] = useState(false)
|
||||||
const onSelectEven = () => {
|
const onSelectEven = () => {
|
||||||
|
if(disabled) return false
|
||||||
let res = !selected
|
let res = !selected
|
||||||
if(res) {
|
if(res) {
|
||||||
onSelect?.()
|
onSelect?.()
|
||||||
@ -25,7 +27,7 @@ export default ({onSelect, onClose, status = false}: params) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<View className={styles.checkbox_main} onClick={() => onSelectEven()}>
|
<View className={styles.checkbox_main} onClick={() => onSelectEven()}>
|
||||||
<View className={classnames(styles.checkbox_item, selected&&styles.checkbox_item_select)}>
|
<View className={classnames(styles.checkbox_item, disabled&&styles.no_checkbox_item, selected&&styles.checkbox_item_select)}>
|
||||||
{selected&&<View className={classnames('iconfont', 'icon-tick', styles.miconfont)}></View>}
|
{selected&&<View className={classnames('iconfont', 'icon-tick', styles.miconfont)}></View>}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
import { View } from "@tarojs/components";
|
import { View } from "@tarojs/components";
|
||||||
import style from "./index.module.scss"
|
import style from "./index.module.scss"
|
||||||
import classnames from "classnames";
|
import classnames from "classnames";
|
||||||
import { memo, ReactNode, useMemo } from "react";
|
import { memo, ReactNode, useEffect, useMemo, useRef } from "react";
|
||||||
import CloseBtnIcon from "@/components/closeBtn"
|
import CloseBtnIcon from "@/components/closeBtn"
|
||||||
|
|
||||||
export interface Params {
|
export interface Params {
|
||||||
title?: string,
|
title?: string, //标题
|
||||||
show?: false|true,
|
show?: false|true, //显示显示弹窗
|
||||||
showTitle?: false|true,
|
showTitle?: false|true, //是否显示标题
|
||||||
onClose?:() => void,
|
onClose?:() => void, //关闭事件
|
||||||
children?: ReactNode,
|
children?: ReactNode, //插槽内容
|
||||||
IconButton?: ReactNode,
|
// IconButton?: ReactNode, //
|
||||||
showIconButton?: false|true,
|
showIconButton?: false|true, //是否显示关闭按钮
|
||||||
position?: 'bottom'|'top'|'right'
|
position?: 'bottom'|'top'|'right', //弹出位置
|
||||||
|
animationEnd?: () => void //弹出动画结束
|
||||||
}
|
}
|
||||||
export default memo((
|
export default memo((
|
||||||
{
|
{
|
||||||
@ -22,9 +23,26 @@ export default memo((
|
|||||||
onClose,
|
onClose,
|
||||||
showIconButton = false,
|
showIconButton = false,
|
||||||
children,
|
children,
|
||||||
position = 'bottom'
|
position = 'bottom',
|
||||||
|
animationEnd
|
||||||
}:Params) => {
|
}:Params) => {
|
||||||
|
|
||||||
|
const animationTime = useRef<any>(null)
|
||||||
|
useEffect(() => {
|
||||||
|
if(show) {
|
||||||
|
animationTime.current = setTimeout(() => {
|
||||||
|
animationEnd?.()
|
||||||
|
}, 260)
|
||||||
|
} else {
|
||||||
|
clearTimeout(animationTime.current)
|
||||||
|
}
|
||||||
|
}, [show])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
clearTimeout(animationTime.current)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
}
|
}
|
||||||
.con{
|
.con{
|
||||||
padding:30px;
|
padding:30px;
|
||||||
padding-bottom: 0;
|
padding-bottom: 100px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
flex:1;
|
flex:1;
|
||||||
height: 0;
|
height: 0;
|
||||||
@ -54,7 +54,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
&:nth-child(n+2) {
|
&:nth-child(n+2) {
|
||||||
margin-top: 30px;
|
margin-top: 37px;
|
||||||
}
|
}
|
||||||
.checkbox{
|
.checkbox{
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -76,6 +76,8 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
|
padding-right: 10px;
|
||||||
|
box-sizing: border-box;
|
||||||
.title{
|
.title{
|
||||||
font-size: $font_size;
|
font-size: $font_size;
|
||||||
color: $color_font_one;
|
color: $color_font_one;
|
||||||
@ -97,6 +99,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.no_product_item_select{
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
.count{
|
.count{
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
@ -5,11 +5,11 @@ import MCheckbox from "@/components/checkbox";
|
|||||||
import LoadingCard from "@/components/loadingCard";
|
import LoadingCard from "@/components/loadingCard";
|
||||||
import InfiniteScroll from "@/components/infiniteScroll";
|
import InfiniteScroll from "@/components/infiniteScroll";
|
||||||
import styles from "./index.module.scss"
|
import styles from "./index.module.scss"
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import Taro from "@tarojs/taro";
|
import Taro from "@tarojs/taro";
|
||||||
import { goLink } from "@/common/common";
|
import { goLink } from "@/common/common";
|
||||||
import {GetShoppingCartApi} from "@/api/shopCart"
|
import {GetShoppingCartApi, DelShoppingCartApi} from "@/api/shopCart"
|
||||||
import { formatHashTag, formatMillionYuan } from "@/common/fotmat";
|
import { formatHashTag, formatImgUrl, formatMillionYuan } from "@/common/fotmat";
|
||||||
|
|
||||||
type param = {
|
type param = {
|
||||||
show?: true|false,
|
show?: true|false,
|
||||||
@ -17,17 +17,35 @@ type param = {
|
|||||||
}
|
}
|
||||||
export default ({show = false, onClose}: param) => {
|
export default ({show = false, onClose}: param) => {
|
||||||
const selectList = [
|
const selectList = [
|
||||||
{title:'不限', unit:'', eunit:''},
|
{value:-1, title:'不限', unit:'', eunit:''},
|
||||||
{title:'大货', unit:'件', eunit:'kg'},
|
{value:0, title:'大货', unit:'件', eunit:'kg'},
|
||||||
{title:'剪板', unit:'米', eunit:'m'},
|
{value:1,title:'剪板', unit:'米', eunit:'m'},
|
||||||
{title:'散剪', unit:'米', eunit:'kg'},
|
{value:2,title:'散剪', unit:'米', eunit:'kg'},
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
const [selectIndex, setSelectIndex] = useState(0)
|
const [selectIndex, setSelectIndex] = useState(-1)
|
||||||
const selectProduct = (index:number) => {
|
const selectProduct = (index:number) => {
|
||||||
setSelectIndex(index)
|
setSelectIndex(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
resetList()
|
||||||
|
setSelectStatus(true)
|
||||||
|
}, [selectIndex])
|
||||||
|
|
||||||
|
//重置勾选数据
|
||||||
|
const resetList = () => {
|
||||||
|
list?.map(item => {
|
||||||
|
if(selectIndex == item.sale_mode || selectIndex == -1) {
|
||||||
|
item.select = true
|
||||||
|
} else {
|
||||||
|
item.select = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setList([...list])
|
||||||
|
}
|
||||||
|
|
||||||
//获取数据
|
//获取数据
|
||||||
const [list, setList] = useState<any[]>([])
|
const [list, setList] = useState<any[]>([])
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
@ -35,15 +53,29 @@ export default ({show = false, onClose}: param) => {
|
|||||||
const getShoppingCart = async () => {
|
const getShoppingCart = async () => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const {data} = await fetchData()
|
const {data} = await fetchData()
|
||||||
console.log('color_list::', data)
|
let color_list = data.color_list||[]
|
||||||
setList(data.color_list)
|
initList(color_list)
|
||||||
|
setList(color_list)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//初始化全部数据
|
||||||
|
const initList = (color_list) => {
|
||||||
|
if(selectIndex == -1) {
|
||||||
|
color_list?.map(item => {
|
||||||
|
item.select = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//显示是展示数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(!show) return
|
if(!show) {
|
||||||
|
setList([])
|
||||||
|
setSelectIndex(-1)
|
||||||
|
} else {
|
||||||
getShoppingCart()
|
getShoppingCart()
|
||||||
|
}
|
||||||
}, [show])
|
}, [show])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -57,10 +89,11 @@ export default ({show = false, onClose}: param) => {
|
|||||||
setShowPopup(show)
|
setShowPopup(show)
|
||||||
}, [show])
|
}, [show])
|
||||||
|
|
||||||
|
//全选反选
|
||||||
const [selectStatus, setSelectStatus] = useState(false)
|
const [selectStatus, setSelectStatus] = useState(false)
|
||||||
const selectAll = () => {
|
const selectAll = () => {
|
||||||
list.map(item => {
|
list.map(item => {
|
||||||
|
if(selectIndex == item.sale_mode || selectIndex == -1)
|
||||||
item.select = !selectStatus
|
item.select = !selectStatus
|
||||||
})
|
})
|
||||||
setSelectStatus(!selectStatus)
|
setSelectStatus(!selectStatus)
|
||||||
@ -70,12 +103,29 @@ export default ({show = false, onClose}: param) => {
|
|||||||
//checkbox选中回调
|
//checkbox选中回调
|
||||||
const selectCallBack = (item) => {
|
const selectCallBack = (item) => {
|
||||||
item.select = true
|
item.select = true
|
||||||
|
checkSelect()
|
||||||
setList([...list])
|
setList([...list])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//checkbox选中判断是否全部选中,全部选中后是全选,否则反选
|
||||||
|
const checkSelect = () => {
|
||||||
|
let list_count = 0
|
||||||
|
let select_count = 0
|
||||||
|
list?.map(item => {
|
||||||
|
if(selectIndex == -1 || selectIndex == item.sale_mode) {
|
||||||
|
list_count ++
|
||||||
|
if(item.select) select_count++
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log('list_count::',list_count)
|
||||||
|
console.log('select_count::',select_count)
|
||||||
|
setSelectStatus(select_count == list_count)
|
||||||
|
}
|
||||||
|
|
||||||
//checkbox关闭回调
|
//checkbox关闭回调
|
||||||
const colseCallBack = (item) => {
|
const colseCallBack = (item) => {
|
||||||
item.select = false
|
item.select = false
|
||||||
|
checkSelect()
|
||||||
setList([...list])
|
setList([...list])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,16 +135,28 @@ export default ({show = false, onClose}: param) => {
|
|||||||
setShowPopup(false)
|
setShowPopup(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//删除购物车内容
|
||||||
|
const {fetchData:delShopFetchData} = DelShoppingCartApi()
|
||||||
const delSelect = () => {
|
const delSelect = () => {
|
||||||
Taro.showModal({
|
Taro.showModal({
|
||||||
content: '删除所选商品?',
|
content: '删除所选商品?',
|
||||||
success: function (res) {
|
success: async function (res) {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
|
getSelectId()
|
||||||
|
const res = await delShopFetchData({id:selectIds.current})
|
||||||
|
if(res.success) {
|
||||||
|
getShoppingCart()
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: '成功',
|
title: '成功',
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
duration: 2000
|
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
Taro.showToast({
|
||||||
|
title: res.msg,
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
} else if (res.cancel) {
|
} else if (res.cancel) {
|
||||||
console.log('用户点击取消')
|
console.log('用户点击取消')
|
||||||
}
|
}
|
||||||
@ -102,6 +164,16 @@ export default ({show = false, onClose}: param) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取面料选中的id
|
||||||
|
const selectIds = useRef<number[]>([])
|
||||||
|
const getSelectId = () => {
|
||||||
|
list?.map(item => {
|
||||||
|
if(selectIndex == -1 || selectIndex == item.sale_mode) {
|
||||||
|
item.select&&selectIds.current.push(item.id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
//格式化金额
|
//格式化金额
|
||||||
const formatPirce = useCallback((price) => {
|
const formatPirce = useCallback((price) => {
|
||||||
const {num} = formatMillionYuan(price, 100)
|
const {num} = formatMillionYuan(price, 100)
|
||||||
@ -115,7 +187,7 @@ export default ({show = false, onClose}: param) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View className={styles.shop_cart_main}>
|
<View className={styles.shop_cart_main}>
|
||||||
<Popup showTitle={false} show={showPopup} onClose={() => closePopup()}>
|
<Popup showTitle={false} show={showPopup} onClose={() => closePopup()} >
|
||||||
<View className={styles.popup_con}>
|
<View className={styles.popup_con}>
|
||||||
<View className={styles.header}>
|
<View className={styles.header}>
|
||||||
<View onClick={selectAll}>{!selectStatus?'全选':'反选'}</View>
|
<View onClick={selectAll}>{!selectStatus?'全选':'反选'}</View>
|
||||||
@ -125,22 +197,21 @@ export default ({show = false, onClose}: param) => {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.search}>
|
<View className={styles.search}>
|
||||||
{selectList.map((item, index) => {
|
{selectList.map((item) => {
|
||||||
return <View key={index} onClick={() => selectProduct(index)} className={classnames(styles.search_item, (selectIndex==index)&&styles.search_item_select)}>{item.title}</View>
|
return <View key={item.value} onClick={() => selectProduct(item.value)} className={classnames(styles.search_item, (selectIndex==item.value)&&styles.search_item_select)}>{item.title}</View>
|
||||||
})}
|
})}
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.con}>
|
<View className={styles.con}>
|
||||||
{loading&&<LoadingCard/>}
|
{loading&&<LoadingCard/>}
|
||||||
{!loading&&list?.length > 0&&<InfiniteScroll refresherTriggered={true} refresherEnabled={true} moreStatus={false} >
|
{!loading&&list?.length > 0&&<InfiniteScroll refresherTriggered={true} refresherEnabled={true} moreStatus={false} >
|
||||||
<View className={styles.product_list}>
|
<View className={styles.product_list}>
|
||||||
{list?.map((item, index) => {
|
{list?.map((item, index) => {
|
||||||
return <View key={index} className={styles.product_item}>
|
return <View key={index} className={classnames(styles.product_item, (selectIndex!=-1&&selectIndex!= item.sale_mode)&&styles.no_product_item_select)}>
|
||||||
<View className={styles.checkbox}>
|
<View className={styles.checkbox}>
|
||||||
<MCheckbox status={item.select} onSelect={() => selectCallBack(item)} onClose={() => colseCallBack(item)}/>
|
<MCheckbox disabled={selectIndex!=-1&&selectIndex!=item.sale_mode} status={item.select} onSelect={() => selectCallBack(item)} onClose={() => colseCallBack(item)}/>
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.img}>
|
<View className={styles.img}>
|
||||||
<Image src="https://bpic.588ku.com//back_origin_min_pic/22/01/11/aa3da17bab9a6556564028e4f1d77874.jpg!/fw/750/quality/99/unsharp/true/compress/true"/>
|
<Image mode="aspectFill" src={formatImgUrl(item.texture_url)}/>
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.des}>
|
<View className={styles.des}>
|
||||||
<View className={styles.title}>{formatHashTag(item.product_code, item.product_name)}</View>
|
<View className={styles.title}>{formatHashTag(item.product_code, item.product_name)}</View>
|
||||||
|
@ -34,21 +34,25 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param)
|
|||||||
]
|
]
|
||||||
const [selectIndex, setSelectIndex] = useState(0)
|
const [selectIndex, setSelectIndex] = useState(0)
|
||||||
const selectProduct = (index:number) => {
|
const selectProduct = (index:number) => {
|
||||||
console.log('number::',index)
|
|
||||||
setSelectIndex(() => index)
|
setSelectIndex(() => index)
|
||||||
|
//重置数据
|
||||||
|
const newList = initList(list)
|
||||||
|
setList([...newList])
|
||||||
|
condition.current.code_or_name = null
|
||||||
|
setSearchShow(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取面料颜色列表
|
//获取面料颜色列表
|
||||||
const {fetchData:colorFetchData, state: colorState} = GetColorList()
|
const {fetchData:colorFetchData, state: colorState} = GetColorList()
|
||||||
const [list, setList] = useState<any[]>([])
|
const [list, setList] = useState<any[]>([])
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const condition = useRef({physical_warehouse:adminUserInfo.physical_warehouse, sale_mode:selectIndex, product_id:0, code_or_name:null})
|
const condition = useRef({physical_warehouse:adminUserInfo?.physical_warehouse, sale_mode:selectIndex, product_id:0, code_or_name:null})
|
||||||
const getColorList = async () => {
|
const getColorList = async () => {
|
||||||
setLoading(() => true)
|
setLoading(() => true)
|
||||||
console.log('数据:::',getFilterData(condition.current))
|
console.log('数据:::',getFilterData(condition.current))
|
||||||
let {data} = await colorFetchData(getFilterData(condition.current))
|
let {data} = await colorFetchData(getFilterData(condition.current))
|
||||||
const list = initList(data.list)
|
let lists = initList(data.list)
|
||||||
setList([...list])
|
setList([...lists])
|
||||||
setLoading(() => false)
|
setLoading(() => false)
|
||||||
}
|
}
|
||||||
const [showPopup, setShowPopup] = useState(false)
|
const [showPopup, setShowPopup] = useState(false)
|
||||||
@ -63,7 +67,6 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param)
|
|||||||
setSelectIndex(0)
|
setSelectIndex(0)
|
||||||
condition.current.code_or_name = null
|
condition.current.code_or_name = null
|
||||||
setSearchShow(false)
|
setSearchShow(false)
|
||||||
|
|
||||||
condition.current.product_id = productId
|
condition.current.product_id = productId
|
||||||
getColorList()
|
getColorList()
|
||||||
}
|
}
|
||||||
@ -138,6 +141,16 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param)
|
|||||||
const {getSelfUserInfo} = UseLogin()
|
const {getSelfUserInfo} = UseLogin()
|
||||||
const {fetchData:addFetchData} = AddShoppingCartApi()
|
const {fetchData:addFetchData} = AddShoppingCartApi()
|
||||||
const addShopCart = async () => {
|
const addShopCart = async () => {
|
||||||
|
try {
|
||||||
|
await getSelfUserInfo()
|
||||||
|
} catch(msg) {
|
||||||
|
Taro.showToast({
|
||||||
|
icon:'none',
|
||||||
|
title:msg
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if(selectCount.sumCount == 0) {
|
if(selectCount.sumCount == 0) {
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
icon:'none',
|
icon:'none',
|
||||||
@ -145,7 +158,6 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param)
|
|||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
await getSelfUserInfo()
|
|
||||||
const state = await addFetchData({
|
const state = await addFetchData({
|
||||||
"sale_mode": selectIndex,
|
"sale_mode": selectIndex,
|
||||||
color_list: selectCount.color_list
|
color_list: selectCount.color_list
|
||||||
@ -165,7 +177,7 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//显示金额
|
//显示金额
|
||||||
const priceFormat = useCallback((item) => {
|
const priceFormat = (item) => {
|
||||||
let price = 0
|
let price = 0
|
||||||
if(selectIndex == 0) {
|
if(selectIndex == 0) {
|
||||||
price = formatMillionYuan(item.bulk_price, 100).num
|
price = formatMillionYuan(item.bulk_price, 100).num
|
||||||
@ -175,15 +187,7 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param)
|
|||||||
price = formatMillionYuan(item.weight_cut_price, 100).num
|
price = formatMillionYuan(item.weight_cut_price, 100).num
|
||||||
}
|
}
|
||||||
return <View className={styles.priceText}><Text>¥</Text>{Number(price) }<Text>{' /' + selectList[selectIndex].eunit}</Text></View>
|
return <View className={styles.priceText}><Text>¥</Text>{Number(price) }<Text>{' /' + selectList[selectIndex].eunit}</Text></View>
|
||||||
}, [list, selectIndex])
|
}
|
||||||
|
|
||||||
//重置数据
|
|
||||||
useEffect(() => {
|
|
||||||
const newList = initList(list)
|
|
||||||
setList([...newList])
|
|
||||||
// condition.current.code_or_name = null
|
|
||||||
// setSearchShow(false)
|
|
||||||
}, [selectIndex])
|
|
||||||
|
|
||||||
//筛选数据
|
//筛选数据
|
||||||
const searchInput = (e) => {
|
const searchInput = (e) => {
|
||||||
@ -219,7 +223,7 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param)
|
|||||||
<View className={styles.text} onClick={() => clearSearch()}>取消</View>
|
<View className={styles.text} onClick={() => clearSearch()}>取消</View>
|
||||||
</View>}
|
</View>}
|
||||||
<View className={styles.colorNum}>
|
<View className={styles.colorNum}>
|
||||||
<View className={styles.title}>颜色分类 (13)</View>
|
<View className={styles.title}>颜色分类 ({list.length})</View>
|
||||||
{!searchShow&&<View className={classnames('iconfont icon-sousuo', styles.miconfont)} onClick={() => changeSearchShow()}></View>}
|
{!searchShow&&<View className={classnames('iconfont icon-sousuo', styles.miconfont)} onClick={() => changeSearchShow()}></View>}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { formatImgUrl } from "@/common/fotmat"
|
||||||
import { Image, Swiper, SwiperItem, View } from "@tarojs/components"
|
import { Image, Swiper, SwiperItem, View } from "@tarojs/components"
|
||||||
import { useMemo, useRef, useState } from "react"
|
import { useMemo, useRef, useState } from "react"
|
||||||
import styles from './index.module.scss'
|
import styles from './index.module.scss'
|
||||||
@ -27,7 +28,7 @@ export default ({list = []}: params) => {
|
|||||||
{list.map((item) => {
|
{list.map((item) => {
|
||||||
return <SwiperItem key={item.id}>
|
return <SwiperItem key={item.id}>
|
||||||
<View className={styles.image_item} >
|
<View className={styles.image_item} >
|
||||||
<Image mode="aspectFill" src='https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F811%2F021315104H2%2F150213104H2-3-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817947&t=5467a207f845ddfc7737d55934e6b26d'></Image>
|
<Image mode="aspectFill" src={formatImgUrl(item)}></Image>
|
||||||
</View>
|
</View>
|
||||||
</SwiperItem>
|
</SwiperItem>
|
||||||
})}
|
})}
|
||||||
|
@ -145,7 +145,13 @@
|
|||||||
background-color: $color_main;
|
background-color: $color_main;
|
||||||
font-size: $font_size;
|
font-size: $font_size;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
position: relative;
|
||||||
|
.phoneBtn{
|
||||||
|
background-color: rgba(0, 0, 0, 0);
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import { Button, Image, RichText, ScrollView, Swiper, SwiperItem, Text, View } from '@tarojs/components'
|
import { Button, Image, RichText, ScrollView, Swiper, SwiperItem, Text, View } from '@tarojs/components'
|
||||||
import Taro, { useDidShow, useRouter, useShareAppMessage } from '@tarojs/taro';
|
import Taro, { useDidShow, usePullDownRefresh, useRouter, useShareAppMessage } from '@tarojs/taro';
|
||||||
import classnames from "classnames";
|
import classnames from "classnames";
|
||||||
import DesSwiper from './components/swiper';
|
import DesSwiper from './components/swiper';
|
||||||
import OrderCount from './components/orderCount';
|
import OrderCount from './components/orderCount';
|
||||||
@ -23,7 +23,8 @@ type params = {
|
|||||||
style?: Object
|
style?: Object
|
||||||
}
|
}
|
||||||
export default (props:params) => {
|
export default (props:params) => {
|
||||||
const {checkLogin} = useLogin()
|
const {checkLogin, getPhoneNumber, userInfo} = useLogin()
|
||||||
|
|
||||||
useDidShow(() => {
|
useDidShow(() => {
|
||||||
checkLogin()
|
checkLogin()
|
||||||
})
|
})
|
||||||
@ -39,6 +40,7 @@ export default (props:params) => {
|
|||||||
const getProductDetail = async () => {
|
const getProductDetail = async () => {
|
||||||
let {data} = await fetchData({id: router.params.id})
|
let {data} = await fetchData({id: router.params.id})
|
||||||
setProductInfo(data)
|
setProductInfo(data)
|
||||||
|
Taro.stopPullDownRefresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
//面料名称
|
//面料名称
|
||||||
@ -46,27 +48,11 @@ export default (props:params) => {
|
|||||||
return formatHashTag(productInfo.code, productInfo.name)
|
return formatHashTag(productInfo.code, productInfo.name)
|
||||||
},[productInfo])
|
},[productInfo])
|
||||||
|
|
||||||
const list = [
|
|
||||||
{
|
|
||||||
title:'数据',
|
|
||||||
img:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F811%2F021315104H2%2F150213104H2-3-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817947&t=5467a207f845ddfc7737d55934e6b26d',
|
|
||||||
url:'',
|
|
||||||
id:1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title:'数据',
|
|
||||||
img:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F811%2F021315104H2%2F150213104H2-3-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817947&t=5467a207f845ddfc7737d55934e6b26d',
|
|
||||||
url:'',
|
|
||||||
id:2
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
const [showCart, setShowCart] = useState(false)
|
const [showCart, setShowCart] = useState(false)
|
||||||
|
|
||||||
const [showOrderCount, setShowOrderCount] = useState(false)
|
const [showOrderCount, setShowOrderCount] = useState(false)
|
||||||
|
|
||||||
const html = `<h1>这里是详情</h1>
|
const html = `
|
||||||
<div style="font-size:13px">你好啊啊</div>
|
|
||||||
<img style="width:100%" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic24.nipic.com%2F20121021%2F10910884_100200815001_2.jpg&refer=http%3A%2F%2Fpic24.nipic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1652257920&t=9353dda34f18ae2fe6803f3da35954bb">
|
<img style="width:100%" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic24.nipic.com%2F20121021%2F10910884_100200815001_2.jpg&refer=http%3A%2F%2Fpic24.nipic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1652257920&t=9353dda34f18ae2fe6803f3da35954bb">
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -99,14 +85,36 @@ export default (props:params) => {
|
|||||||
return {
|
return {
|
||||||
title: '自定义转发标题',
|
title: '自定义转发标题',
|
||||||
path: '/pages/details/index?id=10',
|
path: '/pages/details/index?id=10',
|
||||||
imageUrl: list[0].img
|
imageUrl: ''
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
//开始下单
|
||||||
|
const placeOrder = async (e:any) => {
|
||||||
|
try {
|
||||||
|
await getPhoneNumber(e.detail.code)
|
||||||
|
} catch(msg) {
|
||||||
|
Taro.showToast({
|
||||||
|
icon:"none",
|
||||||
|
title: msg
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
setShowOrderCount(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//页面下拉刷新
|
||||||
|
usePullDownRefresh(() => {
|
||||||
|
getProductDetail()
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className={styles.main}>
|
<View className={styles.main}>
|
||||||
<DesSwiper list={list}/>
|
<DesSwiper list={productInfo.texture_url||[]}/>
|
||||||
<View className={styles.product_header}>
|
<View className={styles.product_header}>
|
||||||
<View className={styles.title}>
|
<View className={styles.title}>
|
||||||
<View className={styles.name}>{productName}</View>
|
<View className={styles.name}>{productName}</View>
|
||||||
@ -154,7 +162,13 @@ export default (props:params) => {
|
|||||||
<View className={classnames('iconfont icon-gouwuche', styles.miconfont)}></View>
|
<View className={classnames('iconfont icon-gouwuche', styles.miconfont)}></View>
|
||||||
<View className={styles.text}>购物车</View>
|
<View className={styles.text}>购物车</View>
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.buy_btn} onClick={() => setShowOrderCount(true)}>开始下单</View>
|
{
|
||||||
|
!userInfo.adminUserInfo?.is_authorize_phone&&<View className={styles.buy_btn} >
|
||||||
|
<Button className={styles.phoneBtn} open-type="getPhoneNumber" onGetPhoneNumber={(e) => placeOrder(e)}></Button>
|
||||||
|
开始下单
|
||||||
|
</View>
|
||||||
|
|| <View className={styles.buy_btn} onClick={(e) => placeOrder(e)}>开始下单</View>
|
||||||
|
}
|
||||||
</View>
|
</View>
|
||||||
<OrderCount show={showOrderCount} onClose={() => setShowOrderCount(false)} title={productName} productId={productInfo.id}/>
|
<OrderCount show={showOrderCount} onClose={() => setShowOrderCount(false)} title={productName} productId={productInfo.id}/>
|
||||||
<ShopCart show={showCart} onClose={() => setShowCart(false)}/>
|
<ShopCart show={showCart} onClose={() => setShowCart(false)}/>
|
||||||
|
@ -35,6 +35,8 @@ export type UserAdminParam = {
|
|||||||
user_id?: number,
|
user_id?: number,
|
||||||
user_name?: string,
|
user_name?: string,
|
||||||
wechat_user_open_id?: number
|
wechat_user_open_id?: number
|
||||||
|
is_authorize_name?: false|true,
|
||||||
|
is_authorize_phone?: false|true
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DataParam = {
|
export type DataParam = {
|
||||||
|
@ -3,7 +3,7 @@ import { WX_APPID } from "@/common/constant"
|
|||||||
import useUserInfo from "./useUserInfo"
|
import useUserInfo from "./useUserInfo"
|
||||||
import Taro, { useRouter } from "@tarojs/taro"
|
import Taro, { useRouter } from "@tarojs/taro"
|
||||||
import { LoginApi } from "@/api/login"
|
import { LoginApi } from "@/api/login"
|
||||||
import { GetWxUserInfoApi, GetAdminUserInfoApi } from "@/api/user"
|
import { GetWxUserInfoApi, GetAdminUserInfoApi, GetPhoneNumberApi } from "@/api/user"
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
@ -99,38 +99,66 @@ export default () => {
|
|||||||
const {fetchData: fetchDataUserInfo} = GetWxUserInfoApi()
|
const {fetchData: fetchDataUserInfo} = GetWxUserInfoApi()
|
||||||
const getSelfUserInfo = async () => {
|
const getSelfUserInfo = async () => {
|
||||||
return new Promise((reslove, reject) => {
|
return new Promise((reslove, reject) => {
|
||||||
if(!userInfo.userInfo) {
|
if(userInfo.adminUserInfo.is_authorize_name) {
|
||||||
|
reslove(true)
|
||||||
|
return true
|
||||||
|
}
|
||||||
Taro.getUserProfile({
|
Taro.getUserProfile({
|
||||||
desc: '用于完善会员资料',
|
desc: '用于完善会员资料',
|
||||||
success: async (res) => {
|
success: async (res) => {
|
||||||
if(!userInfo.session_key) {
|
if(!userInfo.session_key) {
|
||||||
await wxLogin()
|
await wxLogin()
|
||||||
}
|
}
|
||||||
const {data} = await fetchDataUserInfo({
|
const user_res = await fetchDataUserInfo({
|
||||||
session_key: userInfo.session_key,
|
session_key: userInfo.session_key,
|
||||||
raw_data: res.rawData,
|
raw_data: res.rawData,
|
||||||
signature: res.signature,
|
signature: res.signature,
|
||||||
encrypted_data: res.encryptedData,
|
encrypted_data: res.encryptedData,
|
||||||
iv: res.iv
|
iv: res.iv
|
||||||
})
|
})
|
||||||
setUserInfo({...data})
|
if(user_res.success) {
|
||||||
reslove(data)
|
setUserInfo({...user_res.data})
|
||||||
|
reslove(user_res.data)
|
||||||
|
getAdminUserInfo()
|
||||||
|
} else {
|
||||||
|
reject(user_res.msg)
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
fail:(e) => {
|
fail:(e) => {
|
||||||
reject(e)
|
reject(e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
reslove(true)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取手机号码
|
||||||
|
const {fetchData: fetchDataUserPhone} = GetPhoneNumberApi()
|
||||||
|
const getPhoneNumber = (code) =>{
|
||||||
|
return new Promise( async (reslove, reject) => {
|
||||||
|
if(userInfo.adminUserInfo.is_authorize_phone) {
|
||||||
|
reslove(true)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
const res = await fetchDataUserPhone({code})
|
||||||
|
if(res.success) {
|
||||||
|
setUserInfo({...userInfo.userInfo, phone:res.data.phone_number})
|
||||||
|
getAdminUserInfo()
|
||||||
|
reslove(res.data)
|
||||||
|
} else {
|
||||||
|
reject(res.msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
checkLogin,
|
checkLogin,
|
||||||
wxLogin,
|
wxLogin,
|
||||||
getSelfUserInfo
|
getSelfUserInfo,
|
||||||
|
getPhoneNumber,
|
||||||
|
userInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user