修改每日菜谱

This commit is contained in:
ctw committed 2025-01-12 15:42:17 +08:00
1 parent b4ff730fc8
commit 002f8ad6b1
6 files changed
+459 -336

No files matched your search

+4 -4
View File
@@ -10,14 +10,14 @@ ENV = 'development'
# ADMIN 服务地址 # ADMIN 服务地址
VITE_ADMIN_PROXY_PATH = http://123.156.230.15:8089/api/ # 线上 VITE_ADMIN_PROXY_PATH = http://123.156.230.15:8089/api/ # 线上
# VITE_ADMIN_PROXY_PATH = http://pjcloud.center.takin.cc/ # VITE_ADMIN_PROXY_PATH = http://pjcloud.center.takin.cc/
VITE_ADMIN_PROXY_PATH = http://localhost:9999/ # VITE_ADMIN_PROXY_PATH = http://localhost:9999/
#VITE_ADMIN_PROXY_PATH = http://192.168.101.29:9999/ # 邓-本地 # VITE_ADMIN_PROXY_PATH = http://192.168.101.29:9999/ # 邓-本地
# 图片访问基础地址 # 图片访问基础地址
VITE_IMAGE_BASE_PATH = http://123.156.230.15:8089/api # 线上 VITE_IMAGE_BASE_PATH = http://123.156.230.15:8089/api # 线上
# VITE_IMAGE_BASE_PATH = http://pjcloud.center.takin.cc # VITE_IMAGE_BASE_PATH = http://pjcloud.center.takin.cc
VITE_IMAGE_BASE_PATH = http://localhost:9999 # VITE_IMAGE_BASE_PATH = http://localhost:9999
#VITE_IMAGE_BASE_PATH = http://192.168.101.29:9999 # 邓-本地 # VITE_IMAGE_BASE_PATH = http://192.168.101.29:9999 # 邓-本地
# 代码生成服务地址 # 代码生成服务地址
VITE_GEN_PROXY_PATH = http://192.168.110.156:5003 VITE_GEN_PROXY_PATH = http://192.168.110.156:5003
+40 -41
View File
@@ -1,67 +1,66 @@
import request from "/@/utils/request" import request from "/@/utils/request"
export function fetchList(query?: Object) { export function fetchList(query?: Object) {
return request({ return request({
url: '/canteen/canteenDailyMenu/page', url: "/canteen/canteenDailyMenu/page",
method: 'get', method: "get",
params: query params: query,
}) })
} }
export function addObj(obj?: Object) { export function addObj(obj?: Object) {
return request({ return request({
url: '/canteen/canteenDailyMenu', url: "/canteen/canteenDailyMenu",
method: 'post', method: "post",
data: obj data: obj,
}) })
} }
export function getObj(id?: string) { export function getObj(id?: string) {
return request({ return request({
url: '/canteen/canteenDailyMenu/' + id, url: "/canteen/canteenDailyMenu/" + id,
method: 'get' method: "get",
}) })
} }
export function delObjs(ids?: Object) { export function delObjs(data?: Object) {
return request({ return request({
url: '/canteen/canteenDailyMenu', url: "/canteen/canteenDailyMenu",
method: 'delete', method: "delete",
data: ids data,
}) })
} }
export function putObj(obj?: Object) { export function putObj(obj?: Object) {
return request({ return request({
url: '/canteen/canteenDailyMenu', url: "/canteen/canteenDailyMenu",
method: 'put', method: "put",
data: obj data: obj,
}) })
} }
export function selectFoodList(query?: Object) { export function selectFoodList(query?: Object) {
return request({ return request({
url: '/canteen/canteenDailyMenu/selectFoodList', url: "/canteen/canteenDailyMenu/selectFoodList",
method: 'get', method: "get",
params: query params: query,
}) })
} }
//时间生成 //时间生成
export function selectWeekInfo(query?: Object) { export function selectWeekInfo(query?: Object) {
return request({ return request({
url: '/canteen/canteenDailyMenu/selectWeekInfo', url: "/canteen/canteenDailyMenu/selectWeekInfo",
method: 'get', method: "get",
params: query params: query,
}) })
} }
// //获取当前选中的菜品信息 // //获取当前选中的菜品信息
export function selectTimeFoodApi(query?: Object) { export function selectTimeFoodApi(query?: Object) {
return request({ return request({
url: '/canteen/canteenDailyMenu/selectTimeFood', url: "/canteen/canteenDailyMenu/selectTimeFood",
method: 'get', method: "get",
params: query params: query,
}) })
} }
+69 -69
View File
@@ -1,44 +1,44 @@
import { CellStyle, ElMessage } from 'element-plus'; import { CellStyle, ElMessage } from "element-plus"
import other from '/@/utils/other'; import other from "/@/utils/other"
/** /**
* 表格组件基础配置属性 * 表格组件基础配置属性
*/ */
export interface BasicTableProps { export interface BasicTableProps {
// 是否在创建页面时即调用数据列表接口,默认为true // 是否在创建页面时即调用数据列表接口,默认为true
createdIsNeed?: boolean; createdIsNeed?: boolean
// 是否需要分页,默认为true // 是否需要分页,默认为true
isPage?: boolean; isPage?: boolean
// 查询条件表单对象,类型为any // 查询条件表单对象,类型为any
queryForm?: any; queryForm?: any
// 数据列表数组 // 数据列表数组
dataList?: any[]; dataList?: any[]
// 分页属性对象 // 分页属性对象
pagination?: Pagination; pagination?: Pagination
// 数据列表,loading状态标志,默认为false // 数据列表,loading状态标志,默认为false
dataListLoading?: boolean; dataListLoading?: boolean
// 数据列表多选项数组 // 数据列表多选项数组
dataListSelections?: any[]; dataListSelections?: any[]
// 数据列表查询接口api方法,接收任意数量参数,返回Promise // 数据列表查询接口api方法,接收任意数量参数,返回Promise
pageList?: (...arg: any) => Promise<any>; pageList?: (...arg: any) => Promise<any>
// loading标志,默认为false // loading标志,默认为false
loading?: Boolean; loading?: Boolean
// 多选结果数组 // 多选结果数组
selectObjs?: any[]; selectObjs?: any[]
// 排序字段数组 // 排序字段数组
descs?: string[]; descs?: string[]
// 排序方式数组 // 排序方式数组
ascs?: string[]; ascs?: string[]
// props属性对象,类型为any // props属性对象,类型为any
props?: any; props?: any
} }
/** /**
* 表格样式。 * 表格样式。
*/ */
export interface TableStyle { export interface TableStyle {
cellStyle: CellStyle<any>; cellStyle: CellStyle<any>
headerCellStyle: CellStyle<any>; headerCellStyle: CellStyle<any>
} }
/** /**
@@ -46,15 +46,15 @@ export interface TableStyle {
*/ */
export interface Pagination { export interface Pagination {
// 当前页码,默认为1 // 当前页码,默认为1
current?: number; current?: number
// 每页显示条数,默认为10 // 每页显示条数,默认为10
size?: number; size?: number
// 总条数,默认为0 // 总条数,默认为0
total?: number; total?: number
// 每页显示条数选择器的选项数组,默认为[10,20,30,40] // 每页显示条数选择器的选项数组,默认为[10,20,30,40]
pageSizes?: any[]; pageSizes?: any[]
// 分页组件布局方式,可选值有 total,sizes,prev,jump,next,默认为'total,sizes,prev,jump,next' // 分页组件布局方式,可选值有 total,sizes,prev,jump,next,默认为'total,sizes,prev,jump,next'
layout?: String; layout?: String
} }
export function useTable(options?: BasicTableProps) { export function useTable(options?: BasicTableProps) {
@@ -75,7 +75,7 @@ export function useTable(options?: BasicTableProps) {
size: 10, size: 10,
total: 0, total: 0,
pageSizes: [1, 10, 20, 50, 100, 200], pageSizes: [1, 10, 20, 50, 100, 200],
layout: 'total, sizes, prev, pager, next, jumper', layout: "total, sizes, prev, pager, next, jumper",
} as Pagination, } as Pagination,
// 当前选中的数据项,默认为空数组 // 当前选中的数据项,默认为空数组
dataListSelections: [], dataListSelections: [],
@@ -89,10 +89,10 @@ export function useTable(options?: BasicTableProps) {
ascs: [], ascs: [],
// props属性配置对象,用于自定义数据属性,默认值为 {item:'records',totalCount:'total'} // props属性配置对象,用于自定义数据属性,默认值为 {item:'records',totalCount:'total'}
props: { props: {
item: 'records', item: "records",
totalCount: 'total', totalCount: "total",
}, },
}; }
/** /**
* 合并默认属性配置和自定义属性配置 * 合并默认属性配置和自定义属性配置
@@ -103,14 +103,14 @@ export function useTable(options?: BasicTableProps) {
const mergeDefaultOptions = (options: any, props: any): BasicTableProps => { const mergeDefaultOptions = (options: any, props: any): BasicTableProps => {
for (const key in options) { for (const key in options) {
if (!Object.getOwnPropertyDescriptor(props, key)) { if (!Object.getOwnPropertyDescriptor(props, key)) {
props[key] = options[key]; props[key] = options[key]
} }
} }
return props; return props
}; }
// 覆盖默认值 // 覆盖默认值
const state = mergeDefaultOptions(defaultOptions, options); const state = mergeDefaultOptions(defaultOptions, options)
/** /**
* 发起分页查询,并设置表格数据和分页信息 * 发起分页查询,并设置表格数据和分页信息
@@ -120,36 +120,36 @@ export function useTable(options?: BasicTableProps) {
if (state.pageList) { if (state.pageList) {
try { try {
// 开始加载数据,设置state.loading为true // 开始加载数据,设置state.loading为true
state.loading = true; state.loading = true
// 调用state.pageList方法发起分页查询 // 调用state.pageList方法发起分页查询
const res = await state.pageList({ const res = await state.pageList({
...state.queryForm, ...state.queryForm,
current: state.pagination?.current, current: state.pagination?.current,
size: state.pagination?.size, size: state.pagination?.size,
descs: state.descs?.join(','), descs: state.descs?.join(","),
ascs: state.ascs?.join(','), ascs: state.ascs?.join(","),
}); })
// 设置表格展示的数据数组 // 设置表格展示的数据数组
state.dataList = state.isPage ? res.data[state.props.item] : res.data; state.dataList = state.isPage ? res.data[state.props.item] : res.data
// 设置分页信息中的总数据条数 // 设置分页信息中的总数据条数
state.pagination!.total = state.isPage ? res.data[state.props.totalCount] : 0; state.pagination!.total = state.isPage ? res.data[state.props.totalCount] : 0
} catch (err: any) { } catch (err: any) {
// 捕获异常并显示错误提示 // 捕获异常并显示错误提示
ElMessage.error(err.msg || err.data.msg); ElMessage.error(err.msg || err.data.msg)
} finally { } finally {
// 结束加载数据,设置state.loading为false // 结束加载数据,设置state.loading为false
state.loading = false; state.loading = false
} }
} }
}; }
onMounted(() => { onMounted(() => {
if (state.createdIsNeed) { if (state.createdIsNeed) {
query(); query()
} }
}); })
/** /**
* 分页大小改变事件处理函数 * 分页大小改变事件处理函数
@@ -157,10 +157,10 @@ export function useTable(options?: BasicTableProps) {
*/ */
const sizeChangeHandle = (val: number) => { const sizeChangeHandle = (val: number) => {
// 修改state.pagination中的size属性 // 修改state.pagination中的size属性
state.pagination!.size = val; state.pagination!.size = val
// 再次发起查询操作 // 再次发起查询操作
query(); query()
}; }
/** /**
* 当前页码改变事件处理函数 * 当前页码改变事件处理函数
@@ -168,34 +168,34 @@ export function useTable(options?: BasicTableProps) {
*/ */
const currentChangeHandle = (val: number) => { const currentChangeHandle = (val: number) => {
// 修改state.pagination中的current属性 // 修改state.pagination中的current属性
state.pagination!.current = val; state.pagination!.current = val
// 再次发起查询操作 // 再次发起查询操作
query(); query()
}; }
// 排序触发事件 // 排序触发事件
const sortChangeHandle = (column: any) => { const sortChangeHandle = (column: any) => {
const prop = other.toUnderline(column.prop); const prop = other.toUnderline(column.prop)
if (column.order === 'descending') { if (column.order === "descending") {
state.descs?.push(prop); state.descs?.push(prop)
if (state.ascs!.includes(prop)) { if (state.ascs!.includes(prop)) {
state.ascs?.splice(state.ascs.indexOf(prop), 1); state.ascs?.splice(state.ascs.indexOf(prop), 1)
} }
} else if (column.order === 'ascending') { } else if (column.order === "ascending") {
state.ascs?.push(prop); state.ascs?.push(prop)
if (state.descs!.includes(prop)) { if (state.descs!.includes(prop)) {
state.descs?.splice(state.descs.indexOf(prop), 1); state.descs?.splice(state.descs.indexOf(prop), 1)
} }
} else { } else {
if (state.ascs!.includes(prop)) { if (state.ascs!.includes(prop)) {
state.ascs?.splice(state.ascs.indexOf(prop), 1); state.ascs?.splice(state.ascs.indexOf(prop), 1)
} }
if (state.descs!.includes(prop)) { if (state.descs!.includes(prop)) {
state.descs?.splice(state.descs.indexOf(prop), 1); state.descs?.splice(state.descs.indexOf(prop), 1)
} }
} }
query(); query()
}; }
/** /**
* 获取数据列表,并可选择是否刷新当前页码 * 获取数据列表,并可选择是否刷新当前页码
@@ -205,11 +205,11 @@ export function useTable(options?: BasicTableProps) {
const getDataList = (refresh?: any) => { const getDataList = (refresh?: any) => {
// 如果需要刷新,则将state.pagination.current重置为1 // 如果需要刷新,则将state.pagination.current重置为1
if (refresh !== false) { if (refresh !== false) {
state.pagination!.current = 1; state.pagination!.current = 1
} }
// 再次发起查询操作 // 再次发起查询操作
query(); query()
}; }
/** /**
* 下载文件 * 下载文件
@@ -219,21 +219,21 @@ export function useTable(options?: BasicTableProps) {
* @returns 返回一个Promise对象,用于异步处理结果 * @returns 返回一个Promise对象,用于异步处理结果
*/ */
const downBlobFile = (url: string, query: any, fileName: string) => { const downBlobFile = (url: string, query: any, fileName: string) => {
return other.downBlobFile(url, query, fileName); return other.downBlobFile(url, query, fileName)
}; }
/** /**
* 定义表格通用样式 * 定义表格通用样式
* @returns css * @returns css
*/ */
const tableStyle: TableStyle = { const tableStyle: TableStyle = {
cellStyle: { textAlign: 'center' }, cellStyle: { textAlign: "center" },
headerCellStyle: { headerCellStyle: {
textAlign: 'center', textAlign: "center",
background: 'var(--el-table-row-hover-bg-color)', background: "var(--el-table-row-hover-bg-color)",
color: 'var(--el-text-color-primary)', color: "var(--el-text-color-primary)",
}, },
}; }
return { return {
tableStyle, tableStyle,
@@ -242,5 +242,5 @@ export function useTable(options?: BasicTableProps) {
currentChangeHandle, currentChangeHandle,
sortChangeHandle, sortChangeHandle,
downBlobFile, downBlobFile,
}; }
} }
+192 -90
View File
@@ -12,10 +12,14 @@
<p v-else>未知类型</p> <p v-else>未知类型</p>
</el-form-item> </el-form-item>
<el-form-item label="菜品" prop="spuId"> <!-- <el-form-item label="菜品" prop="spuId">
<el-select v-model="spuIds" placeholder="请选择菜品" multiple> <el-select v-model="spuIds" placeholder="请选择菜品" multiple>
<el-option v-for="item in foodData" :key="item.id" :label="item.name" :value="item.id" /> <el-option v-for="item in foodList" :key="item.id" :label="item.name" :value="item.id" />
</el-select> </el-select>
</el-form-item> -->
<el-form-item label="选择菜品">
<el-button @click="handleClickSelect">选择菜品</el-button>
</el-form-item> </el-form-item>
<!-- <el-col :span="12" class="mb20"> <!-- <el-col :span="12" class="mb20">
@@ -27,7 +31,12 @@
<h1 style="font-size: 16px; font-weight: bold; color: #000000; margin: 20px 0">预览图</h1> <h1 style="font-size: 16px; font-weight: bold; color: #000000; margin: 20px 0">预览图</h1>
<div style="width: 100%; display: flex; flex-wrap: wrap"> <div style="width: 100%; display: flex; flex-wrap: wrap">
<img style="width: 250px; height: 200px; margin: 10px" v-for="(image, index) in spuImages" :key="index" :src="image" /> <img
style="width: 250px; height: 200px; margin: 10px"
v-for="(item, index) in selectedList"
:key="item.id"
:src="imageBaseUrl + item.picUrl"
/>
</div> </div>
<template #footer> <template #footer>
@@ -36,126 +45,219 @@
<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button> <el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
</span> </span>
</template> </template>
<el-dialog v-model="selectDialogVisible" title="选择菜品" width="60%" :close-on-click-modal="false" draggable>
<el-row>
<el-form :model="state.queryForm" ref="queryRef" :inline="true" @keyup.enter="getDataList">
<el-form-item label="商品名称" prop="name">
<el-input placeholder="请输入商品名称" v-model="state.queryForm.name" />
</el-form-item>
<el-form-item label="商品分类" prop="categoryId">
<select-ctcg v-model="state.queryForm.categoryId" style="width: 200px" />
</el-form-item>
<el-form-item>
<el-button icon="search" type="primary" @click="getDataList">查询</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</el-row>
<el-table
:data="state.dataList"
v-loading="loading"
border
:cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle"
@selection-change="selectionChangHandle"
@sort-change="sortChangeHandle"
>
<el-table-column type="selection" width="40" align="center" />
<el-table-column type="index" label="#" width="50" />
<el-table-column prop="name" label="商品名称" width="120px" show-overflow-tooltip />
<el-table-column prop="categoryId" label="商品分类" width="100px" show-overflow-tooltip>
<template #default="{ row }">
{{ categoryOptions?.find((item: any) => item?.id === row?.categoryId)?.name }}
</template>
</el-table-column>
<el-table-column prop="picUrl" label="商品封面图" align="center" width="160px" show-overflow-tooltip>
<template #default="scope">
<preview-image :src="scope.row.picUrl" />
</template>
</el-table-column>
<el-table-column prop="sort" label="排序字段" show-overflow-tooltip />
<el-table-column prop="status" label="上架状态" show-overflow-tooltip>
<template #default="scope">
<dict-tag :options="spu_status" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column prop="price" label="商品价格" show-overflow-tooltip>
<template #default="scope">
{{ displayPrice(scope.row.price) }}
</template>
</el-table-column>
<el-table-column prop="marketPrice" label="市场价" show-overflow-tooltip>
<template #default="scope">
{{ displayPrice(scope.row.marketPrice) }}
</template>
</el-table-column>
<el-table-column prop="costPrice" label="成本价" show-overflow-tooltip />
<el-table-column prop="stock" label="库存" show-overflow-tooltip />
<el-table-column prop="salesCount" label="商品销量" show-overflow-tooltip />
<el-table-column prop="createTime" label="创建时间" show-overflow-tooltip min-width="160" />
</el-table>
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
<template #footer>
<div class="dialog-footer">
<el-button @click="selectDialogVisible = false">取消</el-button>
<el-button type="primary" @click="handleSelectDialogConfirm">确认</el-button>
</div>
</template>
</el-dialog>
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts" name="CanteenDailyMenuDialog"> <script setup lang="ts" name="CanteenDailyMenuDialog">
import { useDict } from '/@/hooks/dict'; import { useMessage } from "/@/hooks/message"
import { useMessage } from '/@/hooks/message'; import { rule } from "/@/utils/validate"
import { getObj, addObj, putObj } from '/@/api/canteen/canteenDailyMenu'; import { BasicTableProps, useTable } from "/@/hooks/table"
import { selectFoodList } from '/@/api/canteen/canteenDailyMenu'; import { useDict } from "/@/hooks/dict"
import { rule } from '/@/utils/validate'; import { displayPrice } from "/@/utils/formatMoney"
import { fetchList as getCanteenCategory } from "/@/api/canteen/canteenCategory"
import { getObj, addObj, putObj } from "/@/api/canteen/canteenDailyMenu"
import { fetchList } from "/@/api/canteen/canteenSpu"
const emit = defineEmits(['refresh']); const emit = defineEmits(["refresh"])
//业务变量 const dataFormRef = ref()
const foodData = ref<any>([]); const visible = ref(false)
const spuIds = ref([]); const queryRef = ref()
const spuImages = ref<string[]>([]); const selectObjs = ref([]) as any // 表格多选的数据
// 定义变量内容 const selectedList = ref<any>([])
const dataFormRef = ref(); const loading = ref(false)
const visible = ref(false); const selectDialogVisible = ref<boolean>(false) // 选择菜品对话框开关
const loading = ref(false); const { spu_status } = useDict("spu_status")
// 定义字典 const categoryOptions = ref<any>([]) // 商品分类选项
const { daily_menu } = useDict('daily_menu'); const imageBaseUrl = import.meta.env.VITE_IMAGE_BASE_PATH
const imageBaseUrl = import.meta.env.VITE_IMAGE_BASE_PATH; const dataRules = ref({}) // 定义校验规则
// 提交表单数据 // 提交表单数据
const form = reactive<any>({ const form = reactive<any>({
id: '', id: "",
startTime: '', startTime: "",
spuId: '', hourType: "",
hourType: '', merchantId: "",
merchantId: '', })
deptId: '', // 选择的菜品的id数组
spuIds: '', const spuIds = computed(() => {
}); return selectedList.value?.map((item: any) => item.id)
})
// 定义校验规则 const state: BasicTableProps = reactive<BasicTableProps>({
const dataRules = ref({}); queryForm: {},
pageList: fetchList,
})
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, tableStyle } = useTable(state)
// 多选选择菜品
const selectionChangHandle = (objs: any) => {
selectObjs.value = objs
}
// 清空搜索条件
const resetQuery = () => {
// 清空搜索条件
queryRef.value?.resetFields()
// 清空多选
selectObjs.value = []
getDataList()
}
// 打开弹窗 // 打开弹窗
const openDialog = (id: string, time?: string, hourType?: number, merchantId?: number) => { const openDialog = (id: string, time?: string, hourType?: number, merchantId?: number) => {
visible.value = true; visible.value = true
form.id = ''; form.id = ""
// 重置表单数据 // 重置表单数据
nextTick(() => { dataFormRef.value?.resetFields()
dataFormRef.value?.resetFields(); selectObjs.value = []
}); selectedList.value = []
state.dataList = []
// 获取canteenDailyMenu信息 // 获取canteenDailyMenu信息
if (id) { if (id) {
form.id = id; form.id = id
getcanteenDailyMenuData(id); getcanteenDailyMenuData(id)
} }
if (time) { if (time) {
form.startTime = time; form.startTime = time
} }
if (hourType) { if (hourType) {
form.hourType = hourType; form.hourType = hourType
} }
form.merchantId = merchantId; form.merchantId = merchantId
}; }
watch(spuIds, (newValue, oldValue) => {
spuImages.value = [];
form.spuIds = newValue;
//更新值
if (newValue) {
const newValues = newValue.toString().split(',');
for (let index = 0; index < newValues.length; index++) {
const data = newValues[index];
foodData.value.forEach((sData: any) => {
if (sData.id?.toString() === data) {
spuImages.value.push(imageBaseUrl + sData.picUrl?.toString());
}
});
}
}
});
// 提交
const onSubmit = async () => {
if (spuIds.value.length <= 0) {
useMessage().warning('请选择菜品');
return;
}
const valid = await dataFormRef.value.validate().catch(() => {});
if (!valid) return false;
try {
loading.value = true;
form.id ? await putObj(form) : await addObj(form);
useMessage().success(form.id ? '修改成功' : '添加成功');
visible.value = false;
emit('refresh');
} catch (err: any) {
useMessage().error(err.msg);
} finally {
loading.value = false;
}
};
// 初始化表单数据 // 初始化表单数据
const getcanteenDailyMenuData = (id: string) => { const getcanteenDailyMenuData = (id: string) => {
// 获取数据 // 获取数据
loading.value = true; loading.value = true
getObj(id) getObj(id)
.then((res: any) => { .then((res: any) => {
Object.assign(form, res.data); Object.assign(form, res.data)
}) })
.finally(() => { .finally(() => {
loading.value = false; loading.value = false
}); })
}; }
// 点击选择菜品
const handleClickSelect = async () => {
selectDialogVisible.value = true
if (state.dataList && state.dataList?.length <= 0) {
getDataList()
}
try {
const res = await getCanteenCategory()
categoryOptions.value = res.data.records
} catch (error) {
categoryOptions.value = []
}
}
// 选择菜品点击确认
const handleSelectDialogConfirm = () => {
selectDialogVisible.value = false
selectedList.value = selectObjs.value
}
// 提交
const onSubmit = async () => {
if (selectedList.value.length <= 0) {
useMessage().warning("请选择菜品")
return
}
const valid = await dataFormRef.value.validate().catch(() => {})
if (!valid) return false
try {
loading.value = true
form.id ? await putObj({ ...form, spuIds: spuIds.value }) : await addObj({ ...form, spuIds: spuIds.value })
useMessage().success(form.id ? "修改成功" : "添加成功")
visible.value = false
emit("refresh")
} catch (err: any) {
useMessage().error(err.msg)
} finally {
loading.value = false
}
}
// 暴露变量 // 暴露变量
defineExpose({ defineExpose({
openDialog, openDialog,
}); })
/** 初始化 **/
onMounted(async () => {
// 获取菜品列表
let axiosResponse = await selectFoodList();
foodData.value = axiosResponse.data;
});
</script> </script>
+87 -92
View File
@@ -26,171 +26,166 @@
<tr> <tr>
<td class="w-16 h-48 text-4xl text-center cursor-pointer text-blue-500" @click="addFood(1)">早餐</td> <td class="w-16 h-48 text-4xl text-center cursor-pointer text-blue-500" @click="addFood(1)">早餐</td>
<td class="w-64 h-48 text-center" v-for="(item, index) in foodData1" :key="index"> <td class="w-64 h-48 text-center" v-for="(item, index) in foodData1" :key="index">
<img @click="delteData(item.tid)" :src="item.picUrl" class="p-3 w-full h-full object-cover" /> <img
@click="delteData(item.tid)"
:src="imageBaseUrl + item.picUrl"
class="p-3 w-full h-full object-contain"
/>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="w-16 h-48 text-4xl text-center cursor-pointer text-blue-500" @click="addFood(2)">中餐</td> <td class="w-16 h-48 text-4xl text-center cursor-pointer text-blue-500" @click="addFood(2)">中餐</td>
<td class="w-64 h-48 text-center" v-for="(item, index) in foodData2" :key="index"> <td class="w-64 h-48 text-center" v-for="(item, index) in foodData2" :key="index">
<img @click="delteData(item.tid)" :src="item.picUrl" class="p-3 w-full h-full object-cover" /> <img
@click="delteData(item.tid)"
:src="imageBaseUrl + item.picUrl"
class="p-3 w-full h-full object-contain"
/>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="w-16 h-48 text-4xl text-center cursor-pointer text-blue-500" @click="addFood(3)">晚餐</td> <td class="w-16 h-48 text-4xl text-center cursor-pointer text-blue-500" @click="addFood(3)">晚餐</td>
<td class="w-64 h-48 text-center" v-for="(item, index) in foodData3" :key="index"> <td class="w-64 h-48 text-center" v-for="(item, index) in foodData3" :key="index">
<img @click="delteData(item.tid)" :src="item.picUrl" class="p-3 w-full h-full object-cover" /> <img
@click="delteData(item.tid)"
:src="imageBaseUrl + item.picUrl"
class="p-3 w-full h-full object-contain"
/>
</td> </td>
</tr> </tr>
</table> </table>
</div> </div>
<!-- 编辑、新增 --> <!-- 编辑、新增 -->
<form-dialog ref="formDialogRef" @success="selectTimeFood" /> <form-dialog ref="formDialogRef" @refresh="selectTimeFood" />
</div> </div>
</template> </template>
<script setup lang="ts" name="systemCanteenDailyMenu"> <script setup lang="ts" name="systemCanteenDailyMenu">
import { delObjs, selectTimeFoodApi, selectWeekInfo } from '/@/api/canteen/canteenDailyMenu'; import { delObjs, selectTimeFoodApi, selectWeekInfo } from "/@/api/canteen/canteenDailyMenu"
import { useMessage, useMessageBox } from '/@/hooks/message'; import { useMessage, useMessageBox } from "/@/hooks/message"
import { useDict } from '/@/hooks/dict'; import { pageJoin } from "/@/api/wallet/mch-manage"
import { pageJoin } from '/@/api/wallet/mch-manage';
// 引入组件 const FormDialog = defineAsyncComponent(() => import("./form.vue"))
const FormDialog = defineAsyncComponent(() => import('./form.vue')); const imageBaseUrl = import.meta.env.VITE_IMAGE_BASE_PATH
const { daily_menu } = useDict('daily_menu'); const formDialogRef = ref()
// 定义变量内容 const loading = ref(true)
const formDialogRef = ref();
// 多选变量
const loading = ref(true); // 列表的加载中
// ---------新增业务变量 const message = useMessage() // 消息弹窗
const message = useMessage(); // 消息弹窗
const foodData1 = ref<any>({}); const foodData1 = ref<any>({})
const foodData2 = ref<any>({}); const foodData2 = ref<any>({})
const foodData3 = ref<any>({}); const foodData3 = ref<any>({})
let timedata = ''; let timedata = ""
let isActive = ref(-1); let isActive = ref(-1)
const weekParams = reactive({ const weekParams = reactive({
index: 0, index: 0,
}); })
const weekData = reactive({ const weekData = reactive({
data: [], data: [],
}); //时间数组 }) //时间数组
const merchantId = ref(); const merchantId = ref()
const merchantInfo = ref<any>([]); const merchantInfo = ref<any>([])
const addFood = async (hourType: number) => { const addFood = async (hourType: number) => {
if (!merchantId.value) { if (!merchantId.value) {
useMessage().error('请选择商户再进行新增'); useMessage().error("请选择商户再进行新增")
return; return
} }
//打开新增框 //打开新增框
formDialogRef.value.openDialog(null, timedata, hourType, merchantId.value); formDialogRef.value.openDialog(null, timedata, hourType, merchantId.value)
}; }
//选中具体时间数据 //选中具体时间数据
const timeClick = async (time: string, index: number) => { const timeClick = async (time: string, index: number) => {
//数据查询操作 //数据查询操作
if (time) { if (time) {
//时间处理 //时间处理
time = time.substring(0, time.indexOf('(')); time = time.substring(0, time.indexOf("("))
timedata = time; timedata = time
//选中 //选中
isActive.value = index; isActive.value = index
selectTimeFood(); selectTimeFood()
} }
}; }
//切换时间 //切换时间
const addClick = async (index: number) => { const addClick = async (index: number) => {
//数据值操作 //数据值操作
weekParams.index = weekParams.index + index; weekParams.index = weekParams.index + index
fetchData(); fetchData()
}; }
watch(merchantId, () => { watch(merchantId, () => {
fetchData(); fetchData()
}); })
const fetchData = async () => { const fetchData = async () => {
const weekDataRes = await selectWeekInfo(weekParams); const weekDataRes = await selectWeekInfo(weekParams)
weekData.data = weekDataRes.data; weekData.data = weekDataRes.data
isActive.value = 0; isActive.value = 0
timedata = weekData.data[0]; timedata = weekData.data[0]
// 时间格式 // 时间格式
timedata = timedata.substring(0, timedata.indexOf('(')); timedata = timedata.substring(0, timedata.indexOf("("))
selectTimeFood(); selectTimeFood()
}; }
const selectTimeFood = async () => { const selectTimeFood = async () => {
foodData1.value = []; foodData1.value = []
foodData2.value = []; foodData2.value = []
foodData3.value = []; foodData3.value = []
let params = { let params = {
time: timedata, time: timedata,
merchantId: merchantId.value, merchantId: merchantId.value,
}; }
//最大长度 //最大长度
let count = 0; let count = 0
const result = await selectTimeFoodApi(params); const result = await selectTimeFoodApi(params)
result.data.forEach((r: any) => { result.data.forEach((r: any) => {
if (r.dailyMenuVOS.length > count) { if (r.dailyMenuVOS.length > count) {
count = r.dailyMenuVOS.length; count = r.dailyMenuVOS.length
} }
switch (r.hourType) { switch (r.hourType) {
case 1: case 1:
foodData1.value = r.dailyMenuVOS; foodData1.value = r.dailyMenuVOS
break; break
case 2: case 2:
foodData2.value = r.dailyMenuVOS; foodData2.value = r.dailyMenuVOS
break; break
case 3: case 3:
foodData3.value = r.dailyMenuVOS; foodData3.value = r.dailyMenuVOS
break; break
} }
}); })
}; }
/** 删除数据源按钮 */
// 删除菜品
const delteData = async (tid: number) => { const delteData = async (tid: number) => {
await message.delConfirm('确定删除菜品吗?', '今日菜品?'); await message.delConfirm("确定删除菜品吗?", "今日菜品?")
await delObjs(tid); try {
message.success('common.delSuccess'); await delObjs([tid])
selectTimeFood(); message.success("删除成功")
}; } catch (error) {
message.error("删除失败")
// 删除操作 }
// const handleDelete = async (ids: string[]) => { selectTimeFood()
// try { }
// await useMessageBox().confirm('此操作将永久删除');
// } catch {
// return;
// }
// try {
// await delObjs(ids);
// // getDataList();
// useMessage().success('删除成功');
// } catch (err: any) {
// useMessage().error(err.msg);
// }
// };
/** 初始化下拉框 */ /** 初始化下拉框 */
const merchantInit = async () => { const merchantInit = async () => {
// 获取下拉框选项 // 获取下拉框选项
const res = await pageJoin({ current: 1, size: 9999 }); const res = await pageJoin({ current: 1, size: 9999 })
merchantInfo.value = res.data.records; merchantInfo.value = res.data.records
//默认选中第一个 //默认选中第一个
if (merchantInfo.value) { if (merchantInfo.value) {
merchantId.value = merchantInfo.value[0].id; merchantId.value = merchantInfo.value[0].id
fetchData(); fetchData()
} }
}; }
onMounted(() => { onMounted(() => {
merchantInit(); merchantInit()
}); })
</script> </script>
<style lang="scss"> <style lang="scss">
+67 -40
View File
@@ -17,10 +17,23 @@
</el-row> </el-row>
<el-row> <el-row>
<div class="mb8" style="width: 100%"> <div class="mb8" style="width: 100%">
<el-button icon="folder-add" type="primary" class="ml10" @click="formDialogRef.openDialog()" v-auth="'canteen_canteenSpu_add'"> <el-button
icon="folder-add"
type="primary"
class="ml10"
@click="formDialogRef.openDialog()"
v-auth="'canteen_canteenSpu_add'"
>
新 增 新 增
</el-button> </el-button>
<el-button plain :disabled="multiple" icon="Delete" type="primary" v-auth="'canteen_canteenSpu_del'" @click="handleDelete(selectObjs)"> <el-button
plain
:disabled="multiple"
icon="Delete"
type="primary"
v-auth="'canteen_canteenSpu_del'"
@click="handleDelete(selectObjs)"
>
删 除 删 除
</el-button> </el-button>
<right-toolbar <right-toolbar
@@ -80,10 +93,23 @@
<el-table-column prop="createTime" label="创建时间" show-overflow-tooltip min-width="160" /> <el-table-column prop="createTime" label="创建时间" show-overflow-tooltip min-width="160" />
<el-table-column label="操作" width="150" fixed="right"> <el-table-column label="操作" width="150" fixed="right">
<template #default="scope"> <template #default="scope">
<el-button icon="edit-pen" text type="primary" v-auth="'canteen_canteenSpu_edit'" @click="formDialogRef?.openDialog(scope.row.id)"> <el-button
icon="edit-pen"
text
type="primary"
v-auth="'canteen_canteenSpu_edit'"
@click="formDialogRef?.openDialog(scope.row.id)"
>
编辑 编辑
</el-button> </el-button>
<el-button icon="delete" text type="primary" v-auth="'canteen_canteenSpu_del'" @click="handleDelete([scope.row.id])">删除</el-button> <el-button
icon="delete"
text
type="primary"
v-auth="'canteen_canteenSpu_del'"
@click="handleDelete([scope.row.id])"
>删除</el-button
>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@@ -96,78 +122,79 @@
</template> </template>
<script setup lang="ts" name="systemCanteenSpu"> <script setup lang="ts" name="systemCanteenSpu">
import { BasicTableProps, useTable } from '/@/hooks/table'; import { BasicTableProps, useTable } from "/@/hooks/table"
import { fetchList, delObjs } from '/@/api/canteen/canteenSpu'; import { fetchList, delObjs } from "/@/api/canteen/canteenSpu"
import { useMessage, useMessageBox } from '/@/hooks/message'; import { useMessage, useMessageBox } from "/@/hooks/message"
import { useDict } from '/@/hooks/dict'; import { useDict } from "/@/hooks/dict"
import { displayPrice } from '/@/utils/formatMoney'; import { displayPrice } from "/@/utils/formatMoney"
import { fetchList as getCanteenCategory } from '/@/api/canteen/canteenCategory'; import { fetchList as getCanteenCategory } from "/@/api/canteen/canteenCategory"
// 引入组件 // 引入组件
const FormDialog = defineAsyncComponent(() => import('./form.vue')); const FormDialog = defineAsyncComponent(() => import("./form.vue"))
const { spu_status } = useDict('spu_status'); const { spu_status } = useDict("spu_status")
// 定义变量内容 // 定义变量内容
const formDialogRef = ref(); const formDialogRef = ref()
// 搜索变量 // 搜索变量
const queryRef = ref(); const queryRef = ref()
const showSearch = ref(true); const showSearch = ref(true)
// 多选变量 // 多选变量
const selectObjs = ref([]) as any; const selectObjs = ref([]) as any
const multiple = ref(true); const multiple = ref(true)
const categoryOptions = ref<any>([]); // 商品分类选项 const categoryOptions = ref<any>([]) // 商品分类选项
const state: BasicTableProps = reactive<BasicTableProps>({ const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {}, queryForm: {},
pageList: fetchList, pageList: fetchList,
}); })
onMounted(async () => { onMounted(async () => {
try { try {
const res = await getCanteenCategory(); const res = await getCanteenCategory()
categoryOptions.value = res.data.records; categoryOptions.value = res.data.records
} catch (error) { } catch (error) {
categoryOptions.value = []; categoryOptions.value = []
} }
}); })
// table hook // table hook
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile, tableStyle } = useTable(state); const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile, tableStyle } =
useTable(state)
// 清空搜索条件 // 清空搜索条件
const resetQuery = () => { const resetQuery = () => {
// 清空搜索条件 // 清空搜索条件
queryRef.value?.resetFields(); queryRef.value?.resetFields()
// 清空多选 // 清空多选
selectObjs.value = []; selectObjs.value = []
getDataList(); getDataList()
}; }
// 导出excel // 导出excel
const exportExcel = () => { const exportExcel = () => {
downBlobFile('/canteen/canteenSpu/export', Object.assign(state.queryForm, { ids: selectObjs }), 'canteenSpu.xlsx'); downBlobFile("/canteen/canteenSpu/export", Object.assign(state.queryForm, { ids: selectObjs }), "canteenSpu.xlsx")
}; }
// 多选事件 // 多选事件
const selectionChangHandle = (objs: { id: string }[]) => { const selectionChangHandle = (objs: { id: string }[]) => {
selectObjs.value = objs.map(({ id }) => id); selectObjs.value = objs.map(({ id }) => id)
multiple.value = !objs.length; multiple.value = !objs.length
}; }
// 删除操作 // 删除操作
const handleDelete = async (ids: string[]) => { const handleDelete = async (ids: string[]) => {
try { try {
await useMessageBox().confirm('此操作将永久删除'); await useMessageBox().confirm("此操作将永久删除")
} catch { } catch {
return; return
} }
try { try {
await delObjs(ids); await delObjs(ids)
getDataList(); getDataList()
useMessage().success('删除成功'); useMessage().success("删除成功")
} catch (err: any) { } catch (err: any) {
useMessage().error(err.msg); useMessage().error(err.msg)
} }
}; }
</script> </script>