diff --git a/src/api/erp/purchase-requisition/index.ts b/src/api/erp/purchase-requisition/index.ts
index 2636494..3c30bf7 100644
--- a/src/api/erp/purchase-requisition/index.ts
+++ b/src/api/erp/purchase-requisition/index.ts
@@ -13,6 +13,9 @@ export interface PurchaseRequisitionItem {
productBarCode?: string
productPrice?: number
count?: number
+ totalProductPrice?: number
+ taxPercent?: number
+ taxPrice?: number
totalPrice?: number
purpose?: string
brandId?: number
@@ -46,6 +49,8 @@ export interface PurchaseRequisition {
approveTime?: string
approveRemark?: string
totalCount?: number
+ totalProductPrice?: number
+ totalTaxPrice?: number
totalPrice?: number
additionalFee?: number
emergencyDegree?: number
diff --git a/src/pages-erp/purchase-order/form/index.vue b/src/pages-erp/purchase-order/form/index.vue
index ad411ec..5afcc40 100644
--- a/src/pages-erp/purchase-order/form/index.vue
+++ b/src/pages-erp/purchase-order/form/index.vue
@@ -11,6 +11,10 @@
+
+ {{ formData.purchaseRequisitionNo }}
+ 请选择(可选)
+
+
+
+
+
+
+ 选择请购单
+
+
+
+
+ 加载中...
+
+
+ 暂无已审核的请购单
+
+
+
+
+ {{ req.no }}
+ ¥{{ req.totalPrice || 0 }}
+
+
+ 请购人:{{ req.requesterNickname || '-' }}
+ {{ formatDate(req.requestTime) }}
+
+
+
+
+
+
@@ -215,11 +254,13 @@ import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { PurchaseOrder, PurchaseOrderItem } from '@/api/erp/purchase-order'
import type { ProductSimple } from '@/api/erp/product'
import type { SupplierSimple } from '@/api/erp/supplier'
+import type { PurchaseRequisition } from '@/api/erp/purchase-requisition'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createPurchaseOrder, getPurchaseOrder, updatePurchaseOrder } from '@/api/erp/purchase-order'
import { getProductSimpleList } from '@/api/erp/product'
import { getSupplierSimpleList } from '@/api/erp/supplier'
+import { getPurchaseRequisition, getPurchaseRequisitionPage } from '@/api/erp/purchase-requisition'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
@@ -238,6 +279,8 @@ const getTitle = computed(() => props.id ? '编辑采购订单' : '新增采购
const formLoading = ref(false)
const formData = ref({
id: undefined,
+ purchaseRequisitionId: undefined,
+ purchaseRequisitionNo: undefined,
supplierId: undefined,
orderTime: undefined,
discountPercent: undefined,
@@ -255,6 +298,9 @@ const formRules = {
const formRef = ref()
const supplierList = ref([])
const productList = ref([])
+const requisitionList = ref([])
+const requisitionPickerVisible = ref(false)
+const requisitionLoading = ref(false)
/** 供应商下拉列 */
const supplierColumns = computed(() => [
@@ -271,6 +317,77 @@ function onSupplierConfirm({ value }: any) {
formData.value.supplierId = value?.[0]
}
+/** 格式化日期 */
+function formatDate(dateVal?: string | number) {
+ if (!dateVal) return '-'
+ if (typeof dateVal === 'number') {
+ const d = new Date(dateVal)
+ const pad = (n: number) => n.toString().padStart(2, '0')
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
+ }
+ return String(dateVal).substring(0, 10)
+}
+
+/** 打开请购单选择弹窗 */
+async function openRequisitionPicker() {
+ requisitionPickerVisible.value = true
+ requisitionLoading.value = true
+ try {
+ const res = await getPurchaseRequisitionPage({ pageNo: 1, pageSize: 50, status: 2 })
+ requisitionList.value = res.list || []
+ } finally {
+ requisitionLoading.value = false
+ }
+}
+
+/** 请购单选择回调:带出税率税额等信息 */
+async function onRequisitionSelect(requisition: PurchaseRequisition) {
+ requisitionPickerVisible.value = false
+ formData.value.purchaseRequisitionId = requisition.id
+ formData.value.purchaseRequisitionNo = requisition.no
+
+ // 自动填充供应商
+ if (requisition.supplierId) {
+ formData.value.supplierId = requisition.supplierId
+ }
+
+ try {
+ toast.loading('加载请购单明细...')
+ // 获取请购单详情(包含明细项)
+ const detail = await getPurchaseRequisition(requisition.id!)
+
+ // 转换请购单明细为采购订单明细(带上税率和税额)
+ const orderItems: PurchaseOrderItem[] = (detail.items || []).map(item => ({
+ productId: item.productId,
+ productName: item.productName,
+ productSpec: item.productSpec,
+ productUnitId: item.productUnitId,
+ productUnitName: item.productUnitName,
+ productBarCode: item.productBarCode,
+ productPrice: item.productPrice,
+ count: item.count,
+ totalProductPrice: item.totalProductPrice || item.totalPrice,
+ taxPercent: item.taxPercent || 0,
+ taxPrice: item.taxPrice || 0,
+ totalPrice: item.totalPrice,
+ supplierId: item.supplierId,
+ supplierName: item.supplierName,
+ remark: item.remark,
+ }))
+
+ formData.value.items = orderItems
+
+ // 带上备注
+ if (detail.remark) {
+ formData.value.remark = `基于请购单 ${detail.no} 生成\n${detail.remark}`
+ }
+
+ toast.success('已导入请购单明细')
+ } catch {
+ toast.error('获取请购单详情失败')
+ }
+}
+
/** 产品选择回调:自动填充规格/单位/条码/单价/供应商 */
function onProductConfirm({ value }: any, index: number) {
const productId = value?.[0]
diff --git a/src/pages-erp/purchase-requisition/detail/index.vue b/src/pages-erp/purchase-requisition/detail/index.vue
index cea7861..9fd4dfd 100644
--- a/src/pages-erp/purchase-requisition/detail/index.vue
+++ b/src/pages-erp/purchase-requisition/detail/index.vue
@@ -62,7 +62,9 @@
-
+
+
+
@@ -104,7 +106,19 @@
{{ formatPrice(item.productPrice) }}
- 金额
+ 产品金额
+ {{ formatPrice(item.totalProductPrice) }}
+
+
+ 税率
+ {{ item.taxPercent }}%
+
+
+ 税额
+ {{ formatPrice(item.taxPrice) }}
+
+
+ 含税金额
{{ formatPrice(item.totalPrice) }}
diff --git a/src/pages-erp/purchase-requisition/form/index.vue b/src/pages-erp/purchase-requisition/form/index.vue
index 659db54..bd8778f 100644
--- a/src/pages-erp/purchase-requisition/form/index.vue
+++ b/src/pages-erp/purchase-requisition/form/index.vue
@@ -105,7 +105,25 @@
/>
- 金额
+ 产品金额
+ {{ formatPrice(item.totalProductPrice) }}
+
+
+
+
+
+ 税额
+ {{ formatPrice(item.taxPrice) }}
+
+
+ 含税金额
{{ formatPrice(item.totalPrice) }}
@@ -137,7 +155,9 @@
-
+
+
+
@@ -284,7 +304,17 @@ const totalCount = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.count) || 0), 0) || 0
})
-/** 合计金额 */
+/** 合计产品金额 */
+const totalProductPrice = computed(() => {
+ return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalProductPrice) || 0), 0) || 0
+})
+
+/** 合计税额 */
+const totalTaxPrice = computed(() => {
+ return formData.value.items?.reduce((sum, item) => sum + (Number(item.taxPrice) || 0), 0) || 0
+})
+
+/** 合计金额(含税) */
const totalPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
})
@@ -402,6 +432,9 @@ function addItem() {
productUnitName: undefined,
count: undefined,
productPrice: undefined,
+ totalProductPrice: 0,
+ taxPercent: undefined,
+ taxPrice: 0,
totalPrice: 0,
purpose: undefined,
remark: undefined,
@@ -413,11 +446,19 @@ 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
+ const taxPercent = Number(item.taxPercent) || 0
+ // 产品金额 = 单价 × 数量
+ const totalProductPrice = count * price
+ // 税额 = 产品金额 × 税率 / 100
+ const taxPrice = totalProductPrice * taxPercent / 100
+ // 含税金额 = 产品金额 + 税额
+ item.totalProductPrice = Math.round(totalProductPrice * 100) / 100
+ item.taxPrice = Math.round(taxPrice * 100) / 100
+ item.totalPrice = Math.round((totalProductPrice + taxPrice) * 100) / 100
}
/** 提交表单 */
@@ -446,6 +487,8 @@ async function handleSubmit() {
try {
// 设置合计
formData.value.totalCount = totalCount.value
+ formData.value.totalProductPrice = totalProductPrice.value
+ formData.value.totalTaxPrice = totalTaxPrice.value
formData.value.totalPrice = totalPrice.value
if (props.id) {