index.jsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { Component } from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { connect } from 'react-redux'
  4. import { View, Image } from '@tarojs/components'
  5. import { set } from '../../actions/counter'
  6. import { getProjecList,getWeChatShareDetails } from '../../utils/servers/servers'
  7. import {resourceAddress} from '../../utils/config';
  8. import NavBar from '../../components/NavBar';
  9. import ListBottomStart from '../../components/common/listBottomStart';
  10. import './index.less';
  11. import background from '../../assets/images/background.png';
  12. @connect(({ counter }) => ({
  13. counter
  14. }), (dispatch) => ({
  15. set (value) {
  16. dispatch(set(value))
  17. }
  18. }))
  19. class Index extends Component {
  20. inst = Taro.getCurrentInstance()
  21. constructor(props) {
  22. super(props);
  23. this.state={
  24. list: [],
  25. pageNo: 0,
  26. listState: 'LOADING',
  27. weChatShareDetails:{},
  28. }
  29. this.getProjecList= this.getProjecList.bind(this);
  30. this.getWeChatShareDetails= this.getWeChatShareDetails.bind(this);
  31. }
  32. componentDidShow() {
  33. //设置barter的选择状态
  34. this.props.set(0);
  35. this.getWeChatShareDetails()
  36. }
  37. async componentDidMount() {
  38. await this.getProjecList();
  39. }
  40. onPullDownRefresh(){
  41. this.getProjecList();
  42. }
  43. onReachBottom(){
  44. this.getProjecList(this.state.pageNo+1);
  45. }
  46. async getProjecList (pageNo = 1){
  47. this.setState({
  48. listState: 'LOADING'
  49. })
  50. let msg = await getProjecList({
  51. pageNo: pageNo,
  52. pageSize: 10,
  53. });
  54. if(msg.error.length === 0){
  55. if(msg.data.totalCount === 0){
  56. this.setState({
  57. listState: 'NO_DATA'
  58. })
  59. }else if(msg.data.totalCount === this.state.list.length && pageNo !== 1){
  60. Taro.showToast({title:'没有更多数据了',icon:'none'});
  61. this.setState({
  62. listState: 'NO_MORE_DATA'
  63. })
  64. }else{
  65. this.setState({
  66. list:pageNo === 1 ? msg.data.list : this.state.list.concat(msg.data.list),
  67. pageNo: msg.data.pageNo
  68. },()=>{
  69. if(msg.data.totalCount === this.state.list.length){
  70. this.setState({
  71. listState: 'NO_MORE_DATA'
  72. })
  73. }
  74. })
  75. }
  76. }else{
  77. Taro.showToast({title:msg.error[0].message,icon:'none'});
  78. this.setState({
  79. listState: msg.error[0].field === '403' ? 'NO_DATA' : 'RELOAD'
  80. })
  81. }
  82. Taro.stopPullDownRefresh();
  83. }
  84. getWeChatShareDetails(){
  85. getWeChatShareDetails({type:1}).then(v=>{
  86. if(v.error.length === 0){
  87. this.setState({
  88. weChatShareDetails:v.data
  89. })
  90. }else{
  91. Taro.showToast({title:v.error[0].message,icon:'none'})
  92. }
  93. })
  94. }
  95. onShareAppMessage(){
  96. return {
  97. title: this.state.weChatShareDetails.title,
  98. imageUrl: resourceAddress + this.state.weChatShareDetails.shareUrl
  99. }
  100. }
  101. //朋友圈分享
  102. onShareTimeline(){
  103. return {
  104. title: this.state.weChatShareDetails.title,
  105. imageUrl: resourceAddress + this.state.weChatShareDetails.momentsUrl
  106. }
  107. }
  108. render () {
  109. return (
  110. <View className='indexPage'>
  111. <NavBar
  112. extClass='NavBar'
  113. title='科德高企培育'
  114. background='#7ac7ff'
  115. onHome={()=>{}}
  116. />
  117. <Image src={background} className='background'/>
  118. <View className='title'>推荐</View>
  119. <View className='list'>
  120. {
  121. this.state.list.map((v,k)=>(
  122. <View key={k} className='item' onClick={()=>{
  123. Taro.navigateTo({
  124. url:'/pages/details/index?id='+v.id
  125. })
  126. }}>
  127. <View className='infor'>
  128. <View className='name'>{v.name}</View>
  129. <View className='createTimes'>{v.typeName}</View>
  130. <View className='amount'>
  131. <View className='money'>¥</View>
  132. {v.amount}
  133. </View>
  134. </View>
  135. <Image className='thumbnailUrl' src={resourceAddress+v.thumbnailUrl} resizeMode='center'/>
  136. </View>
  137. ))
  138. }
  139. <ListBottomStart
  140. state={this.state.listState}
  141. reload={()=>{
  142. this.getProjecList(this.state.pageNo+1);
  143. }}/>
  144. </View>
  145. </View>
  146. )
  147. }
  148. }
  149. export default Index