增加上下架商品功能。
This commit is contained in:
parent
d3d72f843e
commit
d602175913
@ -3,7 +3,15 @@ import request from '@/utils/request'
|
|||||||
// 获取商家商品列表
|
// 获取商家商品列表
|
||||||
export function getMerchantProducts(merchantId) {
|
export function getMerchantProducts(merchantId) {
|
||||||
return request({
|
return request({
|
||||||
url: `/api/merchant/product/merchant/${merchantId}`,
|
url: `/api/merchant/product/list`,
|
||||||
method: 'get'
|
method: 'get',
|
||||||
|
params: {
|
||||||
|
merchant_id: merchantId
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改商品状态
|
||||||
|
export const updateProductStatus = (productId, data) => {
|
||||||
|
return request.put(`/api/merchant/product/${productId}`, data)
|
||||||
|
}
|
||||||
@ -29,45 +29,63 @@
|
|||||||
</a-form>
|
</a-form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a-table
|
<div class="table-container">
|
||||||
:columns="columns"
|
<a-table
|
||||||
:data-source="tableData"
|
:columns="columns"
|
||||||
:pagination="pagination"
|
:data-source="tableData"
|
||||||
:loading="loading"
|
:pagination="pagination"
|
||||||
@change="handleTableChange"
|
:loading="loading"
|
||||||
row-key="id"
|
@change="handleTableChange"
|
||||||
>
|
row-key="id"
|
||||||
<template #bodyCell="{ column, text, record }">
|
:scroll="{ x: 1500 }"
|
||||||
<!-- 图片列 -->
|
>
|
||||||
<template v-if="column.key === 'image_url'">
|
<template #bodyCell="{ column, text, record }">
|
||||||
<div class="product-image">
|
<!-- 图片列 -->
|
||||||
<img :src="text" :alt="record.name" />
|
<template v-if="column.key === 'image_url'">
|
||||||
</div>
|
<div class="product-image">
|
||||||
|
<img :src="text" :alt="record.name" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<!-- 价格列 -->
|
||||||
|
<template v-if="['product_price', 'sale_price', 'settlement_amount'].includes(column.key)">
|
||||||
|
¥{{ text }}
|
||||||
|
</template>
|
||||||
|
<!-- 标签列 -->
|
||||||
|
<template v-if="column.key === 'tags'">
|
||||||
|
<a-tag
|
||||||
|
v-for="tag in text?.split(',')"
|
||||||
|
:key="tag"
|
||||||
|
color="blue"
|
||||||
|
>
|
||||||
|
{{ tag }}
|
||||||
|
</a-tag>
|
||||||
|
</template>
|
||||||
|
<!-- 最高抵扣金额 -->
|
||||||
|
<template v-if="column.key === 'max_deduct_points'">
|
||||||
|
{{ text }} 消费金
|
||||||
|
</template>
|
||||||
|
<!-- 状态列 -->
|
||||||
|
<template v-if="column.key === 'status'">
|
||||||
|
<a-tag :color="getStatusColor(record.status)">
|
||||||
|
{{ getStatusText(record.status) }}
|
||||||
|
</a-tag>
|
||||||
|
</template>
|
||||||
|
<!-- 操作列 -->
|
||||||
|
<template v-if="column.key === 'action'">
|
||||||
|
<a-space>
|
||||||
|
<a-button type="link" @click="handleEdit(record)">修改</a-button>
|
||||||
|
<a-button
|
||||||
|
type="link"
|
||||||
|
:loading="record.statusLoading"
|
||||||
|
@click="handleToggleStatus(record)"
|
||||||
|
>
|
||||||
|
{{ record.status === 'LISTING' ? '下架' : '上架' }}
|
||||||
|
</a-button>
|
||||||
|
</a-space>
|
||||||
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<!-- 价格列 -->
|
</a-table>
|
||||||
<template v-if="['product_price', 'sale_price', 'settlement_amount'].includes(column.key)">
|
</div>
|
||||||
¥{{ text }}
|
|
||||||
</template>
|
|
||||||
<!-- 标签列 -->
|
|
||||||
<template v-if="column.key === 'tags'">
|
|
||||||
<a-tag
|
|
||||||
v-for="tag in text?.split(',')"
|
|
||||||
:key="tag"
|
|
||||||
color="blue"
|
|
||||||
>
|
|
||||||
{{ tag }}
|
|
||||||
</a-tag>
|
|
||||||
</template>
|
|
||||||
<!-- 最高抵扣金额 -->
|
|
||||||
<template v-if="column.key === 'max_deduct_points'">
|
|
||||||
{{ text }} 消费金
|
|
||||||
</template>
|
|
||||||
<!-- 操作列 -->
|
|
||||||
<template v-if="column.key === 'action'">
|
|
||||||
<a-button type="link" @click="handleEdit(record)">修改</a-button>
|
|
||||||
</template>
|
|
||||||
</template>
|
|
||||||
</a-table>
|
|
||||||
|
|
||||||
<!-- 添加商品模态框 -->
|
<!-- 添加商品模态框 -->
|
||||||
<a-modal
|
<a-modal
|
||||||
@ -280,7 +298,7 @@ import { defineComponent, ref, onMounted } from 'vue'
|
|||||||
import { message, Upload, InputNumber, Tag } from 'ant-design-vue'
|
import { message, Upload, InputNumber, Tag } from 'ant-design-vue'
|
||||||
import { UploadOutlined } from '@ant-design/icons-vue'
|
import { UploadOutlined } from '@ant-design/icons-vue'
|
||||||
import PageContainer from '@/components/PageContainer.vue'
|
import PageContainer from '@/components/PageContainer.vue'
|
||||||
import { getMerchantProducts } from '@/api/merchant'
|
import { getMerchantProducts, updateProductStatus } from '@/api/merchant'
|
||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@ -323,6 +341,13 @@ export default defineComponent({
|
|||||||
width: 100,
|
width: 100,
|
||||||
align: 'center'
|
align: 'center'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '所属商家',
|
||||||
|
dataIndex: 'merchant_name',
|
||||||
|
key: 'merchant_name',
|
||||||
|
width: 160,
|
||||||
|
ellipsis: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '商品名称',
|
title: '商品名称',
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
@ -363,6 +388,13 @@ export default defineComponent({
|
|||||||
width: 120,
|
width: 120,
|
||||||
align: 'right'
|
align: 'right'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
key: 'status',
|
||||||
|
width: 100,
|
||||||
|
align: 'center'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
@ -391,21 +423,34 @@ export default defineComponent({
|
|||||||
|
|
||||||
// 获取商品列表
|
// 获取商品列表
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
if (!filterForm.value.merchant_id) {
|
|
||||||
tableData.value = []
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
const params = {
|
||||||
|
skip: (pagination.value.current - 1) * pagination.value.pageSize,
|
||||||
|
limit: pagination.value.pageSize
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果选择了商家,添加商家ID参数
|
||||||
|
if (filterForm.value.merchant_id) {
|
||||||
|
params.merchant_id = filterForm.value.merchant_id
|
||||||
|
}
|
||||||
|
|
||||||
const res = await getMerchantProducts(filterForm.value.merchant_id)
|
const res = await getMerchantProducts(filterForm.value.merchant_id)
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
tableData.value = res.data || []
|
tableData.value = (res.data.items || []).map(item => ({
|
||||||
pagination.value.total = res.data.length
|
...item,
|
||||||
|
statusLoading: false
|
||||||
|
}))
|
||||||
|
pagination.value.total = res.data.total
|
||||||
|
} else {
|
||||||
|
tableData.value = []
|
||||||
|
pagination.value.total = 0
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取商品列表失败:', error)
|
console.error('获取商品列表失败:', error)
|
||||||
message.error('获取商品列表失败')
|
message.error('获取商品列表失败')
|
||||||
|
tableData.value = []
|
||||||
|
pagination.value.total = 0
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
@ -623,8 +668,55 @@ export default defineComponent({
|
|||||||
addModalVisible.value = false
|
addModalVisible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取状态文本
|
||||||
|
const getStatusText = (status) => {
|
||||||
|
const statusMap = {
|
||||||
|
'LISTING': '上架',
|
||||||
|
'UNLISTING': '下架'
|
||||||
|
}
|
||||||
|
return statusMap[status] || status
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取状态标签颜色
|
||||||
|
const getStatusColor = (status) => {
|
||||||
|
const colorMap = {
|
||||||
|
'LISTING': 'green',
|
||||||
|
'UNLISTING': 'red'
|
||||||
|
}
|
||||||
|
return colorMap[status] || 'default'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理状态切换
|
||||||
|
const handleToggleStatus = async (record) => {
|
||||||
|
const newStatus = record.status === 'LISTING' ? 'UNLISTING' : 'LISTING'
|
||||||
|
const actionText = newStatus === 'LISTING' ? '上架' : '下架'
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 添加局部loading状态
|
||||||
|
record.statusLoading = true
|
||||||
|
|
||||||
|
const res = await updateProductStatus(record.id, {
|
||||||
|
status: newStatus
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.code === 200) {
|
||||||
|
message.success(`${actionText}成功`)
|
||||||
|
// 更新本地数据状态
|
||||||
|
record.status = newStatus
|
||||||
|
} else {
|
||||||
|
throw new Error(res.message || `${actionText}失败`)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`${actionText}商品失败:`, error)
|
||||||
|
message.error(error.message || `${actionText}失败`)
|
||||||
|
} finally {
|
||||||
|
record.statusLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchMerchantOptions()
|
fetchMerchantOptions()
|
||||||
|
fetchData() // 直接加载所有商品
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -654,14 +746,16 @@ export default defineComponent({
|
|||||||
handleEditUpload,
|
handleEditUpload,
|
||||||
handleEditRemoveImage,
|
handleEditRemoveImage,
|
||||||
handleEditSubmit,
|
handleEditSubmit,
|
||||||
handleEditCancel
|
handleEditCancel,
|
||||||
|
getStatusText,
|
||||||
|
getStatusColor,
|
||||||
|
handleToggleStatus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
.table-header {
|
.table-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@ -731,4 +825,56 @@ export default defineComponent({
|
|||||||
.image-actions .ant-btn {
|
.image-actions .ant-btn {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:deep(.ant-tag) {
|
||||||
|
min-width: 60px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-space) {
|
||||||
|
gap: 8px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-table-cell) {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-table-cell-ellipsis) {
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-list {
|
||||||
|
background: #fff;
|
||||||
|
padding: 24px;
|
||||||
|
min-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-container {
|
||||||
|
overflow-x: auto;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-table-wrapper) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-table) {
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-table-body) {
|
||||||
|
overflow-x: auto !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-table-cell) {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-table-cell-ellipsis) {
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Loading…
Reference in New Issue
Block a user