Commit 78820f96 authored by mengwenhao's avatar mengwenhao

feature:商品列表开发完毕

parent fa960d2a
......@@ -15,7 +15,7 @@ const req = require("../utils/request").httpReq;
* ctx.body = await req(ctx,opts); 将发送请求后的数据传递给前端页面
* };
*/
// 获取分类
exports.getCategoryList = async ctx => {
const url = `${GOODS_URI}/goods/background/get_goods_category_list`;
const opts = {
......@@ -24,7 +24,7 @@ exports.getCategoryList = async ctx => {
};
ctx.body = await req(ctx, opts);
};
// 获取商品列表
exports.getList = async ctx => {
const url = `${GOODS_URI}/goods/background/get_goods_list`;
const opts = {
......@@ -34,3 +34,25 @@ exports.getList = async ctx => {
};
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);
/* 商品管理 */
router.get(`${API_VERSION}/get_goods_category_list`, goods.getCategoryList);
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)
......
......@@ -82,7 +82,7 @@
>
<el-table-column
label="商品id"
prop="goods_sku_id"
prop="goods_spu_id"
align="center"
></el-table-column>
<el-table-column
......@@ -180,7 +180,7 @@
<el-popconfirm
title="您确定要上架该商品吗?"
cancelButtonType="default"
@confirm="changeGoodsState('GROUNDING')"
@confirm="changeGoodsState('GROUNDING', scope.row.goods_spu_id)"
>
<template #reference>
<el-button type="text">上架</el-button>
......@@ -191,7 +191,9 @@
<el-popconfirm
title="您确定要下架该商品吗?"
cancelButtonType="default"
@confirm="changeGoodsState('UNDERCARRIAGE')"
@confirm="
changeGoodsState('UNDERCARRIAGE', scope.row.goods_spu_id)
"
>
<template #reference>
<el-button type="text">下架</el-button>
......@@ -218,7 +220,12 @@
<style lang="less" src="./index.less" scope></style>
<script>
import { getGoodsList, getList } from "@/service/Goods/goods";
import {
getGoodsList,
getList,
putOnline,
putOffline
} from "@/service/Goods/goods";
export default {
name: "GoodsList",
......@@ -290,20 +297,7 @@ export default {
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) {
const valueArray = value.map(item => {
return item[index];
......@@ -316,30 +310,49 @@ export default {
});
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) {
this.searchProps.category_1_id = this.getVal(val, 0);
this.searchProps.category_2_id = this.getVal(val, 1);
},
// 商品状态赋值
handleStatusChange (val) {
this.searchProps.status = this.getValue(val);
},
// 上架状态赋值
handleOnlineStatusChange (val) {
this.searchProps.online_status = this.getValue(val);
},
// 按条件搜索
searchList () {
this.getCommodityList();
},
// 上架/下架操作
changeGoodsState (state) {
console.log(state);
async changeGoodsState (state, spuId) {
// 上架操作
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 {
},
// 去往详情页
goDetail (where) {
this.$router.push({ name: "GoodsDetail", params: { operation: where } });
goDetail (operation, spuId) {
this.$router.push({ name: "GoodsDetail", params: { operation, spuId } });
}
}
};
......
......@@ -5,9 +5,18 @@ export async function getGoodsList () {
const res = await axios.get("/api/v1/get_goods_category_list");
return res;
}
// 获取商品列表
export async function getList (params) {
const res = await axios.get("/api/v1/getGoodsList", { params });
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