react加載更多

import Taro, { Component } from '@tarojs/taro'
import { ScrollView } from '@tarojs/components'
import { Page, AtPage, AtPreview, AtPreviewItem, AtTitle, AtButton } from '@CUI'
import cgi from '../../../config/cgi.js'
import styles from './query_res.module.scss'
const sdk = Taro.getApp().sdk

export default class Index extends Page {
  config = {
    navigationBarTitleText: '查詢(xún)結(jié)果'
  }
  state = {
    page: 1,
    formData: null,
    list: null,
  }
  componentWillMount() {
    console.log('手機(jī)端測(cè)試')
    if (this.$router.params) {
      this.setState({ formData: this.$router.params })
      let params = this.$router.params
      sdk.request({
        url: cgi.publicService,
        method: 'POST',
        data: {
          sessionId: "fujunyinid",
          serviceId: "gwyDevolution",
          taskId: params.taskId,
          pageNo: "1",
          department: params.department,
          searchContent: params.inputValue
        },
        header: { 'content-type': 'application/json' },
      }).then(res => {
      
        if (res.responseBody.list.length === 0) {
          Taro.showToast({
            title: '沒(méi)有相關(guān)數(shù)據(jù)',
            icon: 'none',
            duration: 2000
          })
          setTimeout(() => {
            Taro.navigateBack(1)
          }, 3000)
        } else {
          this.setState({ list: res.responseBody.list })
        }
      })
    }
  }

  componentDidMount() { }

  componentWillUnmount() { }

  componentDidShow() { }

  componentDidHide() { }

  onScrollToLower(e) {
    if (this.state.loading) return
    this.setState({
      loading: true
    })
    Taro.showLoading({
      title: '加載中...',
      mask: true
    })
    this.setState({ page: this.state.page += 1 })
    sdk.request({
      url: cgi.publicService,
      method: 'POST',
      data: {
        sessionId: "fujunyinid",
        serviceId: "gwyDevolution",
        taskId: this.state.formData.taskId,
        pageNo: this.state.page,
        department: this.state.formData.department,
      },
      header: { 'content-type': 'application/json' },
    }).then(res => {
        
          let reslist = res.responseBody.list
         
          if (reslist && reslist.length > 0) {
            this.setState({
              list: this.state.list.concat(reslist)
            })
            this.setState({
              loading: false
            })
          } else {
            Taro.showToast({
              title: '沒(méi)有更多數(shù)據(jù)了...',
              icon: 'none',
              duration: 2000
            })
          }
          Taro.hideLoading()
        })
  }
  render() {
    const Threshold = 40
    return (
      <AtPage className={styles.test}>
        <ScrollView
          className={styles.ScollHight}
          scrollY
          lowerThreshold={Threshold}
          onScrollToLower={this.onScrollToLower.bind(this)}
          onScroll={this.onScroll}
        >
          <AtTitle>查詢(xún)結(jié)果</AtTitle>
          {
            this.state.list && this.state.list.map((item) => {
              return <AtPreview title='' actionText='' onActionClick={this.handleClick}>
                <AtPreviewItem title='項(xiàng)目名稱(chēng):' text={item.projectName} hasBorder />
                <AtPreviewItem title='審批部門(mén):' text={item.department} hasBorder />
                {item.processingDecisions && <AtPreviewItem title='處理決定:' text={item.processingDecisions} />}
              </AtPreview>
            })
          }
        </ScrollView>
      </AtPage>
    )
  }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容