食堂进销
This commit is contained in:
1 parent
7f1cfdb0e7
commit
7fa87b6ebd
5 files changed
+356
-132
No files matched your search
@@ -8,6 +8,14 @@ export function fetchList(query?: Object) {
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchGetSelectTemplatePage(query?: Object) {
|
||||
return request({
|
||||
url: '/canteen/canteenProductionTemplate/getSelectTemplatePage',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
export function addObj(obj?: Object) {
|
||||
return request({
|
||||
url: '/canteen/canteenProductionTemplate',
|
||||
|
||||
@@ -1,134 +1,359 @@
|
||||
<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="productionTime">
|
||||
<el-input v-model="form.productionTime" placeholder="请输入加工日期"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-dialog
|
||||
:title="form.id ? '编辑生产记录' : '新增生产记录'"
|
||||
v-model="visible"
|
||||
width="1300px"
|
||||
:close-on-click-modal="false"
|
||||
draggable
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-width="120px"
|
||||
v-loading="loading"
|
||||
>
|
||||
<!-- 主表信息 -->
|
||||
<el-row :gutter="24">
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="加工日期" prop="productionTime">
|
||||
<el-date-picker
|
||||
v-model="form.productionTime"
|
||||
type="date"
|
||||
placeholder="选择日期"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
:disabled-date="disabledDate"
|
||||
class="w-full"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="加工人" prop="handlerUser">
|
||||
<el-input v-model="form.handlerUser" placeholder="请输入加工人"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="加工批次" prop="recordCode">
|
||||
<el-input v-model="form.recordCode" placeholder="请输入加工批次"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="生产模板">
|
||||
<div style="display: flex; align-items: center;">
|
||||
<el-button @click="openTemplateDialog">选择生产模板</el-button>
|
||||
<span v-if="selectedTemplates.length" style="margin-left: 12px;">
|
||||
已选{{ selectedTemplates.length }}个模板
|
||||
</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="加工人" prop="handlerUser">
|
||||
<el-input v-model="form.handlerUser" placeholder="请输入加工人"/>
|
||||
<!-- 子表信息 -->
|
||||
<el-form-item label="生产详情" style="margin-top: 16px;">
|
||||
<el-table
|
||||
:data="form.productionDetailList"
|
||||
border
|
||||
:span-method="spanMethod"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-table-column prop="dishName" label="菜品名称" width="180" />
|
||||
<el-table-column label="生成数量" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-input-number
|
||||
v-model="row.produceQuantity"
|
||||
:min="1"
|
||||
:precision="0"
|
||||
@change="updateProduceQuantity(row)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="materialName" label="食材名称" width="180" />
|
||||
<el-table-column prop="materialUnit" label="单位" width="80" />
|
||||
<el-table-column prop="baseUsage" label="基准用量" width="120" />
|
||||
<el-table-column prop="lossRate" label="损耗率" width="120">
|
||||
<template #default="{ row }">{{ row.lossRate }}%</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="实际用量" width="180">
|
||||
<template #default="{ row }">
|
||||
<el-input-number
|
||||
v-model="row.actualUsage"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="calculateActualOutput(row)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="实际产出" width="180">
|
||||
<template #default="{ row }">
|
||||
<el-input-number
|
||||
v-model="row.actualOutput"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-form>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="主id" prop="recordId">
|
||||
<el-input v-model="form.recordId" placeholder="请输入主id"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">取 消</el-button>
|
||||
<el-button type="primary" @click="submitForm" :loading="loading">确 定</el-button>
|
||||
</template>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="加工批次号" prop="recordCode">
|
||||
<el-input v-model="form.recordCode" placeholder="请输入加工批次号"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<!-- 生产模板选择弹窗 -->
|
||||
<el-dialog
|
||||
v-model="templateDialogVisible"
|
||||
title="选择生产模板"
|
||||
width="800px"
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<div class="h-[500px] flex flex-col">
|
||||
<el-form :inline="true" class="mb-4">
|
||||
<el-form-item>
|
||||
<el-input
|
||||
v-model="templateQuery.templateName"
|
||||
placeholder="模板名称"
|
||||
clearable
|
||||
@keyup.enter="searchTemplate"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="searchTemplate">搜索</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" placeholder="请输入备注"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<div class="flex-1 overflow-auto">
|
||||
<el-table
|
||||
ref="templateTable"
|
||||
:data="templateList"
|
||||
border
|
||||
@selection-change="handleSelectionChange"
|
||||
height="100%"
|
||||
>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="templateName" label="模板名称" />
|
||||
<el-table-column prop="dishName" label="菜品名称" />
|
||||
<el-table-column prop="baseOutput" label="基准产出量" />
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="部门id" prop="deptId">
|
||||
<el-input v-model="form.deptId" placeholder="请输入部门id"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<div class="mt-4">
|
||||
<pagination
|
||||
v-model:current-page="templateQuery.current"
|
||||
v-model:page-size="templateQuery.size"
|
||||
:total="templateTotal"
|
||||
@size-change="val => { templateQuery.size = val; templateQuery.current = 1; searchTemplate() }"
|
||||
@current-change="val => { templateQuery.current = val; searchTemplate() }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
</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>
|
||||
<div class="dialog-footer" style="margin-top: 20px;">
|
||||
<el-button @click="templateDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="confirmTemplateSelection">确定</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="CanteenProductionRecordDialog">
|
||||
import { useDict } from '/@/hooks/dict';
|
||||
import { useMessage } from "/@/hooks/message";
|
||||
import { getObj, addObj, putObj } from '/@/api/canteen/canteenProductionRecord'
|
||||
import { rule } from '/@/utils/validate';
|
||||
const emit = defineEmits(['refresh']);
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import { useMessage } from "/@/hooks/message"
|
||||
import { fetchGetSelectTemplatePage } from "/@/api/canteen/canteenProductionTemplate"
|
||||
import { addObj, putObj } from "/@/api/canteen/canteenProductionRecord"
|
||||
import Pagination from '/@/components/Pagination/index.vue'
|
||||
|
||||
// 定义变量内容
|
||||
const dataFormRef = ref();
|
||||
const visible = ref(false)
|
||||
const loading = ref(false)
|
||||
// 定义字典
|
||||
const formRef = ref<FormInstance>()
|
||||
const selectedTemplates = ref<any[]>([])
|
||||
|
||||
// 提交表单数据
|
||||
const form = reactive({
|
||||
id:'',
|
||||
productionTime: '',
|
||||
handlerUser: '',
|
||||
recordId: '',
|
||||
recordCode: '',
|
||||
remark: '',
|
||||
deptId: '',
|
||||
});
|
||||
|
||||
// 定义校验规则
|
||||
const dataRules = ref({
|
||||
productionTime: [{required: true, message: '加工日期不能为空', trigger: 'blur'}],
|
||||
recordCode: [{required: true, message: '加工批次号不能为空', trigger: 'blur'}],
|
||||
// 生产模板选择相关
|
||||
const templateDialogVisible = ref(false)
|
||||
const templateList = ref<any[]>([])
|
||||
const templateTotal = ref(0)
|
||||
const templateQuery = reactive({
|
||||
current: 1,
|
||||
size: 10,
|
||||
templateName: ''
|
||||
})
|
||||
|
||||
// 打开弹窗
|
||||
const openDialog = (id: string) => {
|
||||
visible.value = true
|
||||
form.id = ''
|
||||
const form = reactive({
|
||||
id: undefined,
|
||||
productionTime: new Date().toISOString().split('T')[0],
|
||||
handlerUser: '',
|
||||
recordCode: '',
|
||||
productionDetailList: [] as any[]
|
||||
})
|
||||
|
||||
// 重置表单数据
|
||||
nextTick(() => {
|
||||
dataFormRef.value?.resetFields();
|
||||
});
|
||||
const rules = {
|
||||
productionTime: [{ required: true, message: '请选择加工日期', trigger: 'change' }],
|
||||
handlerUser: [{ required: true, message: '请输入加工人', trigger: 'blur' }],
|
||||
recordCode: [{ required: true, message: '请输入加工批次', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
// 获取canteenProductionRecord信息
|
||||
if (id) {
|
||||
form.id = id
|
||||
getcanteenProductionRecordData(id)
|
||||
}
|
||||
};
|
||||
// 行合并逻辑
|
||||
const rowspanMap = ref<number[]>([])
|
||||
const generateRowspanMap = () => {
|
||||
const map: number[] = []
|
||||
let currentDish = ''
|
||||
let count = 0
|
||||
let startIndex = 0
|
||||
|
||||
// 提交
|
||||
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 getcanteenProductionRecordData = (id: string) => {
|
||||
// 获取数据
|
||||
loading.value = true
|
||||
getObj(id).then((res: any) => {
|
||||
Object.assign(form, res.data)
|
||||
}).finally(() => {
|
||||
loading.value = false
|
||||
form.productionDetailList.forEach((item, index) => {
|
||||
if (item.dishName !== currentDish) {
|
||||
if (currentDish !== '') {
|
||||
for (let i = startIndex; i < index; i++) {
|
||||
map[i] = i === startIndex ? count : 0
|
||||
}
|
||||
}
|
||||
currentDish = item.dishName
|
||||
startIndex = index
|
||||
count = 1
|
||||
} else {
|
||||
count++
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
// 暴露变量
|
||||
// 处理最后一组
|
||||
if (currentDish !== '') {
|
||||
for (let i = startIndex; i < form.productionDetailList.length; i++) {
|
||||
map[i] = i === startIndex ? count : 0
|
||||
}
|
||||
}
|
||||
|
||||
rowspanMap.value = map
|
||||
}
|
||||
|
||||
// 单元格合并方法
|
||||
const spanMethod = ({ row, column, rowIndex, columnIndex }: any) => {
|
||||
if (columnIndex === 0 || columnIndex === 1) { // 合并菜品名称和生成数量列
|
||||
const span = rowspanMap.value[rowIndex]
|
||||
return {
|
||||
rowspan: span,
|
||||
colspan: span > 0 ? 1 : 0
|
||||
}
|
||||
}
|
||||
return { rowspan: 1, colspan: 1 }
|
||||
}
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
|
||||
const disabledDate = (time: Date) => {
|
||||
return time.getTime() > Date.now()
|
||||
}
|
||||
|
||||
const searchTemplate = async () => {
|
||||
try {
|
||||
const res = await fetchGetSelectTemplatePage(templateQuery)
|
||||
templateList.value = res.data.records
|
||||
templateTotal.value = res.data.total
|
||||
} catch (error) {
|
||||
console.error('获取生产模板列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSelectionChange = (selection: any[]) => {
|
||||
selectedTemplates.value = selection
|
||||
}
|
||||
|
||||
const confirmTemplateSelection = () => {
|
||||
if (selectedTemplates.value.length === 0) {
|
||||
useMessage().warning('请至少选择一个模板')
|
||||
return
|
||||
}
|
||||
|
||||
form.productionDetailList = []
|
||||
selectedTemplates.value.forEach(template => {
|
||||
const details = template.canteenProductionTemplateDetailList.map((item: any) => ({
|
||||
...item,
|
||||
dishName: template.dishName,
|
||||
materialUnit: item.unit, // 正确传递食材单位字段
|
||||
produceQuantity: 1,
|
||||
actualUsage: item.baseUsage * 1,
|
||||
actualOutput: 0,
|
||||
manualModified: false
|
||||
}))
|
||||
form.productionDetailList.push(...details)
|
||||
})
|
||||
|
||||
generateRowspanMap()
|
||||
templateDialogVisible.value = false
|
||||
}
|
||||
|
||||
// 更新生成数量
|
||||
const updateProduceQuantity = (changedRow: any) => {
|
||||
const dishName = changedRow.dishName
|
||||
form.productionDetailList.forEach(row => {
|
||||
if (row.dishName === dishName) {
|
||||
row.produceQuantity = changedRow.produceQuantity
|
||||
if (!row.manualModified) {
|
||||
row.actualUsage = Number((row.baseUsage * changedRow.produceQuantity).toFixed(2))
|
||||
calculateActualOutput(row)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 计算实际产出
|
||||
const calculateActualOutput = (row: any) => {
|
||||
row.manualModified = true
|
||||
const lossAmount = row.actualUsage * (row.lossRate / 100)
|
||||
row.actualOutput = Number((row.actualUsage - lossAmount).toFixed(2))
|
||||
}
|
||||
|
||||
const openTemplateDialog = () => {
|
||||
templateDialogVisible.value = true
|
||||
selectedTemplates.value = []
|
||||
searchTemplate()
|
||||
}
|
||||
|
||||
const openDialog = (row?: any) => {
|
||||
visible.value = true
|
||||
if (row) {
|
||||
Object.assign(form, row)
|
||||
generateRowspanMap()
|
||||
} else {
|
||||
form.id = undefined
|
||||
form.productionTime = new Date().toISOString().split('T')[0]
|
||||
form.handlerUser = ''
|
||||
form.recordCode = ''
|
||||
form.productionDetailList = []
|
||||
selectedTemplates.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const submitForm = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
loading.value = true
|
||||
try {
|
||||
const api = form.id ? putObj : addObj
|
||||
const res = await api(form)
|
||||
if (res.code === 0) {
|
||||
useMessage().success(form.id ? '修改成功' : '新增成功')
|
||||
emit('refresh')
|
||||
visible.value = false
|
||||
} else {
|
||||
useMessage().error(res.msg || (form.id ? '修改失败' : '新增失败'))
|
||||
}
|
||||
} catch (error: any) {
|
||||
useMessage().error(error.msg || (form.id ? '修改失败' : '新增失败'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
openDialog
|
||||
});
|
||||
</script>
|
||||
})
|
||||
</script>
|
||||
@@ -29,14 +29,14 @@
|
||||
<div class="mb-4">
|
||||
<el-button type="primary" @click="openMaterialDialog">选择食材</el-button>
|
||||
</div>
|
||||
|
||||
|
||||
<el-table :data="form.canteenProductionTemplateDetailList" border>
|
||||
<el-table-column label="食材名称" prop="materialName" />
|
||||
<el-table-column label="基准用量" width="200">
|
||||
<template #default="{ row }">
|
||||
<el-input-number
|
||||
v-model="row.baseUsage"
|
||||
:min="0"
|
||||
<el-input-number
|
||||
v-model="row.baseUsage"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 120px"
|
||||
/>
|
||||
@@ -45,9 +45,9 @@
|
||||
<el-table-column label="损耗率" width="200">
|
||||
<template #default="{ row }">
|
||||
<div style="display: flex; align-items: center;">
|
||||
<el-input-number
|
||||
v-model="row.lossRate"
|
||||
:min="0"
|
||||
<el-input-number
|
||||
v-model="row.lossRate"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:precision="2"
|
||||
style="width: 120px"
|
||||
@@ -371,7 +371,7 @@ const closeDialog = () => {
|
||||
|
||||
const submitForm = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
loading.value = true
|
||||
@@ -397,4 +397,4 @@ const submitForm = async () => {
|
||||
defineExpose({
|
||||
openDialog
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
@@ -36,8 +36,8 @@
|
||||
<el-table-column type="selection" width="40" align="center" />
|
||||
<el-table-column type="index" label="#" width="40" />
|
||||
<el-table-column prop="templateName" label="模版名称" show-overflow-tooltip/>
|
||||
<el-table-column prop="dishId" label="菜品id" show-overflow-tooltip/>
|
||||
<el-table-column prop="baseOutput" label="基准产出量(碗)" show-overflow-tooltip/>
|
||||
<!-- <el-table-column prop="dishId" label="菜品id" show-overflow-tooltip/>-->
|
||||
<el-table-column prop="baseOutput" label="基准产出量" show-overflow-tooltip/>
|
||||
<el-table-column label="操作" width="150">
|
||||
<template #default="scope">
|
||||
<el-button icon="edit-pen" text type="primary" v-auth="'canteen_canteenProductionTemplate_edit'"
|
||||
|
||||
@@ -32,27 +32,18 @@
|
||||
@queryTable="getDataList"></right-toolbar>
|
||||
</div>
|
||||
</el-row>
|
||||
<el-table :data="state.dataList" v-loading="state.loading" border
|
||||
<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="supplierName" label="货商名称" show-overflow-tooltip/>
|
||||
<el-table-column prop="address" label="货商地址" show-overflow-tooltip/>
|
||||
<el-table-column prop="phone" label="电话号码" show-overflow-tooltip/>
|
||||
<el-table-column prop="tax" label="税号" show-overflow-tooltip/>
|
||||
<el-table-column prop="linkName" label="联系人" show-overflow-tooltip/>
|
||||
<el-table-column prop="openAccount" label="开户行账号" show-overflow-tooltip/>
|
||||
<el-table-column prop="email" label="邮箱地址" show-overflow-tooltip/>
|
||||
<el-table-column prop="deptId" label="所属部门ID" show-overflow-tooltip/>
|
||||
<el-table-column prop="supplierType" label="货商类别" show-overflow-tooltip/>
|
||||
<el-table-column prop="supplierArea" label="货商地区" show-overflow-tooltip/>
|
||||
<el-table-column prop="passwordModifyTime" label="修改时间" show-overflow-tooltip/>
|
||||
<el-table-column prop="openName" label="开户行" show-overflow-tooltip/>
|
||||
<el-table-column prop="contractNumber" label="合同号" show-overflow-tooltip/>
|
||||
<el-table-column prop="status" label="状态 0使用 1禁用" show-overflow-tooltip/>
|
||||
<el-table-column prop="pinyinCod" label="拼音简码" show-overflow-tooltip/>
|
||||
<el-table-column label="操作" width="150">
|
||||
<template #default="scope">
|
||||
<el-button icon="edit-pen" text type="primary" v-auth="'canteen_canteenSupplier_edit'"
|
||||
@@ -140,4 +131,4 @@ const handleDelete = async (ids: string[]) => {
|
||||
useMessage().error(err.msg);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</script>
|
||||
Reference in new issue
Block a user