fix: 进一步完善商品列表,修复TODO

This commit is contained in:
puhui999 2023-05-17 01:17:17 +08:00
parent 50b181318b
commit 52bfc4dac0
2 changed files with 111 additions and 116 deletions

View File

@ -33,7 +33,7 @@ export interface SpuType {
picUrl?: string // 商品封面图 picUrl?: string // 商品封面图
sliderPicUrls?: string[] // 商品轮播图 sliderPicUrls?: string[] // 商品轮播图
introduction?: string // 商品简介 introduction?: string // 商品简介
deliveryTemplateId?: number // 运费模版 deliveryTemplateId?: number | null // 运费模版
specType?: boolean // 商品规格 specType?: boolean // 商品规格
subCommissionType?: boolean // 分销类型 subCommissionType?: boolean // 分销类型
skus: SkuType[] // sku数组 skus: SkuType[] // sku数组
@ -48,39 +48,37 @@ export interface SpuType {
recommendGood?: boolean // 是否优品 recommendGood?: boolean // 是否优品
} }
// TODO @puhui999中英文之间有空格 // 获得 Spu 列表
// 获得spu列表 TODO @puhui999这个是 getSpuPage 哈
export const getSpuPage = (params: PageParam) => { export const getSpuPage = (params: PageParam) => {
return request.get({ url: '/product/spu/page', params }) return request.get({ url: '/product/spu/page', params })
} }
// 获得spu列表tabsCount // 获得 Spu 列表 tabsCount
export const getTabsCount = () => { export const getTabsCount = () => {
return request.get({ url: '/product/spu/tabsCount' }) return request.get({ url: '/product/spu/get-count' })
} }
// 创建商品spu // 创建商品 Spu
export const createSpu = (data: SpuType) => { export const createSpu = (data: SpuType) => {
return request.post({ url: '/product/spu/create', data }) return request.post({ url: '/product/spu/create', data })
} }
// 更新商品spu // 更新商品 Spu
export const updateSpu = (data: SpuType) => { export const updateSpu = (data: SpuType) => {
return request.put({ url: '/product/spu/update', data }) return request.put({ url: '/product/spu/update', data })
} }
// 更新商品spu status // 更新商品 Spu status
export const updateStatus = (data: { id: number; status: number }) => { export const updateStatus = (data: { id: number; status: number }) => {
return request.put({ url: '/product/spu/updateStatus', data }) return request.put({ url: '/product/spu/update-status', data })
} }
// 获得商品 spu // 获得商品 Spu
export const getSpu = (id: number) => { export const getSpu = (id: number) => {
return request.get({ url: `/product/spu/get-detail?id=${id}` }) return request.get({ url: `/product/spu/get-detail?id=${id}` })
} }
// 删除商品Spu // 删除商品 Spu
export const deleteSpu = (id: number) => { export const deleteSpu = (id: number) => {
return request.delete({ url: `/product/spu/delete?id=${id}` }) return request.delete({ url: `/product/spu/delete?id=${id}` })
} }

View File

