coin-detail.vue 2.32 KB
<template>
    <div class="yoho-coin" id="coin-detail-list">
        <header-box title="有货币" ref="header"></header-box>
        <div class="coin-total">
            <p>您目前拥有</p>
            <p><b>{{total}}</b></p>
            <p>个有货币</p>
        </div>
        <div class="coin-detail" v-if="coinList && coinList.length">
            <p>明细列表</p>
            <ul class="coin-detail-list" v-infinite-scroll="getCoinData" infinite-scroll-disabled="busy" infinite-scroll-distance="10">
                <li v-for="(coin, index) in coinList" :key="index">
                    <div class="coin-source">
                        <p>{{coin.message}}</p>
                        <time>{{coin.date}}</time>
                    </div>
                    <div class="coin-num"><i v-if="coin.num>0">+</i>{{coin.num}}</div>
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
    'use strict';

    import $ from 'jquery';
    import tip from 'common/tip';
    import HeaderBox from 'component/header.vue';

    export default {
        props: ['total'],
        data() {
            return {
                page: 0,
                limit: 15,
                pageTotal: 1,
                coinList: [],
                busy: false,
            };
        },

        mounted() {
            this.getCoinData();
        },

        methods: {
            getCoinData() {
                this.busy = true;
                if (this.page >= this.pageTotal) {
                    return;
                }
                $.ajax({
                    url: '/me/coin-detail',
                    data: {
                        page: ++this.page,
                        limit: this.limit
                    }
                }).then(result => {
                    if (result.code === 200) {
                        this.busy = false;
                        if (result.data.coinlist.length > 0) {
                            this.coinList = this.coinList.concat(result.data.coinlist);
                            this.pageTotal = result.data.page_total;
                        }
                    }
                }).fail(() => {
                    tip('网络错误');
                });
            }
        },
        components: {HeaderBox}
    };
</script>
<style>
    @import "../../scss/me/_coin.css";
</style>