controller.js 1.24 KB
'use strict';

import {
    Controller
} from 'yoho-mvc';

import {
    DetailView
} from './view';

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

class ListController extends Controller {
    constructor() {
        super();

        this.detail = new DetailView();

        this.created();
    }

    created() {
        let skn = this.detail.getSkn();

        if (!skn) {
            return;
        }

        setTimeout(() => {
            search('//m.yohobuy.com/product/global/gethtml', {
                skn: skn
            }).then((html) => {
                this.detail.setDetailHtml(html);
            });

            if (this.detail.getCart()) {
                search('/cart/index/count').then((data) => {
                    let count;

                    if (data.code === 200) {
                        count = data.data.cart_goods_count || 0;
                        if (count === 0) {
                            return false;
                        }
                        if (count > 99) {
                            count = '99+';
                        }
                        this.detail.setCartCount(count);
                    }
                });
            }
        }, 500);
    }
}

module.exports = ListController;