修改每日菜谱
This commit is contained in:
1 parent
b4ff730fc8
commit
002f8ad6b1
6 files changed
+459
-336
No files matched your search
@@ -12,10 +12,14 @@
|
||||
<p v-else>未知类型</p>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="菜品" prop="spuId">
|
||||
<!-- <el-form-item label="菜品" prop="spuId">
|
||||
<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-form-item> -->
|
||||
|
||||
<el-form-item label="选择菜品">
|
||||
<el-button @click="handleClickSelect">选择菜品</el-button>
|
||||
</el-form-item>
|
||||
|
||||
<!-- <el-col :span="12" class="mb20">
|
||||
@@ -27,7 +31,12 @@
|
||||
|
||||
<h1 style="font-size: 16px; font-weight: bold; color: #000000; margin: 20px 0">预览图</h1>
|
||||
<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>
|
||||
|
||||
<template #footer>
|
||||
@@ -36,126 +45,219 @@
|
||||
<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
|
||||
</span>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="CanteenDailyMenuDialog">
|
||||
import { useDict } from '/@/hooks/dict';
|
||||
import { useMessage } from '/@/hooks/message';
|
||||
import { getObj, addObj, putObj } from '/@/api/canteen/canteenDailyMenu';
|
||||
import { selectFoodList } from '/@/api/canteen/canteenDailyMenu';
|
||||
import { rule } from '/@/utils/validate';
|
||||
import { useMessage } from "/@/hooks/message"
|
||||
import { rule } from "/@/utils/validate"
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table"
|
||||
import { useDict } from "/@/hooks/dict"
|
||||
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 foodData = ref<any>([]);
|
||||
const spuIds = ref([]);
|
||||
const spuImages = ref<string[]>([]);
|
||||
// 定义变量内容
|
||||
const dataFormRef = ref();
|
||||
const visible = ref(false);
|
||||
const loading = ref(false);
|
||||
// 定义字典
|
||||
const { daily_menu } = useDict('daily_menu');
|
||||
const imageBaseUrl = import.meta.env.VITE_IMAGE_BASE_PATH;
|
||||
const dataFormRef = ref()
|
||||
const visible = ref(false)
|
||||
const queryRef = ref()
|
||||
const selectObjs = ref([]) as any // 表格多选的数据
|
||||
const selectedList = ref<any>([])
|
||||
const loading = ref(false)
|
||||
const selectDialogVisible = ref<boolean>(false) // 选择菜品对话框开关
|
||||
const { spu_status } = useDict("spu_status")
|
||||
const categoryOptions = ref<any>([]) // 商品分类选项
|
||||
const imageBaseUrl = import.meta.env.VITE_IMAGE_BASE_PATH
|
||||
const dataRules = ref({}) // 定义校验规则
|
||||
|
||||
// 提交表单数据
|
||||
const form = reactive<any>({
|
||||
id: '',
|
||||
startTime: '',
|
||||
spuId: '',
|
||||
hourType: '',
|
||||
merchantId: '',
|
||||
deptId: '',
|
||||
spuIds: '',
|
||||
});
|
||||
id: "",
|
||||
startTime: "",
|
||||
hourType: "",
|
||||
merchantId: "",
|
||||
})
|
||||
// 选择的菜品的id数组
|
||||
const spuIds = computed(() => {
|
||||
return selectedList.value?.map((item: any) => item.id)
|
||||
})
|
||||
|
||||
// 定义校验规则
|
||||
const dataRules = ref({});
|
||||
const state: BasicTableProps = reactive<BasicTableProps>({
|
||||
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) => {
|
||||
visible.value = true;
|
||||
form.id = '';
|
||||
visible.value = true
|
||||
form.id = ""
|
||||
|
||||
// 重置表单数据
|
||||
nextTick(() => {
|
||||
dataFormRef.value?.resetFields();
|
||||
});
|
||||
dataFormRef.value?.resetFields()
|
||||
selectObjs.value = []
|
||||
selectedList.value = []
|
||||
state.dataList = []
|
||||
|
||||
// 获取canteenDailyMenu信息
|
||||
if (id) {
|
||||
form.id = id;
|
||||
getcanteenDailyMenuData(id);
|
||||
form.id = id
|
||||
getcanteenDailyMenuData(id)
|
||||
}
|
||||
if (time) {
|
||||
form.startTime = time;
|
||||
form.startTime = time
|
||||
}
|
||||
if (hourType) {
|
||||
form.hourType = 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: 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;
|
||||
}
|
||||
};
|
||||
form.merchantId = merchantId
|
||||
}
|
||||
|
||||
// 初始化表单数据
|
||||
const getcanteenDailyMenuData = (id: string) => {
|
||||
// 获取数据
|
||||
loading.value = true;
|
||||
loading.value = true
|
||||
getObj(id)
|
||||
.then((res: any) => {
|
||||
Object.assign(form, res.data);
|
||||
Object.assign(form, res.data)
|
||||
})
|
||||
.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({
|
||||
openDialog,
|
||||
});
|
||||
/** 初始化 **/
|
||||
onMounted(async () => {
|
||||
// 获取菜品列表
|
||||
let axiosResponse = await selectFoodList();
|
||||
foodData.value = axiosResponse.data;
|
||||
});
|
||||
})
|
||||
</script>
|
||||
@@ -26,171 +26,166 @@
|
||||
<tr>
|
||||
<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">
|
||||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
<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">
|
||||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
<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">
|
||||
<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>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 编辑、新增 -->
|
||||
<form-dialog ref="formDialogRef" @success="selectTimeFood" />
|
||||
<form-dialog ref="formDialogRef" @refresh="selectTimeFood" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="systemCanteenDailyMenu">
|
||||
import { delObjs, selectTimeFoodApi, selectWeekInfo } from '/@/api/canteen/canteenDailyMenu';
|
||||
import { useMessage, useMessageBox } from '/@/hooks/message';
|
||||
import { useDict } from '/@/hooks/dict';
|
||||
import { pageJoin } from '/@/api/wallet/mch-manage';
|
||||
import { delObjs, selectTimeFoodApi, selectWeekInfo } from "/@/api/canteen/canteenDailyMenu"
|
||||
import { useMessage, useMessageBox } from "/@/hooks/message"
|
||||
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 foodData2 = ref<any>({});
|
||||
const foodData3 = ref<any>({});
|
||||
const foodData1 = ref<any>({})
|
||||
const foodData2 = ref<any>({})
|
||||
const foodData3 = ref<any>({})
|
||||
|
||||
let timedata = '';
|
||||
let isActive = ref(-1);
|
||||
let timedata = ""
|
||||
let isActive = ref(-1)
|
||||
const weekParams = reactive({
|
||||
index: 0,
|
||||
});
|
||||
})
|
||||
const weekData = reactive({
|
||||
data: [],
|
||||
}); //时间数组
|
||||
const merchantId = ref();
|
||||
const merchantInfo = ref<any>([]);
|
||||
}) //时间数组
|
||||
const merchantId = ref()
|
||||
const merchantInfo = ref<any>([])
|
||||
|
||||
const addFood = async (hourType: number) => {
|
||||
if (!merchantId.value) {
|
||||
useMessage().error('请选择商户再进行新增');
|
||||
return;
|
||||
useMessage().error("请选择商户再进行新增")
|
||||
return
|
||||
}
|
||||
//打开新增框
|
||||
formDialogRef.value.openDialog(null, timedata, hourType, merchantId.value);
|
||||
};
|
||||
formDialogRef.value.openDialog(null, timedata, hourType, merchantId.value)
|
||||
}
|
||||
//选中具体时间数据
|
||||
const timeClick = async (time: string, index: number) => {
|
||||
//数据查询操作
|
||||
if (time) {
|
||||
//时间处理
|
||||
time = time.substring(0, time.indexOf('('));
|
||||
timedata = time;
|
||||
time = time.substring(0, time.indexOf("("))
|
||||
timedata = time
|
||||
//选中
|
||||
isActive.value = index;
|
||||
selectTimeFood();
|
||||
isActive.value = index
|
||||
selectTimeFood()
|
||||
}
|
||||
};
|
||||
}
|
||||
//切换时间
|
||||
const addClick = async (index: number) => {
|
||||
//数据值操作
|
||||
weekParams.index = weekParams.index + index;
|
||||
fetchData();
|
||||
};
|
||||
weekParams.index = weekParams.index + index
|
||||
fetchData()
|
||||
}
|
||||
|
||||
watch(merchantId, () => {
|
||||
fetchData();
|
||||
});
|
||||
fetchData()
|
||||
})
|
||||
|
||||
const fetchData = async () => {
|
||||
const weekDataRes = await selectWeekInfo(weekParams);
|
||||
weekData.data = weekDataRes.data;
|
||||
isActive.value = 0;
|
||||
timedata = weekData.data[0];
|
||||
const weekDataRes = await selectWeekInfo(weekParams)
|
||||
weekData.data = weekDataRes.data
|
||||
isActive.value = 0
|
||||
timedata = weekData.data[0]
|
||||
// 时间格式
|
||||
timedata = timedata.substring(0, timedata.indexOf('('));
|
||||
selectTimeFood();
|
||||
};
|
||||
timedata = timedata.substring(0, timedata.indexOf("("))
|
||||
selectTimeFood()
|
||||
}
|
||||
|
||||
const selectTimeFood = async () => {
|
||||
foodData1.value = [];
|
||||
foodData2.value = [];
|
||||
foodData3.value = [];
|
||||
foodData1.value = []
|
||||
foodData2.value = []
|
||||
foodData3.value = []
|
||||
let params = {
|
||||
time: timedata,
|
||||
merchantId: merchantId.value,
|
||||
};
|
||||
}
|
||||
//最大长度
|
||||
let count = 0;
|
||||
const result = await selectTimeFoodApi(params);
|
||||
let count = 0
|
||||
const result = await selectTimeFoodApi(params)
|
||||
result.data.forEach((r: any) => {
|
||||
if (r.dailyMenuVOS.length > count) {
|
||||
count = r.dailyMenuVOS.length;
|
||||
count = r.dailyMenuVOS.length
|
||||
}
|
||||
switch (r.hourType) {
|
||||
case 1:
|
||||
foodData1.value = r.dailyMenuVOS;
|
||||
break;
|
||||
foodData1.value = r.dailyMenuVOS
|
||||
break
|
||||
case 2:
|
||||
foodData2.value = r.dailyMenuVOS;
|
||||
break;
|
||||
foodData2.value = r.dailyMenuVOS
|
||||
break
|
||||
case 3:
|
||||
foodData3.value = r.dailyMenuVOS;
|
||||
break;
|
||||
foodData3.value = r.dailyMenuVOS
|
||||
break
|
||||
}
|
||||
});
|
||||
};
|
||||
/** 删除数据源按钮 */
|
||||
})
|
||||
}
|
||||
|
||||
// 删除菜品
|
||||
const delteData = async (tid: number) => {
|
||||
await message.delConfirm('确定删除菜品吗?', '今日菜品?');
|
||||
await delObjs(tid);
|
||||
message.success('common.delSuccess');
|
||||
selectTimeFood();
|
||||
};
|
||||
|
||||
// 删除操作
|
||||
// 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);
|
||||
// }
|
||||
// };
|
||||
await message.delConfirm("确定删除菜品吗?", "今日菜品?")
|
||||
try {
|
||||
await delObjs([tid])
|
||||
message.success("删除成功")
|
||||
} catch (error) {
|
||||
message.error("删除失败")
|
||||
}
|
||||
selectTimeFood()
|
||||
}
|
||||
|
||||
/** 初始化下拉框 */
|
||||
const merchantInit = async () => {
|
||||
// 获取下拉框选项
|
||||
const res = await pageJoin({ current: 1, size: 9999 });
|
||||
merchantInfo.value = res.data.records;
|
||||
const res = await pageJoin({ current: 1, size: 9999 })
|
||||
merchantInfo.value = res.data.records
|
||||
|
||||
//默认选中第一个
|
||||
if (merchantInfo.value) {
|
||||
merchantId.value = merchantInfo.value[0].id;
|
||||
fetchData();
|
||||
merchantId.value = merchantInfo.value[0].id
|
||||
fetchData()
|
||||
}
|
||||
};
|
||||
}
|
||||
onMounted(() => {
|
||||
merchantInit();
|
||||
});
|
||||
merchantInit()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
@@ -17,10 +17,23 @@
|
||||
</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_canteenSpu_add'">
|
||||
<el-button
|
||||
icon="folder-add"
|
||||
type="primary"
|
||||
class="ml10"
|
||||
@click="formDialogRef.openDialog()"
|
||||
v-auth="'canteen_canteenSpu_add'"
|
||||
>
|
||||
新 增
|
||||
</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>
|
||||
<right-toolbar
|
||||
@@ -80,10 +93,23 @@
|
||||
<el-table-column prop="createTime" label="创建时间" show-overflow-tooltip min-width="160" />
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<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 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>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -96,78 +122,79 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="systemCanteenSpu">
|
||||
import { BasicTableProps, useTable } from '/@/hooks/table';
|
||||
import { fetchList, delObjs } from '/@/api/canteen/canteenSpu';
|
||||
import { useMessage, useMessageBox } from '/@/hooks/message';
|
||||
import { useDict } from '/@/hooks/dict';
|
||||
import { displayPrice } from '/@/utils/formatMoney';
|
||||
import { fetchList as getCanteenCategory } from '/@/api/canteen/canteenCategory';
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table"
|
||||
import { fetchList, delObjs } from "/@/api/canteen/canteenSpu"
|
||||
import { useMessage, useMessageBox } from "/@/hooks/message"
|
||||
import { useDict } from "/@/hooks/dict"
|
||||
import { displayPrice } from "/@/utils/formatMoney"
|
||||
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 showSearch = ref(true);
|
||||
const queryRef = ref()
|
||||
const showSearch = ref(true)
|
||||
// 多选变量
|
||||
const selectObjs = ref([]) as any;
|
||||
const multiple = ref(true);
|
||||
const categoryOptions = ref<any>([]); // 商品分类选项
|
||||
const selectObjs = ref([]) as any
|
||||
const multiple = ref(true)
|
||||
const categoryOptions = ref<any>([]) // 商品分类选项
|
||||
|
||||
const state: BasicTableProps = reactive<BasicTableProps>({
|
||||
queryForm: {},
|
||||
pageList: fetchList,
|
||||
});
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const res = await getCanteenCategory();
|
||||
categoryOptions.value = res.data.records;
|
||||
const res = await getCanteenCategory()
|
||||
categoryOptions.value = res.data.records
|
||||
} catch (error) {
|
||||
categoryOptions.value = [];
|
||||
categoryOptions.value = []
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
// table hook
|
||||
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile, tableStyle } = useTable(state);
|
||||
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile, tableStyle } =
|
||||
useTable(state)
|
||||
|
||||
// 清空搜索条件
|
||||
const resetQuery = () => {
|
||||
// 清空搜索条件
|
||||
queryRef.value?.resetFields();
|
||||
queryRef.value?.resetFields()
|
||||
// 清空多选
|
||||
selectObjs.value = [];
|
||||
getDataList();
|
||||
};
|
||||
selectObjs.value = []
|
||||
getDataList()
|
||||
}
|
||||
|
||||
// 导出excel
|
||||
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 }[]) => {
|
||||
selectObjs.value = objs.map(({ id }) => id);
|
||||
multiple.value = !objs.length;
|
||||
};
|
||||
selectObjs.value = objs.map(({ id }) => id)
|
||||
multiple.value = !objs.length
|
||||
}
|
||||
|
||||
// 删除操作
|
||||
const handleDelete = async (ids: string[]) => {
|
||||
try {
|
||||
await useMessageBox().confirm('此操作将永久删除');
|
||||
await useMessageBox().confirm("此操作将永久删除")
|
||||
} catch {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await delObjs(ids);
|
||||
getDataList();
|
||||
useMessage().success('删除成功');
|
||||
await delObjs(ids)
|
||||
getDataList()
|
||||
useMessage().success("删除成功")
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg);
|
||||
useMessage().error(err.msg)
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user