bundle.js 1.12 KB
/**
 * Created by targaryen on 2016/11/28.
 */
'use strict';
const utils = '../../../utils';
const _ = require('lodash');
const api = global.yoho.API;
const productProcess = require(`${utils}/product-process`);

/**
 * 从接口获取套装数据
 * @private
 */
const getBundleBySkn = (productSkn) => {
    return api.get('', {
        method: 'app.query.bundleSkn',
        product_skn: productSkn
    }, {cache: false}).then(result => {
        return result;
    });
};

/**
 * 套装详情页数据
 * @param params
 * @returns {*}
 */
const detail = (params) => {
    if (!params.skn) {
        return Promise.resolve({});
    }

    return getBundleBySkn(params.skn).then(result => {
        return {
            bundleInfo: Object.assign(_.get(result, 'data.bundleInfo', {}), {
                discount: parseInt(_.get(result, 'data.bundleInfo.salesPrice', 0), 10) -
                    parseInt(_.get(result, 'data.bundleInfo.discountPrice', 0), 10)
            }),
            productList: productProcess.processProductList(_.get(result, 'data.productList', []))
        };
    });
};

module.exports = {
    getBundleBySkn,
    detail
};