Commit 720ddc60 by zhujian

fix

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