2023-04-24 03:42:44 +00:00
|
|
|
|
<template>
|
|
|
|
|
<!-- 搜索工作栏 -->
|
|
|
|
|
<ContentWrap>
|
|
|
|
|
<el-form
|
|
|
|
|
ref="queryFormRef"
|
|
|
|
|
:inline="true"
|
|
|
|
|
:model="queryParams"
|
|
|
|
|
class="-mb-15px"
|
|
|
|
|
label-width="68px"
|
|
|
|
|
>
|
2023-05-30 10:14:40 +00:00
|
|
|
|
<el-form-item label="商品名称" prop="name">
|
2023-04-24 03:42:44 +00:00
|
|
|
|
<el-input
|
|
|
|
|
v-model="queryParams.name"
|
|
|
|
|
class="!w-240px"
|
|
|
|
|
clearable
|
2023-05-30 10:14:40 +00:00
|
|
|
|
placeholder="请输入商品名称"
|
2023-04-24 03:42:44 +00:00
|
|
|
|
@keyup.enter="handleQuery"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
2023-05-30 10:14:40 +00:00
|
|
|
|
<!-- TODO 分类只能选择二级分类目前还没做,还是先以联调通顺为主 fixL: 已完善 -->
|
2023-05-16 17:17:17 +00:00
|
|
|
|
<el-form-item label="商品分类" prop="categoryId">
|
|
|
|
|
<el-tree-select
|
|
|
|
|
v-model="queryParams.categoryId"
|
|
|
|
|
:data="categoryList"
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
check-strictly
|
|
|
|
|
class="w-1/1"
|
|
|
|
|
node-key="id"
|
|
|
|
|
placeholder="请选择商品分类"
|
2023-05-30 10:14:40 +00:00
|
|
|
|
@change="nodeClick"
|
2023-05-16 17:17:17 +00:00
|
|
|
|
/>
|
2023-04-24 03:42:44 +00:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="创建时间" prop="createTime">
|
|
|
|
|
<el-date-picker
|
|
|
|
|
v-model="queryParams.createTime"
|
|
|
|
|
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
|
|
|
|
|
class="!w-240px"
|
|
|
|
|
end-placeholder="结束日期"
|
|
|
|
|
start-placeholder="开始日期"
|
|
|
|
|
type="daterange"
|
|
|
|
|
value-format="YYYY-MM-DD HH:mm:ss"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item>
|
|
|
|
|
<el-button @click="handleQuery">
|
|
|
|
|
<Icon class="mr-5px" icon="ep:search" />
|
|
|
|
|
搜索
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button @click="resetQuery">
|
|
|
|
|
<Icon class="mr-5px" icon="ep:refresh" />
|
|
|
|
|
重置
|
|
|
|
|
</el-button>
|
2023-06-13 06:14:42 +00:00
|
|
|
|
<el-button v-hasPermi="['product:spu:create']" plain type="primary" @click="openForm">
|
2023-04-24 03:42:44 +00:00
|
|
|
|
<Icon class="mr-5px" icon="ep:plus" />
|
|
|
|
|
新增
|
|
|
|
|
</el-button>
|
2023-06-13 06:14:42 +00:00
|
|
|
|
<el-button
|
|
|
|
|
v-hasPermi="['product:spu:export']"
|
|
|
|
|
:loading="exportLoading"
|
|
|
|
|
plain
|
|
|
|
|
type="success"
|
|
|
|
|
@click="handleExport"
|
|
|
|
|
>
|
|
|
|
|
<Icon class="mr-5px" icon="ep:download" />
|
|
|
|
|
导出
|
|
|
|
|
</el-button>
|
2023-04-24 03:42:44 +00:00
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</ContentWrap>
|
|
|
|
|
|
|
|
|
|
<!-- 列表 -->
|
|
|
|
|
<ContentWrap>
|
2023-05-16 17:17:17 +00:00
|
|
|
|
<el-tabs v-model="queryParams.tabType" @tab-click="handleTabClick">
|
2023-04-24 03:42:44 +00:00
|
|
|
|
<el-tab-pane
|
2023-05-03 17:38:53 +00:00
|
|
|
|
v-for="item in tabsData"
|
|
|
|
|
:key="item.type"
|
2023-04-24 03:42:44 +00:00
|
|
|
|
:label="item.name + '(' + item.count + ')'"
|
2023-05-03 17:38:53 +00:00
|
|
|
|
:name="item.type"
|
2023-04-24 03:42:44 +00:00
|
|
|
|
/>
|
|
|
|
|
</el-tabs>
|
|
|
|
|
<el-table v-loading="loading" :data="list">
|
2023-05-30 10:14:40 +00:00
|
|
|
|
<!-- TODO puhui:这几个属性哈,一行三个 fix
|
2023-05-24 12:27:45 +00:00
|
|
|
|
商品分类:服装鞋包/箱包
|
|
|
|
|
商品市场价格:100.00
|
|
|
|
|
成本价:0.00
|
|
|
|
|
收藏:5
|
2023-05-30 10:14:40 +00:00
|
|
|
|
虚拟销量:999 -->
|
2023-05-16 17:17:17 +00:00
|
|
|
|
<el-table-column type="expand" width="30">
|
|
|
|
|
<template #default="{ row }">
|
2023-05-30 10:14:40 +00:00
|
|
|
|
<el-form class="demo-table-expand" label-position="left">
|
|
|
|
|
<el-row>
|
|
|
|
|
<el-col :span="24">
|
|
|
|
|
<el-row>
|
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item label="商品分类:">
|
|
|
|
|
<span>{{ categoryString(row.categoryId) }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item label="市场价:">
|
|
|
|
|
<span>{{ formatToFraction(row.marketPrice) }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item label="成本价:">
|
|
|
|
|
<span>{{ formatToFraction(row.costPrice) }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
<el-row>
|
|
|
|
|
<el-col :span="24">
|
|
|
|
|
<el-row>
|
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item label="收藏:">
|
|
|
|
|
<!-- TODO 没有这个属性,暂时写死 5 个 -->
|
|
|
|
|
<span>5</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item label="虚拟销量:">
|
|
|
|
|
<span>{{ row.virtualSalesCount }}</span>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
2023-05-16 17:17:17 +00:00
|
|
|
|
</el-form>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column key="id" align="center" label="商品编号" prop="id" />
|
2023-04-24 03:42:44 +00:00
|
|
|
|
<el-table-column label="商品图" min-width="80">
|
|
|
|
|
<template #default="{ row }">
|
2023-05-30 10:14:40 +00:00
|
|
|
|
<el-image :src="row.picUrl" class="w-30px h-30px" @click="imagePreview(row.picUrl)" />
|
2023-04-24 03:42:44 +00:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2023-05-01 18:20:58 +00:00
|
|
|
|
<el-table-column :show-overflow-tooltip="true" label="商品名称" min-width="300" prop="name" />
|
2023-05-19 09:04:13 +00:00
|
|
|
|
<el-table-column align="center" label="商品售价" min-width="90" prop="price">
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
{{ formatToFraction(row.price) }}
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2023-05-01 18:20:58 +00:00
|
|
|
|
<el-table-column align="center" label="销量" min-width="90" prop="salesCount" />
|
2023-04-24 03:42:44 +00:00
|
|
|
|
<el-table-column align="center" label="库存" min-width="90" prop="stock" />
|
|
|
|
|
<el-table-column align="center" label="排序" min-width="70" prop="sort" />
|
|
|
|
|
<el-table-column
|
|
|
|
|
:formatter="dateFormatter"
|
|
|
|
|
align="center"
|
|
|
|
|
label="创建时间"
|
|
|
|
|
prop="createTime"
|
|
|
|
|
width="180"
|
|
|
|
|
/>
|
2023-05-16 17:17:17 +00:00
|
|
|
|
<el-table-column align="center" label="状态" min-width="80">
|
2023-04-24 03:42:44 +00:00
|
|
|
|
<template #default="{ row }">
|
2023-05-16 17:17:17 +00:00
|
|
|
|
<template v-if="row.status >= 0">
|
|
|
|
|
<el-switch
|
|
|
|
|
v-model="row.status"
|
|
|
|
|
:active-value="1"
|
|
|
|
|
:inactive-value="0"
|
|
|
|
|
active-text="上架"
|
|
|
|
|
inactive-text="下架"
|
|
|
|
|
inline-prompt
|
|
|
|
|
@change="changeStatus(row)"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
|
|
|
|
<el-tag type="info">回收站</el-tag>
|
|
|
|
|
</template>
|
2023-05-02 18:28:35 +00:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2023-05-19 09:04:13 +00:00
|
|
|
|
<el-table-column align="center" fixed="right" label="操作" min-width="200">
|
2023-05-02 18:28:35 +00:00
|
|
|
|
<template #default="{ row }">
|
2023-05-31 06:42:45 +00:00
|
|
|
|
<el-button
|
|
|
|
|
v-hasPermi="['product:spu:update']"
|
|
|
|
|
link
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="openDetail(row.id)"
|
|
|
|
|
>
|
2023-05-19 09:04:13 +00:00
|
|
|
|
详情
|
|
|
|
|
</el-button>
|
2023-05-03 17:38:53 +00:00
|
|
|
|
<template v-if="queryParams.tabType === 4">
|
|
|
|
|
<el-button
|
|
|
|
|
v-hasPermi="['product:spu:delete']"
|
|
|
|
|
link
|
|
|
|
|
type="danger"
|
|
|
|
|
@click="handleDelete(row.id)"
|
|
|
|
|
>
|
|
|
|
|
删除
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
v-hasPermi="['product:spu:update']"
|
|
|
|
|
link
|
|
|
|
|
type="primary"
|
2023-05-16 17:17:17 +00:00
|
|
|
|
@click="changeStatus(row, ProductSpuStatusEnum.DISABLE.status)"
|
2023-05-03 17:38:53 +00:00
|
|
|
|
>
|
|
|
|
|
恢复到仓库
|
|
|
|
|
</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
2023-05-19 09:04:13 +00:00
|
|
|
|
<!-- 只有不是上架和回收站的商品可以编辑 -->
|
2023-05-03 17:38:53 +00:00
|
|
|
|
<el-button
|
2023-05-19 09:04:13 +00:00
|
|
|
|
v-if="queryParams.tabType !== 0"
|
2023-05-03 17:38:53 +00:00
|
|
|
|
v-hasPermi="['product:spu:update']"
|
|
|
|
|
link
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="openForm(row.id)"
|
|
|
|
|
>
|
|
|
|
|
修改
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
v-hasPermi="['product:spu:update']"
|
|
|
|
|
link
|
|
|
|
|
type="primary"
|
2023-05-16 17:17:17 +00:00
|
|
|
|
@click="changeStatus(row, ProductSpuStatusEnum.RECYCLE.status)"
|
2023-05-03 17:38:53 +00:00
|
|
|
|
>
|
|
|
|
|
加入回收站
|
|
|
|
|
</el-button>
|
|
|
|
|
</template>
|
2023-04-24 03:42:44 +00:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
<!-- 分页 -->
|
|
|
|
|
<Pagination
|
|
|
|
|
v-model:limit="queryParams.pageSize"
|
|
|
|
|
v-model:page="queryParams.pageNo"
|
|
|
|
|
:total="total"
|
|
|
|
|
@pagination="getList"
|
|
|
|
|
/>
|
|
|
|
|
</ContentWrap>
|
|
|
|
|
</template>
|
2023-05-16 17:17:17 +00:00
|
|
|
|
<script lang="ts" name="ProductSpu" setup>
|
|
|
|
|
import { TabsPaneContext } from 'element-plus'
|
|
|
|
|
import { cloneDeep } from 'lodash-es'
|
|
|
|
|
import { createImageViewer } from '@/components/ImageViewer'
|
2023-05-06 14:54:41 +00:00
|
|
|
|
import { dateFormatter } from '@/utils/formatTime'
|
2023-05-30 10:14:40 +00:00
|
|
|
|
import { checkSelectedNode, defaultProps, handleTree, treeToString } from '@/utils/tree'
|
2023-05-03 17:38:53 +00:00
|
|
|
|
import { ProductSpuStatusEnum } from '@/utils/constants'
|
2023-06-13 06:14:42 +00:00
|
|
|
|
import { formatToFraction } from '@/utils'
|
|
|
|
|
import download from '@/utils/download'
|
2023-05-16 17:17:17 +00:00
|
|
|
|
import * as ProductSpuApi from '@/api/mall/product/spu'
|
|
|
|
|
import * as ProductCategoryApi from '@/api/mall/product/category'
|
|
|
|
|
|
2023-05-03 17:38:53 +00:00
|
|
|
|
const message = useMessage() // 消息弹窗
|
|
|
|
|
const { t } = useI18n() // 国际化
|
|
|
|
|
const { currentRoute, push } = useRouter() // 路由跳转
|
2023-05-06 14:54:41 +00:00
|
|
|
|
|
2023-04-24 03:42:44 +00:00
|
|
|
|
const loading = ref(false) // 列表的加载中
|
2023-06-13 06:14:42 +00:00
|
|
|
|
const exportLoading = ref(false) // 导出的加载中
|
2023-04-24 03:42:44 +00:00
|
|
|
|
const total = ref(0) // 列表的总页数
|
|
|
|
|
const list = ref<any[]>([]) // 列表的数据
|
2023-05-06 14:54:41 +00:00
|
|
|
|
// tabs 数据
|
2023-05-03 17:38:53 +00:00
|
|
|
|
const tabsData = ref([
|
2023-04-24 03:42:44 +00:00
|
|
|
|
{
|
2023-05-03 17:38:53 +00:00
|
|
|
|
count: 0,
|
2023-04-24 03:42:44 +00:00
|
|
|
|
name: '出售中商品',
|
2023-05-03 17:38:53 +00:00
|
|
|
|
type: 0
|
2023-04-24 03:42:44 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
count: 0,
|
|
|
|
|
name: '仓库中商品',
|
2023-05-03 17:38:53 +00:00
|
|
|
|
type: 1
|
2023-04-24 03:42:44 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
count: 0,
|
2023-05-03 17:38:53 +00:00
|
|
|
|
name: '已经售空商品',
|
|
|
|
|
type: 2
|
2023-04-24 03:42:44 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
count: 0,
|
|
|
|
|
name: '警戒库存',
|
2023-05-03 17:38:53 +00:00
|
|
|
|
type: 3
|
2023-04-24 03:42:44 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
count: 0,
|
|
|
|
|
name: '商品回收站',
|
2023-05-03 17:38:53 +00:00
|
|
|
|
type: 4
|
2023-04-24 03:42:44 +00:00
|
|
|
|
}
|
|
|
|
|
])
|
2023-05-06 14:54:41 +00:00
|
|
|
|
|
|
|
|
|
/** 获得每个 Tab 的数量 */
|
2023-05-03 17:38:53 +00:00
|
|
|
|
const getTabsCount = async () => {
|
2023-05-16 17:17:17 +00:00
|
|
|
|
const res = await ProductSpuApi.getTabsCount()
|
|
|
|
|
for (let objName in res) {
|
|
|
|
|
tabsData.value[Number(objName)].count = res[objName]
|
|
|
|
|
}
|
2023-05-03 17:38:53 +00:00
|
|
|
|
}
|
|
|
|
|
const queryParams = ref({
|
2023-04-24 03:42:44 +00:00
|
|
|
|
pageNo: 1,
|
2023-05-03 17:38:53 +00:00
|
|
|
|
pageSize: 10,
|
2023-05-31 06:42:45 +00:00
|
|
|
|
tabType: 0,
|
|
|
|
|
name: '',
|
|
|
|
|
categoryId: null
|
2023-05-16 17:17:17 +00:00
|
|
|
|
}) // 查询参数
|
|
|
|
|
const queryFormRef = ref() // 搜索的表单Ref
|
2023-05-06 14:54:41 +00:00
|
|
|
|
|
2023-05-16 17:17:17 +00:00
|
|
|
|
const handleTabClick = (tab: TabsPaneContext) => {
|
2023-05-31 06:42:45 +00:00
|
|
|
|
queryParams.value.tabType = tab.paneName as number
|
2023-05-03 17:38:53 +00:00
|
|
|
|
getList()
|
|
|
|
|
}
|
2023-05-06 14:54:41 +00:00
|
|
|
|
|
2023-04-24 03:42:44 +00:00
|
|
|
|
/** 查询列表 */
|
|
|
|
|
const getList = async () => {
|
|
|
|
|
loading.value = true
|
|
|
|
|
try {
|
2023-05-16 17:17:17 +00:00
|
|
|
|
const data = await ProductSpuApi.getSpuPage(queryParams.value)
|
2023-04-29 13:39:25 +00:00
|
|
|
|
list.value = data.list
|
|
|
|
|
total.value = data.total
|
2023-04-24 03:42:44 +00:00
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-03 17:38:53 +00:00
|
|
|
|
|
2023-05-02 18:28:35 +00:00
|
|
|
|
/**
|
2023-05-06 14:54:41 +00:00
|
|
|
|
* 更改 SPU 状态
|
|
|
|
|
*
|
2023-05-02 18:28:35 +00:00
|
|
|
|
* @param row
|
2023-05-03 17:38:53 +00:00
|
|
|
|
* @param status 更改前的值
|
|
|
|
|
*/
|
|
|
|
|
const changeStatus = async (row, status?: number) => {
|
2023-05-16 17:17:17 +00:00
|
|
|
|
const deepCopyValue = cloneDeep(unref(row))
|
|
|
|
|
if (typeof status !== 'undefined') deepCopyValue.status = status
|
2023-05-03 17:38:53 +00:00
|
|
|
|
try {
|
|
|
|
|
let text = ''
|
2023-05-16 17:17:17 +00:00
|
|
|
|
switch (deepCopyValue.status) {
|
2023-05-03 17:38:53 +00:00
|
|
|
|
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(
|
2023-05-16 17:17:17 +00:00
|
|
|
|
deepCopyValue.status === -1
|
|
|
|
|
? `确认要将[${row.name}]${text}吗?`
|
|
|
|
|
: row.status === -1 // 再判断一次原对象是否等于-1,例: 把回收站中的商品恢复到仓库中,事件触发时原对象status为-1 深拷贝对象status被赋值为0
|
|
|
|
|
? `确认要将[${row.name}]恢复到仓库吗?`
|
|
|
|
|
: `确认要${text}[${row.name}]吗?`
|
2023-05-03 17:38:53 +00:00
|
|
|
|
)
|
2023-05-16 17:17:17 +00:00
|
|
|
|
await ProductSpuApi.updateStatus({ id: deepCopyValue.id, status: deepCopyValue.status })
|
2023-05-03 17:38:53 +00:00
|
|
|
|
message.success('更新状态成功')
|
2023-05-06 14:54:41 +00:00
|
|
|
|
// 刷新 tabs 数据
|
2023-05-03 17:38:53 +00:00
|
|
|
|
await getTabsCount()
|
|
|
|
|
// 刷新列表
|
|
|
|
|
await getList()
|
|
|
|
|
} catch {
|
|
|
|
|
// 取消更改状态时回显数据
|
|
|
|
|
row.status =
|
|
|
|
|
row.status === ProductSpuStatusEnum.DISABLE.status
|
|
|
|
|
? ProductSpuStatusEnum.ENABLE.status
|
|
|
|
|
: ProductSpuStatusEnum.DISABLE.status
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-06 14:54:41 +00:00
|
|
|
|
|
2023-05-03 17:38:53 +00:00
|
|
|
|
/** 删除按钮操作 */
|
|
|
|
|
const handleDelete = async (id: number) => {
|
|
|
|
|
try {
|
|
|
|
|
// 删除的二次确认
|
|
|
|
|
await message.delConfirm()
|
|
|
|
|
// 发起删除
|
2023-05-16 17:17:17 +00:00
|
|
|
|
await ProductSpuApi.deleteSpu(id)
|
2023-05-03 17:38:53 +00:00
|
|
|
|
message.success(t('common.delSuccess'))
|
|
|
|
|
// 刷新tabs数据
|
|
|
|
|
await getTabsCount()
|
|
|
|
|
// 刷新列表
|
|
|
|
|
await getList()
|
|
|
|
|
} catch {}
|
2023-05-02 18:28:35 +00:00
|
|
|
|
}
|
2023-05-06 14:54:41 +00:00
|
|
|
|
|
2023-05-24 12:27:45 +00:00
|
|
|
|
/** 商品图预览 */
|
2023-05-02 18:28:35 +00:00
|
|
|
|
const imagePreview = (imgUrl: string) => {
|
2023-05-16 17:17:17 +00:00
|
|
|
|
createImageViewer({
|
|
|
|
|
urlList: [imgUrl]
|
|
|
|
|
})
|
2023-05-02 18:28:35 +00:00
|
|
|
|
}
|
2023-05-06 14:54:41 +00:00
|
|
|
|
|
2023-04-24 03:42:44 +00:00
|
|
|
|
/** 搜索按钮操作 */
|
|
|
|
|
const handleQuery = () => {
|
|
|
|
|
getList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 重置按钮操作 */
|
|
|
|
|
const resetQuery = () => {
|
|
|
|
|
queryFormRef.value.resetFields()
|
|
|
|
|
handleQuery()
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-02 18:28:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* 新增或修改
|
2023-05-06 14:54:41 +00:00
|
|
|
|
*
|
|
|
|
|
* @param id 商品 SPU 编号
|
2023-05-02 18:28:35 +00:00
|
|
|
|
*/
|
2023-04-29 13:39:25 +00:00
|
|
|
|
const openForm = (id?: number) => {
|
2023-05-06 14:54:41 +00:00
|
|
|
|
// 修改
|
2023-04-29 13:39:25 +00:00
|
|
|
|
if (typeof id === 'number') {
|
2023-06-03 13:21:43 +00:00
|
|
|
|
push('/product/spu/edit/' + id)
|
2023-05-02 18:28:35 +00:00
|
|
|
|
return
|
2023-04-29 13:39:25 +00:00
|
|
|
|
}
|
2023-05-06 14:54:41 +00:00
|
|
|
|
// 新增
|
2023-06-03 13:21:43 +00:00
|
|
|
|
push('/product/spu/add')
|
2023-04-24 03:42:44 +00:00
|
|
|
|
}
|
2023-05-24 12:27:45 +00:00
|
|
|
|
|
2023-05-19 09:04:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* 查看商品详情
|
|
|
|
|
*/
|
2023-05-31 06:42:45 +00:00
|
|
|
|
const openDetail = (id?: number) => {
|
2023-06-03 13:21:43 +00:00
|
|
|
|
push('/product/spu/detail/' + id)
|
2023-05-19 09:04:13 +00:00
|
|
|
|
}
|
2023-05-23 04:04:21 +00:00
|
|
|
|
|
2023-06-13 06:14:42 +00:00
|
|
|
|
/** 导出按钮操作 */
|
|
|
|
|
const handleExport = async () => {
|
|
|
|
|
try {
|
|
|
|
|
// 导出的二次确认
|
|
|
|
|
await message.exportConfirm()
|
|
|
|
|
// 发起导出
|
|
|
|
|
exportLoading.value = true
|
|
|
|
|
const data = await ProductSpuApi.exportSpu(queryParams)
|
2023-05-24 12:32:38 +00:00
|
|
|
|
download.excel(data, '商品列表.xls')
|
2023-06-13 06:14:42 +00:00
|
|
|
|
} catch {
|
|
|
|
|
} finally {
|
|
|
|
|
exportLoading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-30 10:14:40 +00:00
|
|
|
|
// 监听路由变化更新列表,解决商品保存后,列表不刷新的问题。
|
2023-05-03 17:38:53 +00:00
|
|
|
|
watch(
|
|
|
|
|
() => currentRoute.value,
|
|
|
|
|
() => {
|
|
|
|
|
getList()
|
|
|
|
|
}
|
|
|
|
|
)
|
2023-05-24 12:27:45 +00:00
|
|
|
|
|
2023-05-16 17:17:17 +00:00
|
|
|
|
const categoryList = ref() // 分类树
|
2023-05-30 10:14:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* 获取分类的节点的完整结构
|
|
|
|
|
* @param categoryId 分类id
|
|
|
|
|
*/
|
|
|
|
|
const categoryString = (categoryId) => {
|
|
|
|
|
return treeToString(categoryList.value, categoryId)
|
|
|
|
|
}
|
|
|
|
|
/**
|
2023-05-31 06:42:45 +00:00
|
|
|
|
* 校验所选是否为二级及以下节点
|
2023-05-30 10:14:40 +00:00
|
|
|
|
*/
|
|
|
|
|
const nodeClick = () => {
|
|
|
|
|
if (!checkSelectedNode(categoryList.value, queryParams.value.categoryId)) {
|
|
|
|
|
queryParams.value.categoryId = null
|
2023-05-31 06:42:45 +00:00
|
|
|
|
message.warning('必须选择二级及以下节点!!')
|
2023-05-30 10:14:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-24 03:42:44 +00:00
|
|
|
|
/** 初始化 **/
|
2023-05-16 17:17:17 +00:00
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await getTabsCount()
|
|
|
|
|
await getList()
|
|
|
|
|
// 获得分类树
|
|
|
|
|
const data = await ProductCategoryApi.getCategoryList({})
|
|
|
|
|
categoryList.value = handleTree(data, 'id', 'parentId')
|
2023-04-24 03:42:44 +00:00
|
|
|
|
})
|
|
|
|
|
</script>
|
2023-05-16 17:17:17 +00:00
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.demo-table-expand {
|
2023-05-17 10:24:34 +00:00
|
|
|
|
padding-left: 42px;
|
|
|
|
|
|
2023-05-16 17:17:17 +00:00
|
|
|
|
:deep(.el-form-item__label) {
|
|
|
|
|
width: 82px;
|
2023-05-17 10:24:34 +00:00
|
|
|
|
font-weight: bold;
|
2023-05-16 17:17:17 +00:00
|
|
|
|
color: #99a9bf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|