add NumberValueTotal
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import { axios, type PageResult } from "timi-web";
|
import { axios, type PageResult } from "timi-web";
|
||||||
import type { CustomerEventRankView, EventRecord, EventRecordPage, EventRecordRankPage } from "@/types/EventRecord";
|
import type { CustomerEventRankView, EventRecord, EventRecordPage, EventRecordPageResult, EventRecordRankPage } from "@/types/EventRecord";
|
||||||
import type { Customer } from "@/types/Customer.ts";
|
import type { Customer } from "@/types/Customer.ts";
|
||||||
import { withCurrentStoreId } from "@/utils/store";
|
import { withCurrentStoreId } from "@/utils/store";
|
||||||
|
|
||||||
const BASE_URI = "/gao/event/record";
|
const BASE_URI = "/gao/event/record";
|
||||||
|
|
||||||
async function list(page: EventRecordPage): Promise<PageResult<EventRecord>> {
|
async function list(page: EventRecordPage): Promise<EventRecordPageResult> {
|
||||||
return await axios.post(`${BASE_URI}/list`, withCurrentStoreId(page));
|
return await axios.post(`${BASE_URI}/list`, withCurrentStoreId(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
<div v-text="summaryText" />
|
<div v-text="summaryText" />
|
||||||
<div v-text="summaryBehaviorText" />
|
<div v-text="summaryBehaviorText" />
|
||||||
<div v-text="summaryTotalText" />
|
<div v-text="summaryTotalText" />
|
||||||
|
<div v-if="summaryNumberValueText" v-text="summaryNumberValueText" />
|
||||||
</div>
|
</div>
|
||||||
<t-pull-down-refresh
|
<t-pull-down-refresh
|
||||||
v-model="isRefreshing"
|
v-model="isRefreshing"
|
||||||
@@ -131,14 +132,15 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { DialogPlugin, Toast, type DropdownValue } from "tdesign-mobile-vue";
|
import { DialogPlugin, Toast, type DropdownValue } from "tdesign-mobile-vue";
|
||||||
import { Time, Toolkit, type PageResult, useUserStore } from "timi-web";
|
import { Time, Toolkit, useUserStore } from "timi-web";
|
||||||
import EventAPI from "@/api/EventAPI";
|
import EventAPI from "@/api/EventAPI";
|
||||||
import EventRecordAPI from "@/api/EventRecordAPI";
|
import EventRecordAPI from "@/api/EventRecordAPI";
|
||||||
import { useNavBarStore } from "@/store/navBarStore";
|
import { useNavBarStore } from "@/store/navBarStore";
|
||||||
import type { EventItem } from "@/types/EventItem";
|
import type { EventItem } from "@/types/EventItem";
|
||||||
import type { EventRecordListItemView, EventRecordPage } from "@/types/EventRecord";
|
import type { EventRecordPage, EventRecordPageResult, EventRecordListItemView } from "@/types/EventRecord";
|
||||||
import { getCustomerPhotoURL } from "@/utils/customer";
|
import { getCustomerPhotoURL } from "@/utils/customer";
|
||||||
import { getErrorMessage } from "@/utils/error";
|
import { getErrorMessage } from "@/utils/error";
|
||||||
|
import { formatEventNumberValue } from "@/utils/eventValue";
|
||||||
import { permissionCodes } from "@/utils/permission";
|
import { permissionCodes } from "@/utils/permission";
|
||||||
|
|
||||||
type DateFilterType = "today" | "yesterday" | "beforeYesterday" | "lastWeek" | "all" | "custom";
|
type DateFilterType = "today" | "yesterday" | "beforeYesterday" | "lastWeek" | "all" | "custom";
|
||||||
@@ -192,6 +194,13 @@ const eventFilterLabel = computed(() => {
|
|||||||
.join("、");
|
.join("、");
|
||||||
});
|
});
|
||||||
const summaryBehaviorText = computed(() => `事件:${eventFilterLabel.value}`);
|
const summaryBehaviorText = computed(() => `事件:${eventFilterLabel.value}`);
|
||||||
|
const selectedNumberEvent = computed(() => {
|
||||||
|
if (actionFilter.value.length !== 1) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const event = eventList.value.find(item => item.id === actionFilter.value[0]);
|
||||||
|
return event?.valueType === "NUMBER" ? event : undefined;
|
||||||
|
});
|
||||||
const canDeleteRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.delete));
|
const canDeleteRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.delete));
|
||||||
const summaryText = computed(() => {
|
const summaryText = computed(() => {
|
||||||
if (!isCustomRange.value) {
|
if (!isCustomRange.value) {
|
||||||
@@ -244,13 +253,20 @@ const page = reactive<EventRecordPage>({
|
|||||||
index: 0,
|
index: 0,
|
||||||
size: pageSize
|
size: pageSize
|
||||||
});
|
});
|
||||||
const pageResult = reactive<PageResult<EventRecordListItemView>>({
|
const pageResult = reactive<EventRecordPageResult>({
|
||||||
total: 0,
|
total: 0,
|
||||||
list: []
|
list: [],
|
||||||
|
numberValueTotal: null
|
||||||
});
|
});
|
||||||
let loadToken = 0;
|
let loadToken = 0;
|
||||||
|
|
||||||
const summaryTotalText = computed(() => `共 ${pageResult.total} 条数据,已加载 ${pageResult.list.length} 条`);
|
const summaryTotalText = computed(() => `共 ${pageResult.total} 条数据,已加载 ${pageResult.list.length} 条`);
|
||||||
|
const summaryNumberValueText = computed(() => {
|
||||||
|
if (!selectedNumberEvent.value || pageResult.numberValueTotal === undefined || pageResult.numberValueTotal === null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return `数值合计:${formatEventNumberValue(selectedNumberEvent.value, pageResult.numberValueTotal)}`;
|
||||||
|
});
|
||||||
const loadStateText = computed(() => {
|
const loadStateText = computed(() => {
|
||||||
if (isLoading.value) {
|
if (isLoading.value) {
|
||||||
return "正在加载更多";
|
return "正在加载更多";
|
||||||
@@ -264,6 +280,7 @@ async function reloadRecords(): Promise<void> {
|
|||||||
page.index = 0;
|
page.index = 0;
|
||||||
pageResult.total = 0;
|
pageResult.total = 0;
|
||||||
pageResult.list = [];
|
pageResult.list = [];
|
||||||
|
pageResult.numberValueTotal = null;
|
||||||
isNoMore.value = false;
|
isNoMore.value = false;
|
||||||
await loadRecords();
|
await loadRecords();
|
||||||
} finally {
|
} finally {
|
||||||
@@ -289,6 +306,7 @@ async function loadRecords(): Promise<void> {
|
|||||||
}
|
}
|
||||||
pageResult.list = pageResult.list.concat(result.list || []);
|
pageResult.list = pageResult.list.concat(result.list || []);
|
||||||
pageResult.total = result.total || 0;
|
pageResult.total = result.total || 0;
|
||||||
|
pageResult.numberValueTotal = result.numberValueTotal ?? null;
|
||||||
page.index += 1;
|
page.index += 1;
|
||||||
isNoMore.value = pageResult.list.length >= pageResult.total || (result.list || []).length < page.size;
|
isNoMore.value = pageResult.list.length >= pageResult.total || (result.list || []).length < page.size;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -394,8 +412,7 @@ async function removeRecord(id: string): Promise<void> {
|
|||||||
deletingId.value = id;
|
deletingId.value = id;
|
||||||
try {
|
try {
|
||||||
await EventRecordAPI.remove(id);
|
await EventRecordAPI.remove(id);
|
||||||
pageResult.list = pageResult.list.filter(item => item.id !== id);
|
await reloadRecords();
|
||||||
pageResult.total = Math.max(0, pageResult.total - 1);
|
|
||||||
Toast.success("登记记录已删除");
|
Toast.success("登记记录已删除");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = getErrorMessage(error, "登记记录删除失败");
|
const message = getErrorMessage(error, "登记记录删除失败");
|
||||||
@@ -446,7 +463,7 @@ function buildRangeReq(): Omit<EventRecordPage, "index" | "size"> {
|
|||||||
endAt,
|
endAt,
|
||||||
customerId: customerId.value || undefined,
|
customerId: customerId.value || undefined,
|
||||||
keyword: keyword.value.trim() || undefined,
|
keyword: keyword.value.trim() || undefined,
|
||||||
eventIdList: selectedAllEvent ? undefined : actionFilter.value
|
eventIdList: actionFilter.value.length === 1 ? actionFilter.value : selectedAllEvent ? undefined : actionFilter.value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Attachment, BasePage, Model, User } from "timi-web";
|
import type { Attachment, BasePage, Model, PageResult, User } from "timi-web";
|
||||||
import type { Customer } from "@/types/Customer";
|
import type { Customer } from "@/types/Customer";
|
||||||
import type { EventItem } from "@/types/EventItem";
|
import type { EventItem } from "@/types/EventItem";
|
||||||
|
|
||||||
@@ -31,6 +31,10 @@ export type EventRecordListItemView = {
|
|||||||
registeredAt?: number;
|
registeredAt?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type EventRecordPageResult = PageResult<EventRecordListItemView> & {
|
||||||
|
numberValueTotal?: number | null;
|
||||||
|
};
|
||||||
|
|
||||||
export type EventRecordPage = {
|
export type EventRecordPage = {
|
||||||
storeId?: string;
|
storeId?: string;
|
||||||
customerId?: string;
|
customerId?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user