李红攀:V2.0.001仓库管理
This commit is contained in:
360
src/pages-erp/purchase-requisition/detail/index.vue
Normal file
360
src/pages-erp/purchase-requisition/detail/index.vue
Normal file
@@ -0,0 +1,360 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="请购单详情"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 详情内容 -->
|
||||
<view class="pb-180rpx">
|
||||
<!-- 基本信息 -->
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="请购单号" :value="detail.no || '-'" />
|
||||
<wd-cell title="请购类型">
|
||||
<template #value>
|
||||
<view
|
||||
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
|
||||
:class="getTypeClass(detail.type)"
|
||||
>
|
||||
{{ getTypeLabel(detail.type) }}
|
||||
</view>
|
||||
</template>
|
||||
</wd-cell>
|
||||
<wd-cell title="状态">
|
||||
<template #value>
|
||||
<view
|
||||
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
|
||||
:class="getStatusClass(detail.status)"
|
||||
>
|
||||
{{ getStatusLabel(detail.status) }}
|
||||
</view>
|
||||
</template>
|
||||
</wd-cell>
|
||||
<wd-cell title="优先级">
|
||||
<template #value>
|
||||
<view
|
||||
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
|
||||
:class="getPriorityClass(detail.priority)"
|
||||
>
|
||||
{{ getPriorityLabel(detail.priority) }}
|
||||
</view>
|
||||
</template>
|
||||
</wd-cell>
|
||||
<wd-cell title="紧急程度">
|
||||
<template #value>
|
||||
<view
|
||||
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
|
||||
:class="getEmergencyClass(detail.emergencyDegree)"
|
||||
>
|
||||
{{ getEmergencyLabel(detail.emergencyDegree) }}
|
||||
</view>
|
||||
</template>
|
||||
</wd-cell>
|
||||
<wd-cell title="请购人" :value="detail.requesterNickname || '-'" />
|
||||
<wd-cell title="请购部门" :value="detail.requesterDeptName || '-'" />
|
||||
<wd-cell title="请购时间" :value="formatDate(detail.requestTime)" />
|
||||
<wd-cell title="期望到货" :value="formatDate(detail.expectedTime)" />
|
||||
<wd-cell title="备注" :value="detail.remark || '-'" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 金额信息 -->
|
||||
<wd-cell-group title="金额信息" border>
|
||||
<wd-cell title="合计数量" :value="formatCount(detail.totalCount)" />
|
||||
<wd-cell title="合计金额" :value="formatPrice(detail.totalPrice)" />
|
||||
<wd-cell title="附加费" :value="formatPrice(detail.additionalFee)" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 审核信息 -->
|
||||
<wd-cell-group v-if="detail.status !== 1" title="审核信息" border>
|
||||
<wd-cell title="审核人" :value="detail.approverName || '-'" />
|
||||
<wd-cell title="审核时间" :value="formatDateTime(detail.approveTime)" />
|
||||
<wd-cell title="审核意见" :value="detail.approveRemark || '-'" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 请购产品清单 -->
|
||||
<wd-cell-group title="请购产品清单" border>
|
||||
<view v-if="!detail.items || detail.items.length === 0" class="py-40rpx text-center text-[#999]">
|
||||
暂无产品数据
|
||||
</view>
|
||||
<view v-else>
|
||||
<view
|
||||
v-for="(item, index) in detail.items"
|
||||
:key="index"
|
||||
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
|
||||
>
|
||||
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
|
||||
{{ item.productName || '-' }}
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||
<text class="text-[#999]">规格</text>
|
||||
<text class="text-[#666]">{{ item.productSpec || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||
<text class="text-[#999]">单位</text>
|
||||
<text class="text-[#666]">{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||
<text class="text-[#999]">需求数量</text>
|
||||
<text class="text-[#333] font-semibold">{{ formatCount(item.count) }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||
<text class="text-[#999]">参考单价</text>
|
||||
<text class="text-[#666]">{{ formatPrice(item.productPrice) }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||
<text class="text-[#999]">金额</text>
|
||||
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
|
||||
</view>
|
||||
<view v-if="item.supplierName" class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||
<text class="text-[#999]">建议供应商</text>
|
||||
<text class="text-[#666]">{{ item.supplierName }}</text>
|
||||
</view>
|
||||
<view v-if="item.purpose" class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||
<text class="text-[#999]">用途</text>
|
||||
<text class="text-[#666]">{{ item.purpose }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</wd-cell-group>
|
||||
</view>
|
||||
|
||||
<!-- 底部操作按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-requisition:update']) && detail.status === 1"
|
||||
type="primary"
|
||||
@click="handleEdit"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-requisition:update-status']) && detail.status === 1"
|
||||
type="success"
|
||||
@click="handleApprove"
|
||||
>
|
||||
审核
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-requisition:approve']) && detail.status === 1"
|
||||
type="warning"
|
||||
@click="handleReject"
|
||||
>
|
||||
驳回
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-requisition:delete']) && detail.status === 1"
|
||||
type="error"
|
||||
@click="handleDelete"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PurchaseRequisition } from '@/api/erp/purchase-requisition'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import {
|
||||
deletePurchaseRequisition,
|
||||
EMERGENCY_OPTIONS,
|
||||
getPurchaseRequisition,
|
||||
PRIORITY_OPTIONS,
|
||||
REQUISITION_TYPE_OPTIONS,
|
||||
STATUS_OPTIONS,
|
||||
updatePurchaseRequisitionStatus,
|
||||
} from '@/api/erp/purchase-requisition'
|
||||
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 detail = ref<PurchaseRequisition>({})
|
||||
|
||||
/** 获取类型标签 */
|
||||
function getTypeLabel(type?: number) {
|
||||
return REQUISITION_TYPE_OPTIONS.find(o => o.value === type)?.label || '-'
|
||||
}
|
||||
|
||||
/** 获取类型样式 */
|
||||
function getTypeClass(type?: number) {
|
||||
const map: Record<number, string> = {
|
||||
1: 'bg-[#e6f7ff] text-[#1890ff]',
|
||||
2: 'bg-[#fff7e6] text-[#fa8c16]',
|
||||
3: 'bg-[#f9f0ff] text-[#722ed1]',
|
||||
}
|
||||
return map[type || 1] || 'bg-[#f5f5f5] text-[#666]'
|
||||
}
|
||||
|
||||
/** 获取状态标签 */
|
||||
function getStatusLabel(status?: number) {
|
||||
return STATUS_OPTIONS.find(o => o.value === status)?.label || '-'
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number) {
|
||||
const map: Record<number, string> = {
|
||||
1: 'bg-[#fff7e6] text-[#fa8c16]',
|
||||
2: 'bg-[#f6ffed] text-[#52c41a]',
|
||||
3: 'bg-[#fff1f0] text-[#f5222d]',
|
||||
4: 'bg-[#f5f5f5] text-[#999]',
|
||||
5: 'bg-[#e6f7ff] text-[#1890ff]',
|
||||
}
|
||||
return map[status || 1] || 'bg-[#f5f5f5] text-[#666]'
|
||||
}
|
||||
|
||||
/** 获取优先级标签 */
|
||||
function getPriorityLabel(priority?: number) {
|
||||
return PRIORITY_OPTIONS.find(o => o.value === priority)?.label || '-'
|
||||
}
|
||||
|
||||
/** 获取优先级样式 */
|
||||
function getPriorityClass(priority?: number) {
|
||||
const map: Record<number, string> = {
|
||||
1: 'bg-[#f5f5f5] text-[#999]',
|
||||
2: 'bg-[#e6f7ff] text-[#1890ff]',
|
||||
3: 'bg-[#fff7e6] text-[#fa8c16]',
|
||||
4: 'bg-[#fff1f0] text-[#f5222d]',
|
||||
}
|
||||
return map[priority || 1] || 'bg-[#f5f5f5] text-[#666]'
|
||||
}
|
||||
|
||||
/** 获取紧急程度标签 */
|
||||
function getEmergencyLabel(emergency?: number) {
|
||||
return EMERGENCY_OPTIONS.find(o => o.value === emergency)?.label || '-'
|
||||
}
|
||||
|
||||
/** 获取紧急程度样式 */
|
||||
function getEmergencyClass(emergency?: number) {
|
||||
const map: Record<number, string> = {
|
||||
1: 'bg-[#f5f5f5] text-[#999]',
|
||||
2: 'bg-[#e6f7ff] text-[#1890ff]',
|
||||
3: 'bg-[#fff7e6] text-[#fa8c16]',
|
||||
4: 'bg-[#fff1f0] text-[#f5222d]',
|
||||
}
|
||||
return map[emergency || 1] || 'bg-[#f5f5f5] text-[#666]'
|
||||
}
|
||||
|
||||
/** 格式化数量 */
|
||||
function formatCount(count?: number) {
|
||||
if (count === undefined || count === null) return '-'
|
||||
return count.toFixed(2)
|
||||
}
|
||||
|
||||
/** 格式化金额 */
|
||||
function formatPrice(price?: number) {
|
||||
if (price === undefined || price === null) return '-'
|
||||
return `¥${price.toFixed(2)}`
|
||||
}
|
||||
|
||||
/** 格式化日期 */
|
||||
function formatDate(dateStr?: string) {
|
||||
if (!dateStr) return '-'
|
||||
return dateStr.substring(0, 10)
|
||||
}
|
||||
|
||||
/** 格式化日期时间 */
|
||||
function formatDateTime(dateStr?: string) {
|
||||
if (!dateStr) return '-'
|
||||
return dateStr.substring(0, 16).replace('T', ' ')
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/purchase-requisition/index')
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) return
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
detail.value = await getPurchaseRequisition(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit() {
|
||||
uni.navigateTo({ url: `/pages-erp/purchase-requisition/form/index?id=${props.id}` })
|
||||
}
|
||||
|
||||
/** 审核 */
|
||||
function handleApprove() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要审核通过该请购单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePurchaseRequisitionStatus(props.id, 2)
|
||||
toast.success('审核成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 驳回 */
|
||||
function handleReject() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要驳回该请购单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePurchaseRequisitionStatus(props.id, 3)
|
||||
toast.success('驳回成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
function handleDelete() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该请购单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deletePurchaseRequisition(props.id)
|
||||
toast.success('删除成功')
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
474
src/pages-erp/purchase-requisition/form/index.vue
Normal file
474
src/pages-erp/purchase-requisition/form/index.vue
Normal file
@@ -0,0 +1,474 @@
|
||||
<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-cell title="请购单号" :value="formData.no || '保存时自动生成'" />
|
||||
<wd-cell
|
||||
title="请购类型"
|
||||
title-width="180rpx"
|
||||
is-link
|
||||
:value="getTypeLabel(formData.type)"
|
||||
@click="typePickerVisible = true"
|
||||
/>
|
||||
<wd-cell
|
||||
title="优先级"
|
||||
title-width="180rpx"
|
||||
is-link
|
||||
:value="getPriorityLabel(formData.priority)"
|
||||
@click="priorityPickerVisible = true"
|
||||
/>
|
||||
<wd-cell
|
||||
title="紧急程度"
|
||||
title-width="180rpx"
|
||||
is-link
|
||||
:value="getEmergencyLabel(formData.emergencyDegree)"
|
||||
@click="emergencyPickerVisible = true"
|
||||
/>
|
||||
<wd-cell
|
||||
title="请购时间"
|
||||
title-width="180rpx"
|
||||
is-link
|
||||
:value="formData.requestTime ? formatDate(formData.requestTime) : '请选择'"
|
||||
@click="requestDatePickerVisible = true"
|
||||
/>
|
||||
<wd-cell
|
||||
title="期望到货"
|
||||
title-width="180rpx"
|
||||
is-link
|
||||
:value="formData.expectedTime ? formatDate(formData.expectedTime) : '请选择'"
|
||||
@click="expectedDatePickerVisible = true"
|
||||
/>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 请购产品清单 -->
|
||||
<wd-cell-group title="请购产品清单" border>
|
||||
<view v-if="formData.items.length === 0" class="py-40rpx text-center text-[#999]">
|
||||
暂无产品,请点击下方按钮添加
|
||||
</view>
|
||||
<view v-else>
|
||||
<view
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="index"
|
||||
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
|
||||
>
|
||||
<view class="mb-12rpx flex items-center justify-between">
|
||||
<view class="text-28rpx text-[#333] font-semibold">
|
||||
{{ item.productName || '请选择产品' }}
|
||||
</view>
|
||||
<wd-icon name="delete" size="40rpx" color="#f56c6c" @click="removeItem(index)" />
|
||||
</view>
|
||||
<view class="mb-12rpx">
|
||||
<wd-cell
|
||||
title="产品"
|
||||
title-width="140rpx"
|
||||
is-link
|
||||
:value="item.productName || '请选择'"
|
||||
@click="openProductPicker(index)"
|
||||
/>
|
||||
</view>
|
||||
<view class="mb-12rpx">
|
||||
<wd-input
|
||||
v-model="item.count"
|
||||
label="需求数量"
|
||||
label-width="140rpx"
|
||||
type="number"
|
||||
placeholder="请输入数量"
|
||||
@change="calcItemTotal(item)"
|
||||
/>
|
||||
</view>
|
||||
<view class="mb-12rpx">
|
||||
<wd-input
|
||||
v-model="item.productPrice"
|
||||
label="参考单价"
|
||||
label-width="140rpx"
|
||||
type="digit"
|
||||
placeholder="请输入单价"
|
||||
@change="calcItemTotal(item)"
|
||||
/>
|
||||
</view>
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx">
|
||||
<text class="text-[#999]">金额</text>
|
||||
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
|
||||
</view>
|
||||
<view class="mb-12rpx">
|
||||
<wd-input
|
||||
v-model="item.purpose"
|
||||
label="用途说明"
|
||||
label-width="140rpx"
|
||||
placeholder="请输入用途"
|
||||
/>
|
||||
</view>
|
||||
<view class="mb-12rpx">
|
||||
<wd-input
|
||||
v-model="item.remark"
|
||||
label="备注"
|
||||
label-width="140rpx"
|
||||
placeholder="请输入备注"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="px-24rpx pb-24rpx">
|
||||
<wd-button type="primary" plain block @click="addItem">
|
||||
<wd-icon name="add" class="mr-8rpx" />
|
||||
添加产品
|
||||
</wd-button>
|
||||
</view>
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 合计信息 -->
|
||||
<wd-cell-group title="合计信息" border>
|
||||
<wd-cell title="合计数量" :value="formatCount(totalCount)" />
|
||||
<wd-cell title="合计金额" :value="formatPrice(totalPrice)" />
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<!-- 底部保存按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
type="primary"
|
||||
block
|
||||
:loading="formLoading"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
</wd-button>
|
||||
</view>
|
||||
|
||||
<!-- 请购类型选择器 -->
|
||||
<wd-picker
|
||||
v-model="typePickerVisible"
|
||||
:columns="typeColumns"
|
||||
@confirm="onTypeConfirm"
|
||||
/>
|
||||
|
||||
<!-- 优先级选择器 -->
|
||||
<wd-picker
|
||||
v-model="priorityPickerVisible"
|
||||
:columns="priorityColumns"
|
||||
@confirm="onPriorityConfirm"
|
||||
/>
|
||||
|
||||
<!-- 紧急程度选择器 -->
|
||||
<wd-picker
|
||||
v-model="emergencyPickerVisible"
|
||||
:columns="emergencyColumns"
|
||||
@confirm="onEmergencyConfirm"
|
||||
/>
|
||||
|
||||
<!-- 请购时间选择器 -->
|
||||
<wd-datetime-picker
|
||||
v-model="requestDatePickerVisible"
|
||||
type="date"
|
||||
:value="formData.requestTime"
|
||||
@confirm="onRequestDateConfirm"
|
||||
/>
|
||||
|
||||
<!-- 期望到货选择器 -->
|
||||
<wd-datetime-picker
|
||||
v-model="expectedDatePickerVisible"
|
||||
type="date"
|
||||
:value="formData.expectedTime"
|
||||
@confirm="onExpectedDateConfirm"
|
||||
/>
|
||||
|
||||
<!-- 产品选择器 -->
|
||||
<wd-picker
|
||||
v-model="productPickerVisible"
|
||||
:columns="productColumns"
|
||||
@confirm="onProductConfirm"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
|
||||
import type { PurchaseRequisition, PurchaseRequisitionItem } from '@/api/erp/purchase-requisition'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import {
|
||||
createPurchaseRequisition,
|
||||
EMERGENCY_OPTIONS,
|
||||
getPurchaseRequisition,
|
||||
PRIORITY_OPTIONS,
|
||||
REQUISITION_TYPE_OPTIONS,
|
||||
updatePurchaseRequisition,
|
||||
} from '@/api/erp/purchase-requisition'
|
||||
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<PurchaseRequisition>({
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
type: 1,
|
||||
priority: 2,
|
||||
emergencyDegree: 1,
|
||||
requestTime: undefined,
|
||||
expectedTime: undefined,
|
||||
remark: undefined,
|
||||
items: [],
|
||||
})
|
||||
const formRules = {
|
||||
type: [{ required: true, message: '请购类型不能为空' }],
|
||||
requestTime: [{ required: true, message: '请购时间不能为空' }],
|
||||
expectedTime: [{ required: true, message: '期望到货时间不能为空' }],
|
||||
}
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
// 类型选择器
|
||||
const typePickerVisible = ref(false)
|
||||
const typeColumns = computed(() => [
|
||||
REQUISITION_TYPE_OPTIONS.map(v => ({ value: v.value, label: v.label })),
|
||||
])
|
||||
|
||||
// 优先级选择器
|
||||
const priorityPickerVisible = ref(false)
|
||||
const priorityColumns = computed(() => [
|
||||
PRIORITY_OPTIONS.map(v => ({ value: v.value, label: v.label })),
|
||||
])
|
||||
|
||||
// 紧急程度选择器
|
||||
const emergencyPickerVisible = ref(false)
|
||||
const emergencyColumns = computed(() => [
|
||||
EMERGENCY_OPTIONS.map(v => ({ value: v.value, label: v.label })),
|
||||
])
|
||||
|
||||
// 日期选择器
|
||||
const requestDatePickerVisible = ref(false)
|
||||
const expectedDatePickerVisible = ref(false)
|
||||
|
||||
// 产品列表
|
||||
const productList = ref<{ id: number, name: string, unitName?: string }[]>([])
|
||||
const productPickerVisible = ref(false)
|
||||
const productColumns = computed(() => [
|
||||
productList.value.map(v => ({ value: v.id, label: v.name })),
|
||||
])
|
||||
|
||||
// 当前编辑的产品项索引
|
||||
const currentItemIndex = ref(-1)
|
||||
|
||||
/** 合计数量 */
|
||||
const totalCount = computed(() => {
|
||||
return formData.value.items?.reduce((sum, item) => sum + (Number(item.count) || 0), 0) || 0
|
||||
})
|
||||
|
||||
/** 合计金额 */
|
||||
const totalPrice = computed(() => {
|
||||
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
|
||||
})
|
||||
|
||||
/** 获取类型标签 */
|
||||
function getTypeLabel(type?: number) {
|
||||
return REQUISITION_TYPE_OPTIONS.find(o => o.value === type)?.label || '请选择'
|
||||
}
|
||||
|
||||
/** 获取优先级标签 */
|
||||
function getPriorityLabel(priority?: number) {
|
||||
return PRIORITY_OPTIONS.find(o => o.value === priority)?.label || '请选择'
|
||||
}
|
||||
|
||||
/** 获取紧急程度标签 */
|
||||
function getEmergencyLabel(emergency?: number) {
|
||||
return EMERGENCY_OPTIONS.find(o => o.value === emergency)?.label || '请选择'
|
||||
}
|
||||
|
||||
/** 格式化数量 */
|
||||
function formatCount(count?: number) {
|
||||
if (count === undefined || count === null) return '-'
|
||||
return count.toFixed(2)
|
||||
}
|
||||
|
||||
/** 格式化金额 */
|
||||
function formatPrice(price?: number) {
|
||||
if (price === undefined || price === null) return '-'
|
||||
return `¥${price.toFixed(2)}`
|
||||
}
|
||||
|
||||
/** 格式化日期 */
|
||||
function formatDate(dateStr?: string) {
|
||||
if (!dateStr) return '-'
|
||||
if (typeof dateStr === 'number') {
|
||||
const d = new Date(dateStr)
|
||||
const pad = (n: number) => n.toString().padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
|
||||
}
|
||||
return dateStr.substring(0, 10)
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/purchase-requisition/index')
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) return
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getPurchaseRequisition(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 类型确认 */
|
||||
function onTypeConfirm({ value }: any) {
|
||||
formData.value.type = value?.[0]
|
||||
typePickerVisible.value = false
|
||||
}
|
||||
|
||||
/** 优先级确认 */
|
||||
function onPriorityConfirm({ value }: any) {
|
||||
formData.value.priority = value?.[0]
|
||||
priorityPickerVisible.value = false
|
||||
}
|
||||
|
||||
/** 紧急程度确认 */
|
||||
function onEmergencyConfirm({ value }: any) {
|
||||
formData.value.emergencyDegree = value?.[0]
|
||||
emergencyPickerVisible.value = false
|
||||
}
|
||||
|
||||
/** 请购时间确认 */
|
||||
function onRequestDateConfirm({ value }: any) {
|
||||
formData.value.requestTime = value
|
||||
requestDatePickerVisible.value = false
|
||||
}
|
||||
|
||||
/** 期望到货确认 */
|
||||
function onExpectedDateConfirm({ value }: any) {
|
||||
formData.value.expectedTime = value
|
||||
expectedDatePickerVisible.value = false
|
||||
}
|
||||
|
||||
/** 打开产品选择器 */
|
||||
function openProductPicker(index: number) {
|
||||
currentItemIndex.value = index
|
||||
productPickerVisible.value = true
|
||||
}
|
||||
|
||||
/** 产品确认 */
|
||||
function onProductConfirm({ value }: any) {
|
||||
if (currentItemIndex.value >= 0 && formData.value.items) {
|
||||
const item = formData.value.items[currentItemIndex.value]
|
||||
item.productId = value?.[0]
|
||||
const product = productList.value.find(p => p.id === item.productId)
|
||||
item.productName = product?.name
|
||||
item.productUnitName = product?.unitName
|
||||
}
|
||||
productPickerVisible.value = false
|
||||
}
|
||||
|
||||
/** 添加产品项 */
|
||||
function addItem() {
|
||||
if (!formData.value.items) {
|
||||
formData.value.items = []
|
||||
}
|
||||
formData.value.items.push({
|
||||
productId: undefined,
|
||||
productName: undefined,
|
||||
productUnitName: undefined,
|
||||
count: undefined,
|
||||
productPrice: undefined,
|
||||
totalPrice: 0,
|
||||
purpose: undefined,
|
||||
remark: undefined,
|
||||
})
|
||||
}
|
||||
|
||||
/** 移除产品项 */
|
||||
function removeItem(index: number) {
|
||||
formData.value.items?.splice(index, 1)
|
||||
}
|
||||
|
||||
/** 计算产品项金额 */
|
||||
function calcItemTotal(item: PurchaseRequisitionItem) {
|
||||
const count = Number(item.count) || 0
|
||||
const price = Number(item.productPrice) || 0
|
||||
item.totalPrice = count * price
|
||||
}
|
||||
|
||||
/** 提交表单 */
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formRef.value!.validate()
|
||||
if (!valid) return
|
||||
|
||||
// 校验产品清单
|
||||
if (!formData.value.items || formData.value.items.length === 0) {
|
||||
toast.error('请添加请购产品')
|
||||
return
|
||||
}
|
||||
|
||||
for (const item of formData.value.items) {
|
||||
if (!item.productId) {
|
||||
toast.error('请选择产品')
|
||||
return
|
||||
}
|
||||
if (!item.count || Number(item.count) <= 0) {
|
||||
toast.error('请输入有效的数量')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
formLoading.value = true
|
||||
try {
|
||||
// 设置合计
|
||||
formData.value.totalCount = totalCount.value
|
||||
formData.value.totalPrice = totalPrice.value
|
||||
|
||||
if (props.id) {
|
||||
await updatePurchaseRequisition(formData.value)
|
||||
toast.success('修改成功')
|
||||
} else {
|
||||
await createPurchaseRequisition(formData.value)
|
||||
toast.success('新增成功')
|
||||
}
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
// 加载详情
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
515
src/pages-erp/purchase-requisition/index.vue
Normal file
515
src/pages-erp/purchase-requisition/index.vue
Normal file
@@ -0,0 +1,515 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="采购申请"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 搜索组件 -->
|
||||
<view @click="searchVisible = true">
|
||||
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
|
||||
</view>
|
||||
|
||||
<!-- 快捷筛选标签 -->
|
||||
<view class="flex items-center overflow-hidden rounded-12rpx bg-white mx-24rpx mb-16rpx shadow-sm">
|
||||
<view
|
||||
v-for="tab in statusTabs"
|
||||
:key="tab.value"
|
||||
class="flex-1 py-20rpx text-center text-26rpx relative"
|
||||
:class="queryParams.status === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
|
||||
@click="onTabChange(tab.value)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
<view
|
||||
v-if="queryParams.status === tab.value"
|
||||
class="absolute bottom-0 left-1/4 w-1/2 h-4rpx rounded-2rpx bg-[#1890ff]"
|
||||
/>
|
||||
</view>
|
||||
</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">
|
||||
{{ item.no || '-' }}
|
||||
</view>
|
||||
<view class="flex items-center gap-8rpx">
|
||||
<view
|
||||
class="rounded-8rpx px-12rpx py-4rpx text-22rpx"
|
||||
:class="getTypeClass(item.type)"
|
||||
>
|
||||
{{ getTypeLabel(item.type) }}
|
||||
</view>
|
||||
<view
|
||||
class="rounded-8rpx px-12rpx py-4rpx text-22rpx"
|
||||
:class="getStatusClass(item.status)"
|
||||
>
|
||||
{{ getStatusLabel(item.status) }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 优先级 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">优先级</text>
|
||||
<view
|
||||
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
|
||||
:class="getPriorityClass(item.priority)"
|
||||
>
|
||||
{{ getPriorityLabel(item.priority) }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 请购人 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">请购人</text>
|
||||
<text>{{ item.requesterNickname || '-' }}</text>
|
||||
</view>
|
||||
<!-- 请购部门 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">请购部门</text>
|
||||
<text>{{ item.requesterDeptName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 请购时间 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">请购时间</text>
|
||||
<text>{{ formatDate(item.requestTime) }}</text>
|
||||
</view>
|
||||
<!-- 期望到货 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">期望到货</text>
|
||||
<text>{{ formatDate(item.expectedTime) }}</text>
|
||||
</view>
|
||||
<!-- 紧急程度 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">紧急程度</text>
|
||||
<view
|
||||
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
|
||||
:class="getEmergencyClass(item.emergencyDegree)"
|
||||
>
|
||||
{{ getEmergencyLabel(item.emergencyDegree) }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 数量金额区域 -->
|
||||
<view class="flex items-center justify-around mt-12rpx pt-16rpx border-t border-[#f0f0f0]">
|
||||
<view class="text-center">
|
||||
<view class="text-32rpx text-[#333] font-semibold">{{ formatCount(item.totalCount) }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">总数量</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-32rpx text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">总金额</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-requisition:update']) && item.status === 1"
|
||||
size="small" type="primary" plain @click="handleEdit(item)"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-requisition:update-status']) && item.status === 1"
|
||||
size="small" type="success" plain @click="handleApprove(item.id!)"
|
||||
>
|
||||
审核
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-requisition:approve']) && item.status === 1"
|
||||
size="small" type="warning" plain @click="handleReject(item.id!)"
|
||||
>
|
||||
驳回
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-requisition:delete']) && item.status === 1"
|
||||
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:purchase-requisition:create'])"
|
||||
position="right-bottom"
|
||||
type="primary"
|
||||
:expandable="false"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
|
||||
<!-- 搜索弹窗 -->
|
||||
<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.no" placeholder="请输入请购单号" clearable />
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">请购类型</view>
|
||||
<view class="yd-search-form-radio-group">
|
||||
<view
|
||||
v-for="opt in typeOptions"
|
||||
:key="opt.value"
|
||||
class="yd-search-form-radio"
|
||||
:class="{ 'yd-search-form-radio--active': searchForm.type === opt.value }"
|
||||
@click="searchForm.type = opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">状态</view>
|
||||
<view class="yd-search-form-radio-group">
|
||||
<view
|
||||
v-for="opt in statusOptions"
|
||||
:key="opt.value"
|
||||
class="yd-search-form-radio"
|
||||
:class="{ 'yd-search-form-radio--active': searchForm.status === opt.value }"
|
||||
@click="searchForm.status = opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</view>
|
||||
</view>
|
||||
</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>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PurchaseRequisition } from '@/api/erp/purchase-requisition'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import {
|
||||
deletePurchaseRequisition,
|
||||
EMERGENCY_OPTIONS,
|
||||
getPurchaseRequisitionPage,
|
||||
PRIORITY_OPTIONS,
|
||||
REQUISITION_TYPE_OPTIONS,
|
||||
STATUS_OPTIONS,
|
||||
updatePurchaseRequisitionStatus,
|
||||
} from '@/api/erp/purchase-requisition'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { getNavbarHeight, navigateBackPlus } from '@/utils'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const total = ref(0)
|
||||
const list = ref<PurchaseRequisition[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const queryParams = ref<Record<string, any>>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
status: undefined,
|
||||
})
|
||||
|
||||
// 搜索相关
|
||||
const searchVisible = ref(false)
|
||||
const searchForm = reactive({
|
||||
no: undefined as string | undefined,
|
||||
type: undefined as number | undefined,
|
||||
status: undefined as number | undefined,
|
||||
})
|
||||
|
||||
/** 状态标签 */
|
||||
const statusTabs = [
|
||||
{ value: undefined, label: '全部' },
|
||||
{ value: 1, label: '待审核' },
|
||||
{ value: 2, label: '已审核' },
|
||||
{ value: 5, label: '已采购' },
|
||||
]
|
||||
|
||||
/** 类型选项 */
|
||||
const typeOptions = [
|
||||
{ value: undefined, label: '全部' },
|
||||
...REQUISITION_TYPE_OPTIONS,
|
||||
]
|
||||
|
||||
/** 状态选项 */
|
||||
const statusOptions = [
|
||||
{ value: undefined, label: '全部' },
|
||||
...STATUS_OPTIONS,
|
||||
]
|
||||
|
||||
/** 搜索条件 placeholder */
|
||||
const searchPlaceholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (searchForm.no) conditions.push(`单号:${searchForm.no}`)
|
||||
if (searchForm.type !== undefined) {
|
||||
const typeLabel = REQUISITION_TYPE_OPTIONS.find(o => o.value === searchForm.type)?.label
|
||||
if (typeLabel) conditions.push(`类型:${typeLabel}`)
|
||||
}
|
||||
if (searchForm.status !== undefined) {
|
||||
const statusLabel = STATUS_OPTIONS.find(o => o.value === searchForm.status)?.label
|
||||
if (statusLabel) conditions.push(`状态:${statusLabel}`)
|
||||
}
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索请购单'
|
||||
})
|
||||
|
||||
/** 获取类型标签 */
|
||||
function getTypeLabel(type?: number) {
|
||||
return REQUISITION_TYPE_OPTIONS.find(o => o.value === type)?.label || '-'
|
||||
}
|
||||
|
||||
/** 获取类型样式 */
|
||||
function getTypeClass(type?: number) {
|
||||
const map: Record<number, string> = {
|
||||
1: 'bg-[#e6f7ff] text-[#1890ff]',
|
||||
2: 'bg-[#fff7e6] text-[#fa8c16]',
|
||||
3: 'bg-[#f9f0ff] text-[#722ed1]',
|
||||
}
|
||||
return map[type || 1] || 'bg-[#f5f5f5] text-[#666]'
|
||||
}
|
||||
|
||||
/** 获取状态标签 */
|
||||
function getStatusLabel(status?: number) {
|
||||
return STATUS_OPTIONS.find(o => o.value === status)?.label || '-'
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number) {
|
||||
const map: Record<number, string> = {
|
||||
1: 'bg-[#fff7e6] text-[#fa8c16]',
|
||||
2: 'bg-[#f6ffed] text-[#52c41a]',
|
||||
3: 'bg-[#fff1f0] text-[#f5222d]',
|
||||
4: 'bg-[#f5f5f5] text-[#999]',
|
||||
5: 'bg-[#e6f7ff] text-[#1890ff]',
|
||||
}
|
||||
return map[status || 1] || 'bg-[#f5f5f5] text-[#666]'
|
||||
}
|
||||
|
||||
/** 获取优先级标签 */
|
||||
function getPriorityLabel(priority?: number) {
|
||||
return PRIORITY_OPTIONS.find(o => o.value === priority)?.label || '-'
|
||||
}
|
||||
|
||||
/** 获取优先级样式 */
|
||||
function getPriorityClass(priority?: number) {
|
||||
const map: Record<number, string> = {
|
||||
1: 'bg-[#f5f5f5] text-[#999]',
|
||||
2: 'bg-[#e6f7ff] text-[#1890ff]',
|
||||
3: 'bg-[#fff7e6] text-[#fa8c16]',
|
||||
4: 'bg-[#fff1f0] text-[#f5222d]',
|
||||
}
|
||||
return map[priority || 1] || 'bg-[#f5f5f5] text-[#666]'
|
||||
}
|
||||
|
||||
/** 获取紧急程度标签 */
|
||||
function getEmergencyLabel(emergency?: number) {
|
||||
return EMERGENCY_OPTIONS.find(o => o.value === emergency)?.label || '-'
|
||||
}
|
||||
|
||||
/** 获取紧急程度样式 */
|
||||
function getEmergencyClass(emergency?: number) {
|
||||
const map: Record<number, string> = {
|
||||
1: 'bg-[#f5f5f5] text-[#999]',
|
||||
2: 'bg-[#e6f7ff] text-[#1890ff]',
|
||||
3: 'bg-[#fff7e6] text-[#fa8c16]',
|
||||
4: 'bg-[#fff1f0] text-[#f5222d]',
|
||||
}
|
||||
return map[emergency || 1] || 'bg-[#f5f5f5] text-[#666]'
|
||||
}
|
||||
|
||||
/** 格式化数量 */
|
||||
function formatCount(count?: number) {
|
||||
if (count === undefined || count === null) return '-'
|
||||
return count.toFixed(2)
|
||||
}
|
||||
|
||||
/** 格式化金额 */
|
||||
function formatPrice(price?: number) {
|
||||
if (price === undefined || price === null) return '-'
|
||||
return `¥${price.toFixed(2)}`
|
||||
}
|
||||
|
||||
/** 格式化日期 */
|
||||
function formatDate(dateStr?: string) {
|
||||
if (!dateStr) return '-'
|
||||
return dateStr.substring(0, 10)
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
/** 切换状态标签 */
|
||||
function onTabChange(status: number | undefined) {
|
||||
queryParams.value.status = status
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 查询请购单列表 */
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const params = { ...queryParams.value }
|
||||
if (searchForm.no) params.no = searchForm.no
|
||||
if (searchForm.type !== undefined) params.type = searchForm.type
|
||||
const data = await getPurchaseRequisitionPage(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,
|
||||
status: searchForm.status,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
function handleReset() {
|
||||
searchForm.no = undefined
|
||||
searchForm.type = undefined
|
||||
searchForm.status = undefined
|
||||
searchVisible.value = false
|
||||
queryParams.value = { pageNo: 1, pageSize: 10, status: undefined }
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 加载更多 */
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished') return
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 新增请购单 */
|
||||
function handleAdd() {
|
||||
uni.navigateTo({ url: '/pages-erp/purchase-requisition/form/index' })
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(item: PurchaseRequisition) {
|
||||
uni.navigateTo({ url: `/pages-erp/purchase-requisition/form/index?id=${item.id}` })
|
||||
}
|
||||
|
||||
/** 详情 */
|
||||
function handleDetail(item: PurchaseRequisition) {
|
||||
uni.navigateTo({ url: `/pages-erp/purchase-requisition/detail/index?id=${item.id}` })
|
||||
}
|
||||
|
||||
/** 审核 */
|
||||
function handleApprove(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要审核通过该请购单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePurchaseRequisitionStatus(id, 2)
|
||||
toast.success('审核成功')
|
||||
refreshList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 驳回 */
|
||||
function handleReject(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要驳回该请购单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePurchaseRequisitionStatus(id, 3)
|
||||
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 deletePurchaseRequisition(id)
|
||||
toast.success('删除成功')
|
||||
refreshList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 刷新列表 */
|
||||
function refreshList() {
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 触底加载更多 */
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
Reference in New Issue
Block a user