李红攀:V2.0.001采购订单添加税率
This commit is contained in:
@@ -11,6 +11,10 @@
|
||||
<view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<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-picker
|
||||
v-model="formData.supplierId"
|
||||
@@ -207,6 +211,41 @@
|
||||
保存
|
||||
</wd-button>
|
||||
</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>
|
||||
</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 { 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<PurchaseOrder>({
|
||||
id: undefined,
|
||||
purchaseRequisitionId: undefined,
|
||||
purchaseRequisitionNo: undefined,
|
||||
supplierId: undefined,
|
||||
orderTime: undefined,
|
||||
discountPercent: undefined,
|
||||
@@ -255,6 +298,9 @@ const formRules = {
|
||||
const formRef = ref<FormInstance>()
|
||||
const supplierList = ref<SupplierSimple[]>([])
|
||||
const productList = ref<ProductSimple[]>([])
|
||||
const requisitionList = ref<PurchaseRequisition[]>([])
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user