|
|
@@ -11,6 +11,10 @@ import LoadingMore from '../../../components/common/loading/LoadingMore'
|
|
|
import { isObjEmpty } from '../../../utils/common/common.util'
|
|
|
import SubscribeGroup
|
|
|
from '../../../components/private/subscribe/SubscribeGroup'
|
|
|
+import { fetchPostObj } from '../../../utils/common/fetchRequest'
|
|
|
+import { API } from '../../../configs/api.config'
|
|
|
+import { message } from 'antd'
|
|
|
+import { saveListState } from '../../../redux/actions/listState'
|
|
|
|
|
|
const mPageSize = 10
|
|
|
let mPageIndex = 0
|
|
|
@@ -23,7 +27,7 @@ class SubscribeList extends Component {
|
|
|
|
|
|
this.state = {
|
|
|
refreshing: true,
|
|
|
- hasNextPage: true,
|
|
|
+ // hasNextPage: true,
|
|
|
height: document.documentElement.clientHeight,
|
|
|
subscribeDataSource: new ListView.DataSource({
|
|
|
rowHasChanged: (row1, row2) => row1 !== row2,
|
|
|
@@ -40,22 +44,23 @@ class SubscribeList extends Component {
|
|
|
})
|
|
|
if (this.props.listState && !isObjEmpty(this.props.listState.listData)) {
|
|
|
mPageIndex = this.props.listState.pageIndex
|
|
|
+ mSubscribeList = this.props.listState.listData
|
|
|
this.setState({
|
|
|
- subscribeDataSource: this.props.listState.listData,
|
|
|
- hasNextPage: this.props.listState.hasNextPage,
|
|
|
+ subscribeDataSource: this.state.subscribeDataSource.cloneWithRows(
|
|
|
+ mSubscribeList),
|
|
|
+ // hasNextPage: this.props.listState.hasNextPage,
|
|
|
},
|
|
|
() => {
|
|
|
ReactDOM.findDOMNode(
|
|
|
this.lv).scrollTop = this.props.listState.scrollTop
|
|
|
- if (this.state.hasNextPage) {
|
|
|
- this.loadSubscribeList()
|
|
|
- }
|
|
|
+ // if (this.state.hasNextPage) {
|
|
|
+ this.loadSubscribeList()
|
|
|
+ // }
|
|
|
},
|
|
|
)
|
|
|
} else {
|
|
|
- Toast.loading('加载中...', 0)
|
|
|
- mSubscribeList = []
|
|
|
mPageIndex = 0
|
|
|
+ mSubscribeList = []
|
|
|
this.loadSubscribeList()
|
|
|
}
|
|
|
}
|
|
|
@@ -65,7 +70,7 @@ class SubscribeList extends Component {
|
|
|
}
|
|
|
|
|
|
render () {
|
|
|
- const { subscribeDataSource, height, hasNextPage } = this.state
|
|
|
+ const { subscribeDataSource, height } = this.state
|
|
|
const refreshLayout = this.getRefreshLayout()
|
|
|
return (
|
|
|
<div className='com-column-flex'>
|
|
|
@@ -74,17 +79,19 @@ class SubscribeList extends Component {
|
|
|
dataSource={subscribeDataSource}
|
|
|
initialListSize={mPageSize}
|
|
|
renderFooter={() => {
|
|
|
- return hasNextPage && <LoadingMore/>
|
|
|
+ return <LoadingMore/>
|
|
|
}}
|
|
|
renderRow={(rowData, sectionID, rowID) => {
|
|
|
- return <SubscribeGroup/>
|
|
|
+ return <SubscribeGroup
|
|
|
+ subGroups={rowData}
|
|
|
+ onSubItemClick={this.onSubItemClick.bind(this)}/>
|
|
|
}}
|
|
|
style={{
|
|
|
height,
|
|
|
}}
|
|
|
pullToRefresh={refreshLayout}
|
|
|
onEndReachedThreshold={10}
|
|
|
- onEndReached={hasNextPage ? this.loadSubscribeList : null}
|
|
|
+ onEndReached={this.loadSubscribeList}
|
|
|
pageSize={mPageSize}
|
|
|
/>
|
|
|
</div>
|
|
|
@@ -115,18 +122,66 @@ class SubscribeList extends Component {
|
|
|
}),
|
|
|
})
|
|
|
}
|
|
|
- setTimeout(() => {
|
|
|
- Toast.hide()
|
|
|
- const list = [{}, {}, {}, {}]
|
|
|
- mSubscribeList = mSubscribeList.concat(list)
|
|
|
+
|
|
|
+ fetchPostObj(API.SUBSCRIBE_SUBSCRIBETOPUSH, {
|
|
|
+ pageIndex: mPageIndex,
|
|
|
+ pageSize: mPageSize,
|
|
|
+ }).then(response => {
|
|
|
+ if (!isObjEmpty(response, response.data, response.data.list)) {
|
|
|
+ response.data.list.forEach((groupItem, groupIndex) => {
|
|
|
+ let groupSub = {
|
|
|
+ groupDate: groupItem.groupDate,
|
|
|
+ groupIndex: mSubscribeList.length,
|
|
|
+ }
|
|
|
+ if (!isObjEmpty(groupItem.list)) {
|
|
|
+ groupItem.list.forEach((childItem, childIndex) => {
|
|
|
+ childItem.groupIndex = mSubscribeList.length
|
|
|
+ childItem.childIndex = childIndex
|
|
|
+ })
|
|
|
+ }
|
|
|
+ groupSub.list = groupItem.list
|
|
|
+ mSubscribeList.push(groupSub)
|
|
|
+ })
|
|
|
+ this.setState({
|
|
|
+ subscribeDataSource: this.state.subscribeDataSource.cloneWithRows(
|
|
|
+ mSubscribeList),
|
|
|
+ refreshing: false,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ mPageIndex--
|
|
|
+ }
|
|
|
+ }).catch(error => {
|
|
|
+ mPageIndex--
|
|
|
+ if (typeof error === 'string') {
|
|
|
+ message.error(error)
|
|
|
+ } else {
|
|
|
+ message.error('数据获取失败')
|
|
|
+ }
|
|
|
this.setState({
|
|
|
- subscribeDataSource: this.state.subscribeDataSource.cloneWithRows(
|
|
|
- mSubscribeList),
|
|
|
- hasNextPage: true,
|
|
|
refreshing: false,
|
|
|
})
|
|
|
- }, 1000)
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
+ onSubItemClick = (subObj) => {
|
|
|
+ console.log(mSubscribeList[subObj.groupIndex].list)
|
|
|
+ console.log(mSubscribeList[subObj.groupIndex].list[subObj.childIndex])
|
|
|
+ if (!isObjEmpty(mSubscribeList, mSubscribeList[subObj.groupIndex],
|
|
|
+ mSubscribeList[subObj.groupIndex].list,
|
|
|
+ mSubscribeList[subObj.groupIndex].list[subObj.childIndex])) {
|
|
|
+ mSubscribeList[subObj.groupIndex].list[subObj.childIndex].STATUS_ = -1
|
|
|
+ this.setState({
|
|
|
+ subscribeDataSource: this.state.subscribeDataSource.cloneWithRows(
|
|
|
+ JSON.parse(
|
|
|
+ JSON.stringify(mSubscribeList))),
|
|
|
+ })
|
|
|
+
|
|
|
+ saveListState({
|
|
|
+ scrollTop: ReactDOM.findDOMNode(this.lv).scrollTop,
|
|
|
+ pageIndex: mPageIndex,
|
|
|
+ listData: mSubscribeList,
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|