Commit 4dc0334d authored by 前端-李俊鑫's avatar 前端-李俊鑫

feat: 新增商城资讯收藏

parent 340271e4
import React, { useEffect, useState } from 'react'
import cx from 'classnames'
import { Pagination, message, Modal } from 'antd'
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { StarFilled, EyeOutlined, ClockCircleOutlined } from '@ant-design/icons'
import { PublicApi } from '@/services/api'
import { numFormat } from '@/utils/numberFomat'
import { INFO_CENTER_URL } from '@/constants'
import moment from 'moment'
import styles from './index.less'
const Information: React.FC = () => {
const [list, setList] = useState([])
const [current, setCurrent] = useState<number>(1)
const [pageSize, setPageSize] = useState<number>(10)
const [totalCount, setTotalCount] = useState<number>(0)
useEffect(() => {
fetchCollectInformationList()
}, [current])
/**
* 获取收藏的资讯列表
*/
const fetchCollectInformationList = () => {
const param: any = {
current,
pageSize
}
PublicApi.getManageMemberInformationCollectList(param).then(res => {
if (res.code === 1000) {
setList(res.data.data)
setTotalCount(res.data.totalCount)
}
})
}
const handleChange = (page) => {
setCurrent(page)
}
const linkToDetail = (detail) => {
if (detail.status === 2) {
const el = document.createElement('a')
el.href = detail.url;
el.target = '_blank';
el.id = detail.id
if(!document.getElementById(detail.id)) {
document.body.appendChild(el);
}
el.click()
} else {
message.destroy()
message.info("该文章已下架")
}
}
const handleCancelCollect = (detail) => {
Modal.confirm({
centered: true,
className: styles.mallComfirm,
content: `是否要取消收藏?`,
onOk: () => {
return new Promise((resolve, reject) => {
const param = {
informationId: detail.id,
status: false
}
PublicApi.postManageMemberInformationCollect(param).then(res => {
if (res.code === 1000) {
// fetchPurchaseList()
fetchCollectInformationList()
resolve(true)
} else {
reject()
}
}).catch(() => {
reject()
})
})
}
})
}
return (
<PageHeaderWrapper>
<div className={styles.information_list}>
{
list && list.map((item, index) => (
<div className={styles.information_list_item} key={`information_list_item_${index}`}>
<div className={cx(styles.information_list_item_item, styles.morehalf)}>
<div className={styles.information_header_info}>
<div className={styles.information_header_info_logo}>
<img src={item.imageUrl} />
</div>
<div className={styles.information_header_info_content}>
<div className={styles.information_header_info_content_name} onClick={() => linkToDetail(item)}>
<span>{item.title}</span>
</div>
<div className={styles.information_header_info_content_about}>
<div className={styles.information_header_info_content_about_item}>
<ClockCircleOutlined />
<span>{moment(item.createTime).format("YYYY-MM-DD HH:mm")}</span>
</div>
<div className={styles.information_header_info_content_about_item}>
<EyeOutlined />
<span>{numFormat(item.readCount)}</span>
</div>
</div>
</div>
</div>
</div>
<div className={cx(styles.information_list_item_item)}>
<span className={styles.date}>{moment(item.collectTime).format("YYYY-MM-DD HH:mm")}</span>
</div>
<div className={cx(styles.information_list_item_item, styles.float_right)}>
<div className={cx(styles.collection_state)} onClick={() => handleCancelCollect(item)}>
<StarFilled />
<label>收藏</label>
</div>
</div>
</div>
))
}
</div>
{
totalCount > 0 && (
<div className={styles.pagination_wrap}>
<Pagination showSizeChanger={false} current={current} total={totalCount} pageSize={pageSize} onChange={handleChange} />
</div>
)
}
</PageHeaderWrapper>
)
}
export default Information
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment