商品管理: 打通所有接口(第一版)

This commit is contained in:
puhui999 2023-05-04 01:38:53 +08:00
parent 9ee35fc165
commit 0c6e3a39c9
6 changed files with 206 additions and 70 deletions

View File

@ -5,6 +5,10 @@ import type { SpuType } from './type/spuType'
export const getSpuList = (params: any) => { export const getSpuList = (params: any) => {
return request.get({ url: '/product/spu/page', params }) return request.get({ url: '/product/spu/page', params })
} }
// 获得spu列表tabsCount
export const getTabsCount = () => {
return request.get({ url: '/product/spu/tabsCount' })
}
// 创建商品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 })
@ -13,7 +17,15 @@ export const createSpu = (data: SpuType) => {
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
export const updateStatus = (data: { id: number; status: number }) => {
return request.put({ url: '/product/spu/updateStatus', 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
export const deleteSpu = (id: number) => {
return request.delete({ url: `/product/spu/delete?id=${id}` })
}

View File

@ -220,3 +220,20 @@ export const PayRefundStatusEnum = {
name: '退款关闭' name: '退款关闭'
} }
} }
/**
* SPU枚举类
*/
export const ProductSpuStatusEnum = {
RECYCLE: {
status: -1,
name: '回收站'
},
DISABLE: {
status: 0,
name: '下架'
},
ENABLE: {
status: 1,
name: '上架'
}
}

View File

@ -144,7 +144,7 @@ const getDetail = async () => {
const submitForm = async () => { const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
const newSkus = [...formData.value.skus] //skus使 const newSkus = JSON.parse(JSON.stringify(formData.value.skus)) //skus使
// TODO // TODO
// //
try { try {
@ -184,9 +184,12 @@ const submitForm = async () => {
await managementApi.updateSpu(data) await managementApi.updateSpu(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
close()
} catch (e) { } catch (e) {
console.log(e) // ,skus
console.log(newSkus) if (typeof e === 'string') {
formData.value.skus = newSkus
}
} finally { } finally {
formLoading.value = false formLoading.value = false
} }

View File

@ -117,6 +117,7 @@ watch(
(data) => { (data) => {
if (!data) return if (!data) return
copyValueToTarget(formData.value, data) copyValueToTarget(formData.value, data)
// TODO
checkboxGroup.value = [] checkboxGroup.value = []
formData.value.recommendHot ? checkboxGroup.value.push('recommendHot') : '' formData.value.recommendHot ? checkboxGroup.value.push('recommendHot') : ''
formData.value.recommendBenefit ? checkboxGroup.value.push('recommendBenefit') : '' formData.value.recommendBenefit ? checkboxGroup.value.push('recommendBenefit') : ''

View File

@ -206,9 +206,6 @@ const generateTableData = (data: any[]) => {
} }
const buildList = build(propertiesItemList) const buildList = build(propertiesItemList)
// sku, // sku,
console.log(
buildList.length === formData.value.skus.length || data.some((item) => item.values.length === 0)
)
if ( if (
buildList.length === formData.value.skus.length || buildList.length === formData.value.skus.length ||
data.some((item) => item.values.length === 0) data.some((item) => item.values.length === 0)

View File

@ -57,39 +57,38 @@
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-tabs v-model="queryParams.type" @tab-click="getList"> <el-tabs v-model="queryParams.tabType" @tab-click="handleClick">
<el-tab-pane <el-tab-pane
v-for="(item, index) in headerNum" v-for="item in tabsData"
:key="index" :key="item.type"
:label="item.name + '(' + item.count + ')'" :label="item.name + '(' + item.count + ')'"
:name="item.type.toString()" :name="item.type"
/> />
</el-tabs> </el-tabs>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column type="expand"> <!-- TODO 暂时不做折叠数据 -->
<template #default="{ row }"> <!-- <el-table-column type="expand">-->
<el-form inline label-position="left"> <!-- <template #default="{ row }">-->
<el-form-item label="市场价:"> <!-- <el-form inline label-position="left">-->
<span>{{ row.marketPrice }}</span> <!-- <el-form-item label="市场价:">-->
</el-form-item> <!-- <span>{{ row.marketPrice }}</span>-->
<el-form-item label="成本价:"> <!-- </el-form-item>-->
<span>{{ row.costPrice }}</span> <!-- <el-form-item label="成本价:">-->
</el-form-item> <!-- <span>{{ row.costPrice }}</span>-->
<el-form-item label="虚拟销量:"> <!-- </el-form-item>-->
<span>{{ row.virtualSalesCount }}</span> <!-- <el-form-item label="虚拟销量:">-->
</el-form-item> <!-- <span>{{ row.virtualSalesCount }}</span>-->
</el-form> <!-- </el-form-item>-->
</template> <!-- </el-form>-->
</el-table-column> <!-- </template>-->
<!-- </el-table-column>-->
<el-table-column label="商品图" min-width="80"> <el-table-column label="商品图" min-width="80">
<template #default="{ row }"> <template #default="{ row }">
<div class="demo-image__preview z-100"> <el-image
<el-image :src="row.picUrl"
:src="row.picUrl" style="width: 36px; height: 36px"
style="width: 36px; height: 36px" @click="imagePreview(row.picUrl)"
@click="imagePreview(row.picUrl)" />
/>
</div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column :show-overflow-tooltip="true" label="商品名称" min-width="300" prop="name" /> <el-table-column :show-overflow-tooltip="true" label="商品名称" min-width="300" prop="name" />
@ -108,9 +107,9 @@
<template #default="{ row }"> <template #default="{ row }">
<el-switch <el-switch
v-model="row.status" v-model="row.status"
:active-value="0" :active-value="1"
:disabled="Number(row.status) < 0" :disabled="Number(row.status) < 0"
:inactive-value="1" :inactive-value="0"
active-text="上架" active-text="上架"
inactive-text="下架" inactive-text="下架"
inline-prompt inline-prompt
@ -120,22 +119,42 @@
</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 }">
<el-button <template v-if="queryParams.tabType === 4">
v-hasPermi="['product:spu:query']" <el-button
link v-hasPermi="['product:spu:delete']"
type="primary" link
@click="openForm(row.id)" type="danger"
> @click="handleDelete(row.id)"
修改 >
</el-button> 删除
<el-button </el-button>
v-hasPermi="['product:spu:update']" <el-button
link v-hasPermi="['product:spu:update']"
type="primary" link
@click="changeStatus(row)" type="primary"
> @click="addToTrash(row, ProductSpuStatusEnum.DISABLE.status)"
加入回收站 >
</el-button> 恢复到仓库
</el-button>
</template>
<template v-else>
<el-button
v-hasPermi="['product:spu:update']"
link
type="primary"
@click="openForm(row.id)"
>
修改
</el-button>
<el-button
v-hasPermi="['product:spu:update']"
link
type="primary"
@click="addToTrash(row, ProductSpuStatusEnum.RECYCLE.status)"
>
加入回收站
</el-button>
</template>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -158,64 +177,141 @@
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime' // api import { dateFormatter } from '@/utils/formatTime' // api
import * as managementApi from '@/api/mall/product/management/spu' import * as managementApi from '@/api/mall/product/management/spu'
// const message = useMessage() // import { ProductSpuStatusEnum } from '@/utils/constants'
// const { t } = useI18n() // import { TabsPaneContext } from 'element-plus'
const { push } = useRouter() //
const message = useMessage() //
const { t } = useI18n() //
const { currentRoute, push } = useRouter() //
const loading = ref(false) // const loading = ref(false) //
const total = ref(0) // const total = ref(0) //
const list = ref<any[]>([]) // const list = ref<any[]>([]) //
const headerNum = ref([ // tabs
const tabsData = ref([
{ {
count: 8, count: 0,
name: '出售中商品', name: '出售中商品',
type: 1 type: 0
}, },
{ {
count: 0, count: 0,
name: '仓库中商品', name: '仓库中商品',
type: 1
},
{
count: 0,
name: '已经售空商品',
type: 2 type: 2
}, },
{ {
count: 0, count: 0,
name: '已经售馨商品', name: '警戒库存',
type: 3 type: 3
}, },
{
count: 0,
name: '警戒库存',
type: 4
},
{ {
count: 0, count: 0,
name: '商品回收站', name: '商品回收站',
type: 5 type: 4
} }
]) ])
const getTabsCount = async () => {
try {
const res = await managementApi.getTabsCount()
for (let objName in res) {
tabsData.value[Number(objName)].count = res[objName]
}
} catch {}
}
const imgViewVisible = ref(false) // const imgViewVisible = ref(false) //
const imageViewerList = ref<string[]>([]) // const imageViewerList = ref<string[]>([]) //
const queryParams = reactive({ const queryParams = ref({
pageNo: 1, pageNo: 1,
pageSize: 10 pageSize: 10,
tabType: 0
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const handleClick = (tab: TabsPaneContext) => {
queryParams.value.tabType = tab.paneName
getList()
}
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await managementApi.getSpuList(queryParams) const data = await managementApi.getSpuList(queryParams.value)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } finally {
loading.value = false loading.value = false
} }
} }
/** /**
* 更改SPU状态 * 更改SPU状态
* @param row * @param row
* @param status 更改前的值
*/ */
const changeStatus = (row) => { const changeStatus = async (row, status?: number) => {
console.log(row) // TODO
try {
let text = ''
switch (row.status) {
case ProductSpuStatusEnum.DISABLE.status:
text = ProductSpuStatusEnum.DISABLE.name
break
case ProductSpuStatusEnum.ENABLE.status:
text = ProductSpuStatusEnum.ENABLE.name
break
case ProductSpuStatusEnum.RECYCLE.status:
text = `加入${ProductSpuStatusEnum.RECYCLE.name}`
break
}
await message.confirm(
row.status === -1 ? `确认要将[${row.name}]${text}吗?` : `确认要${text}[${row.name}]吗?`
)
await managementApi.updateStatus({ id: row.id, status: row.status })
message.success('更新状态成功')
// tabs
await getTabsCount()
//
await getList()
} catch {
//
if (typeof status !== 'undefined') {
row.status = status
return
}
//
row.status =
row.status === ProductSpuStatusEnum.DISABLE.status
? ProductSpuStatusEnum.ENABLE.status
: ProductSpuStatusEnum.DISABLE.status
}
}
/**
* 加入回收站
* @param row
* @param status
*/
const addToTrash = (row, status) => {
//
const num = Number(`${row.status}`)
row.status = status
changeStatus(row, num)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await managementApi.deleteSpu(id)
message.success(t('common.delSuccess'))
// tabs
await getTabsCount()
//
await getList()
} catch {}
} }
/** /**
* 商品图预览 * 商品图预览
@ -247,9 +343,19 @@ const openForm = (id?: number) => {
} }
push('/product/productManagementAdd') push('/product/productManagementAdd')
} }
//
watch(
() => currentRoute.value,
() => {
getList()
},
{
immediate: true
}
)
/** 初始化 **/ /** 初始化 **/
onMounted(() => { onMounted(() => {
getTabsCount()
getList() getList()
}) })
</script> </script>