index.jsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import React, { Component } from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { View } from '@tarojs/components'
  4. import { getPublicReleaseList } from '../../utils/servers/servers';
  5. import { AtTabs, AtTabsPane } from 'taro-ui';
  6. import './index.less';
  7. import 'taro-ui/dist/style/components/tabs.scss';
  8. import MyList from './myList';
  9. import MessageNoticebar from "../../components/common/messageNoticebar";
  10. class Examine extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state={
  14. current:0,
  15. list: [],
  16. pageNo: 1,
  17. listState: 'LOADING',
  18. examinelist: [],
  19. examinePageNo: 1,
  20. examineListState: 'LOADING',
  21. }
  22. this.getPublicReleaseList= this.getPublicReleaseList.bind(this);
  23. this.getMyList= this.getMyList.bind(this);
  24. this.getExamineList= this.getExamineList.bind(this);
  25. }
  26. componentDidShow(){
  27. Taro.eventCenter.on('listOperation',(data)=>{
  28. if(data.type === 1 && (!isNaN(parseInt(data.index)))){
  29. let arr = this.state.examinelist.concat([]);
  30. arr[data.index] = {
  31. ...arr[data.index],
  32. ...data
  33. }
  34. this.setState({
  35. examinelist:arr
  36. })
  37. }else if(data.type === 0 && (!isNaN(parseInt(data.index)))){
  38. let arr = this.state.list.concat([]);
  39. arr[data.index] = {
  40. ...arr[data.index],
  41. ...data
  42. }
  43. this.setState({
  44. list:arr
  45. })
  46. }
  47. })
  48. }
  49. async componentDidMount() {
  50. await this.getPublicReleaseList();
  51. }
  52. onPullDownRefresh(){
  53. this.getPublicReleaseList();
  54. }
  55. onReachBottom(){
  56. this.getPublicReleaseList(true);
  57. }
  58. onTabItemTap(obj){
  59. if(obj.index === 1){
  60. this.onTabTap();
  61. }
  62. }
  63. async onTabTap(){
  64. await this.getMyList(1);
  65. await this.getExamineList(1);
  66. }
  67. async getPublicReleaseList (lv){
  68. if(this.state.current === 0){
  69. await this.getMyList(lv ? this.state.pageNo + 1 : 1);
  70. Taro.stopPullDownRefresh();
  71. } else if(this.state.current === 1){
  72. await this.getExamineList(lv ? this.state.examinePageNo + 1 : 1);
  73. Taro.stopPullDownRefresh();
  74. }
  75. }
  76. async getMyList(pageNo){
  77. this.setState({
  78. listState: 'LOADING'
  79. })
  80. let msg = await getPublicReleaseList({
  81. pageNo: pageNo,
  82. pageSize: 10,
  83. type:0,
  84. });
  85. if(msg.error.length === 0){
  86. if(msg.data.totalCount === 0){
  87. this.setState({
  88. listState: 'NO_DATA'
  89. })
  90. }else if(msg.data.totalCount === this.state.list.length && pageNo !== 1){
  91. Taro.showToast({title:'没有更多数据了',icon:'none'});
  92. this.setState({
  93. listState: 'NO_MORE_DATA'
  94. })
  95. }else{
  96. this.setState({
  97. list:pageNo === 1 ? msg.data.list : this.state.list.concat(msg.data.list),
  98. pageNo: msg.data.pageNo
  99. },()=>{
  100. if(msg.data.totalCount === this.state.list.length){
  101. this.setState({
  102. listState: 'NO_MORE_DATA'
  103. })
  104. }
  105. })
  106. }
  107. }else{
  108. Taro.showToast({title:msg.error[0].message,icon:'none'});
  109. this.setState({
  110. listState: msg.error[0].field === '403' ? 'NO_DATA' : 'RELOAD'
  111. })
  112. }
  113. Taro.stopPullDownRefresh();
  114. }
  115. async getExamineList(pageNo){
  116. this.setState({
  117. examineListState: 'LOADING'
  118. })
  119. let msg = await getPublicReleaseList({
  120. pageNo: pageNo,
  121. pageSize: 10,
  122. type:1,
  123. });
  124. if(msg.error.length === 0){
  125. if(msg.data.totalCount === 0){
  126. this.setState({
  127. examineListState: 'NO_DATA'
  128. })
  129. }else if(msg.data.totalCount === this.state.examinelist.length && pageNo !== 1){
  130. Taro.showToast({title:'没有更多数据了',icon:'none'});
  131. this.setState({
  132. examineListState: 'NO_MORE_DATA'
  133. })
  134. }else{
  135. this.setState({
  136. examinelist:pageNo === 1 ? msg.data.list : this.state.examinelist.concat(msg.data.list),
  137. examinePageNo: msg.data.pageNo
  138. },()=>{
  139. if(msg.data.totalCount === this.state.examinelist.length){
  140. this.setState({
  141. examineListState: 'NO_MORE_DATA'
  142. })
  143. }
  144. })
  145. }
  146. }else{
  147. Taro.showToast({title:msg.error[0].message,icon:'none'});
  148. this.setState({
  149. examineListState: msg.error[0].field === '403' ? 'NO_DATA' : 'RELOAD'
  150. })
  151. }
  152. Taro.stopPullDownRefresh();
  153. }
  154. render () {
  155. return (
  156. <View className='indexPage'>
  157. <MessageNoticebar/>
  158. <AtTabs current={this.state.current || 0} tabList={[{ title: '我的' }, { title: '审核' }]} onClick={(current)=>{
  159. this.setState({
  160. current
  161. },()=>{
  162. if((current === 0 && this.state.pageNo === 1) || (current === 1 && this.state.examinePageNo === 1)){
  163. this.getPublicReleaseList();
  164. }
  165. })
  166. }}>
  167. <AtTabsPane current={this.state.current} index={0} >
  168. <MyList
  169. type={0}
  170. list={this.state.list}
  171. listState={this.state.listState}
  172. onRefresh={()=>{
  173. this.getPublicReleaseList(true);
  174. }}/>
  175. </AtTabsPane>
  176. <AtTabsPane current={this.state.current} index={1}>
  177. <MyList
  178. type={1}
  179. list={this.state.examinelist}
  180. listState={this.state.examineListState}
  181. onRefresh={()=>{
  182. this.getPublicReleaseList(true);
  183. }}/>
  184. </AtTabsPane>
  185. </AtTabs>
  186. </View>
  187. )
  188. }
  189. }
  190. export default Examine