李红攀:V2.6.969,请购单BUG修复

This commit is contained in:
2026-06-18 15:58:24 +08:00
parent e404898a78
commit 4c09ffdf00
7 changed files with 239 additions and 183 deletions

View File

@@ -183,6 +183,7 @@ import {
} from '@/api/erp/purchase-requisition' } from '@/api/erp/purchase-requisition'
import { useAccess } from '@/hooks/useAccess' import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils' import { navigateBackPlus } from '@/utils'
import { formatDateTime } from '@/utils/date'
const props = defineProps<{ const props = defineProps<{
id: number | any id: number | any
@@ -276,16 +277,17 @@ function formatPrice(price?: number) {
} }
/** 格式化日期 */ /** 格式化日期 */
function formatDate(dateStr?: string) { function formatDate(date?: string) {
if (!dateStr) return '-' if (!date) return '-'
return dateStr.substring(0, 10) return new Date(date).toLocaleDateString('zh-CN')
} }
/** 格式化日期时间 */ /** 格式化日期时间 */
function formatDateTime(dateStr?: string) { // function formatDateTime(dateStr?: string) {
if (!dateStr) return '-' // if (!dateStr) return '-'
return dateStr.substring(0, 16).replace('T', ' ') // return dateStr.substring(0, 16).replace('T', ' ')
} // }
/** 返回上一页 */ /** 返回上一页 */
function handleBack() { function handleBack() {

View File

@@ -8,7 +8,7 @@
/> />
<!-- 表单区域 --> <!-- 表单区域 -->
<view class="pb-180rpx"> <view>
<wd-form ref="formRef" :model="formData" :rules="formRules"> <wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border> <wd-cell-group title="基本信息" border>
<wd-cell title="请购单号" :value="formData.no || '保存时自动生成'" /> <wd-cell title="请购单号" :value="formData.no || '保存时自动生成'" />
@@ -16,6 +16,7 @@
title="请购类型" title="请购类型"
title-width="180rpx" title-width="180rpx"
is-link is-link
center
:value="getTypeLabel(formData.type)" :value="getTypeLabel(formData.type)"
@click="typePickerVisible = true" @click="typePickerVisible = true"
/> />
@@ -23,6 +24,7 @@
title="优先级" title="优先级"
title-width="180rpx" title-width="180rpx"
is-link is-link
center
:value="getPriorityLabel(formData.priority)" :value="getPriorityLabel(formData.priority)"
@click="priorityPickerVisible = true" @click="priorityPickerVisible = true"
/> />
@@ -30,6 +32,7 @@
title="紧急程度" title="紧急程度"
title-width="180rpx" title-width="180rpx"
is-link is-link
center
:value="getEmergencyLabel(formData.emergencyDegree)" :value="getEmergencyLabel(formData.emergencyDegree)"
@click="emergencyPickerVisible = true" @click="emergencyPickerVisible = true"
/> />
@@ -37,6 +40,7 @@
title="请购时间" title="请购时间"
title-width="180rpx" title-width="180rpx"
is-link is-link
center
:value="formData.requestTime ? formatDate(formData.requestTime) : '请选择'" :value="formData.requestTime ? formatDate(formData.requestTime) : '请选择'"
@click="requestDatePickerVisible = true" @click="requestDatePickerVisible = true"
/> />
@@ -44,6 +48,7 @@
title="期望到货" title="期望到货"
title-width="180rpx" title-width="180rpx"
is-link is-link
center
:value="formData.expectedTime ? formatDate(formData.expectedTime) : '请选择'" :value="formData.expectedTime ? formatDate(formData.expectedTime) : '请选择'"
@click="expectedDatePickerVisible = true" @click="expectedDatePickerVisible = true"
/> />
@@ -57,109 +62,142 @@
clearable clearable
/> />
</wd-cell-group> </wd-cell-group>
</wd-form>
</view>
<!-- 请购产品清单 --> <!-- 请购产品清单 -->
<wd-cell-group title="请购产品清单" border> <view class="mx-24rpx mt-24rpx pb-180rpx">
<view v-if="formData.items.length === 0" class="py-40rpx text-center text-[#999]"> <view class="mb-16rpx flex items-center justify-between">
暂无产品请点击下方按钮添加 <view class="text-32rpx text-[#333] font-semibold">
请购产品清单{{ formData.items?.length || 0 }}
</view>
<wd-button size="small" type="primary" @click="handleAddItem">
+ 添加产品
</wd-button>
</view> </view>
<view v-else>
<view <view
v-for="(item, index) in formData.items" v-for="(item, index) in formData.items"
:key="index" :key="index"
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx" class="mb-16rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
> >
<view class="mb-12rpx flex items-center justify-between"> <view class="flex items-center justify-between bg-[#f8f8f8] px-24rpx py-12rpx">
<view class="text-28rpx text-[#333] font-semibold"> <text class="text-28rpx text-[#333] font-semibold">产品 #{{ index + 1 }} {{ item.productName || '' }}</text>
{{ item.productName || '请选择产品' }} <wd-button size="small" type="error" plain @click="handleRemoveItem(index)">
</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-[#666]">{{ formatPrice(item.totalProductPrice) }}</text>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.taxPercent"
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-[#666]">{{ formatPrice(item.taxPrice) }}</text>
</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> </wd-button>
</view> </view>
</wd-cell-group> <view class="p-24rpx">
<view class="mb-16rpx">
<text class="mb-8rpx block text-24rpx text-[#999]">选择产品</text>
<wd-picker
v-model="item.productId"
:columns="productColumns"
placeholder="请选择产品"
@confirm="(e: any) => onProductConfirm(e, index)"
/>
</view>
<!-- 自动填充的产品信息只读 -->
<view v-if="item.productId" class="mb-16rpx rounded-8rpx bg-[#f9f9f9] p-16rpx">
<view class="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">规格</text>
<text class="text-[#333]">{{ item.productSpec || '-' }}</text>
</view>
<view class="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">单位</text>
<text class="text-[#333]">{{ item.productUnitName || '-' }}</text>
</view>
<view class="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">条码</text>
<text class="text-[#333]">{{ item.productBarCode || '-' }}</text>
</view>
</view>
<view class="mb-16rpx flex gap-16rpx">
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">需求数量</text>
<wd-input
v-model="item.count"
type="number"
placeholder="需求数量"
clearable
@change="calcItemTotal(item)"
/>
</view>
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">参考单价</text>
<wd-input
v-model="item.productPrice"
type="number"
placeholder="参考单价"
clearable
@change="calcItemTotal(item)"
/>
</view>
</view>
<view class="mb-16rpx flex gap-16rpx">
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">税率(%)</text>
<wd-input
v-model="item.taxPercent"
type="number"
placeholder="税率"
clearable
@change="calcItemTotal(item)"
/>
</view>
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">含税金额</text>
<text class="block pt-16rpx text-28rpx text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
<view class="mb-16rpx flex gap-16rpx text-24rpx text-[#999]">
<view class="flex-1">
<text>产品金额: {{ formatPrice(item.totalProductPrice) }}</text>
</view>
<view class="flex-1">
<text>税额: {{ formatPrice(item.taxPrice) }}</text>
</view>
</view>
<view class="mb-16rpx">
<text class="mb-8rpx block text-24rpx text-[#999]">用途说明</text>
<wd-input
v-model="item.purpose"
placeholder="请输入用途"
clearable
/>
</view>
<view>
<text class="mb-8rpx block text-24rpx text-[#999]">备注</text>
<wd-input
v-model="item.remark"
placeholder="请输入备注"
clearable
/>
</view>
</view>
</view>
<view v-if="!formData.items?.length" class="py-60rpx text-center text-28rpx text-[#999]">
暂无产品请点击"添加产品"按钮
</view>
<!-- 合计信息 --> <!-- 合计信息 -->
<wd-cell-group title="合计信息" border> <view v-if="formData.items?.length" class="mt-24rpx rounded-12rpx bg-white p-24rpx shadow-sm">
<wd-cell title="合计数量" :value="formatCount(totalCount)" /> <view class="mb-12rpx flex justify-between text-28rpx">
<wd-cell title="合计产品金额" :value="formatPrice(totalProductPrice)" /> <text class="text-[#999]">合计数量</text>
<wd-cell title="合计税额" :value="formatPrice(totalTaxPrice)" /> <text class="text-[#333]">{{ formatCount(totalCount) }}</text>
<wd-cell title="合计金额(含税)" :value="formatPrice(totalPrice)" /> </view>
</wd-cell-group> <view class="mb-12rpx flex justify-between text-28rpx">
</wd-form> <text class="text-[#999]">合计产品金额</text>
<text class="text-[#333]">{{ formatPrice(totalProductPrice) }}</text>
</view>
<view class="mb-12rpx flex justify-between text-28rpx">
<text class="text-[#999]">合计税额</text>
<text class="text-[#333]">{{ formatPrice(totalTaxPrice) }}</text>
</view>
<view class="flex justify-between text-28rpx">
<text class="text-[#999]">合计金额含税</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(totalPrice) }}</text>
</view>
</view>
</view> </view>
<!-- 底部保存按钮 --> <!-- 底部保存按钮 -->
@@ -210,19 +248,13 @@
:value="formData.expectedTime" :value="formData.expectedTime"
@confirm="onExpectedDateConfirm" @confirm="onExpectedDateConfirm"
/> />
<!-- 产品选择器 -->
<wd-picker
v-model="productPickerVisible"
:columns="productColumns"
@confirm="onProductConfirm"
/>
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types' import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { PurchaseRequisition, PurchaseRequisitionItem } from '@/api/erp/purchase-requisition' import type { PurchaseRequisition, PurchaseRequisitionItem } from '@/api/erp/purchase-requisition'
import type { ProductSimple } from '@/api/erp/product'
import { computed, onMounted, ref } from 'vue' import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni' import { useToast } from 'wot-design-uni'
import { import {
@@ -233,6 +265,7 @@ import {
REQUISITION_TYPE_OPTIONS, REQUISITION_TYPE_OPTIONS,
updatePurchaseRequisition, updatePurchaseRequisition,
} from '@/api/erp/purchase-requisition' } from '@/api/erp/purchase-requisition'
import { getProductSimpleList } from '@/api/erp/product'
import { navigateBackPlus } from '@/utils' import { navigateBackPlus } from '@/utils'
const props = defineProps<{ const props = defineProps<{
@@ -257,11 +290,10 @@ const formData = ref<PurchaseRequisition>({
emergencyDegree: 1, emergencyDegree: 1,
requestTime: undefined, requestTime: undefined,
expectedTime: undefined, expectedTime: undefined,
remark: undefined, remark: '',
items: [], items: [],
}) })
const formRules = { const formRules = {
type: [{ required: true, message: '请购类型不能为空' }],
requestTime: [{ required: true, message: '请购时间不能为空' }], requestTime: [{ required: true, message: '请购时间不能为空' }],
expectedTime: [{ required: true, message: '期望到货时间不能为空' }], expectedTime: [{ required: true, message: '期望到货时间不能为空' }],
} }
@@ -269,35 +301,31 @@ const formRef = ref<FormInstance>()
// 类型选择器 // 类型选择器
const typePickerVisible = ref(false) const typePickerVisible = ref(false)
const typeColumns = computed(() => [ const typeColumns = computed(() =>
REQUISITION_TYPE_OPTIONS.map(v => ({ value: v.value, label: v.label })), REQUISITION_TYPE_OPTIONS.map(v => ({ label: v.label, value: v.value })),
]) )
// 优先级选择器 // 优先级选择器
const priorityPickerVisible = ref(false) const priorityPickerVisible = ref(false)
const priorityColumns = computed(() => [ const priorityColumns = computed(() =>
PRIORITY_OPTIONS.map(v => ({ value: v.value, label: v.label })), PRIORITY_OPTIONS.map(v => ({ label: v.label, value: v.value })),
]) )
// 紧急程度选择器 // 紧急程度选择器
const emergencyPickerVisible = ref(false) const emergencyPickerVisible = ref(false)
const emergencyColumns = computed(() => [ const emergencyColumns = computed(() =>
EMERGENCY_OPTIONS.map(v => ({ value: v.value, label: v.label })), EMERGENCY_OPTIONS.map(v => ({ label: v.label, value: v.value })),
]) )
// 日期选择器 // 日期选择器
const requestDatePickerVisible = ref(false) const requestDatePickerVisible = ref(false)
const expectedDatePickerVisible = ref(false) const expectedDatePickerVisible = ref(false)
// 产品列表 // 产品列表
const productList = ref<{ id: number, name: string, unitName?: string }[]>([]) const productList = ref<ProductSimple[]>([])
const productPickerVisible = ref(false) const productColumns = computed(() =>
const productColumns = computed(() => [ productList.value.map(v => ({ label: v.name, value: v.id })),
productList.value.map(v => ({ value: v.id, label: v.name })), )
])
// 当前编辑的产品项索引
const currentItemIndex = ref(-1)
/** 合计数量 */ /** 合计数量 */
const totalCount = computed(() => { const totalCount = computed(() => {
@@ -347,14 +375,14 @@ function formatPrice(price?: number) {
} }
/** 格式化日期 */ /** 格式化日期 */
function formatDate(dateStr?: string) { function formatDate(dateVal?: string | number) {
if (!dateStr) return '-' if (!dateVal) return '-'
if (typeof dateStr === 'number') { if (typeof dateVal === 'number') {
const d = new Date(dateStr) const d = new Date(dateVal)
const pad = (n: number) => n.toString().padStart(2, '0') const pad = (n: number) => n.toString().padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}` return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
} }
return dateStr.substring(0, 10) return String(dateVal).substring(0, 10)
} }
/** 返回上一页 */ /** 返回上一页 */
@@ -362,6 +390,16 @@ function handleBack() {
navigateBackPlus('/pages-erp/purchase-requisition/index') navigateBackPlus('/pages-erp/purchase-requisition/index')
} }
/** 加载下拉列表数据 */
async function loadDropdownData() {
try {
const products = await getProductSimpleList()
productList.value = products || []
} catch {
// error handled by http
}
}
/** 加载详情 */ /** 加载详情 */
async function getDetail() { async function getDetail() {
if (!props.id) return if (!props.id) return
@@ -375,19 +413,19 @@ async function getDetail() {
/** 类型确认 */ /** 类型确认 */
function onTypeConfirm({ value }: any) { function onTypeConfirm({ value }: any) {
formData.value.type = value?.[0] formData.value.type = value?.[0] ?? formData.value.type
typePickerVisible.value = false typePickerVisible.value = false
} }
/** 优先级确认 */ /** 优先级确认 */
function onPriorityConfirm({ value }: any) { function onPriorityConfirm({ value }: any) {
formData.value.priority = value?.[0] formData.value.priority = value?.[0] ?? formData.value.priority
priorityPickerVisible.value = false priorityPickerVisible.value = false
} }
/** 紧急程度确认 */ /** 紧急程度确认 */
function onEmergencyConfirm({ value }: any) { function onEmergencyConfirm({ value }: any) {
formData.value.emergencyDegree = value?.[0] formData.value.emergencyDegree = value?.[0] ?? formData.value.emergencyDegree
emergencyPickerVisible.value = false emergencyPickerVisible.value = false
} }
@@ -403,47 +441,58 @@ function onExpectedDateConfirm({ value }: any) {
expectedDatePickerVisible.value = false expectedDatePickerVisible.value = false
} }
/** 打开产品选择 */ /** 产品选择回调:自动填充规格/单位/条码 */
function openProductPicker(index: number) { function onProductConfirm({ value }: any, index: number) {
currentItemIndex.value = index const productId = value?.[0]
productPickerVisible.value = true if (formData.value.items && formData.value.items[index]) {
} const item = formData.value.items[index]
item.productId = productId
/** 产品确认 */ const product = productList.value.find(p => p.id === productId)
function onProductConfirm({ value }: any) { if (product) {
if (currentItemIndex.value >= 0 && formData.value.items) { item.productName = product.name
const item = formData.value.items[currentItemIndex.value] item.productSpec = product.standard || ''
item.productId = value?.[0] item.productUnitName = product.unitName || ''
const product = productList.value.find(p => p.id === item.productId) item.productUnitId = product.unitId as any
item.productName = product?.name item.productBarCode = product.barCode || ''
item.productUnitName = product?.unitName item.productPrice = product.purchasePrice
}
} }
productPickerVisible.value = false
} }
/** 添加产品项 */ /** 添加产品项 */
function addItem() { function handleAddItem() {
if (!formData.value.items) { if (!formData.value.items) {
formData.value.items = [] formData.value.items = []
} }
formData.value.items.push({ formData.value.items.push({
productId: undefined, productId: undefined as any,
productName: undefined, productName: undefined as any,
productUnitName: undefined, productUnitId: undefined as any,
count: undefined, productUnitName: undefined as any,
productSpec: undefined as any,
productBarCode: undefined as any,
productPrice: undefined, productPrice: undefined,
count: 1 as any,
totalProductPrice: 0, totalProductPrice: 0,
taxPercent: undefined, taxPercent: undefined,
taxPrice: 0, taxPrice: 0,
totalPrice: 0, totalPrice: 0,
purpose: undefined, purpose: '',
remark: undefined, remark: '',
}) })
} }
/** 移除产品项 */ /** 移除产品项 */
function removeItem(index: number) { function handleRemoveItem(index: number) {
uni.showModal({
title: '提示',
content: `确定要删除第 ${index + 1} 项产品吗?`,
success: (res) => {
if (res.confirm) {
formData.value.items?.splice(index, 1) formData.value.items?.splice(index, 1)
}
},
})
} }
/** 计算产品项金额(含税) */ /** 计算产品项金额(含税) */
@@ -472,13 +521,14 @@ async function handleSubmit() {
return return
} }
for (const item of formData.value.items) { for (let i = 0; i < formData.value.items.length; i++) {
const item = formData.value.items[i]
if (!item.productId) { if (!item.productId) {
toast.error('请选择产品') toast.warning(`${i + 1} 项产品ID不能为空`)
return return
} }
if (!item.count || Number(item.count) <= 0) { if (!item.count) {
toast.error('请输入有效的数量') toast.warning(`${i + 1} 项产品数量不能为空`)
return return
} }
} }
@@ -508,7 +558,7 @@ async function handleSubmit() {
/** 初始化 */ /** 初始化 */
onMounted(async () => { onMounted(async () => {
// 加载详情 await loadDropdownData()
getDetail() getDetail()
}) })
</script> </script>

View File

@@ -359,9 +359,9 @@ function formatPrice(price?: number) {
} }
/** 格式化日期 */ /** 格式化日期 */
function formatDate(dateStr?: string) { function formatDate(date?: string) {
if (!dateStr) return '-' if (!date) return '-'
return dateStr.substring(0, 10) return new Date(date).toLocaleDateString('zh-CN')
} }
/** 返回上一页 */ /** 返回上一页 */

View File

@@ -146,11 +146,12 @@ function formatPrice(price?: number) {
} }
/** 格式化日期 */ /** 格式化日期 */
function formatDate(dateStr?: string) { function formatDate(date?: string) {
if (!dateStr) return '-' if (!date) return '-'
return dateStr.substring(0, 10) return new Date(date).toLocaleDateString('zh-CN')
} }
/** 返回上一页 */ /** 返回上一页 */
function handleBack() { function handleBack() {
navigateBackPlus('/pages-erp/stock-in/index') navigateBackPlus('/pages-erp/stock-in/index')

View File

@@ -234,11 +234,12 @@ function formatPrice(price?: number) {
} }
/** 格式化日期 */ /** 格式化日期 */
function formatDate(dateStr?: string) { function formatDate(date?: string) {
if (!dateStr) return '-' if (!date) return '-'
return dateStr.substring(0, 10) return new Date(date).toLocaleDateString('zh-CN')
} }
/** 返回上一页 */ /** 返回上一页 */
function handleBack() { function handleBack() {
navigateBackPlus() navigateBackPlus()

View File

@@ -146,11 +146,12 @@ function formatPrice(price?: number) {
} }
/** 格式化日期 */ /** 格式化日期 */
function formatDate(dateStr?: string) { function formatDate(date?: string) {
if (!dateStr) return '-' if (!date) return '-'
return dateStr.substring(0, 10) return new Date(date).toLocaleDateString('zh-CN')
} }
/** 返回上一页 */ /** 返回上一页 */
function handleBack() { function handleBack() {
navigateBackPlus('/pages-erp/stock-out/index') navigateBackPlus('/pages-erp/stock-out/index')

View File

@@ -244,11 +244,12 @@ function formatPrice(price?: number) {
} }
/** 格式化日期 */ /** 格式化日期 */
function formatDate(dateStr?: string) { function formatDate(date?: string) {
if (!dateStr) return '-' if (!date) return '-'
return dateStr.substring(0, 10) return new Date(date).toLocaleDateString('zh-CN')
} }
/** 返回上一页 */ /** 返回上一页 */
function handleBack() { function handleBack() {
navigateBackPlus() navigateBackPlus()