controller.js 1.05 KB
'use strict';

import {
    Controller
} from 'js/yoho-mvc';

import {
    TabView,
    GetContent
} from './view';

import {
    globalSearch as search
} from './model';

let hisContent = require('hbs/home/grade-new.hbs');

class GradeController extends Controller {
    constructor() {
        super();
        this.tabView = new TabView();
        this.content = new GetContent();
        this.content.on('search', this.doSearch.bind(this));
        this.page = 1;
        this.loading = false;
    }

    doSearch() {
        if (!this.end && !this.loading) {
            this.page++;
            this.search(this.page);
        }
    }

    search(page) {
        this.loading = true;
        search('//m.yohobuy.com/home/gradeNew/getHis', {page: page}).then(data => {
            if (data.detailHis <= 0) {
                this.end = true;
            } else {
                $('.ul-detail:first').append(hisContent(data));
            }
        }).catch(() => {}).finally(() => {
            this.loading = false;
        });
    }
}


module.exports = GradeController;