feat:树形分类的新增和修改

This commit is contained in:
weiwei committed 2025-09-12 17:08:00 +08:00
1 parent 4b02337db3
commit 1b1642e51d
10 files changed
+276 -177

No files matched your search

+1 -10
View File
@@ -59,16 +59,7 @@
</view>
</z-paging>
<tm-drawer
title=""
:showClose="false"
:showFooter="false"
size="98%"
placement="bottom"
v-model:show="state.showDrawer"
:duration="100"
zIndex="100"
>
<tm-drawer title="" :showClose="false" :showFooter="false" size="98%" v-model:show="state.showDrawer" :duration="100" zIndex="100">
<z-paging
ref="pageRef"
:fixed="true"
@@ -79,7 +79,6 @@
:showClose="true"
:showFooter="false"
size="auto"
placement="bottom"
v-model:show="showDatePicker"
:duration="100"
zIndex="100"
+82 -9
View File
@@ -7,8 +7,8 @@
<text class="c-#0094ff! sub-text-24 mr-20rpx px-2 bg-#0094ff22 rounded-2">{{ item.status == "0" ? "正常" : "禁用" }}</text>
</view>
<view class="flex-row-center gap-2">
<tm-button class="px-2" size="xs" @click="">编辑</tm-button>
<tm-button class="px-2" size="xs" :linear="['to right', '#FFC328', '#E2000099']" @click="">删除</tm-button>
<tm-button class="px-2" size="xs" @click="editCategary(item)">编辑</tm-button>
<tm-button class="px-2" size="xs" :linear="['to right', '#FFC328', '#E2000099']" @click="delCategary(item.id)">删除</tm-button>
</view>
</view>
<view class="h-100rpx"></view>
@@ -20,18 +20,39 @@
<tm-drawer
title="分类"
:showClose="true"
:showFooter="true"
:showFooter="false"
size="90%"
placement="bottom"
v-model:show="categaryFormDrawer"
:duration="100"
zIndex="100"
bgColor="#F5F5F5"
>
<view>分类名称:</view>
<tm-input v-model="form.name" type="text" :showClear="true" placeholder="请输入分类名称"></tm-input>
<view>父级分类:</view>
<shop-categary-tree :node-data="categoryTree" @currentNode="currentNode" />
<view class="card p-4 mb-2">
<view class="prefix_title mb-2">基本信息</view>
<tm-form @submit="saveCategary" v-model="form" :rules="[]" direction="horizontal">
<tm-form-item name="name" label="分类名称">
<tm-input v-model="form.name" type="text" :showClear="true" placeholder="请输入分类名称"></tm-input>
</tm-form-item>
<tm-form-item name="status" label="状态">
<tm-radio-group v-model="form.status" align="flex-end">
<tm-radio
:value="item.value"
:label="item.label"
v-for="(item, index) in [
{ label: '正常', value: '0' },
{ label: '下架', value: '1' },
]"
:key="index"
></tm-radio>
</tm-radio-group>
</tm-form-item>
<view class="prefix_title mb-2">父级分类</view>
<view class="card my-2">
<shop-categary-tree v-model="selectedNode" :node-data="categoryTree" @currentNode="currentNode" />
</view>
<tm-button form-type="submit" block>提 交</tm-button>
</tm-form>
</view>
</tm-drawer>
</crud-layout>
</template>
@@ -47,9 +68,11 @@ const categaryFormDrawer = ref(false)
const form = reactive({
id: "",
name: "",
status: "0", // 状态(0正常,1下架)
parentId: "",
})
const categoryTree = ref([])
const selectedNode = ref<any>({})
onLoad(() => {
getGoodsCategory()
@@ -69,10 +92,60 @@ const getCategaryTree = async () => {
const addCategary = () => {
getCategaryTree()
Object.assign(form, {
id: "",
name: "",
status: "0",
parentId: "",
})
selectedNode.value = {}
categaryFormDrawer.value = true
}
const editCategary = (item) => {
getCategaryTree()
Object.assign(form, item)
selectedNode.value = { id: item.parentId }
categaryFormDrawer.value = true
}
const currentNode = (item) => {
form.parentId = item.categoryId
// form.parentId = item.categoryId
}
const saveCategary = async () => {
console.log(form)
if (!form.name) return uni.showToast({ title: "请填写分类名称", icon: "none" })
if (selectedNode.value.id === form.id) return uni.showToast({ title: "父级分类不能是自身", icon: "none" })
try {
const params = { ...form, parentId: selectedNode.value.id }
uni.showLoading({ title: "保存中..." })
const { code, data, msg } = await (form.id ? prosperityShopApi.editCategary(params) : prosperityShopApi.addCategary(params))
if (code != 0) return uni.showToast({ title: msg || "保存失败", icon: "none" })
uni.showToast({ title: "保存成功", icon: "none" })
categaryFormDrawer.value = false
await getGoodsCategory()
} finally {
uni.hideLoading()
}
}
// 删除分类
const delCategary = async (id: string) => {
if (!id) return uni.showToast({ title: "分类id不存在", icon: "none" })
uni.showModal({
title: "确定删除分类吗?",
content: "",
success: async (res) => {
if (res.confirm) {
uni.showLoading({ title: "正在删除" })
const { code, msg } = await prosperityShopApi.delCategary(id)
if (code != 0) return uni.showToast({ title: msg || "删除失败", icon: "none" })
uni.showToast({ title: "删除成功", icon: "none" })
getGoodsCategory()
uni.hideLoading()
}
},
})
}
</script>
-1
View File
@@ -152,7 +152,6 @@
:showClose="true"
:showFooter="false"
size="auto"
placement="bottom"
v-model:show="showCategaryPicker"
:duration="100"
zIndex="100"
+1 -1
View File
@@ -83,7 +83,7 @@
</view>
</z-paging>
<tm-drawer title="退款" :showClose="true" size="90%" placement="bottom" bgColor="#EBF6FF" v-model:show="state.showDrawer" zIndex="999">
<tm-drawer title="退款" :showClose="true" size="90%" bgColor="#EBF6FF" v-model:show="state.showDrawer" zIndex="999">
<view class="bg-white rounded-16rpx px-10rpx m-b-10rpx animate-both">
<z-tabs
:list="['同意退款', '拒绝退款']"
-1
View File
@@ -102,7 +102,6 @@
:showClose="false"
:showFooter="true"
size="70%"
placement="bottom"
v-model:show="state.showDrawer"
:duration="100"
zIndex="1200"