144 lines
3.9 KiB
JavaScript
144 lines
3.9 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import { Modal, Form, Input, Button, Spin, Pagination } from 'antd';
|
|
|
|
import Nodata from '../../Nodata';
|
|
|
|
import { getNewsMyList, getMyTopArticle, doDocTop } from '../api';
|
|
|
|
|
|
const { TextArea } = Input;
|
|
|
|
|
|
import { getImageUrl } from 'educoder'
|
|
|
|
import '../indexUser.scss';
|
|
|
|
function PointsDoc({ visible , onCancel , onSure , type , username , choosed , history , showCompeleteDialog , member }) {
|
|
const limit = 2;
|
|
|
|
const [ page , setPage ] = useState(1);
|
|
const [ total , setTotal ] = useState(0);
|
|
const [ isSpin , setIsSpin ] = useState(true);
|
|
const [ list , setList ] = useState(undefined);
|
|
const [ currentId , setCurrentId ] = useState(null);
|
|
const [ currentRow , setCurrentRow ] = useState(null);
|
|
|
|
useEffect(()=>{
|
|
if(visible && member) {
|
|
setPage(1);
|
|
}
|
|
},[visible, member])
|
|
|
|
useEffect(()=>{
|
|
if(visible && member) {
|
|
init();
|
|
}
|
|
},[visible, member])
|
|
|
|
|
|
useEffect(()=>{
|
|
if(visible && member) {
|
|
getMyNews();
|
|
}
|
|
},[page])
|
|
|
|
async function init() {
|
|
setIsSpin(true);
|
|
try{
|
|
let res = await getMyTopArticle(member.zoneId);
|
|
if(res && res.data.code === 200){
|
|
setCurrentRow(res.data.data);
|
|
if(res.data.data) {
|
|
setCurrentId(res.data.data.docId);
|
|
} else {
|
|
setCurrentId(null);
|
|
}
|
|
|
|
await getMyNews();
|
|
}
|
|
}finally{
|
|
setIsSpin(false)
|
|
}
|
|
}
|
|
|
|
async function getMyNews(){
|
|
let result = await getNewsMyList(member.zoneId,{auditStatus:1, excludeId: currentId, pageSize:limit, pageNum:page});
|
|
let rows = result.data && result.data.rows;
|
|
if(rows && rows.length>0){
|
|
setList(rows);
|
|
}else{
|
|
setList([]);
|
|
setCurrentRow(null);
|
|
}
|
|
setTotal(result.data.total);
|
|
}
|
|
|
|
function onOk() {
|
|
}
|
|
|
|
async function handlePin(item) {
|
|
setIsSpin(true);
|
|
try {
|
|
let data = Object.assign({}, item, {zoneId: member.zoneId});
|
|
await doDocTop(data);
|
|
onSure();
|
|
} finally {
|
|
setIsSpin(false);
|
|
}
|
|
}
|
|
|
|
return(
|
|
<Modal
|
|
closeIcon={<i className="iconfont icon-guanbi font-20 closeIconFont" onClick={onCancel}></i>}
|
|
className="doc_modal"
|
|
visible={visible}
|
|
title={<div className="title_box">
|
|
专区首页新闻推荐
|
|
</div>}
|
|
closable={true}
|
|
width={800}
|
|
footer={
|
|
<div>
|
|
<Button onClick={onCancel}>取消</Button>
|
|
<Button className="btn_ok" style={{marginLeft:"20px"}} onClick={onOk}>确定</Button>
|
|
</div>
|
|
}
|
|
okText="确定"
|
|
cancelText="取消"
|
|
>
|
|
<div className="info">
|
|
<Spin spinning={isSpin}>
|
|
<div className="line topline">
|
|
<span className="content">新闻标题</span>
|
|
<span className="action">操作</span>
|
|
</div>
|
|
{currentRow && (
|
|
<div className="line dataline">
|
|
<span className="content">{currentRow.docName}</span>
|
|
<span className="action">
|
|
<Button type="primary" shape="round" disabled style={{backgroundColor:'rgba(70, 106, 255, 0.43)', borderColor:'rgba(70, 106, 255, 0.43)', color:'#fff'}}>已置顶</Button>
|
|
</span>
|
|
</div>
|
|
)}
|
|
{list && list.map((item) => (
|
|
<div className="line dataline" key={item.id}>
|
|
<span className="content">{item.name}</span>
|
|
<span className="action">
|
|
<Button type="primary" shape="round" disabled={!!currentRow} onClick={() => handlePin(item)}>置顶</Button>
|
|
</span>
|
|
</div>
|
|
))}
|
|
{ !isSpin && !currentId && (!list || !list.length) && <Nodata _html="暂无数据" />
|
|
}
|
|
</Spin>
|
|
{
|
|
total > limit &&
|
|
<div style={{padding:"20px",textAlign:"right"}}>
|
|
<Pagination showQuickJumper current={page} total={total} pageSize={limit} onChange={(p)=>{setPage(p);}}/>
|
|
</div>
|
|
}
|
|
</div>
|
|
</Modal>
|
|
)
|
|
}
|
|
export default PointsDoc; |