order-info.js 1.24 KB
/**
 * 订单信息读取
 * @author: bikai<kai.bi@yoho.cn>
 * @date: 2015/12/14
 */
var $ = require('jquery');
var info = window.cookie('order-info');

require('../common');

function init() {
    info = {
        uid: window.getUid(),
        deliveryId: $('.dispatch-mode .chosed').data('id') || 1,
        deliveryTimeId: 1,
        paymentTypeId: 1,
        yohoCoin: 0,
        addressId: null,
        couponCode: null,
        couponName: null,
        invoice: null,
        invoiceText: null,
        invoiceType: null,
        invoiceTitle: null,
        receiverMobile: null,
        isModifyTel: false,
        invoicesType: null,
        msg: null,
        cartType: 'ordinary'
    };
    window.setCookie('order-info', JSON.stringify(info));
}

// info 必须是 JSON 字符串
try {
    info = JSON.parse(info);

    // 2015/12/31 hf: fixes bug to 购物车页面调用该JS, 会导致有有货币,值却没有传给服务端. 因此需要再设置一下
    //info['yohoCoin'] = $('.coin').data('yoho-coin') || 0;
} catch (e) {
    init();
}

exports.init = init;

exports.orderInfo = function(key, value) {
    if (value === undefined) {
        return info[key];
    }
    info[key] = value;
    window.setCookie('order-info', JSON.stringify(info));
};