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

// info 必须是 JSON 字符串
try {
    info = JSON.parse(info);
} catch (e) {
    info = {
        deliveryId: 1,
        deliveryTimeId: 1,
        paymentTypeId: 1,
        yohoCoin: $('.coin').data('yoho-coin') || 0,
        addressId: null,
        couponCode: null,
        couponValue: null,
        invoice: null,
        invoiceText: null,
        invoiceType: null,
        msg: null
    };
    window.setCookie('order-info', JSON.stringify(info));
}

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