zoukankan      html  css  js  c++  java
  • vant ui for VUE list 长列表组件使用

    html

     <van-pull-refresh
            v-model="onRefreshLoading"
            success-text="刷新成功"
            @refresh="onRefresh"
          >
            <van-list v-model="loading" :finished="finished" @load="onLoad">
              <div class="page-list" v-if="list && list.length > 0">
                <div
                  class="l-item"
                  @click="checkInfo()"
                  v-for="(item, i) in list"
                  :key="i"
                >
                  <div class="i-left">
                    <div class="i-name">{{ item.typeStr }}</div>
                    <div class="i-date">{{ item.created_at }}</div>
                  </div>
                  <div class="i-right">
                    <div class="i-num">{{ item.amount }}</div>
                    <div class="i-residue">餘額 {{ item.after_amount }}</div>
                  </div>
                </div>
              </div>
              <no-data
                v-show="list.lenght <= 0"
                text="暫時沒有新的帳戶明細"
              ></no-data>
            </van-list>
          </van-pull-refresh>
    

      js

    import {
        mapActions,
        mapGetters
    } from 'vuex'
    
    import {
        minusDate
    } from "@/utils/tools"
    export default {
        data() {
            return {
      
                typeList: [],
                list: [],
                onRefreshLoading: false, //下拉刷新加载状态
                loading: false, //加载状态
                finished: false, // 是否已加载完成,加载完成后不再触发load事件
                isLast: true, //是否最后一页
                preSearchData: {},
                allOpen: false,
                dateOpen: false,
                search: {
                    time_text: "今日",
                    type_text: "全部",
                    time_type: 1, // 1:今天 2:昨天 3:本月 不填,默认为1
                    startDate: new Date(),
                    endDate: new Date(),
                    page: 1,
                    size: 10,
                },
                DateConfig: [{
                        id: 1,
                        text: '今日'
                    }, {
                        id: 2,
                        text: '昨日'
                    },
                    {
                        id: 3,
                        text: '近7日'
                    }, {
                        id: 4,
                        text: '近30日'
                    }, {
                        id: 5,
                        text: '自定义'
                    },
                ],
            };
        },
        methods: {
            //切换时间
            checkDate(item) {
                this.search.time_type = item.id
                this.search.time_text = item.text
                this.list = []
                this.search.page = 1
                if (item.id == 5) {
                    //自定义时间
                } else {
                    this.search.endDate = new Date()
                    switch (item.id) {
                        case 1:
                            this.search.startDate = new Date()
                            break;
                        case 2:
                            this.search.startDate = minusDate(1)
                            break;
                        case 3:
                            this.search.startDate = minusDate(7)
                            break;
                        case 4:
                            this.search.startDate = minusDate(30)
                            break;
                        default:
                            this.search.startDate = new Date()
                            break;
                    }
                    this.dateOpen = false
                    this.getPageList({
                        id: 0
                    })
                }
            },
       
            // 获取记录,如果请求第一页数据必须传id:0 
            async getPageList(options = {}) {
                this.loading = true
                const params = {
                    token: this.UserInfo.token,
                    id: options.id != 0 ? this.dataId : 0, // 本页最后一条数据的ID 第一次可以为0
                    page_size: 10,
                    type: this.search.trading_type,
                    start_date: this.dateFormat(this.search.startDate),
                    end_date: this.dateFormat(this.search.endDate),
                }
                console.log('-----canshu11', params)
                let {
                    data
                } = await Api._getAmountTransDetail(params)
                if (!data) return
                console.log('返回数据11', data)
                if (params.id == 0) {
                    this.list = data.list
                } else {
                    this.list = this.list.concat(data.list); //追加数据
                }
                console.log('返回数据222', this.list)
                this.loading = false; // 加载状态结束 
                //数据全部加载完成
                this.finished = data.isLast; // 停止加载
                //是否最后一页
                this.isLast = data.isLast
                this.dataId = data.dataId
            },
            //下拉刷新
            onRefresh() {
                this.onRefreshLoading = true
                setTimeout(() => {
                    this.onRefreshLoading = false;
                    this.getPageList({
                        id: 0
                    })
                }, 1000);
            },
            onLoad(options) {
                this.getPageList(options); // 调用上面方法,请求数据
            },
            ...mapActions({
                'updateTransTypes': 'updateTransTypes'
            })
        },
        
    }
    

      

  • 相关阅读:
    飞入飞出效果
    【JSOI 2008】星球大战 Starwar
    POJ 1094 Sorting It All Out
    POJ 2728 Desert King
    【ZJOI 2008】树的统计 Count
    【SCOI 2009】生日快乐
    POJ 3580 SuperMemo
    POJ 1639 Picnic Planning
    POJ 2976 Dropping Tests
    SPOJ QTREE
  • 原文地址:https://www.cnblogs.com/lan-cheng/p/14814261.html
Copyright © 2011-2022 走看看