莳松crm管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ss-crm-manage-web/src/views/MiniMall/Product/index.vue

254 lines
6.6 KiB

11 months ago
<template>
<!-- 搜索工作栏 -->
10 months ago
<el-form inline :model="queryParams" class="-mb-15px" label-width="0">
<el-form-item>
11 months ago
<el-input
10 months ago
v-model="queryParams.productName"
class="!w-200px"
11 months ago
clearable
10 months ago
placeholder="请输入产品名称"
11 months ago
@keyup.enter="handleQuery"
/>
</el-form-item>
10 months ago
<el-form-item>
<el-select
v-model="queryParams.productBrand"
placeholder="请选择品牌"
clearable
filterable
@change="handleQuery"
>
<el-option
v-for="item in opts.brand"
9 months ago
:key="item.brandId"
:label="item.name"
:value="item.brandId"
10 months ago
/>
</el-select>
</el-form-item>
<el-form-item>
<el-cascader
:options="opts.productCategory"
v-model="queryParams.productCategory"
placeholder="请选择分类"
clearable
filterable
9 months ago
:props="{ label: 'name', value: 'id', checkStrictly: true }"
10 months ago
show-all-levels
@change="handleQuery"
11 months ago
/>
</el-form-item>
<el-form-item>
10 months ago
<el-button @click="handleQuery" v-hasPermi="['mall:prod:search']"> 搜索 </el-button>
<el-button @click="resetQuery" v-hasPermi="['mall:prod:reset']"> 重置 </el-button>
9 months ago
<el-button plain type="primary" @click="openForm(null)" v-hasPermi="['mall:prod:add']">
10 months ago
新增
</el-button>
11 months ago
</el-form-item>
</el-form>
<!-- 列表 -->
10 months ago
<el-table v-loading="loading" class="mt-20px" :data="tableList" border>
11 months ago
<el-table-column type="expand" width="30">
10 months ago
<template #default="{ row }">
11 months ago
<div class="pl-100px pr-100px">
10 months ago
<el-table :data="row.productSpecList">
<el-table-column label="规格名称" prop="specsName" />
9 months ago
<el-table-column />
<el-table-column
v-for="(item, index) in row.properties"
:key="index"
:label="item.label"
>
<template #default="scope">
{{ scope.row.properties[index].valueName }}
</template>
</el-table-column>
11 months ago
<el-table-column label="售价" prop="price" />
<el-table-column label="简介" prop="intro" />
</el-table>
</div>
</template>
</el-table-column>
10 months ago
<el-table-column key="productId" label="产品编码" prop="productId" />
<el-table-column show-overflow-tooltip label="产品名称" min-width="200" prop="productName" />
<el-table-column label="分类" min-width="90" prop="productCategoryName" />
<el-table-column label="品牌" min-width="90" prop="productBrandName" />
11 months ago
<el-table-column label="商品图" min-width="80">
<template #default="{ row }">
10 months ago
<el-image :src="row.mainImage" @click="imagePreview(row.mainImage)" class="w-30px h-30px" />
11 months ago
</template>
</el-table-column>
10 months ago
<el-table-column label="简介" min-width="70" prop="productIntro" />
11 months ago
<el-table-column :formatter="dateFormatter" label="创建时间" prop="createTime" width="180" />
<el-table-column fixed="right" label="操作" min-width="80">
<template #default="{ row }">
10 months ago
<!-- TODO详情可以后面点做哈 -->
10 months ago
<el-button
link
type="primary"
@click="openForm(row.productId)"
v-hasPermi="['mall:prod:update']"
>
修改
</el-button>
<el-button
link
type="danger"
@click="handleDelete(row.productId)"
v-hasPermi="['mall:prod:delete']"
>
删除
</el-button>
11 months ago
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNo"
:total="total"
@pagination="getList"
/>
</template>
<script setup name="Product">
import { dateFormatter } from '@/utils/formatTime'
import { createImageViewer } from '@/components/ImageViewer'
10 months ago
import * as ProductApi from '@/api/mall/product'
9 months ago
import * as BrandApi from '@/api/mall/product/brand'
import * as CategoryApi from '@/api/mall/product/category'
import { handleTree } from '@/utils/tree'
11 months ago
const { currentRoute, push } = useRouter()
10 months ago
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化
11 months ago
const queryParams = ref({
10 months ago
productName: undefined,
productBrand: undefined,
productCategory: undefined,
11 months ago
pageNo: 1,
pageSize: 10
}) // 查询参数
10 months ago
const opts = ref({
brand: [],
productCategory: []
})
11 months ago
const loading = ref(false) // 列表的加载中
const total = ref(0) // 列表的总页数
10 months ago
const tableList = ref([]) // 列表的数据
11 months ago
/** 删除按钮操作 */
10 months ago
async function handleDelete(id) {
try {
// 删除的二次确认
await message.delConfirm()
// 发起删除
await ProductApi.deleteProduct(id)
message.success(t('common.delSuccess'))
// 刷新列表
await getList()
} catch {}
11 months ago
}
10 months ago
async function getList() {
loading.value = true
try {
9 months ago
const params = { ...queryParams.value }
if (params.productCategory && params.productCategory.length) {
params.productCategory = params.productCategory.at(-1)
}
const data = await ProductApi.getProductPage(params)
tableList.value = data.list.map((prod) => ({
...prod,
properties: prod.productSpecList[0].properties.map((item) => ({
propertyId: item.propertyId,
label: item.propertyName
}))
}))
10 months ago
total.value = data.total
} finally {
loading.value = false
}
11 months ago
}
/** 商品图预览 */
function imagePreview(imgUrl) {
createImageViewer({
urlList: [imgUrl]
})
}
/** 搜索按钮操作 */
function handleQuery() {
10 months ago
queryParams.value.pageNo = 1
11 months ago
getList()
}
9 months ago
async function getOptions() {
BrandApi.getSimpleBrandList().then((data) => {
opts.value.brand = data || []
})
CategoryApi.getCategorySimpleList().then((data) => {
opts.value.productCategory = handleTree(data || [])
})
}
11 months ago
/** 重置按钮操作 */
function resetQuery() {
10 months ago
queryParams.value = {
productName: undefined,
productBrand: undefined,
productCategory: undefined,
pageNo: 1,
pageSize: 10
}
11 months ago
handleQuery()
}
/**
* 新增或修改
*
10 months ago
* @param id 商品 编号
11 months ago
*/
function openForm(id) {
// 修改
9 months ago
if (id) {
11 months ago
push({
path: '/miniMall/productEdit',
query: { id }
})
return
}
// 新增
push('/miniMall/productAdd')
}
watch(
() => currentRoute.value,
() => {
getList()
}
)
handleQuery()
9 months ago
onMounted(() => {
getOptions()
})
11 months ago
</script>
<style lang="scss" scoped>
.demo-table-expand {
padding-left: 42px;
:deep(.el-form-item__label) {
width: 82px;
font-weight: bold;
color: #99a9bf;
}
}
</style>