diff --git a/src/api/supermarket/smHotelDownstreamApp.ts b/src/api/supermarket/smHotelDownstreamApp.ts new file mode 100644 index 00000000..5e217e4a --- /dev/null +++ b/src/api/supermarket/smHotelDownstreamApp.ts @@ -0,0 +1,47 @@ +import request from "/@/utils/request" + +export function fetchList(query?: Object) { + return request({ + url: "/supermarket/smHotelDownstreamApp/page", + method: "get", + params: query, + }) +} + +export function getObj(id: string | number) { + return request({ + url: `/supermarket/smHotelDownstreamApp/${id}`, + method: "get", + }) +} + +export function addObj(obj?: Object) { + return request({ + url: "/supermarket/smHotelDownstreamApp", + method: "post", + data: obj, + }) +} + +export function putObj(obj?: Object) { + return request({ + url: "/supermarket/smHotelDownstreamApp", + method: "put", + data: obj, + }) +} + +export function delObjs(ids?: Object) { + return request({ + url: "/supermarket/smHotelDownstreamApp", + method: "delete", + data: ids, + }) +} + +export function rotateSecret(id: string | number) { + return request({ + url: `/supermarket/smHotelDownstreamApp/rotateSecret/${id}`, + method: "post", + }) +} diff --git a/src/api/supermarket/smHotelOrder.ts b/src/api/supermarket/smHotelOrder.ts index 6ef89f09..d5dfce1b 100644 --- a/src/api/supermarket/smHotelOrder.ts +++ b/src/api/supermarket/smHotelOrder.ts @@ -49,3 +49,11 @@ export function compensateOrder(id: string | number) { method: "post", }) } + +/** 订单来源筛选项(渠道下游 + 开放应用,各自显示名) */ +export function listOrderSourceOptions() { + return request({ + url: "/supermarket/smHotelOrder/orderSourceOptions", + method: "get", + }) +} diff --git a/src/views/canteen/canteenDailyMenu/form.vue b/src/views/canteen/canteenDailyMenu/form.vue index ef216bc7..75328c5a 100644 --- a/src/views/canteen/canteenDailyMenu/form.vue +++ b/src/views/canteen/canteenDailyMenu/form.vue @@ -174,6 +174,8 @@ const emit = defineEmits(["refresh"]) const LS_EXPAND = "canteen_daily_menu_expand_combo" const LS_AUTO_SUM = "canteen_daily_menu_auto_sum_combo" +/** 选择菜品弹窗:商品分类按商户记忆;无记忆取 sort 最大(排序最靠前) */ +const LS_SELECT_CATEGORY = "canteen_daily_menu_select_category" const imageBaseUrl = import.meta.env.VITE_IMAGE_BASE_PATH const { spu_status } = useDict("spu_status") @@ -187,6 +189,8 @@ const loading = ref(false) const categoryOptions = ref([]) const summingId = ref(null) const summingAll = ref(false) +/** 打开选择弹窗时跳过一次分类记忆写入,避免 reset 误清本地偏好 */ +const skipRememberSelectCategory = ref(false) /** 勾选偏好本地记住 */ const expandComboItems = ref(localStorage.getItem(LS_EXPAND) !== "0") @@ -194,6 +198,27 @@ const autoSumComboPrice = ref(localStorage.getItem(LS_AUTO_SUM) === "1") watch(expandComboItems, (v) => localStorage.setItem(LS_EXPAND, v ? "1" : "0")) watch(autoSumComboPrice, (v) => localStorage.setItem(LS_AUTO_SUM, v ? "1" : "0")) +const selectCategoryKey = (merchantId: string | number | "") => + `${LS_SELECT_CATEGORY}:${merchantId || "_"}` + +const pickPreferredCategoryId = (list: any[], saved?: string | number | null) => { + if (!list?.length) return "" + if (saved != null && saved !== "" && list.some((c) => String(c.id) === String(saved))) { + return list.find((c) => String(c.id) === String(saved))?.id ?? "" + } + return list.reduce((best, cur) => { + const bs = Number(best?.sort) || 0 + const cs = Number(cur?.sort) || 0 + return cs > bs ? cur : best + }).id +} + +const resolveSelectCategory = (merchantId: string | number | "", list: any[]) => { + if (!merchantId || !list?.length) return "" + const saved = localStorage.getItem(selectCategoryKey(merchantId)) + return pickPreferredCategoryId(list, saved) +} + /** comboSpuId -> 组成项(含单价) */ const comboChildrenMap = ref>({}) @@ -215,11 +240,23 @@ const state: BasicTableProps = reactive({ merchantId: "", startTime: "", hourType: "", + categoryId: "" as string | number | "", + name: "", }, pageList: getCanteenDailyMenuList, dataList: [], }) +watch( + () => state.queryForm.categoryId, + (cid) => { + if (skipRememberSelectCategory.value) return + const mid = state.queryForm.merchantId || form.merchantId + if (!mid || cid == null || cid === "") return + localStorage.setItem(selectCategoryKey(mid), String(cid)) + }, +) + const openDialog = (merchantId: string, time?: string, hourType?: number) => { visible.value = true selectedFood.value = [] @@ -252,6 +289,7 @@ const handleClickSelect = async () => { useMessage().warning("请先选择餐段") return } + skipRememberSelectCategory.value = true queryRef.value?.resetFields() foodMultipleTableRef.value?.clearSelection() selectDialogVisible.value = true @@ -259,22 +297,38 @@ const handleClickSelect = async () => { state.queryForm.merchantId = form.merchantId state.queryForm.startTime = form.startTime state.queryForm.hourType = form.hourTypes.length === 1 ? form.hourTypes[0] : "" + state.queryForm.name = "" - getDataList() try { - const res = await getCanteenCategory() + const res = await getCanteenCategory( + form.merchantId ? { merchantId: form.merchantId } : undefined, + ) if (res.code === 0) { - categoryOptions.value = res.data + categoryOptions.value = res.data || [] + } else { + categoryOptions.value = [] } } catch { categoryOptions.value = [] } + state.queryForm.categoryId = resolveSelectCategory(form.merchantId, categoryOptions.value) + await nextTick() + skipRememberSelectCategory.value = false + + getDataList() } const { getDataList, currentChangeHandle, sizeChangeHandle } = useTable(state) -const resetQuery = () => { - queryRef.value?.resetFields() +const resetQuery = async () => { + skipRememberSelectCategory.value = true + state.queryForm.name = "" + state.queryForm.categoryId = resolveSelectCategory( + form.merchantId || state.queryForm.merchantId, + categoryOptions.value, + ) + await nextTick() + skipRememberSelectCategory.value = false getDataList() } diff --git a/src/views/canteen/canteenDailyMenu/index.vue b/src/views/canteen/canteenDailyMenu/index.vue index f0a7c3c7..2b8d355a 100644 --- a/src/views/canteen/canteenDailyMenu/index.vue +++ b/src/views/canteen/canteenDailyMenu/index.vue @@ -305,7 +305,20 @@ {{ row.offlineSold != null ? row.offlineSold : 0 }} - + + + + + +