feat(柜体和店铺管理): 添加删除柜体和店铺功能

- 在智能柜体详情页添加删除柜体功能,包含确认对话框和权限控制
- 在店铺表单弹窗中添加删除店铺功能,包含确认对话框和条件判断
- 两个功能均调用对应API并处理成功/失败状态
This commit is contained in:
dzq 2025-10-09 16:41:38 +08:00
parent f7677f136a
commit d89a2a25e2
2 changed files with 73 additions and 3 deletions

View File

@ -1,8 +1,8 @@
<script setup lang="ts">
import { ref, watch, onMounted, computed } from "vue";
import { ElMessage } from "element-plus";
import { ElMessage, ElMessageBox } from "element-plus";
import { paymentMethodOptions, modeToPaymentMethodMap } from "@/utils/maps/payment";
import { addShop, updateShop, ShopDTO, UpdateShopCommand, AddShopCommand } from "@/api/shop/shop";
import { addShop, updateShop, deleteShop, ShopDTO, UpdateShopCommand, AddShopCommand } from "@/api/shop/shop";
import { useWxStore } from "@/store/modules/wx";
import Upload from "@iconify-icons/ep/upload";
import { useSysConfigStoreHook } from "@/store/modules/sysConfig";
@ -27,6 +27,7 @@ const wxStore = useWxStore();
const sysConfigStore = useSysConfigStoreHook();
const formRef = ref();
const deleteDialogVisible = ref(false);
const formData = ref<UpdateShopCommand>({
corpid: wxStore.corpid,
shopId: 0,
@ -134,6 +135,27 @@ const copyLink = () => {
const success = copyTextToClipboard(url);
success ? ElMessage.success('链接复制成功') : ElMessage.error('复制失败,请手动复制');
};
const handleDelete = () => {
deleteDialogVisible.value = true;
};
const confirmDelete = async () => {
try {
await deleteShop(formData.value.shopId.toString());
ElMessage.success("删除成功");
deleteDialogVisible.value = false;
emit("update:visible", false);
emit("refresh");
} catch (error) {
console.error(error);
ElMessage.error("删除失败");
}
};
const cancelDelete = () => {
deleteDialogVisible.value = false;
};
</script>
<template>
@ -209,9 +231,31 @@ const copyLink = () => {
</el-form>
<template #footer>
<el-button @click="handleClose" style="margin-right: 5px;">取消</el-button>
<el-button
v-if="formData.shopId && (props.row.cabinetCount || 0) === 0"
type="danger"
@click="handleDelete"
style="margin-right: 5px;">
删除
</el-button>
<el-button type="primary" @click="handleSubmit">确定</el-button>
</template>
</el-drawer>
<!-- 删除确认对话框 -->
<el-dialog
v-model="deleteDialogVisible"
title="确认删除"
width="400px"
:close-on-click-modal="false">
<span>确定要删除地址 "{{ formData.shopName }}" 此操作不可恢复</span>
<template #footer>
<span class="dialog-footer">
<el-button @click="cancelDelete">取消</el-button>
<el-button type="danger" @click="confirmDelete">确定删除</el-button>
</span>
</template>
</el-dialog>
</template>
<style scoped>
@ -243,4 +287,10 @@ const copyLink = () => {
object-fit: contain;
border-radius: 4px;
}
.dialog-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
}
</style>

View File

@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, onMounted, computed } from "vue";
import { useRoute, useRouter } from "vue-router";
import { getSmartCabinetDetailApi, type SmartCabinetDTO, getBalanceEnableText } from "@/api/cabinet/smart-cabinet";
import { getSmartCabinetDetailApi, type SmartCabinetDTO, getBalanceEnableText, deleteSmartCabinet } from "@/api/cabinet/smart-cabinet";
import { CabinetCellQuery, changeGoodsCellsStock, clearGoodsCells, getCabinetCellList, type CabinetCellDTO } from "@/api/cabinet/cabinet-cell";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { CabinetImgMap } from "@/utils/cabinetImgMap";
@ -279,6 +279,22 @@ async function handleDeleteMainboard(row: CabinetMainboardDTO) {
}
}
async function handleDeleteCabinet() {
try {
await ElMessageBox.confirm(
`确认要删除柜体「${cabinetInfo.value.cabinetName}」吗?此操作将不可恢复。`,
'删除柜体',
{ confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }
);
await deleteSmartCabinet(cabinetId.value.toString());
ElMessage.success('柜体删除成功');
//
router.push('/cabinet/smart-cabinet');
} catch (error) {
console.error('操作取消或失败', error);
}
}
const handleAb98ViewDetail = (ab98UserId: number, name: string) => {
//
@ -341,6 +357,10 @@ onMounted(() => {
<div class="info-details" v-if="activeTab === 'basic'">
<div style="display: flex; justify-content: flex-end; margin-bottom: 16px;">
<el-button v-if="hasPermission('shop:cabinet:write')" type="danger" link :icon="useRenderIcon(Delete)"
@click="handleDeleteCabinet" style="margin-right: 16px;">
删除柜体
</el-button>
<el-button v-if="hasPermission('shop:cabinet:write')" type="primary" link :icon="useRenderIcon(EditPen)"
@click="editCabinetDrawerVisible = true">
编辑柜体