李红攀:V2.0.001小程序的农业溯源
This commit is contained in:
6
env/.env
vendored
6
env/.env
vendored
@@ -1,4 +1,4 @@
|
||||
VITE_APP_TITLE = '芋道管理系统'
|
||||
VITE_APP_TITLE = '亚为mom小程序'
|
||||
VITE_APP_PORT = 9000
|
||||
|
||||
VITE_UNI_APPID = '__UNI__D1E5001'
|
||||
@@ -39,8 +39,8 @@ VITE_APP_TENANT_ENABLE=true
|
||||
VITE_APP_CAPTCHA_ENABLE=false
|
||||
# 默认账户密码
|
||||
VITE_APP_DEFAULT_LOGIN_TENANT_ID = 1
|
||||
VITE_APP_DEFAULT_LOGIN_USERNAME = admin
|
||||
VITE_APP_DEFAULT_LOGIN_PASSWORD = admin123
|
||||
VITE_APP_DEFAULT_LOGIN_USERNAME = YAVII
|
||||
VITE_APP_DEFAULT_LOGIN_PASSWORD = yavii123
|
||||
|
||||
# API 加解密
|
||||
VITE_APP_API_ENCRYPT_ENABLE = true
|
||||
|
||||
74
src/api/agri/biz/flow.ts
Normal file
74
src/api/agri/biz/flow.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { http } from '@/http/http'
|
||||
|
||||
export interface AgriHarvestSubmitReqVO {
|
||||
batchType: string
|
||||
productId?: number
|
||||
productName?: string
|
||||
plotId?: number
|
||||
plotName?: string
|
||||
farmerId?: number
|
||||
quantity?: number
|
||||
unit?: string
|
||||
harvestTime?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface AgriSortingSubmitReqVO {
|
||||
batchId: number
|
||||
weightResult?: number
|
||||
unqualifiedCategory?: string
|
||||
imageUrl?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface AgriPackingSubmitReqVO {
|
||||
batchId: number
|
||||
netWeight?: number
|
||||
labelCode?: string
|
||||
packingTime?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface AgriWarehouseInReqVO {
|
||||
batchId: number
|
||||
inMode?: string
|
||||
warehouseTime?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface AgriShipmentDispatchReqVO {
|
||||
batchId: number
|
||||
vehicleNo: string
|
||||
boxCount?: number
|
||||
shipmentTime?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface AgriShipmentSignReqVO {
|
||||
batchId: number
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export function submitHarvest(data: AgriHarvestSubmitReqVO) {
|
||||
return http.post<number>('/agri/biz/flow/harvest', data)
|
||||
}
|
||||
|
||||
export function submitSorting(data: AgriSortingSubmitReqVO) {
|
||||
return http.post<void>('/agri/biz/flow/sorting', data)
|
||||
}
|
||||
|
||||
export function submitPacking(data: AgriPackingSubmitReqVO) {
|
||||
return http.post<void>('/agri/biz/flow/packing', data)
|
||||
}
|
||||
|
||||
export function submitWarehouseIn(data: AgriWarehouseInReqVO) {
|
||||
return http.post<void>('/agri/biz/flow/warehouse-in', data)
|
||||
}
|
||||
|
||||
export function dispatchShipment(data: AgriShipmentDispatchReqVO) {
|
||||
return http.post<void>('/agri/biz/flow/shipment-dispatch', data)
|
||||
}
|
||||
|
||||
export function signShipment(data: AgriShipmentSignReqVO) {
|
||||
return http.post<void>('/agri/biz/flow/shipment-sign', data)
|
||||
}
|
||||
45
src/api/agri/trace/snapshot.ts
Normal file
45
src/api/agri/trace/snapshot.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import type { PageParam, PageResult } from '@/http/types'
|
||||
import { http } from '@/http/http'
|
||||
|
||||
export interface AgriTraceSnapshotVO {
|
||||
id: number
|
||||
traceCode: string
|
||||
batchId: number
|
||||
batchNo: string
|
||||
productName?: string
|
||||
plotName?: string
|
||||
harvestTime?: string
|
||||
harvestOperatorId?: number
|
||||
harvestOperatorName?: string
|
||||
packingTime?: string
|
||||
packingOperatorId?: number
|
||||
packingOperatorName?: string
|
||||
warehouseTime?: string
|
||||
warehouseOperatorId?: number
|
||||
warehouseOperatorName?: string
|
||||
shipmentTime?: string
|
||||
shipmentOperatorId?: number
|
||||
shipmentOperatorName?: string
|
||||
vehicleNo?: string
|
||||
invoiceStatus?: string
|
||||
snapshotJson?: string
|
||||
}
|
||||
|
||||
export interface AgriTraceSnapshotPageReqVO extends PageParam {
|
||||
batchId?: number
|
||||
batchNo?: string
|
||||
traceCode?: string
|
||||
productName?: string
|
||||
}
|
||||
|
||||
export function getAgriTraceSnapshotPage(params: AgriTraceSnapshotPageReqVO) {
|
||||
return http.get<PageResult<AgriTraceSnapshotVO>>('/agri/trace/snapshot/page', params)
|
||||
}
|
||||
|
||||
export function getAgriTraceSnapshot(id: number) {
|
||||
return http.get<AgriTraceSnapshotVO>(`/agri/trace/snapshot/get?id=${id}`)
|
||||
}
|
||||
|
||||
export function getAgriTraceSnapshotByTraceCode(traceCode: string) {
|
||||
return http.get<AgriTraceSnapshotVO>('/agri/trace/snapshot/get-by-trace-code', { traceCode })
|
||||
}
|
||||
437
src/pages-agri/biz-flow/index.vue
Normal file
437
src/pages-agri/biz-flow/index.vue
Normal file
@@ -0,0 +1,437 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="闭环操作台"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 流程说明 -->
|
||||
<view class="mx-24rpx mt-20rpx mb-16rpx px-24rpx py-16rpx rounded-12rpx bg-[#e6f7ff] text-24rpx text-[#1890ff]">
|
||||
最小闭环操作台:采收 → 分拣 → 装箱 → 入库 → 发运 → 签收
|
||||
</view>
|
||||
|
||||
<!-- 数量/重量看板 -->
|
||||
<view class="mx-24rpx mb-20rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
|
||||
<view class="px-24rpx py-20rpx border-b border-[#f0f0f0] text-28rpx text-[#333] font-semibold">
|
||||
数量 / 重量看板
|
||||
</view>
|
||||
<view class="p-24rpx">
|
||||
<view class="flex flex-wrap">
|
||||
<view class="w-1/2 mb-16rpx">
|
||||
<text class="text-24rpx text-[#999]">当前批次ID</text>
|
||||
<text class="ml-12rpx text-26rpx text-[#333]">{{ metricPanel.batchId ?? '-' }}</text>
|
||||
</view>
|
||||
<view class="w-1/2 mb-16rpx">
|
||||
<text class="text-24rpx text-[#999]">最近更新</text>
|
||||
<text class="ml-12rpx text-26rpx text-[#333]">{{ metricPanel.updatedAt || '-' }}</text>
|
||||
</view>
|
||||
<view class="w-1/2 mb-16rpx">
|
||||
<text class="text-24rpx text-[#999]">采收数量</text>
|
||||
<text class="ml-12rpx text-26rpx text-[#333]">{{ formatMetric(metricPanel.harvestQuantity, metricPanel.harvestUnit) }}</text>
|
||||
</view>
|
||||
<view class="w-1/2 mb-16rpx">
|
||||
<text class="text-24rpx text-[#999]">分拣称重</text>
|
||||
<text class="ml-12rpx text-26rpx text-[#333]">{{ formatMetric(metricPanel.sortingWeight, 'kg') }}</text>
|
||||
</view>
|
||||
<view class="w-1/2">
|
||||
<text class="text-24rpx text-[#999]">装箱净重</text>
|
||||
<text class="ml-12rpx text-26rpx text-[#333]">{{ formatMetric(metricPanel.packingNetWeight, 'kg') }}</text>
|
||||
</view>
|
||||
<view class="w-1/2">
|
||||
<text class="text-24rpx text-[#999]">发运箱数</text>
|
||||
<text class="ml-12rpx text-26rpx text-[#333]">{{ formatMetric(metricPanel.shipmentBoxCount, '箱') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 扫码按钮 -->
|
||||
<view class="mx-24rpx mb-20rpx flex items-center justify-between">
|
||||
<view class="text-28rpx text-[#333]">快捷操作</view>
|
||||
<wd-button size="small" type="info" plain icon="scan" @click="handleScanCode">
|
||||
扫码填充批次ID
|
||||
</wd-button>
|
||||
</view>
|
||||
|
||||
<!-- 操作步骤 Tab -->
|
||||
<view class="mx-24rpx mb-20rpx">
|
||||
<wd-tabs v-model="activeTab">
|
||||
<wd-tab title="采收" name="harvest" />
|
||||
<wd-tab title="分拣" name="sorting" />
|
||||
<wd-tab title="装箱" name="packing" />
|
||||
<wd-tab title="入库" name="warehouse" />
|
||||
<wd-tab title="发运" name="shipment" />
|
||||
<wd-tab title="签收" name="sign" />
|
||||
</wd-tabs>
|
||||
</view>
|
||||
|
||||
<!-- 采收表单 -->
|
||||
<view v-show="activeTab === 'harvest'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
|
||||
<view class="p-24rpx">
|
||||
<wd-cell-group border>
|
||||
<wd-picker
|
||||
v-model="harvestForm.batchType"
|
||||
label="批次类型"
|
||||
:columns="batchTypeColumns"
|
||||
label-width="200rpx"
|
||||
/>
|
||||
<wd-input v-model="harvestForm.productName" label="产品名称" label-width="200rpx" placeholder="请输入产品名称" />
|
||||
<wd-input v-model="harvestForm.plotName" label="地块名称" label-width="200rpx" placeholder="请输入地块名称" />
|
||||
<wd-input
|
||||
v-model="harvestForm.quantity"
|
||||
label="数量"
|
||||
label-width="200rpx"
|
||||
placeholder="请输入数量"
|
||||
type="number"
|
||||
/>
|
||||
<wd-input v-model="harvestForm.unit" label="单位" label-width="200rpx" placeholder="kg" />
|
||||
</wd-cell-group>
|
||||
<view class="mt-32rpx">
|
||||
<wd-button type="primary" block @click="onHarvest">提交采收</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分拣表单 -->
|
||||
<view v-show="activeTab === 'sorting'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
|
||||
<view class="p-24rpx">
|
||||
<wd-cell-group border>
|
||||
<wd-input
|
||||
v-model="sortingForm.batchId"
|
||||
label="批次ID"
|
||||
label-width="200rpx"
|
||||
placeholder="请输入批次ID"
|
||||
type="number"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="sortingForm.weightResult"
|
||||
label="称重结果"
|
||||
label-width="200rpx"
|
||||
placeholder="请输入称重结果"
|
||||
type="digit"
|
||||
/>
|
||||
<wd-input v-model="sortingForm.unqualifiedCategory" label="不合格分类" label-width="200rpx" placeholder="请输入不合格分类" />
|
||||
</wd-cell-group>
|
||||
<view class="mt-32rpx">
|
||||
<wd-button type="primary" block @click="onSorting">提交分拣</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 装箱表单 -->
|
||||
<view v-show="activeTab === 'packing'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
|
||||
<view class="p-24rpx">
|
||||
<wd-cell-group border>
|
||||
<wd-input
|
||||
v-model="packingForm.batchId"
|
||||
label="批次ID"
|
||||
label-width="200rpx"
|
||||
placeholder="请输入批次ID"
|
||||
type="number"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="packingForm.netWeight"
|
||||
label="净重"
|
||||
label-width="200rpx"
|
||||
placeholder="请输入净重"
|
||||
type="digit"
|
||||
/>
|
||||
<wd-input v-model="packingForm.labelCode" label="标签编码" label-width="200rpx" placeholder="请输入标签编码" />
|
||||
</wd-cell-group>
|
||||
<view class="mt-32rpx">
|
||||
<wd-button type="primary" block @click="onPacking">提交装箱</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 入库表单 -->
|
||||
<view v-show="activeTab === 'warehouse'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
|
||||
<view class="p-24rpx">
|
||||
<wd-cell-group border>
|
||||
<wd-input
|
||||
v-model="warehouseForm.batchId"
|
||||
label="批次ID"
|
||||
label-width="200rpx"
|
||||
placeholder="请输入批次ID"
|
||||
type="number"
|
||||
/>
|
||||
<wd-picker
|
||||
v-model="warehouseForm.inMode"
|
||||
label="入库模式"
|
||||
:columns="inModeColumns"
|
||||
label-width="200rpx"
|
||||
/>
|
||||
</wd-cell-group>
|
||||
<view class="mt-32rpx">
|
||||
<wd-button type="primary" block @click="onWarehouseIn">提交入库</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 发运表单 -->
|
||||
<view v-show="activeTab === 'shipment'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
|
||||
<view class="p-24rpx">
|
||||
<wd-cell-group border>
|
||||
<wd-input
|
||||
v-model="shipmentForm.batchId"
|
||||
label="批次ID"
|
||||
label-width="200rpx"
|
||||
placeholder="请输入批次ID"
|
||||
type="number"
|
||||
/>
|
||||
<wd-input v-model="shipmentForm.vehicleNo" label="车牌号" label-width="200rpx" placeholder="请输入车牌号" />
|
||||
<wd-input
|
||||
v-model="shipmentForm.boxCount"
|
||||
label="箱数"
|
||||
label-width="200rpx"
|
||||
placeholder="请输入箱数"
|
||||
type="number"
|
||||
/>
|
||||
</wd-cell-group>
|
||||
<view class="mt-32rpx">
|
||||
<wd-button type="primary" block @click="onDispatch">提交发运</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 签收表单 -->
|
||||
<view v-show="activeTab === 'sign'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
|
||||
<view class="p-24rpx">
|
||||
<wd-cell-group border>
|
||||
<wd-input
|
||||
v-model="signForm.batchId"
|
||||
label="批次ID"
|
||||
label-width="200rpx"
|
||||
placeholder="请输入批次ID"
|
||||
type="number"
|
||||
/>
|
||||
<wd-input v-model="signForm.remark" label="备注" label-width="200rpx" placeholder="请输入备注" />
|
||||
</wd-cell-group>
|
||||
<view class="mt-32rpx">
|
||||
<wd-button type="primary" block @click="onSign">提交签收</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import {
|
||||
dispatchShipment,
|
||||
signShipment,
|
||||
submitHarvest,
|
||||
submitPacking,
|
||||
submitSorting,
|
||||
submitWarehouseIn
|
||||
} from '@/api/agri/biz/flow'
|
||||
import { BATCH_TYPE_OPTIONS, IN_MODE_OPTIONS } from '@/utils/agriTraceDict'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const activeTab = ref('harvest')
|
||||
|
||||
const harvestForm = reactive({
|
||||
batchType: 'HARVEST',
|
||||
productName: '',
|
||||
plotName: '',
|
||||
quantity: '' as string | number,
|
||||
unit: 'kg'
|
||||
})
|
||||
|
||||
const sortingForm = reactive({
|
||||
batchId: '' as string | number,
|
||||
weightResult: '' as string | number,
|
||||
unqualifiedCategory: ''
|
||||
})
|
||||
|
||||
const packingForm = reactive({
|
||||
batchId: '' as string | number,
|
||||
netWeight: '' as string | number,
|
||||
labelCode: ''
|
||||
})
|
||||
|
||||
const warehouseForm = reactive({
|
||||
batchId: '' as string | number,
|
||||
inMode: 'BOX'
|
||||
})
|
||||
|
||||
const shipmentForm = reactive({
|
||||
batchId: '' as string | number,
|
||||
vehicleNo: '',
|
||||
boxCount: '' as string | number
|
||||
})
|
||||
|
||||
const signForm = reactive({
|
||||
batchId: '' as string | number,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const metricPanel = reactive({
|
||||
batchId: undefined as number | undefined,
|
||||
harvestQuantity: undefined as number | undefined,
|
||||
harvestUnit: 'kg',
|
||||
sortingWeight: undefined as number | undefined,
|
||||
packingNetWeight: undefined as number | undefined,
|
||||
shipmentBoxCount: undefined as number | undefined,
|
||||
updatedAt: ''
|
||||
})
|
||||
|
||||
/** 批次类型下拉列 */
|
||||
const batchTypeColumns = computed(() => [
|
||||
BATCH_TYPE_OPTIONS.map(v => ({ value: v.value, label: v.label }))
|
||||
])
|
||||
|
||||
/** 入库模式下拉列 */
|
||||
const inModeColumns = computed(() => [
|
||||
IN_MODE_OPTIONS.map(v => ({ value: v.value, label: v.label }))
|
||||
])
|
||||
|
||||
const formatMetric = (value?: number, unit?: string) => {
|
||||
if (value === undefined || value === null) {
|
||||
return '-'
|
||||
}
|
||||
return unit ? `${value} ${unit}` : `${value}`
|
||||
}
|
||||
|
||||
const refreshMetricPanel = (patch: Partial<typeof metricPanel>) => {
|
||||
Object.assign(metricPanel, patch, {
|
||||
updatedAt: new Date().toLocaleString()
|
||||
})
|
||||
}
|
||||
|
||||
const syncBatchIdToFollowUpForms = (batchId: number) => {
|
||||
sortingForm.batchId = batchId
|
||||
packingForm.batchId = batchId
|
||||
warehouseForm.batchId = batchId
|
||||
shipmentForm.batchId = batchId
|
||||
signForm.batchId = batchId
|
||||
}
|
||||
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
const onHarvest = async () => {
|
||||
const id = await submitHarvest({
|
||||
...harvestForm,
|
||||
quantity: harvestForm.quantity ? Number(harvestForm.quantity) : undefined
|
||||
})
|
||||
refreshMetricPanel({
|
||||
batchId: id,
|
||||
harvestQuantity: harvestForm.quantity ? Number(harvestForm.quantity) : undefined,
|
||||
harvestUnit: harvestForm.unit || 'kg'
|
||||
})
|
||||
syncBatchIdToFollowUpForms(id)
|
||||
uni.showToast({ title: `采收成功,批次ID:${id}`, icon: 'none' })
|
||||
activeTab.value = 'sorting'
|
||||
}
|
||||
|
||||
const onSorting = async () => {
|
||||
await submitSorting({
|
||||
batchId: Number(sortingForm.batchId),
|
||||
weightResult: sortingForm.weightResult ? Number(sortingForm.weightResult) : undefined,
|
||||
unqualifiedCategory: sortingForm.unqualifiedCategory || undefined
|
||||
})
|
||||
refreshMetricPanel({
|
||||
batchId: Number(sortingForm.batchId),
|
||||
sortingWeight: sortingForm.weightResult ? Number(sortingForm.weightResult) : undefined
|
||||
})
|
||||
uni.showToast({ title: '分拣成功', icon: 'success' })
|
||||
activeTab.value = 'packing'
|
||||
}
|
||||
|
||||
const onPacking = async () => {
|
||||
await submitPacking({
|
||||
batchId: Number(packingForm.batchId),
|
||||
netWeight: packingForm.netWeight ? Number(packingForm.netWeight) : undefined,
|
||||
labelCode: packingForm.labelCode || undefined
|
||||
})
|
||||
refreshMetricPanel({
|
||||
batchId: Number(packingForm.batchId),
|
||||
packingNetWeight: packingForm.netWeight ? Number(packingForm.netWeight) : undefined
|
||||
})
|
||||
uni.showToast({ title: '装箱成功', icon: 'success' })
|
||||
activeTab.value = 'warehouse'
|
||||
}
|
||||
|
||||
const onWarehouseIn = async () => {
|
||||
await submitWarehouseIn({
|
||||
batchId: Number(warehouseForm.batchId),
|
||||
inMode: warehouseForm.inMode || undefined
|
||||
})
|
||||
uni.showToast({ title: '入库成功', icon: 'success' })
|
||||
activeTab.value = 'shipment'
|
||||
}
|
||||
|
||||
const onDispatch = async () => {
|
||||
await dispatchShipment({
|
||||
batchId: Number(shipmentForm.batchId),
|
||||
vehicleNo: shipmentForm.vehicleNo,
|
||||
boxCount: shipmentForm.boxCount ? Number(shipmentForm.boxCount) : undefined
|
||||
})
|
||||
refreshMetricPanel({
|
||||
batchId: Number(shipmentForm.batchId),
|
||||
shipmentBoxCount: shipmentForm.boxCount ? Number(shipmentForm.boxCount) : undefined
|
||||
})
|
||||
uni.showToast({ title: '发运成功', icon: 'success' })
|
||||
activeTab.value = 'sign'
|
||||
}
|
||||
|
||||
const onSign = async () => {
|
||||
await signShipment({
|
||||
batchId: Number(signForm.batchId),
|
||||
remark: signForm.remark || undefined
|
||||
})
|
||||
uni.showToast({ title: '签收成功', icon: 'success' })
|
||||
}
|
||||
|
||||
/** 扫码填充批次ID */
|
||||
const handleScanCode = () => {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.scanCode({
|
||||
onlyFromCamera: false,
|
||||
scanType: ['qrCode', 'barCode'],
|
||||
success: (res) => {
|
||||
const result = res.result
|
||||
// 尝试解析批次ID(支持纯数字或JSON格式)
|
||||
let batchId: number | undefined
|
||||
try {
|
||||
const parsed = JSON.parse(result)
|
||||
batchId = parsed.batchId || parsed.id
|
||||
} catch {
|
||||
// 如果不是JSON,尝试直接解析为数字
|
||||
const num = Number(result)
|
||||
if (!isNaN(num) && num > 0) {
|
||||
batchId = num
|
||||
}
|
||||
}
|
||||
if (batchId) {
|
||||
syncBatchIdToFollowUpForms(batchId)
|
||||
refreshMetricPanel({ batchId })
|
||||
uni.showToast({ title: `已填充批次ID: ${batchId}`, icon: 'none' })
|
||||
} else {
|
||||
uni.showToast({ title: '无法识别批次ID', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '扫码取消或失败', icon: 'none' })
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.showToast({ title: '当前环境不支持扫码', icon: 'none' })
|
||||
// #endif
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
334
src/pages-agri/trace-snapshot/index.vue
Normal file
334
src/pages-agri/trace-snapshot/index.vue
Normal file
@@ -0,0 +1,334 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="溯源快照"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 搜索组件 -->
|
||||
<view class="flex items-center px-24rpx">
|
||||
<view class="flex-1" @click="searchVisible = true">
|
||||
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
|
||||
</view>
|
||||
<wd-button size="small" type="primary" icon="scan" class="ml-16rpx" @click="handleScanQuery">
|
||||
扫码
|
||||
</wd-button>
|
||||
</view>
|
||||
|
||||
<!-- 快照列表 -->
|
||||
<view class="px-24rpx">
|
||||
<view
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
@click="handleDetail(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<!-- 头部:溯源码 + 批次号 -->
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-28rpx text-[#333] font-semibold flex-1 truncate">
|
||||
{{ item.traceCode || '-' }}
|
||||
</view>
|
||||
<view class="text-24rpx text-[#1890ff] ml-12rpx">
|
||||
{{ item.batchNo || '' }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 产品名 + 地块名 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text>{{ item.productName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">地块</text>
|
||||
<text>{{ item.plotName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 采收信息 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">采收</text>
|
||||
<text>{{ item.harvestOperatorName || '-' }} / {{ formatTime(item.harvestTime) }}</text>
|
||||
</view>
|
||||
<!-- 装箱信息 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">装箱</text>
|
||||
<text>{{ item.packingOperatorName || '-' }} / {{ formatTime(item.packingTime) }}</text>
|
||||
</view>
|
||||
<!-- 入库信息 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">入库</text>
|
||||
<text>{{ item.warehouseOperatorName || '-' }} / {{ formatTime(item.warehouseTime) }}</text>
|
||||
</view>
|
||||
<!-- 发运信息 -->
|
||||
<view class="flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">发运</text>
|
||||
<text>{{ item.shipmentOperatorName || '-' }} / {{ item.vehicleNo || '-' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无溯源快照数据" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="list.length > 0"
|
||||
:state="loadMoreState"
|
||||
@reload="loadMore"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 搜索弹窗 -->
|
||||
<wd-popup v-model="searchVisible" position="top" @close="searchVisible = false">
|
||||
<view class="yd-search-form-container" :style="{ paddingTop: `${getNavbarHeight()}px` }">
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">批次号</view>
|
||||
<wd-input v-model="searchForm.batchNo" placeholder="请输入批次号" no-border />
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">溯源码</view>
|
||||
<wd-input v-model="searchForm.traceCode" placeholder="请输入溯源码" no-border />
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">产品名</view>
|
||||
<wd-input v-model="searchForm.productName" placeholder="请输入产品名称" no-border />
|
||||
</view>
|
||||
<view class="yd-search-form-actions">
|
||||
<wd-button class="flex-1" plain @click="handleReset">重置</wd-button>
|
||||
<wd-button class="flex-1" type="primary" @click="handleSearch">搜索</wd-button>
|
||||
</view>
|
||||
<view class="mt-20rpx">
|
||||
<wd-button type="info" block plain @click="handleTraceCodeQuery">按溯源码查单条</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<wd-popup v-model="detailVisible" position="bottom" custom-style="height: 70%;">
|
||||
<view class="p-24rpx">
|
||||
<view class="text-32rpx text-[#333] font-semibold mb-24rpx">溯源详情</view>
|
||||
<view v-if="currentDetail" class="text-26rpx text-[#666]">
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">ID</text><text>{{ currentDetail.id }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">溯源码</text><text class="flex-1 break-all">{{ currentDetail.traceCode }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">批次号</text><text>{{ currentDetail.batchNo }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">产品名</text><text>{{ currentDetail.productName || '-' }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">地块名</text><text>{{ currentDetail.plotName || '-' }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">采收操作人</text><text>{{ currentDetail.harvestOperatorName || '-' }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">采收时间</text><text>{{ formatTime(currentDetail.harvestTime) }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">装箱操作人</text><text>{{ currentDetail.packingOperatorName || '-' }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">装箱时间</text><text>{{ formatTime(currentDetail.packingTime) }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">入库操作人</text><text>{{ currentDetail.warehouseOperatorName || '-' }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">入库时间</text><text>{{ formatTime(currentDetail.warehouseTime) }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">发运操作人</text><text>{{ currentDetail.shipmentOperatorName || '-' }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">发运时间</text><text>{{ formatTime(currentDetail.shipmentTime) }}</text></view>
|
||||
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">车牌号</text><text>{{ currentDetail.vehicleNo || '-' }}</text></view>
|
||||
</view>
|
||||
<wd-button type="primary" block class="mt-32rpx" @click="detailVisible = false">关闭</wd-button>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { AgriTraceSnapshotVO } from '@/api/agri/trace/snapshot'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import {
|
||||
getAgriTraceSnapshotByTraceCode,
|
||||
getAgriTraceSnapshotPage
|
||||
} from '@/api/agri/trace/snapshot'
|
||||
import { getNavbarHeight, navigateBackPlus } from '@/utils'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const total = ref(0)
|
||||
const list = ref<AgriTraceSnapshotVO[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const queryParams = ref<Record<string, any>>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
|
||||
// 搜索相关
|
||||
const searchVisible = ref(false)
|
||||
const searchForm = reactive({
|
||||
batchNo: '',
|
||||
traceCode: '',
|
||||
productName: ''
|
||||
})
|
||||
|
||||
// 详情弹窗
|
||||
const detailVisible = ref(false)
|
||||
const currentDetail = ref<AgriTraceSnapshotVO | null>(null)
|
||||
|
||||
/** 搜索条件 placeholder */
|
||||
const searchPlaceholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (searchForm.batchNo) conditions.push(`批次:${searchForm.batchNo}`)
|
||||
if (searchForm.traceCode) conditions.push(`溯源码:${searchForm.traceCode}`)
|
||||
if (searchForm.productName) conditions.push(`产品:${searchForm.productName}`)
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索溯源快照'
|
||||
})
|
||||
|
||||
/** 格式化时间 */
|
||||
function formatTime(time?: string | number) {
|
||||
if (!time) return '-'
|
||||
// 如果是时间戳(数字),转换为日期字符串
|
||||
if (typeof time === 'number') {
|
||||
const date = new Date(time)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}`
|
||||
}
|
||||
// 如果是字符串,处理 ISO 格式
|
||||
if (typeof time === 'string') {
|
||||
return time.replace('T', ' ').substring(0, 16)
|
||||
}
|
||||
return '-'
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
/** 查询列表 */
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const params: Record<string, any> = { ...queryParams.value }
|
||||
if (searchForm.batchNo) params.batchNo = searchForm.batchNo
|
||||
if (searchForm.traceCode) params.traceCode = searchForm.traceCode
|
||||
if (searchForm.productName) params.productName = searchForm.productName
|
||||
const data = await getAgriTraceSnapshotPage(params)
|
||||
list.value = [...list.value, ...data.list]
|
||||
total.value = data.total
|
||||
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
|
||||
loadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
searchVisible.value = false
|
||||
queryParams.value = {
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
function handleReset() {
|
||||
searchForm.batchNo = ''
|
||||
searchForm.traceCode = ''
|
||||
searchForm.productName = ''
|
||||
searchVisible.value = false
|
||||
queryParams.value = { pageNo: 1, pageSize: 10 }
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 按溯源码查单条 */
|
||||
async function handleTraceCodeQuery() {
|
||||
if (!searchForm.traceCode) {
|
||||
uni.showToast({ title: '请先输入溯源码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
searchVisible.value = false
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const data = await getAgriTraceSnapshotByTraceCode(searchForm.traceCode)
|
||||
list.value = data ? [data] : []
|
||||
total.value = list.value.length
|
||||
loadMoreState.value = 'finished'
|
||||
} catch {
|
||||
loadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
/** 查看详情 */
|
||||
function handleDetail(item: AgriTraceSnapshotVO) {
|
||||
currentDetail.value = item
|
||||
detailVisible.value = true
|
||||
}
|
||||
|
||||
/** 加载更多 */
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished') return
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 触底加载更多 */
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
/** 扫码查询 */
|
||||
function handleScanQuery() {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.scanCode({
|
||||
onlyFromCamera: false,
|
||||
scanType: ['qrCode', 'barCode'],
|
||||
success: async (res) => {
|
||||
const result = res.result
|
||||
// 尝试解析溯源码(支持纯字符串或JSON格式)
|
||||
let traceCode: string | undefined
|
||||
try {
|
||||
const parsed = JSON.parse(result)
|
||||
traceCode = parsed.traceCode || parsed.code
|
||||
} catch {
|
||||
// 如果不是JSON,直接使用扫码结果
|
||||
traceCode = result
|
||||
}
|
||||
if (traceCode) {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const data = await getAgriTraceSnapshotByTraceCode(traceCode)
|
||||
list.value = data ? [data] : []
|
||||
total.value = list.value.length
|
||||
loadMoreState.value = 'finished'
|
||||
if (data) {
|
||||
uni.showToast({ title: '查询成功', icon: 'success' })
|
||||
} else {
|
||||
uni.showToast({ title: '未找到该溯源码', icon: 'none' })
|
||||
}
|
||||
} catch {
|
||||
loadMoreState.value = 'error'
|
||||
uni.showToast({ title: '查询失败', icon: 'none' })
|
||||
}
|
||||
} else {
|
||||
uni.showToast({ title: '无法识别溯源码', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '扫码取消或失败', icon: 'none' })
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.showToast({ title: '当前环境不支持扫码', icon: 'none' })
|
||||
// #endif
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
@@ -88,6 +88,28 @@ const menuGroupsData: MenuGroup[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'agri',
|
||||
name: '农业溯源',
|
||||
menus: [
|
||||
{
|
||||
key: 'agriBizFlow',
|
||||
name: '闭环操作台',
|
||||
icon: 'flow',
|
||||
url: '/pages-agri/biz-flow/index',
|
||||
iconColor: '#52c41a',
|
||||
permission: 'agri:biz:harvest',
|
||||
},
|
||||
{
|
||||
key: 'agriTraceSnapshot',
|
||||
name: '溯源快照',
|
||||
icon: 'scan',
|
||||
url: '/pages-agri/trace-snapshot/index',
|
||||
iconColor: '#1890ff',
|
||||
permission: 'agri:trace-snapshot:query',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'stock',
|
||||
name: '库存管理',
|
||||
|
||||
18
src/utils/agriTraceDict.ts
Normal file
18
src/utils/agriTraceDict.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export const BATCH_TYPE_LABEL_MAP: Record<string, string> = {
|
||||
HARVEST: '采收批次',
|
||||
SORTING: '分拣批次',
|
||||
PACKING: '装箱批次',
|
||||
WAREHOUSE: '仓储批次',
|
||||
SHIPMENT: '发运批次'
|
||||
}
|
||||
|
||||
export const IN_MODE_LABEL_MAP: Record<string, string> = {
|
||||
BOX: '按箱入库',
|
||||
PALLET: '按托入库'
|
||||
}
|
||||
|
||||
const toOptions = (labelMap: Record<string, string>) =>
|
||||
Object.entries(labelMap).map(([value, label]) => ({ label, value }))
|
||||
|
||||
export const BATCH_TYPE_OPTIONS = toOptions(BATCH_TYPE_LABEL_MAP)
|
||||
export const IN_MODE_OPTIONS = toOptions(IN_MODE_LABEL_MAP)
|
||||
@@ -124,7 +124,7 @@ export function getEnvBaseUrl() {
|
||||
// # 有些同学可能需要在微信小程序里面根据 develop、trial、release 分别设置上传地址,参考代码如下。
|
||||
// TODO @芋艿:这个后续也要调整。
|
||||
const VITE_SERVER_BASEURL__WEIXIN_DEVELOP = 'http://localhost:48080/admin-api'
|
||||
const VITE_SERVER_BASEURL__WEIXIN_TRIAL = 'http://localhost:48080/admin-api'
|
||||
const VITE_SERVER_BASEURL__WEIXIN_TRIAL = 'http://119.96.62.56:7004/admin-api'
|
||||
const VITE_SERVER_BASEURL__WEIXIN_RELEASE = 'http://localhost:48080/admin-api'
|
||||
|
||||
// 微信小程序端环境区分
|
||||
|
||||
@@ -78,6 +78,7 @@ export default defineConfig(({ command, mode }) => {
|
||||
'src/pages-infra', // “基础设施”模块
|
||||
'src/pages-bpm', // “工作流程”模块
|
||||
'src/pages-erp', // “采购管理”模块
|
||||
'src/pages-agri', // “农业溯源”模块
|
||||
],
|
||||
dts: 'src/types/uni-pages.d.ts',
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user