address.js 3.13 KB
/**
 * [个人中心]收货地址
 * @author: jiangmin
 * @date: 2016/07/05
 */

'use strict';

const api = global.yoho.API;

/**
 * 地址列表数据
 *
 * @param  uid 用户ID
 * @param  limit 分页大小参数(默认10条)
 * @return array 地址接口返回的数据
 */
const getAddressDataAsync = (uid, limit) => {
    return api.get('', {
        method: 'app.address.gethidden',
        uid: uid,
        limit: limit
    }).then(result => {
        // console.log('列表结果result', result);
        if (result.code === '200') {
            return result.data;
        }
        return result;
    });
};

/**
 * 保存地址数据
 *
 * @param uid 用户ID
 * @param address 地址信息
 * @param areaCode 城市码
 * @param consignee 收货人
 * @param mobile 手机号码
 * @param phone 电话号码
 * @return array 地址接口返回的数据
 */
const addAddressData = (uid, address, areaCode, consignee, mobile, phone) => {
    return api.get('', {
        method: 'app.address.add',
        uid: uid,
        address: address,
        area_code: areaCode,
        consignee: consignee,
        mobile: mobile,
        phone: phone
    }).then(result => {
        // console.log("添加result",result);
        return result;
    });
};

/**
 * 修改地址数据
 *
 * @param id 地址id
 * @param uid 用户ID
 * @param address 地址信息
 * @param areaCode 城市码
 * @param consignee 收货人
 * @param mobile 手机号码
 * @param phone 电话号码
 * @return array 地址接口返回的数据
 */
const updateAddressData = (id, uid, address, areaCode, consignee, mobile, phone) => {
    return api.get('', {
        method: 'app.address.update',
        id: id,
        uid: uid,
        address: address,
        area_code: areaCode,
        consignee: consignee,
        mobile: mobile,
        phone: phone
    }).then(result => {
        // console.log("修改result", result);
        return result;
    });
};

/**
 * 删除地址数据
 *
 * @param id 地址id
 * @param uid 用户ID
 * @return array 地址接口返回的数据
 */
const delAddressData = (id, uid) => {
    return api.get('', {
        method: 'app.address.del',
        id: id,
        uid: uid
    }).then(result => {
        // console.log("删除result",result);
        return result;
    });
};

/**
 * 设置默认地址
 *
 * @param id 地址id
 * @param uid 用户ID
 * @return array 地址接口返回的数据
 */
const setDefaultAddress = (id, uid) => {
    return api.get('', {
        method: 'app.address.setdefault',
        id: id,
        uid: uid
    }).then(result => {
        // console.log('设置默认result', result);
        return result;
    });
};

/**
 * 获取地址信息
 * @function getAddressData
 * @return { Array } [返回带有areaId的地址数组]
 * @param id
 * @param caption
 * @param is_support_express
 */
const getAddressData = (areaId) => {
    return api.get('', {
        method: 'app.address.provinces',
        id: areaId || 0
    }).then(result => {
        return result;
    });
};

module.exports = {
    getAddressDataAsync,
    addAddressData,
    updateAddressData,
    delAddressData,
    setDefaultAddress,
    getAddressData
};