remove button in point rule detail
This commit is contained in:
@@ -59,11 +59,22 @@
|
||||
<t-cell title="创建时间" :note="formatDate(rule.createdAt, '未知时间')" />
|
||||
<t-cell title="更新时间" :note="formatDate(rule.updatedAt, '未知时间')" />
|
||||
</t-cell-group>
|
||||
<t-empty v-else :description="isLoading ? '正在加载积分规则' : '积分规则不存在'" />
|
||||
<t-button
|
||||
v-if="rule && canDelete"
|
||||
class="delete red bg-white cell-button"
|
||||
:loading="isDeleting"
|
||||
variant="text"
|
||||
block
|
||||
@click="confirmRemove"
|
||||
>
|
||||
删除
|
||||
</t-button>
|
||||
<t-empty v-if="!rule" :description="isLoading ? '正在加载积分规则' : '积分规则不存在'" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { Text, Time, useUserStore } from "timi-web";
|
||||
import EventAPI from "@/api/EventAPI";
|
||||
import PointAPI from "@/api/PointAPI";
|
||||
@@ -72,6 +83,7 @@ import { useNavBarStore } from "@/store/navBarStore";
|
||||
import type { EventItem } from "@/types/EventItem";
|
||||
import type { PointRule, PointRuleStatus, PointRuleMode, PointRuleTriggerType } from "@/types/Point";
|
||||
import { formatEventNumberValue } from "@/utils/eventValue";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||||
|
||||
@@ -88,6 +100,7 @@ const currentStoreStore = useCurrentStoreStore();
|
||||
// ---------- 权限与门店 ----------
|
||||
|
||||
const canUpdate = computed(() => userStore.hasPermissions(permissionCodes.pointRule.update));
|
||||
const canDelete = computed(() => userStore.hasPermissions(permissionCodes.pointRule.delete));
|
||||
const canReadEvent = computed(() => userStore.hasPermissions(permissionCodes.event.read));
|
||||
const isGlobalManager = computed(() => userStore.hasRoles(gaoRoleCodes.globalManager));
|
||||
const storeName = computed(() => {
|
||||
@@ -106,6 +119,7 @@ const rule = ref<PointRule>();
|
||||
const event = ref<EventItem>();
|
||||
const sourceEvent = ref<EventItem>();
|
||||
const isLoading = ref(false);
|
||||
const isDeleting = ref(false);
|
||||
|
||||
const condition = computed(() => rule.value?.conditionJson);
|
||||
const isConsumeRule = computed(() => (rule.value?.pointValue ?? 0) < 0);
|
||||
@@ -260,8 +274,55 @@ function formatDate(timestamp?: number, emptyText = "不限"): string {
|
||||
return timestamp === undefined || timestamp === null ? emptyText : Time.toDateTime(timestamp);
|
||||
}
|
||||
|
||||
// ---------- 删除 ----------
|
||||
|
||||
async function confirmRemove(): Promise<void> {
|
||||
if (!rule.value?.id || isDeleting.value) {
|
||||
return;
|
||||
}
|
||||
const dialog = DialogPlugin.confirm({
|
||||
title: "删除积分规则",
|
||||
content: `确定删除规则 ${rule.value.name || "未命名规则"} 吗?删除只影响后续登记,不会改变历史流水。`,
|
||||
cancelBtn: "取消",
|
||||
confirmBtn: "删除",
|
||||
onCancel() {
|
||||
dialog.destroy();
|
||||
},
|
||||
async onConfirm() {
|
||||
dialog.destroy();
|
||||
await removeRule();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function removeRule(): Promise<void> {
|
||||
const ruleId = rule.value?.id;
|
||||
if (!ruleId || isDeleting.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
isDeleting.value = true;
|
||||
navBarStore.clearRight();
|
||||
try {
|
||||
await PointAPI.ruleRemove(ruleId);
|
||||
Message.success("积分规则已删除");
|
||||
await router.replace("/management/points/rules");
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "积分规则删除失败"));
|
||||
setEditAction();
|
||||
} finally {
|
||||
isDeleting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 导航 ----------
|
||||
|
||||
function setEditAction(): void {
|
||||
if (canUpdate.value) {
|
||||
navBarStore.setRightText("编辑", "var(--td-brand-color)", toEdit);
|
||||
}
|
||||
}
|
||||
|
||||
async function toEdit(): Promise<void> {
|
||||
const ruleId = String(route.params.id || "");
|
||||
if (!canUpdate.value || !ruleId) {
|
||||
@@ -291,9 +352,7 @@ watch(() => route.params.id, async () => {
|
||||
|
||||
onMounted(() => {
|
||||
navBarStore.clearRight();
|
||||
if (canUpdate.value) {
|
||||
navBarStore.setRightText("编辑", "var(--td-brand-color)", toEdit);
|
||||
}
|
||||
setEditAction();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
@@ -309,6 +368,10 @@ onUnmounted(() => {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.delete {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.rule-header {
|
||||
gap: .75rem;
|
||||
margin: 0 1rem;
|
||||
|
||||
@@ -88,17 +88,6 @@
|
||||
</t-form-item>
|
||||
</card-container>
|
||||
</t-form>
|
||||
<t-button
|
||||
v-if="!isCreateMode"
|
||||
class="delete red bg-white cell-button"
|
||||
v-can="permissionCodes.pointRule.delete"
|
||||
:loading="isRemoving"
|
||||
variant="text"
|
||||
block
|
||||
@click="confirmRemove"
|
||||
>
|
||||
删除
|
||||
</t-button>
|
||||
</div>
|
||||
<t-popup v-model="storePickerVisible" placement="bottom">
|
||||
<t-picker
|
||||
@@ -188,7 +177,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { Time, useUserStore } from "timi-web";
|
||||
import EventAPI from "@/api/EventAPI";
|
||||
import PointAPI from "@/api/PointAPI";
|
||||
@@ -240,7 +228,6 @@ const pageAccess = computed(() => ({
|
||||
// ---------- 基础表单 ----------
|
||||
|
||||
const isSaving = ref(false);
|
||||
const isRemoving = ref(false);
|
||||
const formModel = reactive({
|
||||
id: "",
|
||||
storeId: "",
|
||||
@@ -745,43 +732,6 @@ async function saveRule(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 删除 ----------
|
||||
|
||||
async function confirmRemove(): Promise<void> {
|
||||
if (!formModel.id || isRemoving.value) {
|
||||
return;
|
||||
}
|
||||
const dialog = DialogPlugin.confirm({
|
||||
title: "删除积分规则",
|
||||
content: `确定删除规则 ${formModel.name || "未命名规则"} 吗?删除只影响后续登记,不会改变历史流水。`,
|
||||
cancelBtn: "取消",
|
||||
confirmBtn: "删除",
|
||||
onCancel() {
|
||||
dialog.destroy();
|
||||
},
|
||||
async onConfirm() {
|
||||
dialog.destroy();
|
||||
await removeRule();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function removeRule(): Promise<void> {
|
||||
if (!formModel.id) {
|
||||
return;
|
||||
}
|
||||
isRemoving.value = true;
|
||||
try {
|
||||
await PointAPI.ruleRemove(formModel.id);
|
||||
Message.success("积分规则已删除");
|
||||
await router.replace("/management/points/rules");
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "积分规则删除失败"));
|
||||
} finally {
|
||||
isRemoving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 页面数据 ----------
|
||||
|
||||
async function fillForm(): Promise<void> {
|
||||
@@ -920,10 +870,6 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.delete {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
:global(html.theme-dark) {
|
||||
|
||||
Reference in New Issue
Block a user