食堂进销
This commit is contained in:
1 parent
14373975aa
commit
1f493466a1
4 files changed
+31
-65
No files matched your search
@@ -8,6 +8,16 @@ export function fetchList(query?: Object) {
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
同步菜品到库存
|
||||
*/
|
||||
export function ansyncStock() {
|
||||
return request({
|
||||
url: '/canteen/canteenStock/canteen/ansync',
|
||||
method: 'post',
|
||||
})
|
||||
}
|
||||
|
||||
export function addObj(obj?: Object) {
|
||||
return request({
|
||||
url: '/canteen/canteenStock',
|
||||
|
||||
@@ -43,11 +43,8 @@
|
||||
</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']);
|
||||
|
||||
// 定义变量内容
|
||||
@@ -64,7 +61,7 @@ const form = reactive({
|
||||
inventoryLowerLimit: '',
|
||||
inventoryUpperLimit: '',
|
||||
itemId: '', // 存储商品ID,用于提交到库存API
|
||||
itemType: '1', // 假设 1 表示成品
|
||||
itemType: '2', // 固定为2
|
||||
stockId: '', // 存储库存记录ID
|
||||
});
|
||||
|
||||
@@ -106,8 +103,6 @@ const onSubmit = async () => {
|
||||
// 构建库存对象并提交
|
||||
const stockObj = {
|
||||
id: form.stockId, // 使用库存记录的ID
|
||||
itemId: form.id,
|
||||
itemType: form.itemType,
|
||||
baseStock: form.baseStock,
|
||||
currentStock: form.currentStock,
|
||||
inventoryUpperLimit: form.inventoryUpperLimit,
|
||||
@@ -116,11 +111,11 @@ const onSubmit = async () => {
|
||||
|
||||
console.log('准备提交到 canteenStock API:', stockObj);
|
||||
await putObj(stockObj);
|
||||
useMessage().success('修改成功 - 已使用canteenStock API');
|
||||
useMessage().success('修改成功');
|
||||
visible.value = false;
|
||||
emit('refresh');
|
||||
} catch (err: any) {
|
||||
console.error('canteenStock API错误:', err);
|
||||
console.error('错误', err);
|
||||
useMessage().error(err.msg);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
@@ -132,46 +127,15 @@ 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用于更新
|
||||
if (res.data) {
|
||||
const stockData = res.data;
|
||||
form.stockId = stockData.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('获取库存信息失败');
|
||||
|
||||
@@ -3,13 +3,9 @@
|
||||
<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()"
|
||||
<el-button icon="refresh" type="primary" class="ml10" @click="handleSyncStock"
|
||||
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;"
|
||||
@@ -22,7 +18,7 @@
|
||||
@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="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" />
|
||||
@@ -36,7 +32,6 @@
|
||||
<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>
|
||||
@@ -53,13 +48,12 @@
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table";
|
||||
import { fetchList, delObjs } from "/@/api/canteen/canteenStock";
|
||||
import { fetchErpList } from "/@/api/canteen/canteenSpu";
|
||||
import { ansyncStock } from "/@/api/canteen/canteenStock";
|
||||
import { useMessage, useMessageBox } from "/@/hooks/message";
|
||||
import { useDict } from '/@/hooks/dict';
|
||||
|
||||
// 引入组件
|
||||
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
|
||||
// 定义查询字典
|
||||
|
||||
// 定义变量内容
|
||||
const formDialogRef = ref()
|
||||
// 搜索变量
|
||||
@@ -68,6 +62,7 @@ const showSearch = ref(true)
|
||||
// 多选变量
|
||||
const selectObjs = ref([]) as any
|
||||
const multiple = ref(true)
|
||||
const loading = ref(false)
|
||||
|
||||
const state: BasicTableProps = reactive<BasicTableProps>({
|
||||
queryForm: {},
|
||||
@@ -104,20 +99,17 @@ const selectionChangHandle = (objs: { id: string }[]) => {
|
||||
multiple.value = !objs.length;
|
||||
};
|
||||
|
||||
// 删除操作
|
||||
const handleDelete = async (ids: string[]) => {
|
||||
// 同步库存
|
||||
const handleSyncStock = async () => {
|
||||
try {
|
||||
await useMessageBox().confirm('此操作将永久删除');
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await delObjs(ids);
|
||||
loading.value = true;
|
||||
await ansyncStock();
|
||||
useMessage().success('同步库存成功');
|
||||
getDataList();
|
||||
useMessage().success('删除成功');
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -108,7 +108,7 @@
|
||||
<el-table-column prop="name" label="菜品名称" min-width="200"/>
|
||||
<el-table-column label="菜品图片" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-image
|
||||
<preview-image
|
||||
v-if="row.picUrl"
|
||||
:src="row.picUrl"
|
||||
:preview-src-list="[row.picUrl]"
|
||||
@@ -127,7 +127,7 @@
|
||||
加载中
|
||||
</div>
|
||||
</template>
|
||||
</el-image>
|
||||
</preview-image>
|
||||
<div v-else class="w-[60px] h-[60px] flex items-center justify-center bg-[#f5f7fa] text-[#c0c4cc] text-xs">
|
||||
无图
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user