Merge branch 'master' of https://codeup.aliyun.com/bsdtec/biz-pc-cloud
This commit is contained in:
commit
6fb1e8cccc
4 files changed
+324
-10
No files matched your search
@@ -8,6 +8,15 @@ export function fetchList(query?: Object) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fetchErpList(query?: Object) {
|
||||||
|
return request({
|
||||||
|
url: '/canteen/canteenSpu/erp/page',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function fetchSimpleList(query?: Object) {
|
export function fetchSimpleList(query?: Object) {
|
||||||
return request({
|
return request({
|
||||||
url: '/canteen/canteenSpu/getCanteenSpuSimplePage',
|
url: '/canteen/canteenSpu/getCanteenSpuSimplePage',
|
||||||
|
|||||||
@@ -0,0 +1,187 @@
|
|||||||
|
<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="请输入菜品名称" disabled/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :span="12" class="mb20">
|
||||||
|
<el-form-item label="期初库存" prop="baseStock">
|
||||||
|
<el-input v-model="form.baseStock" placeholder="请输入期初库存"/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :span="12" class="mb20">
|
||||||
|
<el-form-item label="当前库存" prop="currentStock">
|
||||||
|
<el-input v-model="form.currentStock" placeholder="请输入当前库存"/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :span="12" class="mb20">
|
||||||
|
<el-form-item label="库存下限" prop="inventoryLowerLimit">
|
||||||
|
<el-input v-model="form.inventoryLowerLimit" placeholder="请输入库存下限"/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="12" class="mb20">
|
||||||
|
<el-form-item label="库存上限" prop="inventoryUpperLimit">
|
||||||
|
<el-input v-model="form.inventoryUpperLimit" placeholder="请输入库存上限"/>
|
||||||
|
</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="CanteenErpMaterialDialog">
|
||||||
|
import { useDict } from '/@/hooks/dict';
|
||||||
|
import { useMessage } from "/@/hooks/message";
|
||||||
|
import { getObj, putObj, fetchList } from '/@/api/canteen/canteenStock';
|
||||||
|
import { getObj as getErpObj } from '/@/api/canteen/canteenErpMaterial';
|
||||||
|
import { rule } from '/@/utils/validate';
|
||||||
|
const emit = defineEmits(['refresh']);
|
||||||
|
|
||||||
|
// 定义变量内容
|
||||||
|
const dataFormRef = ref();
|
||||||
|
const visible = ref(false);
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
// 提交表单数据
|
||||||
|
const form = reactive({
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
baseStock: '',
|
||||||
|
currentStock: '',
|
||||||
|
inventoryLowerLimit: '',
|
||||||
|
inventoryUpperLimit: '',
|
||||||
|
itemId: '', // 存储商品ID,用于提交到库存API
|
||||||
|
itemType: '1', // 假设 1 表示成品
|
||||||
|
stockId: '', // 存储库存记录ID
|
||||||
|
});
|
||||||
|
|
||||||
|
// 定义校验规则
|
||||||
|
const dataRules = ref({
|
||||||
|
baseStock: [{required: true, message: '期初库存不能为空', trigger: 'blur'}],
|
||||||
|
currentStock: [{required: true, message: '当前库存不能为空', trigger: 'blur'}],
|
||||||
|
inventoryLowerLimit: [{required: true, message: '库存下限不能为空', trigger: 'blur'}],
|
||||||
|
inventoryUpperLimit: [{required: true, message: '库存上限不能为空', trigger: 'blur'}],
|
||||||
|
});
|
||||||
|
|
||||||
|
// 打开弹窗
|
||||||
|
const openDialog = (id: string, name: string = '') => {
|
||||||
|
visible.value = true;
|
||||||
|
form.id = '';
|
||||||
|
form.name = name; // 直接设置菜品名称
|
||||||
|
|
||||||
|
// 重置表单数据
|
||||||
|
nextTick(() => {
|
||||||
|
dataFormRef.value?.resetFields();
|
||||||
|
form.name = name; // 重置后再次设置菜品名称
|
||||||
|
console.log('设置菜品名称:', name); // 添加调试日志
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取 canteenErpMaterial 信息
|
||||||
|
if (id) {
|
||||||
|
form.id = id;
|
||||||
|
getErpMaterialAndStock(id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 提交
|
||||||
|
const onSubmit = async () => {
|
||||||
|
const valid = await dataFormRef.value.validate().catch(() => {});
|
||||||
|
if (!valid) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
// 构建库存对象并提交
|
||||||
|
const stockObj = {
|
||||||
|
id: form.stockId, // 使用库存记录的ID
|
||||||
|
itemId: form.id,
|
||||||
|
itemType: form.itemType,
|
||||||
|
baseStock: form.baseStock,
|
||||||
|
currentStock: form.currentStock,
|
||||||
|
inventoryUpperLimit: form.inventoryUpperLimit,
|
||||||
|
inventoryLowerLimit: form.inventoryLowerLimit,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('准备提交到 canteenStock API:', stockObj);
|
||||||
|
await putObj(stockObj);
|
||||||
|
useMessage().success('修改成功 - 已使用canteenStock API');
|
||||||
|
visible.value = false;
|
||||||
|
emit('refresh');
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('canteenStock API错误:', err);
|
||||||
|
useMessage().error(err.msg);
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 初始化表单数据 - 获取商品信息和库存信息
|
||||||
|
const getErpMaterialAndStock = (id: string) => {
|
||||||
|
// 获取数据
|
||||||
|
loading.value = true;
|
||||||
|
|
||||||
|
// 获取商品信息
|
||||||
|
getObj(id).then((res: any) => {
|
||||||
|
// 只取单位等显示信息,保留传入的菜品名称
|
||||||
|
form.id = id;
|
||||||
|
|
||||||
|
// 通过商品ID查询对应的库存记录
|
||||||
|
getStockByItemId(id);
|
||||||
|
}).catch(err => {
|
||||||
|
useMessage().error('获取商品信息失败');
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 根据商品ID获取库存信息
|
||||||
|
const getStockByItemId = (itemId: string) => {
|
||||||
|
// 这里应该是根据商品ID获取库存记录
|
||||||
|
// 实际实现可能需要一个专门的API来查询
|
||||||
|
// 这里我们简化为直接根据参数构建查询条件
|
||||||
|
const params = {
|
||||||
|
itemId: itemId,
|
||||||
|
itemType: form.itemType
|
||||||
|
};
|
||||||
|
|
||||||
|
// 查询库存记录,根据实际API调整
|
||||||
|
fetchList(params).then((res: any) => {
|
||||||
|
if (res.data && res.data.records && res.data.records.length > 0) {
|
||||||
|
// 假设第一条记录是我们需要的
|
||||||
|
const stockData = res.data.records[0];
|
||||||
|
form.stockId = stockData.id; // 保存库存ID用于更新
|
||||||
|
form.baseStock = stockData.baseStock;
|
||||||
|
form.currentStock = stockData.currentStock;
|
||||||
|
form.inventoryUpperLimit = stockData.inventoryUpperLimit;
|
||||||
|
form.inventoryLowerLimit = stockData.inventoryLowerLimit;
|
||||||
|
} else {
|
||||||
|
// 没有找到库存记录,可能是新记录
|
||||||
|
form.stockId = '';
|
||||||
|
form.baseStock = '';
|
||||||
|
form.currentStock = '';
|
||||||
|
form.inventoryUpperLimit = '';
|
||||||
|
form.inventoryLowerLimit = '';
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
useMessage().error('获取库存信息失败');
|
||||||
|
}).finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 暴露变量
|
||||||
|
defineExpose({
|
||||||
|
openDialog
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
<template>
|
||||||
|
<div class="layout-padding">
|
||||||
|
<div class="layout-padding-auto layout-padding-view">
|
||||||
|
<el-row>
|
||||||
|
<div class="mb8" style="width: 100%">
|
||||||
|
<el-button icon="folder-add" type="primary" class="ml10" @click="formDialogRef.openDialog()"
|
||||||
|
v-auth="'canteen_canteenErpMaterial_add'">
|
||||||
|
新 增
|
||||||
|
</el-button>
|
||||||
|
<el-button plain :disabled="multiple" icon="Delete" type="primary"
|
||||||
|
v-auth="'canteen_canteenErpMaterial_del'" @click="handleDelete(selectObjs)">
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
<right-toolbar v-model:showSearch="showSearch" :export="'canteen_canteenErpMaterial_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="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="baseStock" label="期初库存" show-overflow-tooltip/>
|
||||||
|
<el-table-column prop="currentStock" label="总库存" show-overflow-tooltip/>
|
||||||
|
<el-table-column prop="inventoryLowerLimit" label="库存下限" show-overflow-tooltip/>
|
||||||
|
<el-table-column prop="inventoryUpperLimit" label="库存上限" show-overflow-tooltip/>
|
||||||
|
<el-table-column label="操作" width="150">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button icon="edit-pen" text type="primary" v-auth="'canteen_canteenErpMaterial_edit'"
|
||||||
|
@click="formDialogRef.openDialog(scope.row.id, scope.row.name)">编辑</el-button>
|
||||||
|
<el-button icon="delete" text type="primary" v-auth="'canteen_canteenErpMaterial_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="systemCanteenErpMaterial">
|
||||||
|
import { BasicTableProps, useTable } from "/@/hooks/table";
|
||||||
|
import { fetchList, delObjs } from "/@/api/canteen/canteenStock";
|
||||||
|
import { fetchErpList } from "/@/api/canteen/canteenSpu";
|
||||||
|
import { useMessage, useMessageBox } from "/@/hooks/message";
|
||||||
|
import { useDict } from '/@/hooks/dict';
|
||||||
|
|
||||||
|
// 引入组件
|
||||||
|
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
|
||||||
|
// 定义查询字典
|
||||||
|
|
||||||
|
// 定义变量内容
|
||||||
|
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: fetchErpList
|
||||||
|
})
|
||||||
|
|
||||||
|
// table hook
|
||||||
|
const {
|
||||||
|
getDataList,
|
||||||
|
currentChangeHandle,
|
||||||
|
sizeChangeHandle,
|
||||||
|
sortChangeHandle,
|
||||||
|
downBlobFile,
|
||||||
|
tableStyle
|
||||||
|
} = useTable(state)
|
||||||
|
|
||||||
|
// 清空搜索条件
|
||||||
|
const resetQuery = () => {
|
||||||
|
// 清空搜索条件
|
||||||
|
queryRef.value?.resetFields()
|
||||||
|
// 清空多选
|
||||||
|
selectObjs.value = []
|
||||||
|
getDataList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出excel
|
||||||
|
const exportExcel = () => {
|
||||||
|
downBlobFile('/canteen/canteenStock/export', Object.assign(state.queryForm, { ids: selectObjs }), 'canteenStock.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>
|
||||||
@@ -347,7 +347,6 @@ const confirmTemplateSelection = () => {
|
|||||||
newSelectedTemplates.forEach(template => {
|
newSelectedTemplates.forEach(template => {
|
||||||
const details = template.canteenProductionTemplateDetailList.map((item: any) => ({
|
const details = template.canteenProductionTemplateDetailList.map((item: any) => ({
|
||||||
...item,
|
...item,
|
||||||
dishId: template.dishId,
|
|
||||||
dishName: template.dishName,
|
dishName: template.dishName,
|
||||||
materialUnit: item.unit,
|
materialUnit: item.unit,
|
||||||
produceQuantity: 1,
|
produceQuantity: 1,
|
||||||
@@ -490,18 +489,14 @@ const submitForm = async () => {
|
|||||||
|
|
||||||
// 格式化生产详情列表,将食材按菜品分组
|
// 格式化生产详情列表,将食材按菜品分组
|
||||||
const formatProductionDetails = (details: any[]) => {
|
const formatProductionDetails = (details: any[]) => {
|
||||||
// 使用dishId作为键来分组,如果没有dishId,则使用dishName作为备选
|
|
||||||
const dishMap = new Map<string, any>()
|
const dishMap = new Map<string, any>()
|
||||||
|
|
||||||
// 按菜品分组
|
// 按菜品名称分组
|
||||||
details.forEach(item => {
|
details.forEach(item => {
|
||||||
// 使用dishId作为键,如果没有则使用dishName
|
if (!dishMap.has(item.dishName)) {
|
||||||
const key = item.dishId ? item.dishId.toString() : item.dishName
|
|
||||||
|
|
||||||
if (!dishMap.has(key)) {
|
|
||||||
// 创建新的菜品组
|
// 创建新的菜品组
|
||||||
dishMap.set(key, {
|
dishMap.set(item.dishName, {
|
||||||
dishId: item.dishId || null, // 确保有dishId,即使是null
|
dishId: item.dishId,
|
||||||
dishName: item.dishName,
|
dishName: item.dishName,
|
||||||
produceQuantity: item.produceQuantity,
|
produceQuantity: item.produceQuantity,
|
||||||
// 创建食材列表
|
// 创建食材列表
|
||||||
@@ -510,7 +505,7 @@ const formatProductionDetails = (details: any[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 将食材添加到对应菜品组的食材列表中
|
// 将食材添加到对应菜品组的食材列表中
|
||||||
const dish = dishMap.get(key)
|
const dish = dishMap.get(item.dishName)
|
||||||
dish.materialDetailList.push({
|
dish.materialDetailList.push({
|
||||||
materialId: item.materialId,
|
materialId: item.materialId,
|
||||||
materialName: item.materialName,
|
materialName: item.materialName,
|
||||||
|
|||||||
Reference in new issue
Block a user