index.jsx 5.6 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.getMyList(1);
  61. this.getExamineList(1);
  62. }
  63. }
  64. async getPublicReleaseList (lv){
  65. if(this.state.current === 0){
  66. await this.getMyList(lv ? this.state.pageNo + 1 : 1);
  67. Taro.stopPullDownRefresh();
  68. } else if(this.state.current === 1){
  69. await this.getExamineList(lv ? this.state.examinePageNo + 1 : 1);
  70. Taro.stopPullDownRefresh();
  71. }
  72. }
  73. async getMyList(pageNo){
  74. this.setState({
  75. listState: 'LOADING'
  76. })
  77. let msg = await getPublicReleaseList({
  78. pageNo: pageNo,
  79. pageSize: 10,
  80. type:0,
  81. });
  82. if(msg.error.length === 0){
  83. if(msg.data.totalCount === 0){
  84. this.setState({
  85. listState: 'NO_DATA'
  86. })
  87. }else if(msg.data.totalCount === this.state.list.length && pageNo !== 1){
  88. Taro.showToast({title:'没有更多数据了',icon:'none'});
  89. this.setState({
  90. listState: 'NO_MORE_DATA'
  91. })
  92. }else{
  93. this.setState({
  94. list:pageNo === 1 ? msg.data.list : this.state.list.concat(msg.data.list),
  95. pageNo: msg.data.pageNo
  96. },()=>{
  97. if(msg.data.totalCount === this.state.list.length){
  98. this.setState({
  99. listState: 'NO_MORE_DATA'
  100. })
  101. }
  102. })
  103. }
  104. }else{
  105. Taro.showToast({title:msg.error[0].message,icon:'none'});
  106. this.setState({
  107. listState: msg.error[0].field === '403' ? 'NO_DATA' : 'RELOAD'
  108. })
  109. }
  110. Taro.stopPullDownRefresh();
  111. }
  112. async getExamineList(pageNo){
  113. this.setState({
  114. examineListState: 'LOADING'
  115. })
  116. let msg = await getPublicReleaseList({
  117. pageNo: pageNo,
  118. pageSize: 10,
  119. type:1,
  120. });
  121. if(msg.error.length === 0){
  122. if(msg.data.totalCount === 0){
  123. this.setState({
  124. examineListState: 'NO_DATA'
  125. })
  126. }else if(msg.data.totalCount === this.state.examinelist.length && pageNo !== 1){
  127. Taro.showToast({title:'没有更多数据了',icon:'none'});
  128. this.setState({
  129. examineListState: 'NO_MORE_DATA'
  130. })
  131. }else{
  132. this.setState({
  133. examinelist:pageNo === 1 ? msg.data.list : this.state.examinelist.concat(msg.data.list),
  134. examinePageNo: msg.data.pageNo
  135. },()=>{
  136. if(msg.data.totalCount === this.state.examinelist.length){
  137. this.setState({
  138. examineListState: 'NO_MORE_DATA'
  139. })
  140. }else if(pageNo === 1 && (msg.data.list.length || []) < 10){
  141. this.setState({
  142. examineListState: 'NO_MORE_DATA'
  143. })
  144. }
  145. })
  146. }
  147. }else{
  148. Taro.showToast({title:msg.error[0].message,icon:'none'});
  149. this.setState({
  150. examineListState: msg.error[0].field === '403' ? 'NO_DATA' : 'RELOAD'
  151. })
  152. }
  153. Taro.stopPullDownRefresh();
  154. }
  155. render () {
  156. return (
  157. <View className='indexPage'>
  158. <MessageNoticebar/>
  159. <AtTabs current={this.state.current || 0} tabList={[{ title: '我的' }, { title: '审核' }]} onClick={(current)=>{
  160. this.setState({
  161. current
  162. },()=>{
  163. if((current === 0 && this.state.pageNo === 1) || (current === 1 && this.state.examinePageNo === 1)){
  164. this.getPublicReleaseList();
  165. }
  166. })
  167. }}>
  168. <AtTabsPane current={this.state.current} index={0} >
  169. <MyList
  170. type={0}
  171. list={this.state.list}
  172. listState={this.state.listState}
  173. onRefresh={()=>{
  174. this.getPublicReleaseList(true);
  175. }}/>
  176. </AtTabsPane>
  177. <AtTabsPane current={this.state.current} index={1}>
  178. <MyList
  179. type={1}
  180. list={this.state.examinelist}
  181. listState={this.state.examineListState}
  182. onRefresh={()=>{
  183. this.getPublicReleaseList(true);
  184. }}/>
  185. </AtTabsPane>
  186. </AtTabs>
  187. </View>
  188. )
  189. }
  190. }
  191. export default Examine