system-copyright-react/src/components/CouponModal/HeadCouponModal.tsx

253 lines
12 KiB
TypeScript
Raw Normal View History

2024-09-06 17:26:09 +08:00
import { useEffect, useState } from 'react'
2024-08-30 15:53:34 +08:00
import './HeadCouponModal.css'
2024-09-06 17:26:09 +08:00
import { get } from '../../util/AjaxUtils'
import {
Pagination,
message,
Empty,
Spin
} from 'antd';
2024-09-02 16:41:02 +08:00
// import { useNavigate } from 'react-router-dom';
// import { Empty } from 'antd'
// import contentImg from '../../static/coupon/content.png'
import useLogo from '../../static/coupon/useLogo.png'
import overdueImg from '../../static/coupon/overdueImg.png'
export default function HeadCouponModal(props: any) {
2024-09-06 17:26:09 +08:00
const [messageApi, contextHolder] = message.useMessage();
const [loading,setLoading] = useState(false)
2024-08-30 15:53:34 +08:00
const [title, setTitle] = useState('未使用')
2024-09-06 17:26:09 +08:00
// 分页
const [page, setPage] = useState(1)
const [total, setTotal] = useState(0)
// 是否有效
const [isEffective, setisEffective] = useState(1)
const [isUsed, setisUsed] = useState(0)
// 展示的优惠券数组
const [couponArray, setCouponArray] = useState<any[]>([])
// 获取优惠券信息
const getCouponData = () => {
get({
messageApi,
url: `/api/coupon/user/listpage/self`,
// url: `/api/proj/refund/apply/listpage?applyStatus=${state.type}`,
config: {
params: {
page: page,
rows: 10,
isEffective,
isUsed,
}
},
onBefore() {
setLoading(true)
},
onSuccess(data: any) {
setTotal(data.data.total)
setCouponArray(data.data.rows)
},
onFinally() {
setLoading(false)
},
})
}
useEffect(() => {
getCouponData()
}, [])
useEffect(() => {
getCouponData()
}, [page, isEffective, isUsed])
2024-08-30 15:53:34 +08:00
return (
2024-09-02 16:41:02 +08:00
<div className='headModal'>
2024-09-06 17:26:09 +08:00
{contextHolder}
2024-08-30 15:53:34 +08:00
<div className='headModal-top'>
<div className={title == '未使用' ? 'top-active' : 'top-title'}
onClick={() => {
setTitle('未使用')
2024-09-06 17:26:09 +08:00
setisUsed(0)
setisEffective(1)
setPage(1)
2024-08-30 15:53:34 +08:00
}}
>使</div>
<div className={title == '已使用' ? 'top-active' : 'top-title'} style={{ marginLeft: 50 }}
onClick={() => {
setTitle('已使用')
2024-09-06 17:26:09 +08:00
setisUsed(1)
setisEffective(1)
setPage(1)
2024-08-30 15:53:34 +08:00
}}
>使</div>
<div className={title == '已过期' ? 'top-active' : 'top-title'} style={{ marginLeft: 50 }}
onClick={() => {
setTitle('已过期')
2024-09-06 17:26:09 +08:00
setisUsed(0)
setisEffective(0)
setPage(1)
2024-08-30 15:53:34 +08:00
}}
></div>
</div>
<div className='headModal-bot'>
2024-09-06 17:26:09 +08:00
<Spin tip="加载中,请稍后..." size="small" spinning={loading}>
<div style={{ display: title == '未使用' ? 'block' : 'none' }}>
{couponArray.map((item) => {
return (
<div className='couponList' key={item.couponId}>
<div className='content'>
<div className='content-noUse-left'>
<div className='content-left-num'>
<div
style={{ marginTop: -10 }}
>
<span style={{ fontSize: 30 }}></span>
<span style={{ fontSize: 60, fontWeight: 700 }}>{item.coupon.amount / 100}</span>
</div>
</div>
</div>
<div className='content-right'>
<div className='content-text'>
使
</div>
<div className='content-bot'>
<div className='content-time'>
2024-09-10 15:04:08 +08:00
:{item.coupon.gmtStart} {item.coupon.gmtEnd}
2024-09-06 17:26:09 +08:00
</div>
<div className='content-button' onClick={() => {
props.closeModal()
}}>
使
</div>
</div>
</div>
2024-08-30 15:53:34 +08:00
</div>
2024-09-02 16:41:02 +08:00
2024-08-30 15:53:34 +08:00
</div>
2024-09-06 17:26:09 +08:00
)
})}
<div style={{ display: couponArray.length > 10 ? 'unset' : 'none' }}>
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Pagination defaultCurrent={page} total={total} pageSize={10} showSizeChanger={false}
onChange={(value) => {
setPage(value)
}}
/>
2024-08-30 15:53:34 +08:00
</div>
2024-09-06 17:26:09 +08:00
</div>
<div style={{ display: couponArray.length <= 0 ? 'unset' : 'none' }}>
<div className='noDatebox'>
<Empty description="暂无 优惠券" />
2024-08-30 15:53:34 +08:00
</div>
</div>
</div>
2024-09-06 17:26:09 +08:00
<div style={{ display: title == '已使用' ? 'block' : 'none' }}>
{couponArray.map((item) => {
return (
<div className='couponList' key={item.couponId}>
<div className='content'>
<div className='content-use-left'>
<div className='content-left-num'>
<div
style={{ marginTop: -10 }}
>
<span style={{ fontSize: 30 }}></span>
<span style={{ fontSize: 60, fontWeight: 700 }}>{item.coupon.amount / 100}</span>
</div>
2024-09-02 16:41:02 +08:00
2024-09-06 17:26:09 +08:00
</div>
</div>
<div className='content-right'>
<div className='content-text' style={{ marginTop: 10 }}>
使
</div>
<div className='content-bot' style={{ marginTop: 5 }}>
<div className='content-time'>
2024-09-10 15:04:08 +08:00
:{item.coupon.gmtStart} {item.coupon.gmtEnd}
2024-09-06 17:26:09 +08:00
</div>
2024-09-02 16:41:02 +08:00
2024-09-06 17:26:09 +08:00
</div>
<div className='content-projName'>
{/* 使用的产品 */}
{item.productName}
</div>
</div>
2024-09-02 16:41:02 +08:00
</div>
2024-09-06 17:26:09 +08:00
<div className='use-img'>
<img src={useLogo} alt="" width={'100%'} height={'100%'} />
</div>
2024-09-02 16:41:02 +08:00
</div>
2024-09-06 17:26:09 +08:00
)
})}
<div style={{ display: couponArray.length > 10 ? 'unset' : 'none' }}>
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Pagination defaultCurrent={page} total={total} pageSize={10} showSizeChanger={false}
onChange={(value) => {
setPage(value)
}} />
2024-09-02 16:41:02 +08:00
</div>
</div>
2024-09-06 17:26:09 +08:00
<div style={{ display: couponArray.length <= 0 ? 'unset' : 'none' }}>
<div className='noDatebox'>
<Empty description="无已使用优惠券" />
</div>
2024-09-02 16:41:02 +08:00
</div>
2024-09-06 17:26:09 +08:00
2024-09-02 16:41:02 +08:00
</div>
2024-09-06 17:26:09 +08:00
<div style={{ display: title == '已过期' ? 'block' : 'none' }}>
{couponArray.map((item) => {
return (
<div className='couponList' key={item.couponId}>
<div className='content'>
<div className='content-use-left'>
<div className='content-left-num'>
<div
style={{ marginTop: -10 }}
>
<span style={{ fontSize: 30 }}></span>
<span style={{ fontSize: 60, fontWeight: 700 }}>{item.coupon.amount / 100}</span>
</div>
2024-09-02 16:41:02 +08:00
2024-09-06 17:26:09 +08:00
</div>
</div>
<div className='content-right'>
<div className='content-text'>
使
</div>
<div className='content-bot'>
<div className='content-time'>
:{item.coupon.gmtEnd}
</div>
</div>
</div>
<div className='use-img' style={{ height: 76, width: 88 }}>
<img src={overdueImg} alt="" width={'100%'} height={'100%'} />
</div>
2024-09-02 16:41:02 +08:00
</div>
2024-09-06 17:26:09 +08:00
2024-09-02 16:41:02 +08:00
</div>
2024-09-06 17:26:09 +08:00
)
})}
<div style={{ display: couponArray.length > 10 ? 'unset' : 'none' }}>
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Pagination defaultCurrent={page} total={total} pageSize={10} showSizeChanger={false}
onChange={(value) => {
setPage(value)
}}
/>
2024-09-02 16:41:02 +08:00
</div>
2024-09-06 17:26:09 +08:00
</div>
<div style={{ display: couponArray.length <= 0 ? 'unset' : 'none' }}>
<div className='noDatebox'>
<Empty description="无已过期优惠券" />
2024-09-02 16:41:02 +08:00
</div>
</div>
</div>
2024-09-06 17:26:09 +08:00
</Spin>
2024-08-30 15:53:34 +08:00
</div>
</div>
)
}