调整商品分类管理
This commit is contained in:
parent
576ab7c857
commit
164991bf2f
@ -24,3 +24,7 @@ export function apiProductCategoryDelete(params: any) {
|
|||||||
export function apiProductCategoryDetail(params: any) {
|
export function apiProductCategoryDetail(params: any) {
|
||||||
return request.get({ url: '/productCategory/detail', params })
|
return request.get({ url: '/productCategory/detail', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function apiProductCategoryAll(params: any) {
|
||||||
|
return request.get({ url: '/productCategory/all', params })
|
||||||
|
}
|
||||||
|
@ -1,116 +1,102 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="edit-popup">
|
<div class="edit-popup">
|
||||||
<popup
|
<popup ref="popupRef" :title="popupTitle" :async="true" width="550px" @confirm="handleSubmit"
|
||||||
ref="popupRef"
|
@close="handleClose">
|
||||||
:title="popupTitle"
|
<el-form ref="formRef" :model="formData" label-width="90px">
|
||||||
:async="true"
|
<el-form-item label="上级分类" prop="pid">
|
||||||
width="550px"
|
<el-tree-select class="flex-1" v-model="formData.pid" :data="categoryList" clearable node-key="id"
|
||||||
@confirm="handleSubmit"
|
:props="{
|
||||||
@close="handleClose"
|
label: 'name'
|
||||||
>
|
}" :default-expand-all="true" placeholder="请选择上级分类" check-strictly />
|
||||||
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
</el-form-item>
|
||||||
<el-form-item label="上级分类" prop="pid">
|
<el-form-item label="名称" prop="name">
|
||||||
<el-select class="flex-1" v-model="formData.pid" clearable placeholder="请选择上级分类">
|
<el-input v-model="formData.name" clearable placeholder="请输入名称" />
|
||||||
<el-option
|
</el-form-item>
|
||||||
v-for="(item, index) in dictData.show_status"
|
|
||||||
:key="index"
|
</el-form>
|
||||||
:label="item.name"
|
</popup>
|
||||||
:value="parseInt(item.value)"
|
</div>
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="名称" prop="name">
|
|
||||||
<el-input v-model="formData.name" clearable placeholder="请输入名称" />
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
</popup>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup name="productCategoryEdit">
|
<script lang="ts" setup name="productCategoryEdit">
|
||||||
import type { FormInstance } from 'element-plus'
|
import type { FormInstance } from 'element-plus'
|
||||||
import Popup from '@/components/popup/index.vue'
|
import Popup from '@/components/popup/index.vue'
|
||||||
import { apiProductCategoryAdd, apiProductCategoryEdit, apiProductCategoryDetail } from '@/api/product_category'
|
import { apiProductCategoryAdd, apiProductCategoryEdit, apiProductCategoryDetail, apiProductCategoryLists } from '@/api/product_category'
|
||||||
import { timeFormat } from '@/utils/util'
|
import { arrayToTree, treeToArray } from '@/utils/util'
|
||||||
import type { PropType } from 'vue'
|
const emit = defineEmits(['success', 'close'])
|
||||||
defineProps({
|
const formRef = shallowRef<FormInstance>()
|
||||||
dictData: {
|
const popupRef = shallowRef<InstanceType<typeof Popup>>()
|
||||||
type: Object as PropType<Record<string, any[]>>,
|
const mode = ref('add')
|
||||||
default: () => ({})
|
const categoryList = ref<any[]>([])
|
||||||
}
|
|
||||||
})
|
|
||||||
const emit = defineEmits(['success', 'close'])
|
|
||||||
const formRef = shallowRef<FormInstance>()
|
|
||||||
const popupRef = shallowRef<InstanceType<typeof Popup>>()
|
|
||||||
const mode = ref('add')
|
|
||||||
|
|
||||||
|
const getCategoryList = async () => {
|
||||||
|
const data : any = await apiProductCategoryLists({ page_type: 0 })
|
||||||
|
const topData : any = { id: 0, name: '顶级', children: [] }
|
||||||
|
topData.children = arrayToTree(
|
||||||
|
treeToArray(data.lists)
|
||||||
|
)
|
||||||
|
categoryList.value.push(topData)
|
||||||
|
}
|
||||||
|
|
||||||
// 弹窗标题
|
getCategoryList()
|
||||||
const popupTitle = computed(() => {
|
|
||||||
return mode.value == 'edit' ? '编辑商品分类' : '新增商品分类'
|
|
||||||
})
|
|
||||||
|
|
||||||
// 表单数据
|
// 弹窗标题
|
||||||
const formData = reactive({
|
const popupTitle = computed(() => {
|
||||||
id: '',
|
return mode.value == 'edit' ? '编辑商品分类' : '新增商品分类'
|
||||||
pid: '',
|
})
|
||||||
name: '',
|
|
||||||
})
|
|
||||||
|
|
||||||
|
// 表单数据
|
||||||
|
const formData = reactive({
|
||||||
|
id: '',
|
||||||
|
pid: '',
|
||||||
|
name: '',
|
||||||
|
})
|
||||||
|
|
||||||
// 表单验证
|
// 获取详情
|
||||||
const formRules = reactive<any>({
|
const setFormData = async (data : Record<any, any>) => {
|
||||||
|
for (const key in formData) {
|
||||||
|
if (data[key] != null && data[key] != undefined) {
|
||||||
|
//@ts-ignore
|
||||||
|
formData[key] = data[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
})
|
const getDetail = async (row : Record<string, any>) => {
|
||||||
|
const data = await apiProductCategoryDetail({
|
||||||
|
id: row.id
|
||||||
|
})
|
||||||
|
setFormData(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交按钮
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
await formRef.value?.validate()
|
||||||
|
const data = { ...formData, }
|
||||||
|
mode.value == 'edit'
|
||||||
|
? await apiProductCategoryEdit(data)
|
||||||
|
: await apiProductCategoryAdd(data)
|
||||||
|
popupRef.value?.close()
|
||||||
|
emit('success')
|
||||||
|
}
|
||||||
|
|
||||||
// 获取详情
|
//打开弹窗
|
||||||
const setFormData = async (data: Record<any, any>) => {
|
const open = (type = 'add', pid = 0) => {
|
||||||
for (const key in formData) {
|
console.log(type);
|
||||||
if (data[key] != null && data[key] != undefined) {
|
console.log(pid);
|
||||||
//@ts-ignore
|
mode.value = type
|
||||||
formData[key] = data[key]
|
formData.pid = pid
|
||||||
}
|
popupRef.value?.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭回调
|
||||||
|
const handleClose = () => {
|
||||||
|
emit('close')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
defineExpose({
|
||||||
|
open,
|
||||||
const getDetail = async (row: Record<string, any>) => {
|
setFormData,
|
||||||
const data = await apiProductCategoryDetail({
|
getDetail
|
||||||
id: row.id
|
})
|
||||||
})
|
|
||||||
setFormData(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 提交按钮
|
|
||||||
const handleSubmit = async () => {
|
|
||||||
await formRef.value?.validate()
|
|
||||||
const data = { ...formData, }
|
|
||||||
mode.value == 'edit'
|
|
||||||
? await apiProductCategoryEdit(data)
|
|
||||||
: await apiProductCategoryAdd(data)
|
|
||||||
popupRef.value?.close()
|
|
||||||
emit('success')
|
|
||||||
}
|
|
||||||
|
|
||||||
//打开弹窗
|
|
||||||
const open = (type = 'add') => {
|
|
||||||
mode.value = type
|
|
||||||
popupRef.value?.open()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 关闭回调
|
|
||||||
const handleClose = () => {
|
|
||||||
emit('close')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
defineExpose({
|
|
||||||
open,
|
|
||||||
setFormData,
|
|
||||||
getDetail
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
@ -1,144 +1,108 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<el-card class="!border-none mb-4" shadow="never">
|
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
|
||||||
<el-form
|
<el-button v-perms="['product_category/add']" type="primary" @click="handleAdd()">
|
||||||
class="mb-[-16px]"
|
<template #icon>
|
||||||
:model="queryParams"
|
<icon name="el-icon-Plus" />
|
||||||
inline
|
</template>
|
||||||
>
|
新增
|
||||||
<el-form-item label="上级分类" prop="pid">
|
</el-button>
|
||||||
<el-select class="w-[280px]" v-model="queryParams.pid" clearable placeholder="请选择上级分类">
|
<el-button @click="handleExpand"> 展开/折叠 </el-button>
|
||||||
<el-option label="全部" value=""></el-option>
|
<div class="mt-4">
|
||||||
<el-option
|
<el-table ref="tableRef" class="mt-4" size="large" border v-loading="pager.loading" :data="pager.lists"
|
||||||
v-for="(item, index) in dictData.show_status"
|
row-key="id" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
|
||||||
:key="index"
|
<el-table-column label="上级分类" prop="name" min-width="150" show-overflow-tooltip />
|
||||||
:label="item.name"
|
<el-table-column label="分类名称" prop="name" min-width="150" show-overflow-tooltip />
|
||||||
:value="item.value"
|
<el-table-column label="创建时间" prop="create_time" min-width="150" show-overflow-tooltip />
|
||||||
/>
|
<el-table-column label="操作" width="160" fixed="right">
|
||||||
</el-select>
|
<template #default="{ row }">
|
||||||
</el-form-item>
|
<el-button v-if="row.level < 2" v-perms="['auth.menu/add']" type="primary" link @click="handleAdd(row.id)">
|
||||||
<el-form-item label="名称" prop="name">
|
新增
|
||||||
<el-input class="w-[280px]" v-model="queryParams.name" clearable placeholder="请输入名称" />
|
</el-button>
|
||||||
</el-form-item>
|
<el-button v-perms="['auth.menu/edit']" type="primary" link @click="handleEdit(row)">
|
||||||
<el-form-item>
|
编辑
|
||||||
<el-button type="primary" @click="resetPage">查询</el-button>
|
</el-button>
|
||||||
<el-button @click="resetParams">重置</el-button>
|
<el-button v-perms="['auth.menu/delete']" type="danger" link @click="handleDelete(row.id)">
|
||||||
</el-form-item>
|
删除
|
||||||
</el-form>
|
</el-button>
|
||||||
</el-card>
|
</template>
|
||||||
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
|
</el-table-column>
|
||||||
<el-button v-perms="['product_category/add']" type="primary" @click="handleAdd">
|
</el-table>
|
||||||
<template #icon>
|
</div>
|
||||||
<icon name="el-icon-Plus" />
|
</el-card>
|
||||||
</template>
|
<edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
|
||||||
新增
|
</div>
|
||||||
</el-button>
|
|
||||||
<el-button
|
|
||||||
v-perms="['product_category/delete']"
|
|
||||||
:disabled="!selectData.length"
|
|
||||||
@click="handleDelete(selectData)"
|
|
||||||
>
|
|
||||||
删除
|
|
||||||
</el-button>
|
|
||||||
<div class="mt-4">
|
|
||||||
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
|
|
||||||
<el-table-column type="selection" width="55" />
|
|
||||||
<el-table-column label="ID" prop="id" show-overflow-tooltip />
|
|
||||||
<el-table-column label="上级分类" prop="pid">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<dict-value :options="dictData.show_status" :value="row.pid" />
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="名称" prop="name" show-overflow-tooltip />
|
|
||||||
<el-table-column label="创建时间" prop="create_time" show-overflow-tooltip />
|
|
||||||
<el-table-column label="操作" width="120" fixed="right">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-button
|
|
||||||
v-perms="['product_category/edit']"
|
|
||||||
type="primary"
|
|
||||||
link
|
|
||||||
@click="handleEdit(row)"
|
|
||||||
>
|
|
||||||
编辑
|
|
||||||
</el-button>
|
|
||||||
<el-button
|
|
||||||
v-perms="['product_category/delete']"
|
|
||||||
type="danger"
|
|
||||||
link
|
|
||||||
@click="handleDelete(row.id)"
|
|
||||||
>
|
|
||||||
删除
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</div>
|
|
||||||
<div class="flex mt-4 justify-end">
|
|
||||||
<pagination v-model="pager" @change="getLists" />
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup name="productCategoryLists">
|
<script lang="ts" setup name="productCategoryLists">
|
||||||
import { usePaging } from '@/hooks/usePaging'
|
import { usePaging } from '@/hooks/usePaging'
|
||||||
import { useDictData } from '@/hooks/useDictOptions'
|
import { apiProductCategoryLists, apiProductCategoryDelete } from '@/api/product_category'
|
||||||
import { apiProductCategoryLists, apiProductCategoryDelete } from '@/api/product_category'
|
import { timeFormat } from '@/utils/util'
|
||||||
import { timeFormat } from '@/utils/util'
|
import feedback from '@/utils/feedback'
|
||||||
import feedback from '@/utils/feedback'
|
import EditPopup from './edit.vue'
|
||||||
import EditPopup from './edit.vue'
|
import type { ElTable } from 'element-plus'
|
||||||
|
|
||||||
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
||||||
// 是否显示编辑框
|
// 是否显示编辑框
|
||||||
const showEdit = ref(false)
|
const showEdit = ref(false)
|
||||||
|
|
||||||
|
// 查询条件
|
||||||
|
const queryParams = reactive({
|
||||||
|
pid: '',
|
||||||
|
name: '',
|
||||||
|
})
|
||||||
|
|
||||||
// 查询条件
|
// 选中数据
|
||||||
const queryParams = reactive({
|
const selectData = ref<any[]>([])
|
||||||
pid: '',
|
|
||||||
name: '',
|
|
||||||
})
|
|
||||||
|
|
||||||
// 选中数据
|
// 表格选择后回调事件
|
||||||
const selectData = ref<any[]>([])
|
const handleSelectionChange = (val : any[]) => {
|
||||||
|
selectData.value = val.map(({ id }) => id)
|
||||||
|
}
|
||||||
|
|
||||||
// 表格选择后回调事件
|
// 分页相关
|
||||||
const handleSelectionChange = (val: any[]) => {
|
const { pager, getLists, resetParams, resetPage } = usePaging({
|
||||||
selectData.value = val.map(({ id }) => id)
|
fetchFun: apiProductCategoryLists,
|
||||||
}
|
params: queryParams
|
||||||
|
})
|
||||||
|
|
||||||
// 获取字典数据
|
let isExpand = false
|
||||||
const { dictData } = useDictData('show_status')
|
const tableRef = shallowRef<InstanceType<typeof ElTable>>()
|
||||||
|
const handleExpand = () => {
|
||||||
|
isExpand = !isExpand
|
||||||
|
toggleExpand(pager.lists, isExpand)
|
||||||
|
}
|
||||||
|
|
||||||
// 分页相关
|
const toggleExpand = (children : any[], unfold = true) => {
|
||||||
const { pager, getLists, resetParams, resetPage } = usePaging({
|
for (const key in children) {
|
||||||
fetchFun: apiProductCategoryLists,
|
tableRef.value?.toggleRowExpansion(children[key], unfold)
|
||||||
params: queryParams
|
if (children[key].children) {
|
||||||
})
|
toggleExpand(children[key].children!, unfold)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 添加
|
// 添加
|
||||||
const handleAdd = async () => {
|
const handleAdd = async (pid = 0) => {
|
||||||
showEdit.value = true
|
showEdit.value = true
|
||||||
await nextTick()
|
await nextTick()
|
||||||
editRef.value?.open('add')
|
editRef.value?.open('add', pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 编辑
|
// 编辑
|
||||||
const handleEdit = async (data: any) => {
|
const handleEdit = async (data : any) => {
|
||||||
showEdit.value = true
|
showEdit.value = true
|
||||||
await nextTick()
|
await nextTick()
|
||||||
editRef.value?.open('edit')
|
editRef.value?.open('edit')
|
||||||
editRef.value?.setFormData(data)
|
editRef.value?.setFormData(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
const handleDelete = async (id: number | any[]) => {
|
const handleDelete = async (id : number | any[]) => {
|
||||||
await feedback.confirm('确定要删除?')
|
await feedback.confirm('确定要删除?')
|
||||||
await apiProductCategoryDelete({ id })
|
await apiProductCategoryDelete({ id })
|
||||||
getLists()
|
getLists()
|
||||||
}
|
}
|
||||||
|
|
||||||
getLists()
|
getLists()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user