|
|
/**
|
|
|
* Created by TaoHuang on 2017/5/9.
|
|
|
*/
|
|
|
|
|
|
import _ from 'lodash';
|
|
|
import request from 'axios';
|
|
|
|
|
|
const apiUrl = {
|
|
|
categoryList: '/platform/getShopsCategoryList',
|
|
|
updateCategory: '/platform/addOrUpdateShopsCategory',
|
|
|
deleteCategory: '/platform/deleteShopsCategory',
|
|
|
listProduct: '/platform/getAllProduct',
|
|
|
listBindProduct: '/platform/getBindProduct',
|
|
|
countBindProduct: '/platform/getBindProductCount',
|
|
|
createBindProduct:'/platform/addCategoryLinkProduct',
|
|
|
deleteBindProduct:'/platform/deleteCategoryLinkProduct'
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获得所有分类
|
|
|
* @param page
|
|
|
*/
|
|
|
function getCategoryList(page = 1) {
|
|
|
return request.get(apiUrl.categoryList, {
|
|
|
params: {
|
|
|
page
|
|
|
}
|
|
|
}).then(res => res.data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新或者新建分类
|
|
|
* @param id 有id 时是更新,没有id 是新建
|
|
|
* @param name
|
|
|
*/
|
|
|
function updateCategoryName(id, name) {
|
|
|
let data = {
|
|
|
categoryName: name,
|
|
|
};
|
|
|
|
|
|
if (id) {
|
|
|
data.categoryId = id
|
|
|
}
|
|
|
|
|
|
return request.post(apiUrl.updateCategory, data).then(res => res.data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除一个分类
|
|
|
* @param id
|
|
|
*/
|
|
|
function deleteCategory(id) {
|
|
|
return request.post(apiUrl.deleteCategory, {
|
|
|
categoryId: id
|
|
|
}).then(res => res.data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 列出该店铺中所有的商品
|
|
|
* @param categoryId
|
|
|
* @param page
|
|
|
* @param size
|
|
|
*/
|
|
|
function listProduct(page = 1, size = 20) {
|
|
|
return request.post(apiUrl.listProduct, { page, size } )
|
|
|
.then(res => res.data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 列出分类下所有商品
|
|
|
* @param categoryId
|
|
|
* @param page
|
|
|
* @param size
|
|
|
*/
|
|
|
function listBindProduct(categoryId, page = 1, size = 20) {
|
|
|
return request.post(apiUrl.listBindProduct, { categoryId, page, size })
|
|
|
.then(res => res.data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获得分类下商品的个数
|
|
|
* @param categoryId
|
|
|
*/
|
|
|
function countBindProduct(categoryId) {
|
|
|
return request.post(apiUrl.countBindProduct, { categoryId })
|
|
|
.then(res => res.data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 增加类目中关联的商品
|
|
|
* @param categoryId {string | array}
|
|
|
* @param productSKN
|
|
|
*/
|
|
|
function createBindProduct(categoryId, productSKN) {
|
|
|
if (_.isArray(productSKN)) {
|
|
|
|
|
|
}
|
|
|
return request.post(apiUrl.createBindProduct, {
|
|
|
categoryId, productSKN: _.isArray(productSKN) ? productSKN.join(',') : productSKN
|
|
|
}).then(res => res.data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除类目中关联的商品
|
|
|
* @param categoryId {string | array}
|
|
|
* @param productSKN
|
|
|
*/
|
|
|
function deleteBindProduct(categoryId, productSKN) {
|
|
|
return request.post(apiUrl.deleteBindProduct, {
|
|
|
categoryId, productSKN: _.isArray(productSKN) ? productSKN.join(',') : productSKN
|
|
|
}).then(res => res.data);
|
|
|
}
|
|
|
|
|
|
export default {
|
|
|
getCategoryList,
|
|
|
updateCategoryName,
|
|
|
deleteCategory,
|
|
|
listProduct,
|
|
|
listBindProduct,
|
|
|
countBindProduct,
|
|
|
createBindProduct,
|
|
|
deleteBindProduct
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|