@ -18,15 +18,17 @@
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
/> />
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <!-- TODO 分类只能选择二级分类目前还没做还是先以联调通顺为主 -->
<el-select v-model="queryParams.status" class="!w-240px" clearable placeholder="请选择状态"> <el-form-item label="商品分类" prop="categoryId">
<el-option <el-tree-select
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" v-model="queryParams.categoryId"
:key="dict.value" :data="categoryList"
:label="dict.label" :props="defaultProps"
:value="dict.value" check-strictly
class="w-1/1"
node-key="id"
placeholder="请选择商品分类"
/> />
</el-select>
</el-form-item> </el-form-item>
<el-form-item label="创建时间" prop="createTime"> <el-form-item label="创建时间" prop="createTime">
<el-date-picker <el-date-picker
@ -59,7 +61,7 @@
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-tabs v-model="queryParams.tabType" @tab-click="handleClick"> <el-tabs v-model="queryParams.tabType" @tab-click="handleTabClick">
<el-tab-pane <el-tab-pane
v-for="item in tabsData" v-for="item in tabsData"
:key="item.type" :key="item.type"
@ -68,28 +70,29 @@
/> />
</el-tabs> </el-tabs>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<!-- TODO puhui999: ID 编号的展示 --> <!-- TODO 折叠数据按需增加暂定以下三个 -->
<!-- TODO 暂时不做折叠数据 --> <el-table-column type="expand" width="30">
<!-- <el-table-column type="expand">--> <template #default="{ row }">
<!-- <template #default="{ row }">--> <el-form class="demo-table-expand" inline label-position="left">
<!-- <el-form inline label-position="left">--> <el-form-item label="市场价:">
<!-- <el-form-item label="市场价:">--> <span>{{ row.marketPrice }}</span>
<!-- <span>{{ row.marketPrice }}</span>--> </el-form-item>
<!-- </el-form-item>--> <el-form-item label="成本价:">
<!-- <el-form-item label="成本价:">--> <span>{{ row.costPrice }}</span>
<!-- <span>{{ row.costPrice }}</span>--> </el-form-item>
<!-- </el-form-item>--> <el-form-item label="虚拟销量:">
<!-- <el-form-item label="虚拟销量:">--> <span>{{ row.virtualSalesCount }}</span>
<!-- <span>{{ row.virtualSalesCount }}</span>--> </el-form-item>
<!-- </el-form-item>--> </el-form>
<!-- </el-form>--> </template>
<!-- </template>--> </el-table-column>
<!-- </el-table-column>--> <!-- TODO puhui999: ID 编号的展示 fix-->
<el-table-column key="id" align="center" label="商品编号" prop="id" />
<el-table-column label="商品图" min-width="80"> <el-table-column label="商品图" min-width="80">
<template #default="{ row }"> <template #default="{ row }">
<el-image <el-image
:src="row.picUrl" :src="row.picUrl"
style="width: 36px; height: 36px" style="width: 30px; height: 30px"
@click="imagePreview(row.picUrl)" @click="imagePreview(row.picUrl)"
/> />
</template> </template>
@ -107,13 +110,13 @@
prop="createTime" prop="createTime"
width="180" width="180"
/> />
<el-table-column fixed="right" label="状态" min-width="80"> <el-table-column align="center" label="状态" min-width="80">
<template #default="{ row }"> <template #default="{ row }">
<!-- TODO @puhui是不是不用 Number(row.status) 去比较哈直接 row.status < 0 --> <!-- fix: 修复打开回收站时商品误触改变商品状态的事件因为el-switch只用0和1没有-1所以当商品状态为-1时状态使用el-tag显示 -->
<template v-if="row.status >= 0">
<el-switch <el-switch
v-model="row.status" v-model="row.status"
:active-value="1" :active-value="1"
:disabled="Number(row.status) < 0"
:inactive-value="0" :inactive-value="0"
active-text="上架" active-text="上架"
inactive-text="下架" inactive-text="下架"
@ -121,6 +124,10 @@
@change="changeStatus(row)" @change="changeStatus(row)"
/> />
</template> </template>
<template v-else>
<el-tag type="info">回收站</el-tag>
</template>
</template>
</el-table-column> </el-table-column>
<el-table-column align="center" fixed="right" label="操作" min-width="150"> <el-table-column align="center" fixed="right" label="操作" min-width="150">
<template #default="{ row }"> <template #default="{ row }">
@ -138,7 +145,7 @@
v-hasPermi="['product:spu:update']" v-hasPermi="['product:spu:update']"
link link
type="primary" type="primary"
@click="addToTrash(row, ProductSpuStatusEnum.DISABLE.status)" @click="changeStatus(row, ProductSpuStatusEnum.DISABLE.status)"
> >
恢复到仓库 恢复到仓库
</el-button> </el-button>
@ -156,7 +163,7 @@
v-hasPermi="['product:spu:update']" v-hasPermi="['product:spu:update']"
link link
type="primary" type="primary"
@click="addToTrash(row, ProductSpuStatusEnum.RECYCLE.status)" @click="changeStatus(row, ProductSpuStatusEnum.RECYCLE.status)"
> >
加入回收站 加入回收站
</el-button> </el-button>
@ -172,21 +179,17 @@
@pagination="getList" @pagination="getList"
/> />
</ContentWrap> </ContentWrap>
<!-- https://kailong110120130.gitee.io/vue-element-plus-admin-doc/components/image-viewer.html -->
<!-- 必须在表格外面展示不然单元格会遮挡图层 -->
<el-image-viewer
v-if="imgViewVisible"
:url-list="imageViewerList"
@close="imgViewVisible = false"
/>
</template> </template>
<script lang="ts" name="ProductList" setup> <script lang="ts" name="ProductSpu" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
// TODO @puhui999managementApi=ProductSpuApi
import * as managementApi from '@/api/mall/product/management/spu'
import { ProductSpuStatusEnum } from '@/utils/constants'
import { TabsPaneContext } from 'element-plus' import { TabsPaneContext } from 'element-plus'
import { cloneDeep } from 'lodash-es'
import { createImageViewer } from '@/components/ImageViewer'
import { dateFormatter } from '@/utils/formatTime'
import { defaultProps, handleTree } from '@/utils/tree'
import { ProductSpuStatusEnum } from '@/utils/constants'
import * as ProductSpuApi from '@/api/mall/product/spu'
import * as ProductCategoryApi from '@/api/mall/product/category'
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
const { currentRoute, push } = useRouter() // const { currentRoute, push } = useRouter() //
@ -225,26 +228,21 @@ const tabsData = ref([
/** 获得每个 Tab 的数量 */ /** 获得每个 Tab 的数量 */
const getTabsCount = async () => { const getTabsCount = async () => {
// TODO @puhui999 try catch // TODO @puhui999 try catch fix
try { const res = await ProductSpuApi.getTabsCount()
const res = await managementApi.getTabsCount()
for (let objName in res) { for (let objName in res) {
tabsData.value[Number(objName)].count = res[objName] tabsData.value[Number(objName)].count = res[objName]
} }
} catch {}
} }
const imgViewVisible = ref(false) //
const imageViewerList = ref<string[]>([]) //
const queryParams = ref({ const queryParams = ref({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
tabType: 0 tabType: 0
}) }) //
const queryFormRef = ref() // const queryFormRef = ref() // Ref
// TODO @puhui999 handleTabClick // TODO @puhui999 handleTabClickfix
const handleClick = (tab: TabsPaneContext) => { const handleTabClick = (tab: TabsPaneContext) => {
queryParams.value.tabType = tab.paneName queryParams.value.tabType = tab.paneName
getList() getList()
} }
@ -253,7 +251,7 @@ const handleClick = (tab: TabsPaneContext) => {
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await managementApi.getSpuList(queryParams.value) const data = await ProductSpuApi.getSpuPage(queryParams.value)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } finally {
@ -261,7 +259,7 @@ const getList = async () => {
} }
} }
// TODO @puhui999 changeStatus addToTrash // TODO @puhui999 changeStatus addToTrash fix
/** /**
* 更改 SPU 状态 * 更改 SPU 状态
* *
@ -269,10 +267,12 @@ const getList = async () => {
* @param status 更改前的值 * @param status 更改前的值
*/ */
const changeStatus = async (row, status?: number) => { const changeStatus = async (row, status?: number) => {
// TODO // fix: changeStatus
const deepCopyValue = cloneDeep(unref(row))
if (typeof status !== 'undefined') deepCopyValue.status = status
try { try {
let text = '' let text = ''
switch (row.status) { switch (deepCopyValue.status) {
case ProductSpuStatusEnum.DISABLE.status: case ProductSpuStatusEnum.DISABLE.status:
text = ProductSpuStatusEnum.DISABLE.name text = ProductSpuStatusEnum.DISABLE.name
break break
@ -283,21 +283,21 @@ const changeStatus = async (row, status?: number) => {
text = `加入${ProductSpuStatusEnum.RECYCLE.name}` text = `加入${ProductSpuStatusEnum.RECYCLE.name}`
break break
} }
// fix:
await message.confirm( await message.confirm(
row.status === -1 ? `确认要将[${row.name}]${text}吗?` : `确认要${text}[${row.name}]吗?` deepCopyValue.status === -1
? `确认要将[${row.name}]${text}吗?`
: row.status === -1 // -1: status-1 status0
? `确认要将[${row.name}]恢复到仓库吗?`
: `确认要${text}[${row.name}]吗?`
) )
await managementApi.updateStatus({ id: row.id, status: row.status }) await ProductSpuApi.updateStatus({ id: deepCopyValue.id, status: deepCopyValue.status })
message.success('更新状态成功') message.success('更新状态成功')
// tabs // tabs
await getTabsCount() await getTabsCount()
// //
await getList() await getList()
} catch { } catch {
//
if (typeof status !== 'undefined') {
row.status = status
return
}
// //
row.status = row.status =
row.status === ProductSpuStatusEnum.DISABLE.status row.status === ProductSpuStatusEnum.DISABLE.status
@ -306,26 +306,13 @@ const changeStatus = async (row, status?: number) => {
} }
} }
/**
* 加入回收站
*
* @param row
* @param status
*/
const addToTrash = (row, status) => {
//
const num = Number(`${row.status}`)
row.status = status
changeStatus(row, num)
}
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (id: number) => { const handleDelete = async (id: number) => {
try { try {
// //
await message.delConfirm() await message.delConfirm()
// //
await managementApi.deleteSpu(id) await ProductSpuApi.deleteSpu(id)
message.success(t('common.delSuccess')) message.success(t('common.delSuccess'))
// tabs // tabs
await getTabsCount() await getTabsCount()
@ -339,8 +326,10 @@ const handleDelete = async (id: number) => {
* @param imgUrl * @param imgUrl
*/ */
const imagePreview = (imgUrl: string) => { const imagePreview = (imgUrl: string) => {
imageViewerList.value = [imgUrl] // fix: https://kailong110120130.gitee.io/vue-element-plus-admin-doc/components/image-viewer.html
imgViewVisible.value = true createImageViewer({
urlList: [imgUrl]
})
} }
/** 搜索按钮操作 */ /** 搜索按钮操作 */
@ -369,20 +358,28 @@ const openForm = (id?: number) => {
push('/product/productManagementAdd') push('/product/productManagementAdd')
} }
// TODO @puhui999 // TODO @puhui999fix:
watch( watch(
() => currentRoute.value, () => currentRoute.value,
() => { () => {
getList() getList()
},
{
immediate: true
} }
) )
const categoryList = ref() //
/** 初始化 **/ /** 初始化 **/
onMounted(() => { onMounted(async () => {
getTabsCount() await getTabsCount()
getList() await getList()
//
const data = await ProductCategoryApi.getCategoryList({})
categoryList.value = handleTree(data, 'id', 'parentId')
}) })
</script> </script>
<style lang="scss" scoped>
.demo-table-expand {
:deep(.el-form-item__label) {
width: 82px;
color: #99a9bf;
}
}
</style>