Commit 720ddc60 by zhujian

fix

parent 67ebc4a5
...@@ -16,7 +16,7 @@ declare var formatDate: any; ...@@ -16,7 +16,7 @@ declare var formatDate: any;
function StudyTable(props: any) { function StudyTable(props: any) {
console.log(props, 'rtyjukl') console.log(props, 'rtyjukl')
const [query, setQuery] = useState<any>({ const [query, setQuery] = useState<any>({
current: 1, size: 10, size: 10,
taskId: props.taskId, taskId: props.taskId,
source: 0, source: 0,
storeId: User.getStoreId(), storeId: User.getStoreId(),
...@@ -26,8 +26,10 @@ function StudyTable(props: any) { ...@@ -26,8 +26,10 @@ function StudyTable(props: any) {
const [list, setList] = useState<any[]>([]); const [list, setList] = useState<any[]>([]);
const [total, setTotal] = useState<any>(0); const [total, setTotal] = useState<any>(0);
const [name, setName] = useState<any>(''); const [name, setName] = useState<any>('');
const [current, setCurrent] = useState<any>(1);
const [orderFiled, setOrderFiled] = useState<any>(null); const [orderFiled, setOrderFiled] = useState<any>(null);
const [sort, setSort] = useState<any>(null); const [sort, setSort] = useState<any>(null);
const [sortedList, setSortedList] = useState<any[]>([]);
const timer = useRef<any>(null); const timer = useRef<any>(null);
const sortNameMap: any = { const sortNameMap: any = {
learnPercentage: 'LEARN_NUM', learnPercentage: 'LEARN_NUM',
...@@ -37,21 +39,36 @@ function StudyTable(props: any) { ...@@ -37,21 +39,36 @@ function StudyTable(props: any) {
useEffect(() => { useEffect(() => {
getList() getList()
}, [query, orderFiled, sort]) }, [query])
useEffect(() => {
console.log(sort,orderFiled)
if (sort && orderFiled) {
const _list =[...list];
_list.sort((pre: any, next: any) => {
if (sort === 'ascend') {
return (pre[orderFiled] || 0) - (next[orderFiled] || 0)
} else {
return (next[orderFiled] || 0) - (pre[orderFiled] || 0)
}
})
function getList() { setSortedList(_list)
const _query = { ...query };
delete _query.sortMap;
if (sort) {
_query.sortMap = { } else {
[sortNameMap[orderFiled]]: sort === "ascend" ? 'SORT_ASC' : 'SORT_DESC' setSortedList(list)
}
} }
Service.Hades('public/hades/getTaskCustomerRecordPage', _query).then((res: any) => { }, [list, sort, orderFiled])
res.result.records.map((item: any) => {
function getList() {
Service.Hades('public/hades/getTaskCustomerRecordPage', query).then((res: any) => {
res.result.map((item: any) => {
item.department = item.departmentNameList.map((_item: any) => { item.department = item.departmentNameList.map((_item: any) => {
if (_item == '1000') { if (_item == '1000') {
return '微信' return '微信'
...@@ -61,8 +78,8 @@ function StudyTable(props: any) { ...@@ -61,8 +78,8 @@ function StudyTable(props: any) {
}) })
}) })
setList(res.result.records) setList(res.result)
setTotal(res.result.total) setTotal(res.result.length)
}) })
} }
...@@ -180,6 +197,7 @@ function StudyTable(props: any) { ...@@ -180,6 +197,7 @@ function StudyTable(props: any) {
console.log(sorter) console.log(sorter)
setOrderFiled(sorter.field || null) setOrderFiled(sorter.field || null)
setSort(sorter.order) setSort(sorter.order)
setCurrent(1)
} }
...@@ -201,9 +219,9 @@ function StudyTable(props: any) { ...@@ -201,9 +219,9 @@ function StudyTable(props: any) {
timer.current = setTimeout(() => { timer.current = setTimeout(() => {
setQuery({ setQuery({
...query, ...query,
current: 1,
customerName: name customerName: name
}) })
setCurrent(1)
}, 500) }, 500)
}} }}
...@@ -228,9 +246,9 @@ function StudyTable(props: any) { ...@@ -228,9 +246,9 @@ function StudyTable(props: any) {
onChange={(value) => { onChange={(value) => {
setQuery({ setQuery({
...query, ...query,
current: 1,
learnState: value learnState: value
}) })
setCurrent(1)
}} }}
suffixIcon={ suffixIcon={
<span className='icon iconfont' style={{ fontSize: '12px', color: '#BFBFBF' }}> <span className='icon iconfont' style={{ fontSize: '12px', color: '#BFBFBF' }}>
...@@ -262,10 +280,10 @@ function StudyTable(props: any) { ...@@ -262,10 +280,10 @@ function StudyTable(props: any) {
onChange={(dates: any) => { onChange={(dates: any) => {
setQuery({ setQuery({
...query, ...query,
current: 1,
startTime: dates[0]?.startOf('day').valueOf(), startTime: dates[0]?.startOf('day').valueOf(),
endTime: dates[0]?.endOf('day').valueOf(), endTime: dates[0]?.endOf('day').valueOf(),
}) })
setCurrent(1)
}} }}
/> />
...@@ -278,13 +296,14 @@ function StudyTable(props: any) { ...@@ -278,13 +296,14 @@ function StudyTable(props: any) {
<span className='resetBtn iconfont icon' onClick={() => { <span className='resetBtn iconfont icon' onClick={() => {
setName(''); setName('');
setQuery({ setQuery({
current: 1, size: 10, size: 10,
taskId: props.taskId, taskId: props.taskId,
source: 0, source: 0,
storeId: User.getStoreId(), storeId: User.getStoreId(),
storeUserId: User.getStoreUserId(), storeUserId: User.getStoreUserId(),
userId: User.getStoreUserId(), userId: User.getStoreUserId(),
}) })
setCurrent(1)
setSort('') setSort('')
}}> }}>
&#xe61b;{' '} &#xe61b;{' '}
...@@ -300,8 +319,8 @@ function StudyTable(props: any) { ...@@ -300,8 +319,8 @@ function StudyTable(props: any) {
type: 'college', type: 'college',
description: '暂无数据', description: '暂无数据',
}} }}
rowKey={(record: any) => record.storeCustomerId} rowKey={(record: any, index: any) => record.storeCustomerId + '_' + index}
dataSource={list} dataSource={sortedList.slice((current - 1) * query.size, current * query.size)}
columns={columns} columns={columns}
pagination={false} pagination={false}
className='user-learning-table' className='user-learning-table'
...@@ -312,11 +331,12 @@ function StudyTable(props: any) { ...@@ -312,11 +331,12 @@ function StudyTable(props: any) {
{list && list.length > 0 && ( {list && list.length > 0 && (
<div className='box-footer'> <div className='box-footer'>
<PageControl <PageControl
current={query.current - 1} current={current - 1}
pageSize={query.size} pageSize={query.size}
total={total} total={total}
toPage={(page: any) => { toPage={(page: any) => {
setQuery({ ...query, current: page + 1 }) setCurrent(page + 1)
}} }}
/> />
......
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