refactor: 会员商品收藏

(cherry picked from commit f2c71d5836)
This commit is contained in:
niou233 2023-11-08 17:29:57 +08:00 committed by shizhong
parent cc577dfc6f
commit 4d02972b86
2 changed files with 0 additions and 115 deletions

View File

@ -8,21 +8,5 @@ export interface Favorite {
// 获得 ProductFavorite 列表 // 获得 ProductFavorite 列表
export const getFavoritePage = (params: PageParam) => { export const getFavoritePage = (params: PageParam) => {
params.keyword = params.name
return request.get({ url: '/product/favorite/page', params }) return request.get({ url: '/product/favorite/page', params })
} }
// 收藏商品 Favorite
export const createFavorite = (data: Favorite) => {
return request.post({ url: '/product/favorite/create', data })
}
// 取消商品收藏 Favorite
export const delFavorite = (data: Favorite) => {
return request.delete({ url: '/product/favorite/delete', data })
}
// 是否收藏过商品 Favorite
export const exitsFavorite = (data: Favorite) => {
return request.post({ url: '/product/favorite/exits', data })
}

View File

@ -1,46 +1,4 @@
<template> <template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="商品名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入商品名称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="收藏时间" prop="createTime">
<el-date-picker
v-model="queryParams.createTime"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery">
<Icon icon="ep:search" class="mr-5px" />
搜索
</el-button>
<el-button @click="resetQuery">
<Icon icon="ep:refresh" class="mr-5px" />
重置
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
@ -67,28 +25,6 @@
<dict-tag :type="DICT_TYPE.PRODUCT_SPU_STATUS" :value="scope.row.status" /> <dict-tag :type="DICT_TYPE.PRODUCT_SPU_STATUS" :value="scope.row.status" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" fixed="right" label="操作" min-width="200">
<template #default="{ row }">
<el-button
v-if="row.favoriteStatus === 0"
v-hasPermi="['product:spu:delete']"
link
type="danger"
@click="handleAdd(row)"
>
收藏
</el-button>
<el-button
v-if="row.favoriteStatus === 1"
v-hasPermi="['product:spu:delete']"
link
type="danger"
@click="handleDelete(row)"
>
取消收藏
</el-button>
</template>
</el-table-column>
</el-table> </el-table>
<!-- 分页 --> <!-- 分页 -->
<Pagination <Pagination
@ -145,41 +81,6 @@ const resetQuery = () => {
handleQuery() handleQuery()
} }
/** 取消收藏按钮操作 */
const handleDelete = async (row: object) => {
try {
console.log(row)
//
await message.delStarConfirm()
//
await FavoriteApi.delFavorite({ userId: queryParams.userId, spuId: row.spuId })
message.success(t('common.delStarSuccess'))
row.favoriteStatus = 0
//
// await getList()
} catch {}
}
/** 收藏按钮操作 */
const handleAdd = async (row: object) => {
try {
const data = { userId: queryParams.userId, spuId: row.spuId }
//
const result = await FavoriteApi.exitsFavorite(data)
if (result === false) {
//
await FavoriteApi.createFavorite(data)
message.success(t('common.starSuccess'))
row.favoriteStatus = 1
//
// await getList()
} else {
message.warning(t('common.existStar'))
row.favoriteStatus = 1
}
} catch {}
}
const { userId } = defineProps({ const { userId } = defineProps({
userId: { userId: {
type: Number, type: Number,