Blame view

public/js/home/family-coin.page.js 6.27 KB
李靖 authored
1 2 3
import 'home/family-coin.page.css';
import $ from 'yoho-jquery';
import Page from 'yoho-page';
李靖 authored
4
import tip from 'plugin/tip';
李靖 authored
5
import resultRender from 'home/coin-list.hbs';
张孝茹 authored
6
import yoho from 'yoho-app';
李靖 authored
7 8 9 10 11 12 13 14 15 16 17

class ScoreDetail extends Page {
    constructor() {
        super();

        this.selector = {
            $coverBg: $('.cover-bg'),
            $tabItem: $('.tab-item'),
            $scoreDetailC: $('.score-detail-c'),
            $chosen: $('.tab-item .list').find('li'),
            $defaultChosen: $('.tab-item .list').find('li:first'),
李靖 authored
18 19 20 21 22
            $defaultChosenTime: $('#time .list').find('li:last'),
            $result: $('.result'),
            $source: $('#source').find('.name'),
            $queryType: $('#queryType').find('.name'),
            $time: $('#time').find('.name')
李靖 authored
23 24 25 26 27 28
        };

        this.view = {
            resultRender
        };
李靖 authored
29
        this.source = window.queryString.plateType || -1;
李靖 authored
30
        this.queryType = 0;
李靖 authored
31 32
        this.endTime = Date.parse(new Date());
        this.beginTime = parseInt(this.endTime, 10) - parseInt(31104000000, 10); // 默认显示一年内
李靖 authored
33 34 35 36
        this.page = 1;
        this.loading = false;
        this.end = false;
张孝茹 authored
37 38 39 40 41 42 43 44 45 46 47
        this.appPoint = {
            '全部': 0,  // eslint-disable-line
            'Yoho!Buy': 1,
            'mars': 2,  // eslint-disable-line
            'Yoho!Now': 3,
            'Yo!GREEN': 4,
            'Yo!COFFEE': 5,
            'Yo!LITTLE': 6,
            'Yo!GALLERY': 7
        };
李靖 authored
48 49 50 51 52 53 54
        this.init();
    }

    init() {
        this.setHeight();
        this.bindEvents();
        this.chosenData();
李靖 authored
55
        this.scroll();
李靖 authored
56
        this.defaultTab();
张孝茹 authored
57 58 59 60 61 62

        if (yoho && yoho.isMarsApp) {
            yoho.ready(() => {
                yoho.invokeMethod('set.removeTopRightButton');
            });
        }
李靖 authored
63 64 65 66 67 68 69 70 71 72 73
    }

    defaultTab() {
        this.selector.$defaultChosen.addClass('chosen');
        this.selector.$defaultChosenTime.addClass('chosen').siblings('li').removeClass('chosen');
        if (window.queryString.plateType) {
            let $defaultSource = $('#source').find(`li[data-source=${window.queryString.plateType}]`);

            $defaultSource.addClass('chosen').siblings('li').removeClass('chosen');
            this.selector.$source.text($defaultSource.find('.title').text());
        }
李靖 authored
74 75 76
    }

    scroll() {
李靖 authored
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
        $(window).scroll(() => {
            window.requestAnimationFrame(this.scrollHandler.bind(this));
        });
    }

    scrollHandler() {
        if (($(window).scrollTop() + $(window).height() >= $(document).height() * 0.8)) {
            this.doMore();
        }
    }

    doMore() {
        if (!this.end && !this.loading) {
            this.page++;
            this.chosenData();
        }
    }

    bindEvents() {
        this.selector.$tabItem.on('click', this.tab.bind(this));
        this.selector.$coverBg.on('click', this.coverBg.bind(this));
        this.selector.$chosen.on('click', this.chosen.bind(this));
    }
张孝茹 authored
101 102 103 104 105 106 107 108 109 110 111 112
    sourcePoint(name) {
        if (window._yas && window._yas.sendCustomInfo) {
            window._yas.sendCustomInfo({
                op: 'YB_MY_YF_COINDETAIL_APP_C',
                appop: 'YB_MY_YF_COINDETAIL_APP_C',
                param: JSON.stringify({
                    APP_TYPE: this.appPoint[name]
                })
            }, true);
        }
    }
李靖 authored
113 114 115 116 117 118 119
    chosen(e) {
        let $this = $(e.currentTarget);
        let $parensId = $this.parents('.tab-item').attr('id');

        this.selector.$result.empty();
        switch ($parensId) {
            case 'source':
李靖 authored
120
                this.source = $this.data('source');
李靖 authored
121
                this.selector.$source.text($this.find('.title').text());
张孝茹 authored
122
                this.sourcePoint($this.find('.title').text());
李靖 authored
123 124
                break;
            case 'queryType':
李靖 authored
125
                this.queryType = $this.data('type');
李靖 authored
126
                this.selector.$queryType.text($this.find('.title').text());
李靖 authored
127 128
                break;
            case 'time':
李靖 authored
129 130 131 132
                if ($this.data('begin')) {
                    this.beginTime = $this.data('begin');
                    this.endTime = Date.parse(new Date());
                    this.beginTime = parseInt(this.endTime, 10) - parseInt(this.beginTime, 10);
李靖 authored
133 134 135
                } else {
                    this.beginTime = '';
                    this.endTime = '';
李靖 authored
136
                }
李靖 authored
137
                this.selector.$time.text($this.find('.title').text());
李靖 authored
138
                break;
李靖 authored
139 140
            default:
                tip.show('请稍后再试~~');
李靖 authored
141 142
        }
        this.end = false;
李靖 authored
143
        this.page = 1;
李靖 authored
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
        this.chosenData();
        $this.addClass('chosen').siblings('li').removeClass('chosen');
        return false;
    }

    setHeight() {
        let wHeight = $(window).height();

        this.selector.$coverBg.css('min-height', `${wHeight}px`);
    }

    tab(e) {
        let $this = $(e.currentTarget);

        // $this.find('li:first').addClass('chosen');
        // $this.find('li:first').siblings('li').removeClass('chosen');
        if ($this.hasClass('active')) {
            $this.removeClass('active');
            this.selector.$scoreDetailC.removeClass('active');
        } else {
            $this.addClass('active');
            $this.siblings('.tab-item').removeClass('active');
            this.selector.$scoreDetailC.addClass('active');
        }
    }

    coverBg() {
        this.selector.$scoreDetailC.removeClass('active');
        this.selector.$tabItem.removeClass('active');
    }

    chosenData() {
        this.loading = true;
        this.ajax({
            url: '/home/family/coinDetail/getCoinData',
            data: {
                source: this.source,
                queryType: this.queryType,
                beginTime: this.beginTime,
                endTime: this.endTime,
                page: this.page
            }
        }).then(result => {
            if (result && result.coinList.length > 0) {
                this.selector.$result.append(this.view.resultRender(result));
                this.loading = false;
            } else {
                this.end = true;
李靖 authored
192
                tip.show('没有更多数据了~~~');
李靖 authored
193
            }
李靖 authored
194 195
            this.selector.$tabItem.removeClass('active');
            this.selector.$scoreDetailC.removeClass('active');
李靖 authored
196 197 198 199 200 201 202 203 204
        }).catch(error => {
            console.error(error);
        });
    }
}

$(() => {
    new ScoreDetail();
});