order-ensure.js 1.61 KB
// import qs from 'yoho-qs';

class OrderEnsure {
    constructor(order) { // 参数为使用哪个 cookie
        this.order = order;
        this.orderInfo = order.orderInfo;

        this.selector = {
            invoice: $('.invoice'),
            invoiceType: $('.invoice-type'),
            userMobile: $('.user-mobile')
        };

        this.init();
        this.bindEvents();
    }

    init() {
        if (window.getUid() !== this.orderInfo('uid')) {
            this.order.init();
            window.location.reload();
        }
    }

    bindEvents() {
        this.selector.invoice.on('click', '.checkbox', this.needInvoice.bind(this));
    }

    /**
     * 是否需要开发票
     */
    needInvoice(event) {
        let $this = $(event.currentTarget);

        this.orderInfo('invoice', $this.hasClass('icon-cb-radio'));
        if ($this.hasClass('icon-cb-radio')) {
            this.selector.invoice.addClass('focus');
            this.selector.invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');
            this.orderInfo('receiverMobile', this.selector.userMobile.val());
            this.orderInfo('invoices_type', 2);
        }
        if ($this.hasClass('icon-radio')) {
            this.selector.invoice.removeClass('focus');
            this.selector.invoiceType.html('');
            this.orderInfo('invoices_title', null);
            this.orderInfo('invoices_type', null);
            this.orderInfo('receiverMobile', null);
            this.orderInfo('buyerTaxNumber', null);
        }
        event.preventDefault();
        event.stopPropagation();
    }
}

module.exports = OrderEnsure;