order-info.js 1.07 KB
/**
 * 订单信息读取
 * @author: bikai<kai.bi@yoho.cn>
 * @date: 2015/12/14
 */
const cookie = require('yoho-cookie');
let info = cookie.get('order-info');

// cookie 参数
let actCkOpthn = {
    path: '/cart/index'
};

function init() {
    info = {
        uid: window.getUid(),
        deliveryId: $('.dispatch-mode .chosed').data('id') || 1,
        deliveryTimeId: 1,
        paymentTypeId: 1,
        yohoCoin: 0,
        addressId: null,
        coupon_code: null,
        invoice: null,
        invoices_title: null,
        invoices_type: null,
        receiverMobile: null,
        isModifyTel: false,
        invoicesType: null,
        msg: null,
        cartType: 'ordinary'
    };
    cookie.set('order-info', JSON.stringify(info), actCkOpthn);
}

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

exports.init = init;
exports.orderInfo = function(key, value) {
    if (typeof value === 'undefined') {
        return info[key];
    }
    info[key] = value;
    cookie.set('order-info', JSON.stringify(info), actCkOpthn);
};