需求修改

This commit is contained in:
ll
2025-08-25 16:32:45 +08:00
parent a10983b719
commit 3f4de7df2b
10 changed files with 1632 additions and 88 deletions

View File

@@ -1,5 +1,6 @@
<template>
<div class="app-container">
<!-- 搜索表单 -->
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="年月" prop="datetime">
<el-date-picker clearable
@@ -25,6 +26,7 @@
</el-form-item>
</el-form>
<!-- 操作按钮区域 -->
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
@@ -67,7 +69,7 @@
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<!-- 修改表格列宽设置 -->
<!-- 数据表格 -->
<el-table
v-loading="loading"
:data="dryMatterCorrectionList"
@@ -88,7 +90,8 @@
<el-table-column label="干物质标准" align="center" prop="standard" />
<el-table-column label="干物质系数" align="center" prop="coefficient">
<template #default="scope">
<span>{{ scope.row.coefficient != null ? scope.row.coefficient.toFixed(4) : '' }}</span>
<!-- 修复确保显示两位小数 -->
<span>{{ formatCoefficient(scope.row.coefficient) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
@@ -99,6 +102,7 @@
</el-table-column>
</el-table>
<!-- 分页组件 -->
<pagination
v-show="total>0"
:total="total"
@@ -107,7 +111,7 @@
@pagination="getList"
/>
<!-- 添加或修改干物质校正对话框 -->
<!-- 添加/修改对话框 -->
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
<el-form ref="dryMatterCorrectionRef" :model="form" :rules="rules" label-width="100px">
<el-form-item label="年月" prop="datetime">
@@ -136,7 +140,8 @@
<el-input v-model="form.standard" placeholder="请输入干物质标准" @input="calculateCoefficient" />
</el-form-item>
<el-form-item label="干物质系数">
<el-input :value="form.coefficient != null ? form.coefficient.toFixed(4) : ''" placeholder="自动计算" readonly>
<!-- 修复确保显示两位小数 -->
<el-input :value="formatCoefficient(form.coefficient)" placeholder="自动计算" readonly>
</el-input>
</el-form-item>
</el-form>
@@ -151,6 +156,7 @@
</template>
<script setup name="DryMatterCorrection">
// 导入API方法
import {
listDryMatterCorrection,
getDryMatterCorrection,
@@ -162,6 +168,7 @@ import {
const { proxy } = getCurrentInstance()
const { da_ranch } = proxy.useDict('da_ranch')
// 响应式数据
const dryMatterCorrectionList = ref([])
const open = ref(false)
const loading = ref(true)
@@ -172,9 +179,11 @@ const multiple = ref(true)
const total = ref(0)
const title = ref("")
// 使用reactive创建响应式对象
const data = reactive({
form: {
coefficient: null
coefficient: null,
standard: 18 // 设置默认值为18
},
queryParams: {
pageNum: 1,
@@ -183,8 +192,16 @@ const data = reactive({
factory: null,
},
rules: {
datetime: [{ required: true, message: "年月不能为空", trigger: "blur" }],
factory: [{ required: true, message: "厂区不能为空", trigger: "blur" }],
datetime: [{
required: true,
message: "年月不能为空",
trigger: "blur"
}],
factory: [{
required: true,
message: "厂区不能为空",
trigger: "blur"
}],
content: [
{ required: true, message: "干物质含量不能为空", trigger: "blur" },
{ pattern: /^\d+(\.\d+)?$/, message: "请输入有效数字", trigger: "blur" }
@@ -205,10 +222,20 @@ const data = reactive({
const { queryParams, form, rules } = toRefs(data)
/** 计算干物质系数 */
/** 格式化系数显示,保留两位小数 */
function formatCoefficient(value) {
if (value === null || value === undefined) return '';
// 确保是数字类型,然后保留两位小数
const num = typeof value === 'string' ? parseFloat(value) : value;
return !isNaN(num) ? num.toFixed(2) : '';
}
/** 计算干物质系数 - 保留两位小数 */
function calculateCoefficient() {
if (form.value.content && form.value.standard && form.value.standard != 0) {
form.value.coefficient = parseFloat(form.value.content) / parseFloat(form.value.standard);
const content = parseFloat(form.value.content);
const standard = parseFloat(form.value.standard);
form.value.coefficient = Math.round((content / standard) * 100) / 100;
} else {
form.value.coefficient = null;
}
@@ -237,12 +264,13 @@ function reset() {
datetime: null,
factory: null,
content: null,
standard: null,
standard: 18, // 重置时也设置默认值为18
coefficient: null
}
proxy.resetForm("dryMatterCorrectionRef")
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.value.pageNum = 1
@@ -294,7 +322,9 @@ function submitForm() {
if (valid) {
// 确保系数已计算
if (form.value.content && form.value.standard && form.value.standard != 0) {
form.value.coefficient = form.value.content / form.value.standard;
const content = parseFloat(form.value.content);
const standard = parseFloat(form.value.standard);
form.value.coefficient = Math.round((content / standard) * 100) / 100;
}
if (form.value.id != null) {
@@ -302,12 +332,26 @@ function submitForm() {
proxy.$modal.msgSuccess("修改成功")
open.value = false
getList()
}).catch(error => {
// 捕获重复记录的错误
if (error.message && error.message.includes("已存在记录")) {
proxy.$modal.msgError(error.message);
} else {
proxy.$modal.msgError("修改失败:" + (error.message || "未知错误"));
}
})
} else {
addDryMatterCorrection(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功")
open.value = false
getList()
}).catch(error => {
// 捕获重复记录的错误
if (error.message && error.message.includes("已存在记录")) {
proxy.$modal.msgError(error.message);
} else {
proxy.$modal.msgError("新增失败:" + (error.message || "未知错误"));
}
})
}
}

View File

@@ -49,8 +49,16 @@
<el-table-column prop="parity" label="胎次" />
<el-table-column prop="factory" label="厂区" />
<el-table-column prop="classes" label="班次" />
<el-table-column prop="milk" label="班次产奶量" />
<el-table-column prop="correctedMilk" label="班次校正奶量" />
<el-table-column prop="milk" label="班次产奶量" >
<template #default="{ row }">
{{ row.milk ? Number(row.milk).toFixed(2) : '-' }}
</template>
</el-table-column>
<el-table-column prop="correctedMilk" label="班次校正奶量" >
<template #default="{ row }">
{{ row.milk ? Number(row.milk).toFixed(2) : '-' }}
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total"

View File

@@ -1,41 +1,217 @@
<template>
<div class="app-container">
<el-table
v-loading="loading"
:data="parityCorrectionList"
style="width: 100%"
border
stripe
>
<el-table-column label="胎次" align="center" prop="parity" width="120" />
<el-table-column label="系数" align="center" prop="coef" width="120" />
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<!-- 搜索条件 只保留胎次 -->
<el-form-item label="胎次" prop="parity">
<el-input
v-model="queryParams.parity"
placeholder="请输入胎次"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="Plus"
@click="handleAdd"
v-hasPermi="['parityCorrection:parityCorrection:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="Edit"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['parityCorrection:parityCorrection:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['parityCorrection:parityCorrection:remove']"
>删除</el-button>
</el-col>
<!-- 去掉导出按钮 -->
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="parityCorrectionList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<!-- 去掉 ${comment} -->
<el-table-column label="胎次" align="center" prop="parity" />
<el-table-column label="系数" align="center" prop="coef" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['parityCorrection:parityCorrection:edit']">修改</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['parityCorrection:parityCorrection:remove']">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改胎次校正对话框 -->
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
<el-form ref="parityCorrectionRef" :model="form" :rules="rules" label-width="80px">
<el-form-item label="胎次" prop="parity">
<el-input v-model="form.parity" placeholder="请输入胎次" />
</el-form-item>
<el-form-item label="系数" prop="coef">
<el-input v-model="form.coef" placeholder="请输入系数" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup name="ParityCorrection">
import { listParityCorrection } from '@/api/dairyProducts/parityCorrection/parityCorrection.js'
import { ref, onMounted } from 'vue'
import { listParityCorrection, getParityCorrection, delParityCorrection, addParityCorrection, updateParityCorrection } from "@/api/dairyProducts/parityCorrection/parityCorrection"
const { proxy } = getCurrentInstance()
const loading = ref(false)
const parityCorrectionList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const data = reactive({
form: {},
queryParams: {
pageNum: 1,
pageSize: 10,
parity: null // ✅ 只保留胎次
},
rules: {}
})
const { queryParams, form, rules } = toRefs(data)
/** 查询胎次校正列表 */
function getList() {
loading.value = true
listParityCorrection().then(res => {
parityCorrectionList.value = res.rows || res.data || [] // 兼容两种返回风格
}).finally(() => {
listParityCorrection(queryParams.value).then(response => {
parityCorrectionList.value = response.rows
total.value = response.total
loading.value = false
})
}
onMounted(() => {
getList()
})
</script>
<style scoped>
.app-container {
padding: 20px;
// 取消按钮
function cancel() {
open.value = false
reset()
}
</style>
// 表单重置
function reset() {
form.value = {
id: null,
parity: null,
coef: null
}
proxy.resetForm("parityCorrectionRef")
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.value.pageNum = 1
getList()
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm("queryRef")
handleQuery()
}
// 多选框选中数据
function handleSelectionChange(selection) {
ids.value = selection.map(item => item.id)
single.value = selection.length != 1
multiple.value = !selection.length
}
/** 新增按钮操作 */
function handleAdd() {
reset()
open.value = true
title.value = "添加胎次校正"
}
/** 修改按钮操作 */
function handleUpdate(row) {
reset()
const _id = row.id || ids.value
getParityCorrection(_id).then(response => {
form.value = response.data
open.value = true
title.value = "修改胎次校正"
})
}
/** 提交按钮 */
function submitForm() {
proxy.$refs["parityCorrectionRef"].validate(valid => {
if (valid) {
if (form.value.id != null) {
updateParityCorrection(form.value).then(() => {
proxy.$modal.msgSuccess("修改成功")
open.value = false
getList()
})
} else {
addParityCorrection(form.value).then(() => {
proxy.$modal.msgSuccess("新增成功")
open.value = false
getList()
})
}
}
})
}
/** 删除按钮操作 */
function handleDelete(row) {
const _ids = row.id || ids.value
proxy.$modal.confirm('是否确认删除胎次校正编号为"' + _ids + '"的数据项?').then(function() {
return delParityCorrection(_ids)
}).then(() => {
getList()
proxy.$modal.msgSuccess("删除成功")
}).catch(() => {})
}
getList()
</script>

View File

@@ -83,7 +83,7 @@
<el-table-column label="系统奶量" align="center" prop="systemMilk" /> <!-- 修改这里 -->
<el-table-column label="称重系数" align="center" prop="coefficient">
<template #default="scope">
<span>{{ scope.row.coefficient.toFixed(4) }}</span>
<span>{{ scope.row.coefficient.toFixed(2) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
@@ -245,25 +245,31 @@ function handleUpdate(row) {
})
}
/** 提交按钮 */
/* 提交按钮 */
function submitForm() {
proxy.$refs["weightCorrectionRef"].validate(valid => {
if (valid) {
// 确保数值类型正确
form.value.actual = parseFloat(form.value.actual)
form.value.systemMilk = parseFloat(form.value.systemMilk) // 修改这里
form.value.systemMilk = parseFloat(form.value.systemMilk)
if (form.value.id != null) {
updateWeightCorrection(form.value).then(response => {
proxy.$modal.msgSuccess("修改成功")
open.value = false
getList()
}).catch(error => {
// 捕获后端返回的错误信息并显示
proxy.$modal.msgError(error.response.data.msg || "修改失败")
})
} else {
addWeightCorrection(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功")
open.value = false
getList()
}).catch(error => {
// 捕获后端返回的错误信息并显示
proxy.$modal.msgError(error.response.data.msg || "新增失败")
})
}
}