李红攀:V2.0.001采购订单添加税率
This commit is contained in:
@@ -13,6 +13,9 @@ export interface PurchaseRequisitionItem {
|
|||||||
productBarCode?: string
|
productBarCode?: string
|
||||||
productPrice?: number
|
productPrice?: number
|
||||||
count?: number
|
count?: number
|
||||||
|
totalProductPrice?: number
|
||||||
|
taxPercent?: number
|
||||||
|
taxPrice?: number
|
||||||
totalPrice?: number
|
totalPrice?: number
|
||||||
purpose?: string
|
purpose?: string
|
||||||
brandId?: number
|
brandId?: number
|
||||||
@@ -46,6 +49,8 @@ export interface PurchaseRequisition {
|
|||||||
approveTime?: string
|
approveTime?: string
|
||||||
approveRemark?: string
|
approveRemark?: string
|
||||||
totalCount?: number
|
totalCount?: number
|
||||||
|
totalProductPrice?: number
|
||||||
|
totalTaxPrice?: number
|
||||||
totalPrice?: number
|
totalPrice?: number
|
||||||
additionalFee?: number
|
additionalFee?: number
|
||||||
emergencyDegree?: number
|
emergencyDegree?: number
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
<view>
|
<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="关联请购单" title-width="180rpx" is-link center @click="openRequisitionPicker">
|
||||||
|
<text v-if="formData.purchaseRequisitionNo" class="text-[#1890ff]">{{ formData.purchaseRequisitionNo }}</text>
|
||||||
|
<text v-else class="text-[#999]">请选择(可选)</text>
|
||||||
|
</wd-cell>
|
||||||
<wd-cell title="供应商" title-width="180rpx" prop="supplierId" center>
|
<wd-cell title="供应商" title-width="180rpx" prop="supplierId" center>
|
||||||
<wd-picker
|
<wd-picker
|
||||||
v-model="formData.supplierId"
|
v-model="formData.supplierId"
|
||||||
@@ -207,6 +211,41 @@
|
|||||||
保存
|
保存
|
||||||
</wd-button>
|
</wd-button>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 请购单选择弹窗 -->
|
||||||
|
<wd-popup v-model="requisitionPickerVisible" position="bottom" :safe-area-inset-bottom="true">
|
||||||
|
<view class="bg-white">
|
||||||
|
<view class="flex items-center justify-between border-b border-[#eee] px-24rpx py-24rpx">
|
||||||
|
<text class="text-32rpx font-semibold">选择请购单</text>
|
||||||
|
<wd-icon name="close" size="40rpx" @click="requisitionPickerVisible = false" />
|
||||||
|
</view>
|
||||||
|
<view class="max-h-[60vh] overflow-y-auto">
|
||||||
|
<view v-if="requisitionLoading" class="py-60rpx text-center text-[#999]">
|
||||||
|
加载中...
|
||||||
|
</view>
|
||||||
|
<view v-else-if="requisitionList.length === 0" class="py-60rpx text-center text-[#999]">
|
||||||
|
暂无已审核的请购单
|
||||||
|
</view>
|
||||||
|
<view v-else>
|
||||||
|
<view
|
||||||
|
v-for="req in requisitionList"
|
||||||
|
:key="req.id"
|
||||||
|
class="border-b border-[#f5f5f5] px-24rpx py-20rpx"
|
||||||
|
@click="onRequisitionSelect(req)"
|
||||||
|
>
|
||||||
|
<view class="mb-8rpx flex items-center justify-between">
|
||||||
|
<text class="text-28rpx text-[#333] font-semibold">{{ req.no }}</text>
|
||||||
|
<text class="text-24rpx text-[#1890ff]">¥{{ req.totalPrice || 0 }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="flex items-center justify-between text-24rpx text-[#999]">
|
||||||
|
<text>请购人:{{ req.requesterNickname || '-' }}</text>
|
||||||
|
<text>{{ formatDate(req.requestTime) }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</wd-popup>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -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 { PurchaseOrder, PurchaseOrderItem } from '@/api/erp/purchase-order'
|
||||||
import type { ProductSimple } from '@/api/erp/product'
|
import type { ProductSimple } from '@/api/erp/product'
|
||||||
import type { SupplierSimple } from '@/api/erp/supplier'
|
import type { SupplierSimple } from '@/api/erp/supplier'
|
||||||
|
import type { PurchaseRequisition } from '@/api/erp/purchase-requisition'
|
||||||
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 { createPurchaseOrder, getPurchaseOrder, updatePurchaseOrder } from '@/api/erp/purchase-order'
|
import { createPurchaseOrder, getPurchaseOrder, updatePurchaseOrder } from '@/api/erp/purchase-order'
|
||||||
import { getProductSimpleList } from '@/api/erp/product'
|
import { getProductSimpleList } from '@/api/erp/product'
|
||||||
import { getSupplierSimpleList } from '@/api/erp/supplier'
|
import { getSupplierSimpleList } from '@/api/erp/supplier'
|
||||||
|
import { getPurchaseRequisition, getPurchaseRequisitionPage } from '@/api/erp/purchase-requisition'
|
||||||
import { navigateBackPlus } from '@/utils'
|
import { navigateBackPlus } from '@/utils'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -238,6 +279,8 @@ const getTitle = computed(() => props.id ? '编辑采购订单' : '新增采购
|
|||||||
const formLoading = ref(false)
|
const formLoading = ref(false)
|
||||||
const formData = ref<PurchaseOrder>({
|
const formData = ref<PurchaseOrder>({
|
||||||
id: undefined,
|
id: undefined,
|
||||||
|
purchaseRequisitionId: undefined,
|
||||||
|
purchaseRequisitionNo: undefined,
|
||||||
supplierId: undefined,
|
supplierId: undefined,
|
||||||
orderTime: undefined,
|
orderTime: undefined,
|
||||||
discountPercent: undefined,
|
discountPercent: undefined,
|
||||||
@@ -255,6 +298,9 @@ const formRules = {
|
|||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
const supplierList = ref<SupplierSimple[]>([])
|
const supplierList = ref<SupplierSimple[]>([])
|
||||||
const productList = ref<ProductSimple[]>([])
|
const productList = ref<ProductSimple[]>([])
|
||||||
|
const requisitionList = ref<PurchaseRequisition[]>([])
|
||||||
|
const requisitionPickerVisible = ref(false)
|
||||||
|
const requisitionLoading = ref(false)
|
||||||
|
|
||||||
/** 供应商下拉列 */
|
/** 供应商下拉列 */
|
||||||
const supplierColumns = computed(() => [
|
const supplierColumns = computed(() => [
|
||||||
@@ -271,6 +317,77 @@ function onSupplierConfirm({ value }: any) {
|
|||||||
formData.value.supplierId = value?.[0]
|
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) {
|
function onProductConfirm({ value }: any, index: number) {
|
||||||
const productId = value?.[0]
|
const productId = value?.[0]
|
||||||
|
|||||||
@@ -62,7 +62,9 @@
|
|||||||
<!-- 金额信息 -->
|
<!-- 金额信息 -->
|
||||||
<wd-cell-group title="金额信息" border>
|
<wd-cell-group title="金额信息" border>
|
||||||
<wd-cell title="合计数量" :value="formatCount(detail.totalCount)" />
|
<wd-cell title="合计数量" :value="formatCount(detail.totalCount)" />
|
||||||
<wd-cell title="合计金额" :value="formatPrice(detail.totalPrice)" />
|
<wd-cell title="合计产品金额" :value="formatPrice(detail.totalProductPrice)" />
|
||||||
|
<wd-cell title="合计税额" :value="formatPrice(detail.totalTaxPrice)" />
|
||||||
|
<wd-cell title="合计金额(含税)" :value="formatPrice(detail.totalPrice)" />
|
||||||
<wd-cell title="附加费" :value="formatPrice(detail.additionalFee)" />
|
<wd-cell title="附加费" :value="formatPrice(detail.additionalFee)" />
|
||||||
</wd-cell-group>
|
</wd-cell-group>
|
||||||
|
|
||||||
@@ -104,7 +106,19 @@
|
|||||||
<text class="text-[#666]">{{ formatPrice(item.productPrice) }}</text>
|
<text class="text-[#666]">{{ formatPrice(item.productPrice) }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="mb-8rpx flex items-center justify-between text-26rpx">
|
<view class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||||
<text class="text-[#999]">金额</text>
|
<text class="text-[#999]">产品金额</text>
|
||||||
|
<text class="text-[#666]">{{ formatPrice(item.totalProductPrice) }}</text>
|
||||||
|
</view>
|
||||||
|
<view v-if="item.taxPercent" class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||||
|
<text class="text-[#999]">税率</text>
|
||||||
|
<text class="text-[#666]">{{ item.taxPercent }}%</text>
|
||||||
|
</view>
|
||||||
|
<view v-if="item.taxPrice" class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||||
|
<text class="text-[#999]">税额</text>
|
||||||
|
<text class="text-[#666]">{{ formatPrice(item.taxPrice) }}</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>
|
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view v-if="item.supplierName" class="mb-8rpx flex items-center justify-between text-26rpx">
|
<view v-if="item.supplierName" class="mb-8rpx flex items-center justify-between text-26rpx">
|
||||||
|
|||||||
@@ -105,7 +105,25 @@
|
|||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
<view class="mb-12rpx flex items-center justify-between text-26rpx">
|
<view class="mb-12rpx flex items-center justify-between text-26rpx">
|
||||||
<text class="text-[#999]">金额</text>
|
<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>
|
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="mb-12rpx">
|
<view class="mb-12rpx">
|
||||||
@@ -137,7 +155,9 @@
|
|||||||
<!-- 合计信息 -->
|
<!-- 合计信息 -->
|
||||||
<wd-cell-group title="合计信息" border>
|
<wd-cell-group title="合计信息" border>
|
||||||
<wd-cell title="合计数量" :value="formatCount(totalCount)" />
|
<wd-cell title="合计数量" :value="formatCount(totalCount)" />
|
||||||
<wd-cell title="合计金额" :value="formatPrice(totalPrice)" />
|
<wd-cell title="合计产品金额" :value="formatPrice(totalProductPrice)" />
|
||||||
|
<wd-cell title="合计税额" :value="formatPrice(totalTaxPrice)" />
|
||||||
|
<wd-cell title="合计金额(含税)" :value="formatPrice(totalPrice)" />
|
||||||
</wd-cell-group>
|
</wd-cell-group>
|
||||||
</wd-form>
|
</wd-form>
|
||||||
</view>
|
</view>
|
||||||
@@ -284,7 +304,17 @@ const totalCount = computed(() => {
|
|||||||
return formData.value.items?.reduce((sum, item) => sum + (Number(item.count) || 0), 0) || 0
|
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(() => {
|
const totalPrice = computed(() => {
|
||||||
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
|
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
|
||||||
})
|
})
|
||||||
@@ -402,6 +432,9 @@ function addItem() {
|
|||||||
productUnitName: undefined,
|
productUnitName: undefined,
|
||||||
count: undefined,
|
count: undefined,
|
||||||
productPrice: undefined,
|
productPrice: undefined,
|
||||||
|
totalProductPrice: 0,
|
||||||
|
taxPercent: undefined,
|
||||||
|
taxPrice: 0,
|
||||||
totalPrice: 0,
|
totalPrice: 0,
|
||||||
purpose: undefined,
|
purpose: undefined,
|
||||||
remark: undefined,
|
remark: undefined,
|
||||||
@@ -413,11 +446,19 @@ function removeItem(index: number) {
|
|||||||
formData.value.items?.splice(index, 1)
|
formData.value.items?.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 计算产品项金额 */
|
/** 计算产品项金额(含税) */
|
||||||
function calcItemTotal(item: PurchaseRequisitionItem) {
|
function calcItemTotal(item: PurchaseRequisitionItem) {
|
||||||
const count = Number(item.count) || 0
|
const count = Number(item.count) || 0
|
||||||
const price = Number(item.productPrice) || 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 {
|
try {
|
||||||
// 设置合计
|
// 设置合计
|
||||||
formData.value.totalCount = totalCount.value
|
formData.value.totalCount = totalCount.value
|
||||||
|
formData.value.totalProductPrice = totalProductPrice.value
|
||||||
|
formData.value.totalTaxPrice = totalTaxPrice.value
|
||||||
formData.value.totalPrice = totalPrice.value
|
formData.value.totalPrice = totalPrice.value
|
||||||
|
|
||||||
if (props.id) {
|
if (props.id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user