引入包厢,完善每日菜谱

This commit is contained in:
zjf committed 2024-12-16 16:24:12 +08:00
1 parent a912f3006a
commit af6425ddea
7 files changed
+401 -84

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
import request from "/@/utils/request"
export function fetchList(query?: Object) {
return request({
url: '/canteen/boxesInfo/page',
method: 'get',
params: query
})
}
export function addObj(obj?: Object) {
return request({
url: '/canteen/boxesInfo',
method: 'post',
data: obj
})
}
export function getObj(id?: string) {
return request({
url: '/canteen/boxesInfo/' + id,
method: 'get'
})
}
export function delObjs(ids?: Object) {
return request({
url: '/canteen/boxesInfo',
method: 'delete',
data: ids
})
}
export function putObj(obj?: Object) {
return request({
url: '/canteen/boxesInfo',
method: 'put',
data: obj
})
}
+1
View File
@@ -64,3 +64,4 @@ export function selectTimeFoodApi(query?: Object) {
params: query
})
}
+13
View File
@@ -39,3 +39,16 @@ export function putObj(obj?: Object) {
})
}
/**
* 商户下拉
* @param type
*/
export function selectMerchantList(type?: string) {
return request({
url: '/canteen/merchantInfo/selectMerchantList',
method: 'get',
params:{
type:type
}
})
}
+148
View File
@@ -0,0 +1,148 @@
<template>
<el-dialog :title="form.id ? '编辑' : '新增'" v-model="visible"
:close-on-click-modal="false" draggable>
<el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="90px" v-loading="loading">
<el-row :gutter="24">
<el-col :span="12" class="mb20">
<el-form-item label="包厢名称" prop="name">
<el-input v-model="form.name" placeholder="请输入包厢名称"/>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="容纳人数" prop="capacity">
<el-input v-model="form.capacity" placeholder="请输入容纳人数"/>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="包厢描述" prop="description">
<editor v-if="visible" v-model:get-html="form.description" placeholder="请输入包厢描述"></editor>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="包厢地址" prop="address">
<el-input type="textarea" v-model="form.address" placeholder="请输入包厢地址"/>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="包厢图片" prop="images">
<upload-img v-model="form.images"></upload-img>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="包厢状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio :label="item.value" v-for="(item, index) in boxes_status" border :key="index">{{ item.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="商户id" prop="merchantId">
<el-select v-model="form.merchantId" placeholder="请选择商户id">
<el-option label="请选择">0</el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts" name="BoxesInfoDialog">
import { useDict } from '/@/hooks/dict';
import { useMessage } from "/@/hooks/message";
import { getObj, addObj, putObj } from '/@/api/canteen/boxesInfo'
import { rule } from '/@/utils/validate';
const emit = defineEmits(['refresh']);
// 定义变量内容
const dataFormRef = ref();
const visible = ref(false)
const loading = ref(false)
// 定义字典
const { boxes_status } = useDict('boxes_status')
// 提交表单数据
const form = reactive({
id:'',
name: '',
capacity: '',
description: '',
address: '',
images: '',
status: '',
merchantId: '',
});
// 定义校验规则
const dataRules = ref({
name: [{required: true, message: '包厢名称不能为空', trigger: 'blur'}],
capacity: [{required: true, message: '容纳人数不能为空', trigger: 'blur'}, { validator: rule.number, trigger: 'blur' }],
images: [{required: true, message: '包厢图片不能为空', trigger: 'blur'}],
})
// 打开弹窗
const openDialog = (id: string) => {
visible.value = true
form.id = ''
// 重置表单数据
nextTick(() => {
dataFormRef.value?.resetFields();
});
// 获取boxesInfo信息
if (id) {
form.id = id
getboxesInfoData(id)
}
};
// 提交
const onSubmit = async () => {
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 getboxesInfoData = (id: string) => {
// 获取数据
loading.value = true
getObj(id).then((res: any) => {
Object.assign(form, res.data)
}).finally(() => {
loading.value = false
})
};
// 暴露变量
defineExpose({
openDialog
});
</script>
+138
View File
@@ -0,0 +1,138 @@
<template>
<div class="layout-padding">
<div class="layout-padding-auto layout-padding-view">
<el-row v-show="showSearch">
<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>
<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-row>
<div class="mb8" style="width: 100%">
<el-button icon="folder-add" type="primary" class="ml10" @click="formDialogRef.openDialog()"
v-auth="'canteen_boxesInfo_add'">
新 增
</el-button>
<el-button plain :disabled="multiple" icon="Delete" type="primary"
v-auth="'canteen_boxesInfo_del'" @click="handleDelete(selectObjs)">
删除
</el-button>
<right-toolbar v-model:showSearch="showSearch" :export="'canteen_boxesInfo_export'"
@exportExcel="exportExcel" class="ml10 mr20" style="float: right;"
@queryTable="getDataList"></right-toolbar>
</div>
</el-row>
<el-table :data="state.dataList" v-loading="state.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="40" />
<el-table-column prop="name" label="包厢名称" show-overflow-tooltip/>
<el-table-column prop="capacity" label="容纳人数" show-overflow-tooltip/>
<el-table-column prop="description" label="包厢描述" show-overflow-tooltip/>
<el-table-column prop="address" label="包厢地址" show-overflow-tooltip/>
<el-table-column prop="images" label="包厢图片" show-overflow-tooltip/>
<el-table-column prop="status" label="包厢状态" show-overflow-tooltip>
<template #default="scope">
<dict-tag :options="boxes_status" :value="scope.row.status"></dict-tag>
</template>
</el-table-column>
<el-table-column prop="price" label="包厢价格单位分" show-overflow-tooltip/>
<el-table-column prop="merchantId" label="商户id" show-overflow-tooltip/>
<el-table-column label="操作" width="150">
<template #default="scope">
<el-button icon="edit-pen" text type="primary" v-auth="'canteen_boxesInfo_edit'"
@click="formDialogRef.openDialog(scope.row.id)">编辑</el-button>
<el-button icon="delete" text type="primary" v-auth="'canteen_boxesInfo_del'" @click="handleDelete([scope.row.id])">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
</div>
<!-- 编辑、新增 -->
<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />
</div>
</template>
<script setup lang="ts" name="systemBoxesInfo">
import { BasicTableProps, useTable } from "/@/hooks/table";
import { fetchList, delObjs } from "/@/api/canteen/boxesInfo";
import { useMessage, useMessageBox } from "/@/hooks/message";
import { useDict } from '/@/hooks/dict';
// 引入组件
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
// 定义查询字典
const { boxes_status } = useDict('boxes_status')
// 定义变量内容
const formDialogRef = ref()
// 搜索变量
const queryRef = ref()
const showSearch = ref(true)
// 多选变量
const selectObjs = ref([]) as any
const multiple = ref(true)
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {},
pageList: fetchList
})
// table hook
const {
getDataList,
currentChangeHandle,
sizeChangeHandle,
sortChangeHandle,
downBlobFile,
tableStyle
} = useTable(state)
// 清空搜索条件
const resetQuery = () => {
// 清空搜索条件
queryRef.value?.resetFields()
// 清空多选
selectObjs.value = []
getDataList()
}
// 导出excel
const exportExcel = () => {
downBlobFile('/canteen/boxesInfo/export', Object.assign(state.queryForm, { ids: selectObjs }), 'boxesInfo.xlsx')
}
// 多选事件
const selectionChangHandle = (objs: { id: string }[]) => {
selectObjs.value = objs.map(({ id }) => id);
multiple.value = !objs.length;
};
// 删除操作
const handleDelete = async (ids: string[]) => {
try {
await useMessageBox().confirm('此操作将永久删除');
} catch {
return;
}
try {
await delObjs(ids);
getDataList();
useMessage().success('删除成功');
} catch (err: any) {
useMessage().error(err.msg);
}
};
</script>
+34 -5
View File
@@ -9,9 +9,9 @@
</el-form-item>
<el-form-item label="时间" prop="hourType">
<p v-if="form.hourType === 1">早餐</p>
<p v-else-if="form.hourType === 2">午餐</p>
<p v-else-if="form.hourType === 3">晚餐</p>
<p v-if="form.hourType == 1">早餐</p>
<p v-else-if="form.hourType == 2">午餐</p>
<p v-else-if="form.hourType == 3">晚餐</p>
<p v-else>未知类型</p>
</el-form-item>
@@ -49,6 +49,7 @@ const emit = defineEmits(['refresh']);
//业务变量
const foodData = ref([])
const spuIds = ref([])
const spuImages = ref([])
// 定义变量内容
const dataFormRef = ref();
const visible = ref(false)
@@ -64,13 +65,14 @@ const form = reactive({
hourType: '',
merchantId: '',
deptId: '',
spuIds:''
});
// 定义校验规则
const dataRules = ref({})
// 打开弹窗
const openDialog = (id: string) => {
const openDialog = (id: string,time?: string, hourType?: number,merchantId?:number) => {
visible.value = true
form.id = ''
@@ -84,10 +86,37 @@ const openDialog = (id: string) => {
form.id = id
getcanteenDailyMenuData(id)
}
};
if (time) {
form.startTime = time
}
if (hourType) {
form.hourType = hourType
}
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) => {
if (sData.id?.toString() === data) {
spuImages.value.push(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;
+26 -79
View File
@@ -1,4 +1,5 @@
<template>
<div class="layout-padding">
<div style="margin-left: 4.5%;margin-top: 1.5%">
<el-select
v-model="merchantId"
@@ -51,16 +52,16 @@
</table>
</div>
<!-- 编辑、新增 -->
<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />
<form-dialog ref="formDialogRef" @success="selectTimeFood" />
</div>
</template>
<script setup lang="ts" name="systemCanteenDailyMenu">
import { BasicTableProps, useTable } from "/@/hooks/table";
import { fetchList, delObjs ,selectTimeFoodApi,selectWeekInfo,} from "/@/api/canteen/canteenDailyMenu";
import { delObjs ,selectTimeFoodApi,selectWeekInfo,} from "/@/api/canteen/canteenDailyMenu";
import { useMessage, useMessageBox } from "/@/hooks/message";
import { useDict } from '/@/hooks/dict';
import {selectMerchantList} from "/@/api/canteen/merchantInfo";
// 引入组件
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
@@ -69,19 +70,9 @@ const FormDialog = defineAsyncComponent(() => import('./form.vue'));
const { daily_menu } = useDict('daily_menu')
// 定义变量内容
const formDialogRef = ref()
// 搜索变量
const queryRef = ref()
const showSearch = ref(true)
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
// 多选变量
const selectObjs = ref([]) as any
const multiple = ref(true)
const loading = ref(true) // 列表的加载中
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {},
pageList: fetchList
})
// ---------新增业务变量
const message = useMessage() // 消息弹窗
const weekData = reactive({
@@ -100,38 +91,17 @@ const merchantStatus = ref(true)
const merchantInfo = ref([])
let tableWitch = 1000
// table hook
const {
getDataList,
currentChangeHandle,
sizeChangeHandle,
sortChangeHandle,
downBlobFile,
tableStyle
} = useTable(state)
const openForm = (
type: string,
id?: number,
time?: string,
hourType?: number,
merchantId?: number
) => {
formDialogRef.value.open(type, id, time, hourType, merchantId)
}
const addFood = async (hourType: number) => {
if (!merchantId.value) {
useMessage().error('请选择商户再进行新增')
return
}
try {
//打开新增框
openForm('create', undefined, timedata, hourType, merchantId.value)
} catch {}
formDialogRef.value.openDialog(null,timedata,hourType,merchantId.value)
}
//选中具体时间数据
const timeClick = async (time: string, index: number) => {
try {
//数据查询操作
if (time) {
//时间处理
@@ -141,30 +111,26 @@ const timeClick = async (time: string, index: number) => {
isActive.value = index
selectTimeFood()
}
} catch {}
}
//切换时间
const addClick = async (index: number) => {
try {
//数据值操作
weekParams.index = weekParams.index + index
fetchData()
} catch {}
}
const merchantSelect = async () => {
// getList()
fetchData()
}
const fetchData = async () => {
try {
let weekDataRes= await selectWeekInfo(weekParams);
console.log(weekDataRes)
weekData.data = weekDataRes.data
isActive.value = 0
timedata = weekData.data[0]
//时间格式
timedata = timedata.substring(0, timedata.indexOf('('))
selectTimeFood()
} catch (error) {
console.error('Error fetching data:', error)
// 在这里处理错误,比如设置错误信息等
}
}
const selectTimeFood = async () => {
@@ -172,7 +138,6 @@ const selectTimeFood = async () => {
foodData2.value = []
foodData3.value = []
tableWitch = 1000
try {
let params = {
time: timedata,
merchantId: merchantId.value
@@ -201,36 +166,17 @@ const selectTimeFood = async () => {
} else {
tableWitch = 600
}
} catch (error) {
console.error('Error fetching data:', error)
// 在这里处理错误,比如设置错误信息等
}
}
/** 删除数据源按钮 */
const delteData = async (tid: number) => {
try {
await message.delConfirm('确定删除菜品吗?')
await delObjs(tid)
message.success(('common.delSuccess'))
selectTimeFood()
} catch {}
}
// 清空搜索条件
const resetQuery = () => {
// 清空搜索条件
queryRef.value?.resetFields()
// 清空多选
selectObjs.value = []
getDataList()
}
// 多选事件
const selectionChangHandle = (objs: { id: string }[]) => {
selectObjs.value = objs.map(({ id }) => id);
multiple.value = !objs.length;
};
// 删除操作
const handleDelete = async (ids: string[]) => {
@@ -242,7 +188,7 @@ const handleDelete = async (ids: string[]) => {
try {
await delObjs(ids);
getDataList();
// getDataList();
useMessage().success('删除成功');
} catch (err: any) {
useMessage().error(err.msg);
@@ -252,7 +198,7 @@ const handleDelete = async (ids: string[]) => {
// const getList = async () => {
// loading.value = true
// try {
// const data = await fetchData(queryParams)
// const data = await fetchList(queryParams)
// list.value = data.list
// total.value = data.total
// } finally {
@@ -263,21 +209,22 @@ const handleDelete = async (ids: string[]) => {
/** 初始化下拉框 */
const merchantInit = async () => {
// 获取下拉框
// merchantInfo.value = await ManageApi.selectMerchantList()
// //默认选中第一个
// if (merchantInfo.value) {
// merchantId.value = merchantInfo.value[0].id
// if (merchantInfo.value.length > 1) {
// merchantStatus.value = false
// }
// getList()
let res = await selectMerchantList("1")
merchantInfo.value=res.data
//默认选中第一个
if (merchantInfo.value) {
merchantId.value = merchantInfo.value[0].id
if (merchantInfo.value.length > 1) {
merchantStatus.value = false
}
// getList()
}
}
/** 初始化 **/
onMounted(() => {
fetchData()
// merchantInit()
merchantInit()
})
</script>