Commit 78820f96 authored by mengwenhao's avatar mengwenhao

feature:商品列表开发完毕

parent fa960d2a
...@@ -15,7 +15,7 @@ const req = require("../utils/request").httpReq; ...@@ -15,7 +15,7 @@ const req = require("../utils/request").httpReq;
* ctx.body = await req(ctx,opts); 将发送请求后的数据传递给前端页面 * ctx.body = await req(ctx,opts); 将发送请求后的数据传递给前端页面
* }; * };
*/ */
// 获取分类
exports.getCategoryList = async ctx => { exports.getCategoryList = async ctx => {
const url = `${GOODS_URI}/goods/background/get_goods_category_list`; const url = `${GOODS_URI}/goods/background/get_goods_category_list`;
const opts = { const opts = {
...@@ -24,7 +24,7 @@ exports.getCategoryList = async ctx => { ...@@ -24,7 +24,7 @@ exports.getCategoryList = async ctx => {
}; };
ctx.body = await req(ctx, opts); ctx.body = await req(ctx, opts);
}; };
// 获取商品列表
exports.getList = async ctx => { exports.getList = async ctx => {
const url = `${GOODS_URI}/goods/background/get_goods_list`; const url = `${GOODS_URI}/goods/background/get_goods_list`;
const opts = { const opts = {
...@@ -34,3 +34,25 @@ exports.getList = async ctx => { ...@@ -34,3 +34,25 @@ exports.getList = async ctx => {
}; };
ctx.body = await req(ctx, opts); ctx.body = await req(ctx, opts);
}; };
// 商品上架
exports.putOnline = async ctx => {
const url = `${GOODS_URI}/goods/background/online`;
const opts = {
url,
method: "POST",
json: true,
body: ctx.request.body
};
ctx.body = await req(ctx, opts);
};
// 商品下架
exports.putOffline = async ctx => {
const url = `${GOODS_URI}/goods/background/offline`;
const opts = {
url,
method: "POST",
json: true,
body: ctx.request.body
};
ctx.body = await req(ctx, opts);
};
\ No newline at end of file
...@@ -40,6 +40,8 @@ router.post(`${API_VERSION}/op_business_update`, enterprise.opBusinessUpdate); ...@@ -40,6 +40,8 @@ router.post(`${API_VERSION}/op_business_update`, enterprise.opBusinessUpdate);
/* 商品管理 */ /* 商品管理 */
router.get(`${API_VERSION}/get_goods_category_list`, goods.getCategoryList); router.get(`${API_VERSION}/get_goods_category_list`, goods.getCategoryList);
router.get(`${API_VERSION}/getGoodsList`, goods.getList); router.get(`${API_VERSION}/getGoodsList`, goods.getList);
router.post(`${API_VERSION}/goods/background/online`, goods.putOnline);
router.post(`${API_VERSION}/goods/background/offline`, goods.putOffline);
//生活号 //生活号
router.post(`${API_VERSION}/merchant/lifeinner/life_info`, life.get_life_info) router.post(`${API_VERSION}/merchant/lifeinner/life_info`, life.get_life_info)
......
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
> >
<el-table-column <el-table-column
label="商品id" label="商品id"
prop="goods_sku_id" prop="goods_spu_id"
align="center" align="center"
></el-table-column> ></el-table-column>
<el-table-column <el-table-column
...@@ -180,7 +180,7 @@ ...@@ -180,7 +180,7 @@
<el-popconfirm <el-popconfirm
title="您确定要上架该商品吗?" title="您确定要上架该商品吗?"
cancelButtonType="default" cancelButtonType="default"
@confirm="changeGoodsState('GROUNDING')" @confirm="changeGoodsState('GROUNDING', scope.row.goods_spu_id)"
> >
<template #reference> <template #reference>
<el-button type="text">上架</el-button> <el-button type="text">上架</el-button>
...@@ -191,7 +191,9 @@ ...@@ -191,7 +191,9 @@
<el-popconfirm <el-popconfirm
title="您确定要下架该商品吗?" title="您确定要下架该商品吗?"
cancelButtonType="default" cancelButtonType="default"
@confirm="changeGoodsState('UNDERCARRIAGE')" @confirm="
changeGoodsState('UNDERCARRIAGE', scope.row.goods_spu_id)
"
> >
<template #reference> <template #reference>
<el-button type="text">下架</el-button> <el-button type="text">下架</el-button>
...@@ -218,7 +220,12 @@ ...@@ -218,7 +220,12 @@
<style lang="less" src="./index.less" scope></style> <style lang="less" src="./index.less" scope></style>
<script> <script>
import { getGoodsList, getList } from "@/service/Goods/goods"; import {
getGoodsList,
getList,
putOnline,
putOffline
} from "@/service/Goods/goods";
export default { export default {
name: "GoodsList", name: "GoodsList",
...@@ -290,20 +297,7 @@ export default { ...@@ -290,20 +297,7 @@ export default {
console.error(error); console.error(error);
} }
}, },
// 获取数组返回值并转换为字符串
// 获取列表
async getCommodityList () {
try {
const res = await getList(this.searchProps);
if (res.code !== 0) return this.$message.error(res.reason);
console.log("商品列表", res);
this.goodsList = res.result.list;
this.totalCount = res.result.count;
} catch (error) {
console.error(error);
}
},
getVal (value, index = 0) { getVal (value, index = 0) {
const valueArray = value.map(item => { const valueArray = value.map(item => {
return item[index]; return item[index];
...@@ -316,30 +310,49 @@ export default { ...@@ -316,30 +310,49 @@ export default {
}); });
return values.join(); return values.join();
}, },
// 获取列表
async getCommodityList () {
try {
const res = await getList(this.searchProps);
if (res.code !== 0) return this.$message.error(res.reason);
console.log("商品列表", res);
this.goodsList = res.result.list;
this.totalCount = res.result.count;
} catch (error) {
console.error(error);
}
},
// 所属分类赋值 // 所属分类赋值
handleTypeChange (val) { handleTypeChange (val) {
this.searchProps.category_1_id = this.getVal(val, 0); this.searchProps.category_1_id = this.getVal(val, 0);
this.searchProps.category_2_id = this.getVal(val, 1); this.searchProps.category_2_id = this.getVal(val, 1);
}, },
// 商品状态赋值 // 商品状态赋值
handleStatusChange (val) { handleStatusChange (val) {
this.searchProps.status = this.getValue(val); this.searchProps.status = this.getValue(val);
}, },
// 上架状态赋值 // 上架状态赋值
handleOnlineStatusChange (val) { handleOnlineStatusChange (val) {
this.searchProps.online_status = this.getValue(val); this.searchProps.online_status = this.getValue(val);
}, },
// 按条件搜索 // 按条件搜索
searchList () { searchList () {
this.getCommodityList(); this.getCommodityList();
}, },
// 上架/下架操作 // 上架/下架操作
changeGoodsState (state) { async changeGoodsState (state, spuId) {
console.log(state); // 上架操作
if (state === "GROUNDING") {
const res = await putOnline(spuId);
if (res.code !== 0) return this.$message.error(res.status);
this.$message.success("商品上架成功");
}
// 下架操作
else if (state === "UNDERCARRIAGE") {
const res = await putOffline(spuId);
if (res.code !== 0) return this.$message.error(res.status);
this.$message.success("商品下架成功");
}
}, },
// 页码变化 // 页码变化
...@@ -350,8 +363,8 @@ export default { ...@@ -350,8 +363,8 @@ export default {
}, },
// 去往详情页 // 去往详情页
goDetail (where) { goDetail (operation, spuId) {
this.$router.push({ name: "GoodsDetail", params: { operation: where } }); this.$router.push({ name: "GoodsDetail", params: { operation, spuId } });
} }
} }
}; };
......
...@@ -5,9 +5,18 @@ export async function getGoodsList () { ...@@ -5,9 +5,18 @@ export async function getGoodsList () {
const res = await axios.get("/api/v1/get_goods_category_list"); const res = await axios.get("/api/v1/get_goods_category_list");
return res; return res;
} }
// 获取商品列表 // 获取商品列表
export async function getList (params) { export async function getList (params) {
const res = await axios.get("/api/v1/getGoodsList", { params }); const res = await axios.get("/api/v1/getGoodsList", { params });
return res; return res;
} }
// 商品上架
export async function putOnline (query) {
const res = await axios.post("/api/v1/goods/background/online", { goods_spu_id: query });
return res;
}
// 商品下架
export async function putOffline (query) {
const res = await axios.post("/api/v1/goods/background/offline", { goods_spu_id: query });
return res;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment