|
|
@@ -8,33 +8,11 @@
|
|
|
</template>
|
|
|
|
|
|
<div class="toolbar">
|
|
|
- <el-button type="primary" @click="handleAdd">
|
|
|
- <el-icon><Plus /></el-icon>
|
|
|
- 新增地磅单
|
|
|
- </el-button>
|
|
|
- <el-button @click="handleExport">
|
|
|
- <el-icon><Document /></el-icon>
|
|
|
- 导出 Excel
|
|
|
- </el-button>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- 搜索和日期筛选 -->
|
|
|
- <div class="search-bar">
|
|
|
- <el-date-picker
|
|
|
- v-model="dateRange"
|
|
|
- type="daterange"
|
|
|
- range-separator="至"
|
|
|
- start-placeholder="开始日期"
|
|
|
- end-placeholder="结束日期"
|
|
|
- format="YYYY-MM-DD"
|
|
|
- value-format="YYYY-MM-DD"
|
|
|
- @change="handleSearch"
|
|
|
- />
|
|
|
<el-input
|
|
|
v-model="searchKeyword"
|
|
|
placeholder="搜索车牌号/货物名称"
|
|
|
clearable
|
|
|
- style="width: 300px; margin-left: 16px"
|
|
|
+ style="width: 300px"
|
|
|
@clear="handleSearch"
|
|
|
@keyup.enter="handleSearch"
|
|
|
>
|
|
|
@@ -43,33 +21,66 @@
|
|
|
</template>
|
|
|
</el-input>
|
|
|
<el-button type="primary" @click="handleSearch" style="margin-left: 8px">搜索</el-button>
|
|
|
+ <el-button type="primary" @click="handleAdd">
|
|
|
+ <el-icon><Plus /></el-icon>
|
|
|
+ 新增地磅单
|
|
|
+ </el-button>
|
|
|
+ <el-button @click="handleExport">
|
|
|
+ <el-icon><Document /></el-icon>
|
|
|
+ 导出 Excel
|
|
|
+ </el-button>
|
|
|
</div>
|
|
|
|
|
|
<art-table
|
|
|
- :data="tableData"
|
|
|
+ :data="paginatedData"
|
|
|
:loading="loading"
|
|
|
:pagination="true"
|
|
|
:total="total"
|
|
|
+ :index="true"
|
|
|
v-model:current-page="currentPage"
|
|
|
v-model:page-size="pageSize"
|
|
|
@current-change="handlePageChange"
|
|
|
@size-change="handleSizeChange"
|
|
|
>
|
|
|
- <el-table-column prop="vehicleNo" label="车牌号" width="120" />
|
|
|
- <el-table-column prop="cargoName" label="货物名称" width="150" />
|
|
|
- <el-table-column prop="businessType" label="业务类型" width="100">
|
|
|
+ <el-table-column prop="grossWeightTime" label="日期" min-width="120">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.grossWeightTime ? row.grossWeightTime.split(' ')[0] : (row.createdAt ? row.createdAt.split(' ')[0] : '') }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="planNo" label="计划单号" min-width="120" />
|
|
|
+ <el-table-column prop="batchNo" label="出入库单号" min-width="140" />
|
|
|
+ <el-table-column prop="vehicleNo" label="车牌号" min-width="120" />
|
|
|
+ <el-table-column prop="cargoName" label="货物名称" min-width="150" />
|
|
|
+ <el-table-column prop="businessType" label="业务类型" min-width="100">
|
|
|
<template #default="{ row }">
|
|
|
<el-tag :type="row.businessType === '入库' ? 'success' : 'warning'">
|
|
|
{{ row.businessType }}
|
|
|
</el-tag>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column prop="grossWeight" label="毛重(kg)" width="120" />
|
|
|
- <el-table-column prop="tareWeight" label="皮重(kg)" width="120" />
|
|
|
- <el-table-column prop="netWeight" label="净重(kg)" width="120" />
|
|
|
- <el-table-column prop="grossWeightTime" label="毛重时间" width="160" />
|
|
|
- <el-table-column label="操作" width="200" fixed="right">
|
|
|
+ <el-table-column prop="supplier" label="供货单位" min-width="150" show-overflow-tooltip />
|
|
|
+ <el-table-column prop="consignee" label="收货单位" min-width="150" show-overflow-tooltip />
|
|
|
+ <el-table-column prop="grossWeight" label="毛重(kg)" min-width="120" />
|
|
|
+ <el-table-column prop="grossWeightTime" label="毛重时间" min-width="160" />
|
|
|
+ <el-table-column prop="tareWeight" label="皮重(kg)" min-width="120" />
|
|
|
+ <el-table-column prop="tareWeightTime" label="皮重时间" min-width="160" />
|
|
|
+ <el-table-column prop="deduction" label="扣杂(kg)" min-width="120">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.deduction || 0 }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="netWeight" label="净重(kg)" min-width="120" />
|
|
|
+ <el-table-column prop="currentQuantity" label="本次量(吨)" min-width="120">
|
|
|
<template #default="{ row }">
|
|
|
+ {{ row.currentQuantity !== undefined && row.currentQuantity !== null ? (row.currentQuantity / 1000).toFixed(2) : '--' }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" width="280" fixed="right">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-button link type="primary" @click="handleView(row)">
|
|
|
+ <el-icon><View /></el-icon>
|
|
|
+ 查看
|
|
|
+ </el-button>
|
|
|
<el-button link type="primary" @click="handleEdit(row)">
|
|
|
<el-icon><Edit /></el-icon>
|
|
|
编辑
|
|
|
@@ -80,6 +91,7 @@
|
|
|
type="warning"
|
|
|
@click="handleVoid(row.id)"
|
|
|
>
|
|
|
+ <el-icon><Close /></el-icon>
|
|
|
作废
|
|
|
</el-button>
|
|
|
<el-button link type="danger" @click="handleDelete(row.id)">
|
|
|
@@ -107,7 +119,19 @@
|
|
|
</el-col>
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="货物名称" prop="cargoName">
|
|
|
- <el-input v-model="formData.cargoName" placeholder="请输入货物名称" />
|
|
|
+ <el-select
|
|
|
+ v-model="formData.cargoName"
|
|
|
+ placeholder="请选择货物名称"
|
|
|
+ filterable
|
|
|
+ style="width: 100%"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="cargo in cargos"
|
|
|
+ :key="cargo.id"
|
|
|
+ :label="cargo.name"
|
|
|
+ :value="cargo.name"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
@@ -126,15 +150,51 @@
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
+ <el-row :gutter="16">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="出入库单号" prop="batchNo">
|
|
|
+ <el-input v-model="formData.batchNo" placeholder="出入库单号" readonly />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="本次量(吨)">
|
|
|
+ <el-input :value="currentQuantityInTons" placeholder="本次量(吨)" readonly />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
<el-row :gutter="16">
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="供货单位" prop="supplier">
|
|
|
- <el-input v-model="formData.supplier" placeholder="请输入供货单位" />
|
|
|
+ <el-select
|
|
|
+ v-model="formData.supplier"
|
|
|
+ placeholder="请选择供货单位"
|
|
|
+ filterable
|
|
|
+ style="width: 100%"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="company in companies"
|
|
|
+ :key="company.id"
|
|
|
+ :label="company.name"
|
|
|
+ :value="company.name"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="收货单位" prop="consignee">
|
|
|
- <el-input v-model="formData.consignee" placeholder="请输入收货单位" />
|
|
|
+ <el-select
|
|
|
+ v-model="formData.consignee"
|
|
|
+ placeholder="请选择收货单位"
|
|
|
+ filterable
|
|
|
+ style="width: 100%"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="company in companies"
|
|
|
+ :key="company.id"
|
|
|
+ :label="company.name"
|
|
|
+ :value="company.name"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
@@ -145,8 +205,10 @@
|
|
|
v-model="formData.grossWeight"
|
|
|
:min="0"
|
|
|
:precision="2"
|
|
|
+ :controls="false"
|
|
|
+ placeholder="请输入毛重"
|
|
|
style="width: 100%"
|
|
|
- @change="calculateNetWeight"
|
|
|
+ @change="handleGrossWeightChange"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
@@ -170,8 +232,10 @@
|
|
|
v-model="formData.tareWeight"
|
|
|
:min="0"
|
|
|
:precision="2"
|
|
|
+ :controls="false"
|
|
|
+ placeholder="请输入皮重"
|
|
|
style="width: 100%"
|
|
|
- @change="calculateNetWeight"
|
|
|
+ @change="handleTareWeightChange"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
@@ -195,6 +259,8 @@
|
|
|
v-model="formData.deduction"
|
|
|
:min="0"
|
|
|
:precision="2"
|
|
|
+ :controls="false"
|
|
|
+ placeholder="请输入扣杂"
|
|
|
style="width: 100%"
|
|
|
@change="calculateNetWeight"
|
|
|
/>
|
|
|
@@ -202,7 +268,10 @@
|
|
|
</el-col>
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="净重(kg)">
|
|
|
- <el-input :value="netWeight.toFixed(2)" disabled />
|
|
|
+ <el-input
|
|
|
+ :value="formData.grossWeight > 0 && formData.tareWeight > 0 ? netWeight.toFixed(2) : '--'"
|
|
|
+ disabled
|
|
|
+ />
|
|
|
<el-alert
|
|
|
v-if="isNetInvalid"
|
|
|
type="error"
|
|
|
@@ -225,28 +294,111 @@
|
|
|
</el-button>
|
|
|
</template>
|
|
|
</el-dialog>
|
|
|
+
|
|
|
+ <!-- 关联数据对话框 -->
|
|
|
+ <el-dialog v-model="relatedModalOpen" title="查看关联数据" width="1200px">
|
|
|
+ <div v-loading="loadingRelated" class="dialog-content">
|
|
|
+ <!-- 计划 -->
|
|
|
+ <div v-if="relatedData.plan" class="data-item">
|
|
|
+ <div class="data-item-header">
|
|
|
+ <el-tag type="primary">计划</el-tag>
|
|
|
+ </div>
|
|
|
+ <el-descriptions :column="2" border style="margin-top: 12px;">
|
|
|
+ <el-descriptions-item label="计划号">{{ relatedData.plan.planNo }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="业务类型">{{ relatedData.plan.businessType }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="往来单位">{{ relatedData.plan.customerName }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="产品">{{ relatedData.plan.product }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="计划日期">{{ relatedData.plan.planDate }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="起始日期">{{ relatedData.plan.startDate }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="截止日期">{{ relatedData.plan.endDate }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="执行状态">
|
|
|
+ <el-tag :type="relatedData.plan.executionStatus === '已入库' || relatedData.plan.executionStatus === '已出库' ? 'success' : 'warning'">
|
|
|
+ {{ relatedData.plan.executionStatus }}
|
|
|
+ </el-tag>
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="计划量(吨)">{{ relatedData.plan.plannedQuantity }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="已执行量(吨)">
|
|
|
+ {{ ((relatedData.plan.executedQuantity || 0) / 1000).toFixed(2) }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="备注" :span="2">{{ relatedData.plan.remarks || '-' }}</el-descriptions-item>
|
|
|
+ </el-descriptions>
|
|
|
+ </div>
|
|
|
+ <el-empty v-else-if="!relatedData.inventory" description="暂无关联的计划" />
|
|
|
+
|
|
|
+ <!-- 分割线 -->
|
|
|
+ <el-divider v-if="relatedData.plan && relatedData.inventory" />
|
|
|
+
|
|
|
+ <!-- 出入库单 -->
|
|
|
+ <div v-if="relatedData.inventory" class="data-item">
|
|
|
+ <div class="data-item-header">
|
|
|
+ <el-tag type="info">出入库单</el-tag>
|
|
|
+ </div>
|
|
|
+ <el-descriptions :column="2" border style="margin-top: 12px;">
|
|
|
+ <el-descriptions-item label="出入库单号">{{ relatedData.inventory.batchNo }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="日期">{{ relatedData.inventory.date }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="往来单位">{{ relatedData.inventory.partnerCompany }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="业务类型">
|
|
|
+ <el-tag :type="relatedData.inventory.businessType === '入库' ? 'success' : 'warning'">
|
|
|
+ {{ relatedData.inventory.businessType }}
|
|
|
+ </el-tag>
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="产品">{{ relatedData.inventory.product }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="车牌号">{{ relatedData.inventory.vehicleNo }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="数量(吨)">{{ relatedData.inventory.quantity }}</el-descriptions-item>
|
|
|
+ <el-descriptions-item label="状态">
|
|
|
+ <el-tag
|
|
|
+ :type="
|
|
|
+ relatedData.inventory.status === '已完成'
|
|
|
+ ? 'success'
|
|
|
+ : relatedData.inventory.status === '待入库' || relatedData.inventory.status === '待出库'
|
|
|
+ ? 'warning'
|
|
|
+ : 'info'
|
|
|
+ "
|
|
|
+ >
|
|
|
+ {{ relatedData.inventory.status || '待处理' }}
|
|
|
+ </el-tag>
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="备注" :span="2">{{ relatedData.inventory.remarks || '-' }}</el-descriptions-item>
|
|
|
+ </el-descriptions>
|
|
|
+ </div>
|
|
|
+ <el-empty v-else-if="!relatedData.plan" description="暂无关联的出入库单" />
|
|
|
+ </div>
|
|
|
+ <template #footer>
|
|
|
+ <el-button @click="relatedModalOpen = false">关闭</el-button>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import { ref, reactive, computed, onMounted } from 'vue'
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
- import { Plus, Document, Search, Edit, Delete } from '@element-plus/icons-vue'
|
|
|
+ import { Plus, Document, Search, Edit, Delete, Close, View } from '@element-plus/icons-vue'
|
|
|
import { weighingApi, type WeighingRecord, type WeighingCreate } from '@/api/weighingApi'
|
|
|
+ import { companyApi, cargoApi, type Company, type Cargo } from '@/api/masterDataApi'
|
|
|
+ import { planApi, type Plan } from '@/api/plansApi'
|
|
|
+ import { inventoryApi, type InventoryRecord } from '@/api/inventoryApi'
|
|
|
+ import { useRoute } from 'vue-router'
|
|
|
import dayjs from 'dayjs'
|
|
|
import ArtTable from '@/components/Table/ArtTable.vue'
|
|
|
|
|
|
const loading = ref(false)
|
|
|
const saving = ref(false)
|
|
|
const tableData = ref<WeighingRecord[]>([])
|
|
|
+ const allData = ref<WeighingRecord[]>([])
|
|
|
const total = ref(0)
|
|
|
const currentPage = ref(1)
|
|
|
const pageSize = ref(10)
|
|
|
const searchKeyword = ref('')
|
|
|
- const dateRange = ref<[string, string] | null>(null)
|
|
|
+ const companies = ref<Company[]>([])
|
|
|
+ const cargos = ref<Cargo[]>([])
|
|
|
+ const route = useRoute()
|
|
|
|
|
|
const modalOpen = ref(false)
|
|
|
const editingRecord = ref<WeighingRecord | null>(null)
|
|
|
+ const relatedModalOpen = ref(false)
|
|
|
+ const loadingRelated = ref(false)
|
|
|
+ const relatedData = ref<{ plan: Plan | null, inventory: InventoryRecord | null }>({ plan: null, inventory: null })
|
|
|
|
|
|
const formRef = ref()
|
|
|
const formData = reactive<WeighingCreate>({
|
|
|
@@ -257,51 +409,99 @@
|
|
|
batchNo: '',
|
|
|
supplier: '',
|
|
|
consignee: '',
|
|
|
- grossWeight: 0,
|
|
|
- grossWeightTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- tareWeight: 0,
|
|
|
- tareWeightTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- deduction: 0,
|
|
|
+ grossWeight: undefined as any,
|
|
|
+ grossWeightTime: '',
|
|
|
+ tareWeight: undefined as any,
|
|
|
+ tareWeightTime: '',
|
|
|
+ deduction: undefined as any,
|
|
|
netWeight: 0,
|
|
|
- remarks: ''
|
|
|
+ remarks: '',
|
|
|
+ purchasePlanId: undefined,
|
|
|
+ inboundOutboundId: undefined,
|
|
|
+ weighingPoint: '山峡化工',
|
|
|
+ plannedQuantity: undefined,
|
|
|
+ currentQuantity: undefined,
|
|
|
+ executedQuantity: undefined
|
|
|
})
|
|
|
|
|
|
const formRules = {
|
|
|
vehicleNo: [{ required: true, message: '请输入车牌号', trigger: 'blur' }],
|
|
|
- cargoName: [{ required: true, message: '请输入货物名称', trigger: 'blur' }],
|
|
|
- supplier: [{ required: true, message: '请输入供货单位', trigger: 'blur' }],
|
|
|
- consignee: [{ required: true, message: '请输入收货单位', trigger: 'blur' }],
|
|
|
- grossWeight: [{ required: true, message: '请输入毛重', trigger: 'blur' }],
|
|
|
- tareWeight: [{ required: true, message: '请输入皮重', trigger: 'blur' }]
|
|
|
+ cargoName: [{ required: true, message: '请选择货物名称', trigger: 'change' }],
|
|
|
+ supplier: [{ required: true, message: '请选择供货单位', trigger: 'change' }],
|
|
|
+ consignee: [{ required: true, message: '请选择收货单位', trigger: 'change' }]
|
|
|
}
|
|
|
|
|
|
const netWeight = computed(() => {
|
|
|
- const gross = formData.grossWeight || 0
|
|
|
- const tare = formData.tareWeight || 0
|
|
|
- const deduction = formData.deduction || 0
|
|
|
+ const gross = formData.grossWeight ?? 0
|
|
|
+ const tare = formData.tareWeight ?? 0
|
|
|
+ const deduction = formData.deduction ?? 0
|
|
|
return Number((gross - tare - deduction).toFixed(2))
|
|
|
})
|
|
|
|
|
|
- const isNetInvalid = computed(() => netWeight.value <= 0)
|
|
|
+ // 本次量(吨)- 从 kg 转换为吨显示
|
|
|
+ const currentQuantityInTons = computed(() => {
|
|
|
+ if (formData.currentQuantity !== undefined && formData.currentQuantity !== null) {
|
|
|
+ return (formData.currentQuantity / 1000).toFixed(2)
|
|
|
+ }
|
|
|
+ return '--'
|
|
|
+ })
|
|
|
+
|
|
|
+ // 只有在毛重和皮重都存在时,才需要验证净重
|
|
|
+ const isNetInvalid = computed(() => {
|
|
|
+ const hasGrossWeight = formData.grossWeight && formData.grossWeight > 0
|
|
|
+ const hasTareWeight = formData.tareWeight && formData.tareWeight > 0
|
|
|
+ // 如果毛重和皮重都存在,净重必须大于0
|
|
|
+ if (hasGrossWeight && hasTareWeight) {
|
|
|
+ return netWeight.value <= 0
|
|
|
+ }
|
|
|
+ // 如果只有其中一个,或者都没有,不验证净重
|
|
|
+ return false
|
|
|
+ })
|
|
|
|
|
|
const calculateNetWeight = () => {
|
|
|
formData.netWeight = netWeight.value
|
|
|
}
|
|
|
|
|
|
+ // 处理毛重变化
|
|
|
+ const handleGrossWeightChange = () => {
|
|
|
+ calculateNetWeight()
|
|
|
+ // 如果毛重大于0且毛重时间为空,自动填充当前时间
|
|
|
+ if (formData.grossWeight && formData.grossWeight > 0 && !formData.grossWeightTime) {
|
|
|
+ formData.grossWeightTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理皮重变化
|
|
|
+ const handleTareWeightChange = () => {
|
|
|
+ calculateNetWeight()
|
|
|
+ // 如果皮重大于0且皮重时间为空,自动填充当前时间
|
|
|
+ if (formData.tareWeight && formData.tareWeight > 0 && !formData.tareWeightTime) {
|
|
|
+ formData.tareWeightTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分页后的数据
|
|
|
+ const paginatedData = computed(() => {
|
|
|
+ const start = (currentPage.value - 1) * pageSize.value
|
|
|
+ const end = start + pageSize.value
|
|
|
+ return allData.value.slice(start, end)
|
|
|
+ })
|
|
|
+
|
|
|
const loadData = async () => {
|
|
|
loading.value = true
|
|
|
try {
|
|
|
const params: any = {}
|
|
|
- if (dateRange.value) {
|
|
|
- params.dateFrom = dateRange.value[0]
|
|
|
- params.dateTo = dateRange.value[1]
|
|
|
- }
|
|
|
if (searchKeyword.value) {
|
|
|
params.vehicleNo = searchKeyword.value
|
|
|
}
|
|
|
const records = await weighingApi.list(params)
|
|
|
- tableData.value = records
|
|
|
+ allData.value = records
|
|
|
total.value = records.length
|
|
|
+ // 如果当前页超出范围,重置到第一页
|
|
|
+ const maxPage = Math.ceil(total.value / pageSize.value) || 1
|
|
|
+ if (currentPage.value > maxPage) {
|
|
|
+ currentPage.value = 1
|
|
|
+ }
|
|
|
} catch (error) {
|
|
|
ElMessage.error('加载数据失败')
|
|
|
} finally {
|
|
|
@@ -316,13 +516,11 @@
|
|
|
|
|
|
const handlePageChange = (page: number) => {
|
|
|
currentPage.value = page
|
|
|
- loadData()
|
|
|
}
|
|
|
|
|
|
const handleSizeChange = (size: number) => {
|
|
|
pageSize.value = size
|
|
|
currentPage.value = 1
|
|
|
- loadData()
|
|
|
}
|
|
|
|
|
|
const handleAdd = () => {
|
|
|
@@ -335,17 +533,36 @@
|
|
|
batchNo: '',
|
|
|
supplier: '',
|
|
|
consignee: '',
|
|
|
- grossWeight: 0,
|
|
|
- grossWeightTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- tareWeight: 0,
|
|
|
- tareWeightTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- deduction: 0,
|
|
|
+ grossWeight: undefined as any,
|
|
|
+ grossWeightTime: '',
|
|
|
+ tareWeight: undefined as any,
|
|
|
+ tareWeightTime: '',
|
|
|
+ deduction: undefined as any,
|
|
|
netWeight: 0,
|
|
|
- remarks: ''
|
|
|
+ remarks: '',
|
|
|
+ purchasePlanId: undefined,
|
|
|
+ inboundOutboundId: undefined,
|
|
|
+ weighingPoint: '山峡化工',
|
|
|
+ plannedQuantity: undefined,
|
|
|
+ currentQuantity: undefined,
|
|
|
+ executedQuantity: undefined
|
|
|
})
|
|
|
modalOpen.value = true
|
|
|
}
|
|
|
|
|
|
+ const handleView = async (record: WeighingRecord) => {
|
|
|
+ loadingRelated.value = true
|
|
|
+ try {
|
|
|
+ const data = await weighingApi.getRelated(record.id)
|
|
|
+ relatedData.value = data
|
|
|
+ relatedModalOpen.value = true
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('加载关联数据失败')
|
|
|
+ } finally {
|
|
|
+ loadingRelated.value = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
const handleEdit = (record: WeighingRecord) => {
|
|
|
editingRecord.value = record
|
|
|
Object.assign(formData, {
|
|
|
@@ -362,7 +579,13 @@
|
|
|
tareWeightTime: record.tareWeightTime,
|
|
|
deduction: record.deduction || 0,
|
|
|
netWeight: record.netWeight,
|
|
|
- remarks: record.remarks || ''
|
|
|
+ remarks: record.remarks || '',
|
|
|
+ purchasePlanId: record.purchasePlanId,
|
|
|
+ inboundOutboundId: record.inboundOutboundId,
|
|
|
+ weighingPoint: record.weighingPoint || '山峡化工',
|
|
|
+ plannedQuantity: record.plannedQuantity,
|
|
|
+ currentQuantity: record.currentQuantity,
|
|
|
+ executedQuantity: record.executedQuantity
|
|
|
})
|
|
|
modalOpen.value = true
|
|
|
}
|
|
|
@@ -402,12 +625,50 @@
|
|
|
if (valid) {
|
|
|
saving.value = true
|
|
|
try {
|
|
|
- formData.netWeight = netWeight.value
|
|
|
+ // 计算净重(如果毛重和皮重都存在)
|
|
|
+ const hasGrossWeight = formData.grossWeight && formData.grossWeight > 0
|
|
|
+ const hasTareWeight = formData.tareWeight && formData.tareWeight > 0
|
|
|
+ if (hasGrossWeight && hasTareWeight) {
|
|
|
+ formData.netWeight = netWeight.value
|
|
|
+ } else {
|
|
|
+ // 如果毛重或皮重不存在,净重设为0
|
|
|
+ formData.netWeight = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保提交时,如果值为undefined,转换为0
|
|
|
+ const submitGrossWeight = formData.grossWeight === undefined || formData.grossWeight === null ? 0 : formData.grossWeight
|
|
|
+ const submitTareWeight = formData.tareWeight === undefined || formData.tareWeight === null ? 0 : formData.tareWeight
|
|
|
+ const submitDeduction = formData.deduction === undefined || formData.deduction === null ? 0 : formData.deduction
|
|
|
+
|
|
|
+ // 构建提交数据,确保所有字段都被包含
|
|
|
+ const submitData: any = {
|
|
|
+ vehicleNo: formData.vehicleNo,
|
|
|
+ planNo: formData.planNo || undefined,
|
|
|
+ cargoName: formData.cargoName,
|
|
|
+ businessType: formData.businessType,
|
|
|
+ batchNo: formData.batchNo || undefined,
|
|
|
+ supplier: formData.supplier,
|
|
|
+ consignee: formData.consignee,
|
|
|
+ grossWeight: submitGrossWeight,
|
|
|
+ grossWeightTime: formData.grossWeightTime || '',
|
|
|
+ tareWeight: submitTareWeight,
|
|
|
+ tareWeightTime: formData.tareWeightTime || '',
|
|
|
+ deduction: submitDeduction,
|
|
|
+ netWeight: formData.netWeight,
|
|
|
+ plannedQuantity: formData.plannedQuantity || undefined,
|
|
|
+ executedQuantity: formData.executedQuantity || undefined,
|
|
|
+ purchasePlanId: formData.purchasePlanId || undefined,
|
|
|
+ inboundOutboundId: formData.inboundOutboundId || undefined,
|
|
|
+ weighingPoint: formData.weighingPoint || '山峡化工',
|
|
|
+ remarks: formData.remarks || undefined,
|
|
|
+ currentQuantity: formData.currentQuantity || undefined
|
|
|
+ }
|
|
|
+
|
|
|
if (editingRecord.value) {
|
|
|
- await weighingApi.update(editingRecord.value.id, formData)
|
|
|
+ await weighingApi.update(editingRecord.value.id, submitData)
|
|
|
ElMessage.success('更新成功')
|
|
|
} else {
|
|
|
- await weighingApi.create(formData)
|
|
|
+ await weighingApi.create(submitData)
|
|
|
ElMessage.success('保存成功')
|
|
|
}
|
|
|
modalOpen.value = false
|
|
|
@@ -476,8 +737,89 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ const loadCompanies = async () => {
|
|
|
+ try {
|
|
|
+ companies.value = await companyApi.list()
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('加载往来单位失败')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const loadCargos = async () => {
|
|
|
+ try {
|
|
|
+ cargos.value = await cargoApi.list()
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('加载货物列表失败')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从路由参数填充表单数据
|
|
|
+ const initFromRoute = async () => {
|
|
|
+ const inboundOutboundId = route.query.inboundOutboundId as string
|
|
|
+ if (inboundOutboundId) {
|
|
|
+ try {
|
|
|
+ // 获取出入库单数据
|
|
|
+ const inventory = await inventoryApi.get(Number(inboundOutboundId))
|
|
|
+
|
|
|
+ // 填充基础数据(优先使用路由参数,如果没有则使用出入库单数据)
|
|
|
+ formData.vehicleNo = (route.query.vehicleNo as string) || inventory.vehicleNo
|
|
|
+ formData.cargoName = (route.query.cargoName as string) || inventory.product
|
|
|
+ const businessType = (route.query.businessType as '入库' | '出库') || inventory.businessType
|
|
|
+ formData.businessType = businessType
|
|
|
+
|
|
|
+ // 根据业务类型设置供货单位和收货单位
|
|
|
+ // 入库单:供货单位 = 往来单位,收货单位 = 安庆市山峡化工有限公司
|
|
|
+ // 出库单:供货单位 = 安庆市山峡化工有限公司,收货单位 = 往来单位
|
|
|
+ if (route.query.supplier) {
|
|
|
+ formData.supplier = route.query.supplier as string
|
|
|
+ } else {
|
|
|
+ formData.supplier = businessType === '入库' ? inventory.partnerCompany : '安庆市山峡化工有限公司'
|
|
|
+ }
|
|
|
+
|
|
|
+ if (route.query.consignee) {
|
|
|
+ formData.consignee = route.query.consignee as string
|
|
|
+ } else {
|
|
|
+ formData.consignee = businessType === '入库' ? '安庆市山峡化工有限公司' : inventory.partnerCompany
|
|
|
+ }
|
|
|
+
|
|
|
+ formData.planNo = (route.query.planNo as string) || inventory.planNo || ''
|
|
|
+ // 填充出入库单号(优先使用路由参数,如果没有则使用出入库单数据)
|
|
|
+ formData.batchNo = (route.query.batchNo as string) || inventory.batchNo || ''
|
|
|
+ formData.inboundOutboundId = Number(inboundOutboundId)
|
|
|
+ formData.weighingPoint = '山峡化工'
|
|
|
+
|
|
|
+ // 本次量:优先使用路由参数中的quantity(吨),如果没有则使用出入库单的quantity(吨),然后转换为kg
|
|
|
+ const quantityInTons = route.query.quantity ? Number(route.query.quantity) : inventory.quantity
|
|
|
+ formData.currentQuantity = quantityInTons * 1000
|
|
|
+
|
|
|
+ // 如果有计划ID,获取计划数据(优先使用路由参数)
|
|
|
+ const purchasePlanId = (route.query.purchasePlanId as string) || inventory.purchasePlanId?.toString()
|
|
|
+ if (purchasePlanId) {
|
|
|
+ // 先设置计划ID,确保即使获取计划数据失败也能保存计划ID
|
|
|
+ formData.purchasePlanId = Number(purchasePlanId)
|
|
|
+ try {
|
|
|
+ const plan = await planApi.get(Number(purchasePlanId))
|
|
|
+ // 计划量就是计划的plannedQuantity(单位:吨),需要转换为kg
|
|
|
+ formData.plannedQuantity = plan.plannedQuantity * 1000
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取计划数据失败', error)
|
|
|
+ // 即使获取计划数据失败,计划ID也已经设置了
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 打开弹窗
|
|
|
+ modalOpen.value = true
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('加载出入库单数据失败')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
loadData()
|
|
|
+ loadCompanies()
|
|
|
+ loadCargos()
|
|
|
+ initFromRoute()
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
@@ -486,16 +828,57 @@
|
|
|
margin-bottom: 16px;
|
|
|
display: flex;
|
|
|
gap: 8px;
|
|
|
- }
|
|
|
-
|
|
|
- .search-bar {
|
|
|
- margin-bottom: 16px;
|
|
|
- display: flex;
|
|
|
align-items: center;
|
|
|
}
|
|
|
|
|
|
.card-header {
|
|
|
font-weight: 600;
|
|
|
}
|
|
|
+
|
|
|
+ :deep(.art-table) {
|
|
|
+ width: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
+ :deep(.el-table) {
|
|
|
+ width: 100% !important;
|
|
|
+ table-layout: auto;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保固定列正常工作
|
|
|
+ :deep(.el-table__fixed-right) {
|
|
|
+ right: 0 !important;
|
|
|
+ }
|
|
|
+
|
|
|
+ .data-item {
|
|
|
+ margin-bottom: 16px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .data-item-header {
|
|
|
+ margin-bottom: 8px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .dialog-content {
|
|
|
+ max-height: 60vh;
|
|
|
+ overflow-y: auto;
|
|
|
+ padding-right: 8px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .dialog-content::-webkit-scrollbar {
|
|
|
+ width: 8px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .dialog-content::-webkit-scrollbar-track {
|
|
|
+ background: #f1f1f1;
|
|
|
+ border-radius: 4px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .dialog-content::-webkit-scrollbar-thumb {
|
|
|
+ background: #c1c1c1;
|
|
|
+ border-radius: 4px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .dialog-content::-webkit-scrollbar-thumb:hover {
|
|
|
+ background: #a8a8a8;
|
|
|
+ }
|
|
|
</style>
|
|
|
|