index.js 3.31 KB
import React, { Component } from 'react';
import { connect } from 'dva';
import { Toast ,PullToRefresh} from 'antd-mobile';
import moment from 'moment';
import shareHide from "../../utils/shareHide";
import Iscroll from "../../components/Iscroll";
import NoData from "../../components/NoData";

import css from './css.less';
import { message } from 'antd';
class Index extends Component{
  constructor(props) {
    super(props);
    this.state = {
      list: [],
      isloading: false,
      pageNo:1,
      pageSize:20,
      finish:'',
      refreshing:false,
      dataEnd:false
    }
  }

  componentDidMount() {
    document.title = '行业动态';
    const _this = this;
    const userId = localStorage.id ? localStorage.id : null;
    this.setState({ userId })
    shareHide();
    Toast.loading('loading...',1000)
    this.props.dispatch({
      type: 'industrynews/getNewsList',
      payload: {
        status:1,
        pageNo:1,
        pageSize:20
      },
      callback(res) {
        _this.setState({ list: res ? res : [], isloading: true })
        Toast.hide();
      },
      error(err) {
        message.error(err.message)
      }
    })

  }
 getNewsListItem=()=>{
  let _this = this;
  let pageNo = this.state.pageNo +1;
  this.props.dispatch({
      type: 'industrynews/getNewsList',
      payload: {
        status:1,
        pageNo:pageNo,
        pageSize:20
      },
      callback(res) {
        let list = _this.state.list;
        let pageNo = _this.state.pageNo;
        let finish = _this.state.finish;
        let dataEnd = false;
        if(res && res.length>0){
          list = list.concat(res);
          pageNo = pageNo +1;
          finish = "完成刷新";
        }else{
          finish = "没有更多数据了";
          dataEnd = true;
        }
        _this.setState({ 
          list: list, 
          isloading: true,
          refreshing:false,
          pageNo:pageNo,
          finish:finish,
          dataEnd:dataEnd
        })
        Toast.hide();
      },
      error(err) {
        message.error(err.message)
      }
    })
 }

  render() {
    const { list, isloading } = this.state;
    return <div className={css.industryWrap + ' ' + ((list.length === 0 && isloading) ? css.noInfo : '' )}>
    <Iscroll
        id="industrynews"
        iscrollOptions={{
          preventDefault: true,
        }}
        onPullUpLoadMore={() => this.getNewsListItem()}
        hasUp={true}
        hasDown={false}
        dataEnd={this.state.dataEnd}
        haveBackTop={true}
        noUpStr={'已全部加载完毕'}
        >
          <div>
            {
              list.length > 0 && list.map(itm => <dl
                key={itm.id}
                onClick={() => {
                  this.props.history.push({ pathname: "/industrynews/detail", search: 'id=' + itm.id });
                }}
              >
                <dt><img src={itm.imgUrl} /></dt>
                <dd>
                  <div className={css.tit}>{itm.title}</div>
                  <div className={css.subinfo}>
                    <span className={css.viewCount}>{itm.viewCount}</span>
                    <span className={css.time}>{moment(itm.modifyTime).format('YYYY-MM-DD')}</span>
                  </div>
                </dd>
              </dl>)
            }
          </div>
        </Iscroll>
    </div>
  }
}

export default connect()(Index);