李红攀:V2.0.001小程序的采摘管理
This commit is contained in:
126
src/pages-erp/pick-broccoli/components/search-form.vue
Normal file
126
src/pages-erp/pick-broccoli/components/search-form.vue
Normal file
@@ -0,0 +1,126 @@
|
||||
<template>
|
||||
<!-- 搜索框入口 -->
|
||||
<view @click="visible = true">
|
||||
<wd-search :placeholder="placeholder" hide-cancel disabled />
|
||||
</view>
|
||||
|
||||
<!-- 搜索弹窗 -->
|
||||
<wd-popup v-model="visible" position="top" @close="visible = 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="formData.pickCode"
|
||||
placeholder="请输入采摘编号"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
采摘人员
|
||||
</view>
|
||||
<wd-input
|
||||
v-model="formData.userName"
|
||||
placeholder="请输入采摘人员姓名"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
状态
|
||||
</view>
|
||||
<wd-radio-group v-model="formData.status" shape="button">
|
||||
<wd-radio :value="-1">
|
||||
全部
|
||||
</wd-radio>
|
||||
<wd-radio :value="1">
|
||||
已采摘
|
||||
</wd-radio>
|
||||
<wd-radio :value="2">
|
||||
已装框
|
||||
</wd-radio>
|
||||
<wd-radio :value="3">
|
||||
已装车
|
||||
</wd-radio>
|
||||
<wd-radio :value="4">
|
||||
已入库
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</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>
|
||||
</wd-popup>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { getNavbarHeight } from '@/utils'
|
||||
|
||||
const emit = defineEmits<{
|
||||
search: [data: Record<string, any>]
|
||||
reset: []
|
||||
}>()
|
||||
|
||||
const visible = ref(false)
|
||||
const formData = reactive({
|
||||
pickCode: undefined as string | undefined,
|
||||
userName: undefined as string | undefined,
|
||||
status: -1,
|
||||
})
|
||||
|
||||
const statusMap: Record<number, string> = {
|
||||
1: '已采摘',
|
||||
2: '已装框',
|
||||
3: '已装车',
|
||||
4: '已入库',
|
||||
}
|
||||
|
||||
/** 搜索条件 placeholder 拼接 */
|
||||
const placeholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (formData.pickCode) {
|
||||
conditions.push(`编号:${formData.pickCode}`)
|
||||
}
|
||||
if (formData.userName) {
|
||||
conditions.push(`人员:${formData.userName}`)
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
conditions.push(`状态:${statusMap[formData.status] || formData.status}`)
|
||||
}
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索采摘记录'
|
||||
})
|
||||
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
visible.value = false
|
||||
const params: Record<string, any> = {}
|
||||
if (formData.pickCode) {
|
||||
params.pickCode = formData.pickCode
|
||||
}
|
||||
if (formData.userName) {
|
||||
params.userName = formData.userName
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
params.status = formData.status
|
||||
}
|
||||
emit('search', params)
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
function handleReset() {
|
||||
formData.pickCode = undefined
|
||||
formData.userName = undefined
|
||||
formData.status = -1
|
||||
visible.value = false
|
||||
emit('reset')
|
||||
}
|
||||
</script>
|
||||
237
src/pages-erp/pick-broccoli/detail/index.vue
Normal file
237
src/pages-erp/pick-broccoli/detail/index.vue
Normal file
@@ -0,0 +1,237 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="采摘记录详情"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 详情内容 -->
|
||||
<view v-if="formData">
|
||||
<!-- 基本信息 -->
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="采摘编号" :value="formData.pickCode" />
|
||||
<wd-cell title="状态">
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(formData.status)"
|
||||
>
|
||||
{{ getStatusText(formData.status) }}
|
||||
</view>
|
||||
</wd-cell>
|
||||
<wd-cell title="关联产品" :value="formData.productName || '-'" />
|
||||
<wd-cell title="采摘人员" :value="formData.userName || '-'" />
|
||||
<wd-cell title="田间编号" :value="formData.fieldCode || '-'" />
|
||||
<wd-cell title="采摘时间" :value="formatDate(formData.pickTime)" />
|
||||
<wd-cell title="创建时间" :value="formatDate(formData.createTime)" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 采摘信息 -->
|
||||
<wd-cell-group title="采摘信息" border>
|
||||
<wd-cell title="框编号" :value="formData.basketCode || '-'" />
|
||||
<wd-cell title="每筐重量" :value="formData.basketWeight ? `${formData.basketWeight} kg` : '-'" />
|
||||
<wd-cell title="车牌号" :value="formData.licensePlate || '-'" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 装车信息 (status >= 3) -->
|
||||
<wd-cell-group v-if="(formData.status ?? 0) >= 3" title="装车信息" border>
|
||||
<wd-cell title="装车人员" :value="formData.loaderName || '-'" />
|
||||
<wd-cell title="装车时间" :value="formatDate(formData.loadTime)" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 卸车入库信息 (status === 4) -->
|
||||
<wd-cell-group v-if="formData.status === 4" title="卸车入库信息" border>
|
||||
<wd-cell title="卸车人员" :value="formData.unloaderName || '-'" />
|
||||
<wd-cell title="卸车时间" :value="formatDate(formData.unloadTime)" />
|
||||
<wd-cell title="入库仓库" :value="formData.warehouseName || '-'" />
|
||||
<wd-cell title="卸车批次号" :value="formData.unloadBatch || '-'" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 备注 -->
|
||||
<wd-cell-group v-if="formData.remark" title="备注" border>
|
||||
<wd-cell :value="formData.remark" />
|
||||
</wd-cell-group>
|
||||
</view>
|
||||
|
||||
<!-- 底部操作按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<view class="yd-detail-footer-actions">
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && (formData?.status ?? 0) < 3"
|
||||
class="flex-1" type="primary" @click="handleEdit"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && formData?.status === 1"
|
||||
class="flex-1" type="success" @click="handleStatusUpdate(2, '装框')"
|
||||
>
|
||||
装框
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && formData?.status === 2"
|
||||
class="flex-1" type="warning" @click="handleLoadTruck"
|
||||
>
|
||||
装车
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:delete']) && (formData?.status ?? 0) < 3"
|
||||
class="flex-1" type="error" :loading="deleting" @click="handleDelete"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PickBroccoli } from '@/api/erp/pick-broccoli'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deletePickBroccoli, getPickBroccoli, loadTruck, updatePickBroccoliStatus } from '@/api/erp/pick-broccoli'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const formData = ref<PickBroccoli>()
|
||||
const deleting = ref(false)
|
||||
|
||||
/** 格式化日期 */
|
||||
function formatDate(date?: string) {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
/** 获取状态文本 */
|
||||
function getStatusText(status?: number) {
|
||||
switch (status) {
|
||||
case 1: return '已采摘'
|
||||
case 2: return '已装框'
|
||||
case 3: return '已装车'
|
||||
case 4: return '已卸车入库'
|
||||
default: return '未知'
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number) {
|
||||
switch (status) {
|
||||
case 1: return 'bg-[#e6f7ff] text-[#1890ff]'
|
||||
case 2: return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
case 3: return 'bg-[#f9f0ff] text-[#722ed1]'
|
||||
case 4: return 'bg-[#f6ffed] text-[#52c41a]'
|
||||
default: return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/pick-broccoli/index')
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getPickBroccoli(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit() {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/pick-broccoli/form/index?id=${props.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 状态更新(装框) */
|
||||
function handleStatusUpdate(status: number, text: string) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `确认将该记录状态更新为"${text}完成"吗?`,
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePickBroccoliStatus(props.id, status)
|
||||
toast.success(`${text}操作成功`)
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 装车操作 */
|
||||
function handleLoadTruck() {
|
||||
uni.showModal({
|
||||
title: '装车',
|
||||
content: '请输入车牌号',
|
||||
editable: true,
|
||||
placeholderText: '车牌号',
|
||||
success: async (res) => {
|
||||
if (!res.confirm || !res.content) return
|
||||
try {
|
||||
await loadTruck(props.id, res.content, 0, '')
|
||||
toast.success('装车操作成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
function handleDelete() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该采摘记录吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
deleting.value = true
|
||||
try {
|
||||
await deletePickBroccoli(props.id)
|
||||
toast.success('删除成功')
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
354
src/pages-erp/pick-broccoli/form/index.vue
Normal file
354
src/pages-erp/pick-broccoli/form/index.vue
Normal file
@@ -0,0 +1,354 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
:title="getTitle"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<view class="pb-180rpx">
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<!-- 基本信息 -->
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-input
|
||||
v-model="formData.pickCode"
|
||||
label="采摘编号"
|
||||
label-width="180rpx"
|
||||
prop="pickCode"
|
||||
placeholder="自动生成"
|
||||
:disabled="isLoaded"
|
||||
readonly
|
||||
>
|
||||
<template v-if="!props.id" #suffix>
|
||||
<wd-button size="small" type="primary" @click="handleGenerateCode">
|
||||
生成
|
||||
</wd-button>
|
||||
</template>
|
||||
</wd-input>
|
||||
<wd-cell title="采摘人员" title-width="180rpx" prop="userName" center>
|
||||
<wd-picker
|
||||
v-model="formData.userId"
|
||||
:columns="userColumns"
|
||||
label=""
|
||||
placeholder="请选择采摘人员"
|
||||
:disabled="isLoaded"
|
||||
@confirm="onUserConfirm"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="关联产品" title-width="180rpx" prop="productName" center>
|
||||
<wd-picker
|
||||
v-model="formData.productId"
|
||||
:columns="productColumns"
|
||||
label=""
|
||||
placeholder="请选择产品"
|
||||
:disabled="isLoaded"
|
||||
@confirm="onProductConfirm"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="田间编号" title-width="180rpx" prop="fieldCode" center>
|
||||
<wd-picker
|
||||
v-model="formData.fieldCode"
|
||||
:columns="fieldColumns"
|
||||
label=""
|
||||
placeholder="请选择田间编号"
|
||||
:disabled="isLoaded"
|
||||
/>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 采摘信息 -->
|
||||
<wd-cell-group title="采摘信息" border>
|
||||
<wd-cell title="框编号" title-width="180rpx" prop="basketCode" center>
|
||||
<wd-picker
|
||||
v-model="formData.basketCode"
|
||||
:columns="basketColumns"
|
||||
label=""
|
||||
placeholder="请选择框编号"
|
||||
:disabled="isLoaded"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-model="formData.basketWeight"
|
||||
label="每筐重量(kg)"
|
||||
label-width="180rpx"
|
||||
type="number"
|
||||
placeholder="请输入每筐重量"
|
||||
clearable
|
||||
:disabled="isLoaded"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.licensePlate"
|
||||
label="车牌号"
|
||||
label-width="180rpx"
|
||||
clearable
|
||||
placeholder="请输入车牌号"
|
||||
:disabled="isLoaded"
|
||||
/>
|
||||
<wd-cell title="采摘时间" title-width="180rpx" prop="pickTime" center>
|
||||
<wd-datetime-picker
|
||||
v-model="formData.pickTime"
|
||||
type="datetime"
|
||||
label=""
|
||||
placeholder="请选择采摘时间"
|
||||
:disabled="isLoaded"
|
||||
/>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 状态信息(编辑时) -->
|
||||
<wd-cell-group v-if="formData.id" title="状态信息" border>
|
||||
<wd-cell title="当前状态" :value="getStatusText(formData.status)" />
|
||||
<wd-cell v-if="formData.loadTime" title="装车时间" :value="formatDate(formData.loadTime)" />
|
||||
<wd-cell v-if="formData.loaderName" title="装车人" :value="formData.loaderName" />
|
||||
<wd-cell v-if="formData.unloadTime" title="卸车时间" :value="formatDate(formData.unloadTime)" />
|
||||
<wd-cell v-if="formData.unloaderName" title="卸车人员" :value="formData.unloaderName" />
|
||||
<wd-cell v-if="formData.warehouseName" title="仓库名称" :value="formData.warehouseName" />
|
||||
<wd-cell v-if="formData.unloadBatch" title="卸车批次号" :value="formData.unloadBatch" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 备注 -->
|
||||
<wd-cell-group title="其他" border>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入备注信息(可选)"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
:disabled="isLoaded"
|
||||
/>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<!-- 底部保存按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
type="primary"
|
||||
block
|
||||
:loading="formLoading"
|
||||
:disabled="isLoaded"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
|
||||
import type { PickBroccoli } from '@/api/erp/pick-broccoli'
|
||||
import type { User } from '@/api/system/user'
|
||||
import type { ProductSimple } from '@/api/erp/product'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { createPickBroccoli, generatePickCode, getPickBroccoli, updatePickBroccoli } from '@/api/erp/pick-broccoli'
|
||||
import { getSimpleUserList } from '@/api/system/user'
|
||||
import { getProductSimpleList } from '@/api/erp/product'
|
||||
import { getFarmingManagementPage } from '@/api/erp/farming'
|
||||
import { getBoxPage } from '@/api/erp/box'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
const getTitle = computed(() => props.id ? '编辑采摘记录' : '新增采摘记录')
|
||||
const formLoading = ref(false)
|
||||
const formData = ref<PickBroccoli>({
|
||||
id: undefined,
|
||||
pickCode: '',
|
||||
userId: undefined,
|
||||
userName: '',
|
||||
productId: undefined,
|
||||
productName: '',
|
||||
fieldCode: '',
|
||||
basketCode: '',
|
||||
basketWeight: undefined,
|
||||
licensePlate: '',
|
||||
pickTime: undefined,
|
||||
status: 1,
|
||||
remark: '',
|
||||
})
|
||||
const formRules = {
|
||||
pickCode: [{ required: true, message: '采摘编号不能为空' }],
|
||||
userName: [{ required: true, message: '采摘人员不能为空' }],
|
||||
productName: [{ required: true, message: '关联产品不能为空' }],
|
||||
fieldCode: [{ required: true, message: '田间编号不能为空' }],
|
||||
basketCode: [{ required: true, message: '框编号不能为空' }],
|
||||
pickTime: [{ required: true, message: '采摘时间不能为空' }],
|
||||
}
|
||||
const formRef = ref<FormInstance>()
|
||||
const userList = ref<User[]>([])
|
||||
const productList = ref<ProductSimple[]>([])
|
||||
const fieldList = ref<string[]>([])
|
||||
const basketList = ref<string[]>([])
|
||||
|
||||
/** 采摘人员下拉列 */
|
||||
const userColumns = computed(() => [
|
||||
userList.value.map(u => ({ value: u.id, label: u.nickname })),
|
||||
])
|
||||
|
||||
/** 产品下拉列 */
|
||||
const productColumns = computed(() => [
|
||||
productList.value.map(p => ({ value: p.id, label: p.name })),
|
||||
])
|
||||
|
||||
/** 田间编号下拉列 */
|
||||
const fieldColumns = computed(() => [
|
||||
fieldList.value.map(code => ({ value: code, label: code })),
|
||||
])
|
||||
|
||||
/** 框编号下拉列 */
|
||||
const basketColumns = computed(() => [
|
||||
basketList.value.map(code => ({ value: code, label: code })),
|
||||
])
|
||||
|
||||
/** 采摘人员选择回调 */
|
||||
function onUserConfirm({ value }: any) {
|
||||
const userId = value?.[0]
|
||||
formData.value.userId = userId
|
||||
const user = userList.value.find(u => u.id === userId)
|
||||
if (user) {
|
||||
formData.value.userName = user.nickname
|
||||
}
|
||||
}
|
||||
|
||||
/** 产品选择回调 */
|
||||
function onProductConfirm({ value }: any) {
|
||||
const productId = value?.[0]
|
||||
formData.value.productId = productId
|
||||
const product = productList.value.find(p => p.id === productId)
|
||||
if (product) {
|
||||
formData.value.productName = product.name
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载下拉列表数据 */
|
||||
async function loadDropdownData() {
|
||||
try {
|
||||
const [users, products, farmingResult, boxResult] = await Promise.all([
|
||||
getSimpleUserList(),
|
||||
getProductSimpleList(),
|
||||
getFarmingManagementPage(),
|
||||
getBoxPage(),
|
||||
])
|
||||
userList.value = users || []
|
||||
productList.value = products || []
|
||||
// 提取田间编号
|
||||
const farmingList = farmingResult?.list || []
|
||||
fieldList.value = [...new Set(farmingList.filter(f => f.code?.trim()).map(f => f.code))]
|
||||
// 提取框编号
|
||||
const boxList = boxResult?.list || []
|
||||
basketList.value = boxList.filter(b => b.boxNumber?.trim()).map(b => b.boxNumber)
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
}
|
||||
|
||||
/** 已装车状态时禁用所有字段 */
|
||||
const isLoaded = computed(() => (formData.value.status ?? 0) >= 3)
|
||||
|
||||
/** 格式化日期 */
|
||||
function formatDate(date?: string) {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
/** 获取状态文本 */
|
||||
function getStatusText(status?: number) {
|
||||
switch (status) {
|
||||
case 1: return '已采摘'
|
||||
case 2: return '已装框'
|
||||
case 3: return '已装车'
|
||||
case 4: return '已卸车入库'
|
||||
default: return '未知'
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/pick-broccoli/index')
|
||||
}
|
||||
|
||||
/** 生成采摘编号 */
|
||||
async function handleGenerateCode() {
|
||||
try {
|
||||
const data = await generatePickCode()
|
||||
if (data && data.code) {
|
||||
formData.value.pickCode = data.code
|
||||
} else {
|
||||
// 前端生成备用编号
|
||||
const d = new Date()
|
||||
const y = d.getFullYear()
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(d.getDate()).padStart(2, '0')
|
||||
const rnd = Math.floor(Math.random() * 1000000).toString().padStart(6, '0')
|
||||
formData.value.pickCode = `CJXL${y}${m}${day}${rnd}`
|
||||
}
|
||||
} catch {
|
||||
// 前端生成备用编号
|
||||
const d = new Date()
|
||||
const y = d.getFullYear()
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(d.getDate()).padStart(2, '0')
|
||||
const rnd = Math.floor(Math.random() * 1000000).toString().padStart(6, '0')
|
||||
formData.value.pickCode = `CJXL${y}${m}${day}${rnd}`
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
// 新增时自动生成编号
|
||||
await handleGenerateCode()
|
||||
return
|
||||
}
|
||||
formData.value = await getPickBroccoli(props.id)
|
||||
}
|
||||
|
||||
/** 提交表单 */
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formRef.value!.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
|
||||
formLoading.value = true
|
||||
try {
|
||||
if (props.id) {
|
||||
await updatePickBroccoli(formData.value)
|
||||
toast.success('修改成功')
|
||||
} else {
|
||||
await createPickBroccoli(formData.value)
|
||||
toast.success('新增成功')
|
||||
}
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
await loadDropdownData()
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
331
src/pages-erp/pick-broccoli/index.vue
Normal file
331
src/pages-erp/pick-broccoli/index.vue
Normal file
@@ -0,0 +1,331 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="采摘管理"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 搜索组件 -->
|
||||
<SearchForm @search="handleQuery" @reset="handleReset" />
|
||||
|
||||
<!-- 采摘记录列表 -->
|
||||
<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="handleCardClick(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<!-- 头部:采摘编号 + 状态 -->
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">
|
||||
{{ item.pickCode }}
|
||||
</view>
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(item.status)"
|
||||
>
|
||||
{{ getStatusText(item.status) }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 产品 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text>{{ item.productName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 采摘人员 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">采摘人员</text>
|
||||
<text>{{ item.userName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 田间编号 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">田间编号</text>
|
||||
<text>{{ item.fieldCode || '-' }}</text>
|
||||
</view>
|
||||
<!-- 框编号 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">框编号</text>
|
||||
<text>{{ item.basketCode || '-' }}</text>
|
||||
</view>
|
||||
<!-- 重量 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">重量</text>
|
||||
<text class="font-semibold">{{ item.basketWeight || 0 }} kg</text>
|
||||
</view>
|
||||
<!-- 车牌号 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">车牌号</text>
|
||||
<text>{{ item.licensePlate || '-' }}</text>
|
||||
</view>
|
||||
<!-- 采摘时间 -->
|
||||
<view class="flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">采摘时间</text>
|
||||
<text>{{ formatDate(item.pickTime) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && (item.status ?? 0) < 3"
|
||||
size="small" type="primary" plain @click="handleEdit(item)"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:query'])"
|
||||
size="small" plain @click="handleDetail(item)"
|
||||
>
|
||||
详情
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && item.status === 1"
|
||||
size="small" type="success" plain @click="handleStatusUpdate(item, 2, '装框')"
|
||||
>
|
||||
装框
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && item.status === 2"
|
||||
size="small" type="warning" plain @click="handleLoadTruck(item)"
|
||||
>
|
||||
装车
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:delete']) && (item.status ?? 0) < 3"
|
||||
size="small" type="error" plain @click="handleDelete(item.id!)"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</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-fab
|
||||
v-if="hasAccessByCodes(['erp:pick-broccoli:create'])"
|
||||
position="right-bottom"
|
||||
type="primary"
|
||||
:expandable="false"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PickBroccoli } from '@/api/erp/pick-broccoli'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deletePickBroccoli, getPickBroccoliPage, loadTruck, updatePickBroccoliStatus } from '@/api/erp/pick-broccoli'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import SearchForm from './components/search-form.vue'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const total = ref(0)
|
||||
const list = ref<PickBroccoli[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const queryParams = ref<Record<string, any>>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
|
||||
/** 格式化日期 */
|
||||
function formatDate(date?: string) {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
/** 获取状态文本 */
|
||||
function getStatusText(status?: number) {
|
||||
switch (status) {
|
||||
case 1: return '已采摘'
|
||||
case 2: return '已装框'
|
||||
case 3: return '已装车'
|
||||
case 4: return '已入库'
|
||||
default: return '未知'
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number) {
|
||||
switch (status) {
|
||||
case 1: return 'bg-[#e6f7ff] text-[#1890ff]'
|
||||
case 2: return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
case 3: return 'bg-[#f9f0ff] text-[#722ed1]'
|
||||
case 4: return 'bg-[#f6ffed] text-[#52c41a]'
|
||||
default: return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
/** 查询采摘记录列表 */
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const params = { ...queryParams.value }
|
||||
const data = await getPickBroccoliPage(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 handleQuery(data?: Record<string, any>) {
|
||||
queryParams.value = {
|
||||
...data,
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
function handleReset() {
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
/** 加载更多 */
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished') {
|
||||
return
|
||||
}
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 刷新列表 */
|
||||
function refreshList() {
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 卡片点击 — 打开详情 */
|
||||
function handleCardClick(item: PickBroccoli) {
|
||||
handleDetail(item)
|
||||
}
|
||||
|
||||
/** 新增采摘记录 */
|
||||
function handleAdd() {
|
||||
uni.navigateTo({
|
||||
url: '/pages-erp/pick-broccoli/form/index',
|
||||
})
|
||||
}
|
||||
|
||||
/** 查看详情 */
|
||||
function handleDetail(item: PickBroccoli) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/pick-broccoli/detail/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(item: PickBroccoli) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/pick-broccoli/form/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 状态更新(装框) */
|
||||
function handleStatusUpdate(item: PickBroccoli, status: number, text: string) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `确认将该记录状态更新为"${text}完成"吗?`,
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePickBroccoliStatus(item.id!, status)
|
||||
toast.success(`${text}操作成功`)
|
||||
refreshList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 装车操作 — 简易输入车牌号 + 装车人 */
|
||||
function handleLoadTruck(item: PickBroccoli) {
|
||||
// 小程序端用简化方式:直接输入车牌号
|
||||
uni.showModal({
|
||||
title: '装车',
|
||||
content: '请输入车牌号',
|
||||
editable: true,
|
||||
placeholderText: '车牌号',
|
||||
success: async (res) => {
|
||||
if (!res.confirm || !res.content) return
|
||||
try {
|
||||
// 使用当前用户作为装车人(简化处理)
|
||||
await loadTruck(item.id!, res.content, 0, '')
|
||||
toast.success('装车操作成功')
|
||||
refreshList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
function handleDelete(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该采摘记录吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deletePickBroccoli(id)
|
||||
toast.success('删除成功')
|
||||
refreshList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 触底加载更多 */
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
Reference in New Issue
Block a user