李红攀:V2.0.001小程序的采摘管理
This commit is contained in:
104
src/pages-erp/purchase-order/components/search-form.vue
Normal file
104
src/pages-erp/purchase-order/components/search-form.vue
Normal file
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<!-- 搜索框入口 -->
|
||||
<view @click="visible = true">
|
||||
<wd-search :placeholder="placeholder" hide-cancel disabled />
|
||||
</view>
|
||||
|
||||
<!-- 搜索弹窗 -->
|
||||
<wd-popup v-model="visible" position="top" @close="visible = 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="formData.no"
|
||||
placeholder="请输入采购单编号"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
采购状态
|
||||
</view>
|
||||
<wd-radio-group v-model="formData.status" shape="button">
|
||||
<wd-radio :value="-1">
|
||||
全部
|
||||
</wd-radio>
|
||||
<wd-radio :value="10">
|
||||
未审批
|
||||
</wd-radio>
|
||||
<wd-radio :value="20">
|
||||
已审批
|
||||
</wd-radio>
|
||||
<wd-radio :value="30">
|
||||
已驳回
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { getNavbarHeight } from '@/utils'
|
||||
|
||||
const emit = defineEmits<{
|
||||
search: [data: Record<string, any>]
|
||||
reset: []
|
||||
}>()
|
||||
|
||||
const visible = ref(false)
|
||||
const formData = reactive({
|
||||
no: undefined as string | undefined,
|
||||
status: -1,
|
||||
})
|
||||
|
||||
const statusMap: Record<number, string> = {
|
||||
10: '未审批',
|
||||
20: '已审批',
|
||||
30: '已驳回',
|
||||
}
|
||||
|
||||
/** 搜索条件 placeholder 拼接 */
|
||||
const placeholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (formData.no) {
|
||||
conditions.push(`编号:${formData.no}`)
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
conditions.push(`状态:${statusMap[formData.status] || formData.status}`)
|
||||
}
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索采购订单'
|
||||
})
|
||||
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
visible.value = false
|
||||
const params: Record<string, any> = {}
|
||||
if (formData.no) {
|
||||
params.no = formData.no
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
params.status = formData.status
|
||||
}
|
||||
emit('search', params)
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
function handleReset() {
|
||||
formData.no = undefined
|
||||
formData.status = -1
|
||||
visible.value = false
|
||||
emit('reset')
|
||||
}
|
||||
</script>
|
||||
297
src/pages-erp/purchase-order/detail/index.vue
Normal file
297
src/pages-erp/purchase-order/detail/index.vue
Normal file
@@ -0,0 +1,297 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="采购订单详情"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 详情内容 -->
|
||||
<view v-if="formData">
|
||||
<!-- 基本信息 -->
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="采购单编号" :value="formData.no" />
|
||||
<wd-cell title="采购状态">
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(formData.status)"
|
||||
>
|
||||
{{ getStatusText(formData.status) }}
|
||||
</view>
|
||||
</wd-cell>
|
||||
<wd-cell title="供应商" :value="formData.supplierName || '-'" />
|
||||
<wd-cell title="下单时间" :value="formatDateTime(formData.orderTime)" />
|
||||
<wd-cell title="创建人" :value="formData.creatorName || '-'" />
|
||||
<wd-cell title="审核人" :value="formData.auditorName || '-'" />
|
||||
<wd-cell title="创建时间" :value="formatDateTime(formData.createTime)" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 合同信息 -->
|
||||
<wd-cell-group title="合同信息" border>
|
||||
<wd-cell title="发票类别" :value="formData.invoiceTypeName || '-'" />
|
||||
<wd-cell title="运费承担方" :value="formData.freightPayerName || '-'" />
|
||||
<wd-cell title="结算方式" :value="formData.settlementMethodName || '-'" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 金额信息 -->
|
||||
<wd-cell-group title="金额信息" border>
|
||||
<wd-cell title="合计数量" :value="String(formData.totalCount || 0)" />
|
||||
<wd-cell title="合计产品价格" :value="`¥${formData.totalProductPrice || 0}`" />
|
||||
<wd-cell title="合计税额" :value="`¥${formData.totalTaxPrice || 0}`" />
|
||||
<wd-cell title="优惠率" :value="`${formData.discountPercent || 0}%`" />
|
||||
<wd-cell title="优惠金额" :value="`¥${formData.discountPrice || 0}`" />
|
||||
<wd-cell title="定金金额" :value="`¥${formData.depositPrice || 0}`" />
|
||||
<wd-cell title="最终合计价格">
|
||||
<text class="text-[#f5222d] font-semibold">¥{{ formData.totalPrice || 0 }}</text>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 入库/退货信息 -->
|
||||
<wd-cell-group title="入库/退货" border>
|
||||
<wd-cell title="入库数量" :value="String(formData.inCount || 0)" />
|
||||
<wd-cell title="退货数量" :value="String(formData.returnCount || 0)" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 请购单信息 -->
|
||||
<wd-cell-group v-if="formData.purchaseRequisitionNo" title="关联请购单" border>
|
||||
<wd-cell title="请购单编号" :value="formData.purchaseRequisitionNo" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 订单明细 -->
|
||||
<view class="mx-24rpx mt-24rpx">
|
||||
<view class="mb-16rpx text-32rpx text-[#333] font-semibold">
|
||||
订单明细({{ formData.items?.length || 0 }}项)
|
||||
</view>
|
||||
<view v-if="formData.items && formData.items.length > 0">
|
||||
<view
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="item.id || index"
|
||||
class="mb-16rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
>
|
||||
<!-- 产品头部 -->
|
||||
<view class="flex items-center justify-between bg-[#f8f8f8] px-24rpx py-16rpx">
|
||||
<view class="flex items-center">
|
||||
<text class="text-28rpx text-[#333] font-semibold">{{ item.productName || '-' }}</text>
|
||||
<text v-if="item.productBarCode" class="ml-12rpx text-22rpx text-[#999]">{{ item.productBarCode }}</text>
|
||||
</view>
|
||||
<text v-if="item.supplierName" class="text-24rpx text-[#1890ff]">{{ item.supplierName }}</text>
|
||||
</view>
|
||||
<view class="p-24rpx">
|
||||
<!-- 产品规格 -->
|
||||
<view v-if="item.productSpec" class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<text class="mr-8rpx text-[#999]">规格:</text>
|
||||
<text>{{ item.productSpec }}</text>
|
||||
</view>
|
||||
<!-- 单价 / 数量 / 单位 -->
|
||||
<view class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">单价:</text>
|
||||
<text class="text-[#f5222d]">¥{{ item.productPrice || 0 }}</text>
|
||||
</view>
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">数量:</text>
|
||||
<text class="font-semibold">{{ item.count || 0 }}</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">单位:</text>
|
||||
<text>{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 税率 / 税额 -->
|
||||
<view v-if="item.taxPercent" class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">税率:</text>
|
||||
<text>{{ item.taxPercent }}%</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">税额:</text>
|
||||
<text>¥{{ item.taxPrice || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 入库 / 退货 / 库存 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">入库:</text>
|
||||
<text>{{ item.inCount || 0 }}</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">退货:</text>
|
||||
<text>{{ item.returnCount || 0 }}</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">库存:</text>
|
||||
<text>{{ item.stockCount || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 备注 -->
|
||||
<view v-if="item.remark" class="text-24rpx text-[#999]">
|
||||
备注:{{ item.remark }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="py-60rpx text-center text-28rpx text-[#999]">
|
||||
暂无订单明细
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 备注 -->
|
||||
<wd-cell-group v-if="formData.remark" title="备注" border>
|
||||
<wd-cell :value="formData.remark" />
|
||||
</wd-cell-group>
|
||||
</view>
|
||||
|
||||
<!-- 底部操作按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<view class="yd-detail-footer-actions">
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-order:update']) && formData?.status === 10"
|
||||
class="flex-1" type="warning" @click="handleEdit"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-order:update-status']) && formData?.status === 10"
|
||||
class="flex-1" type="success" @click="handleApprove"
|
||||
>
|
||||
审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-order:delete']) && formData?.status !== 20"
|
||||
class="flex-1" type="error" :loading="deleting" @click="handleDelete"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PurchaseOrder } from '@/api/erp/purchase-order'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deletePurchaseOrder, getPurchaseOrder, updatePurchaseOrderStatus } from '@/api/erp/purchase-order'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import { formatDateTime } from '@/utils/date'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const formData = ref<PurchaseOrder>()
|
||||
const deleting = ref(false)
|
||||
|
||||
/** 获取状态文本 */
|
||||
function getStatusText(status?: number) {
|
||||
switch (status) {
|
||||
case 10: return '未审批'
|
||||
case 20: return '已审批'
|
||||
case 30: return '已驳回'
|
||||
default: return '未知'
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number) {
|
||||
switch (status) {
|
||||
case 10: return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
case 20: return 'bg-[#f6ffed] text-[#52c41a]'
|
||||
case 30: return 'bg-[#fff1f0] text-[#f5222d]'
|
||||
default: return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/purchase-order/index')
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getPurchaseOrder(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 编辑操作 */
|
||||
function handleEdit() {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/purchase-order/form/index?id=${props.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 审批操作 */
|
||||
function handleApprove() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要审批通过该采购订单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await updatePurchaseOrderStatus(props.id, 20)
|
||||
toast.success('审批成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除操作 */
|
||||
function handleDelete() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该采购订单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
deleting.value = true
|
||||
try {
|
||||
await deletePurchaseOrder([props.id])
|
||||
toast.success('删除成功')
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
412
src/pages-erp/purchase-order/form/index.vue
Normal file
412
src/pages-erp/purchase-order/form/index.vue
Normal file
@@ -0,0 +1,412 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
:title="getTitle"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="供应商" title-width="180rpx" prop="supplierId" center>
|
||||
<wd-picker
|
||||
v-model="formData.supplierId"
|
||||
:columns="supplierColumns"
|
||||
label=""
|
||||
placeholder="请选择供应商"
|
||||
@confirm="onSupplierConfirm"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="采购时间" title-width="180rpx" prop="orderTime" center>
|
||||
<wd-datetime-picker
|
||||
v-model="formData.orderTime"
|
||||
type="datetime"
|
||||
label=""
|
||||
placeholder="请选择采购时间"
|
||||
/>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="合同信息" border>
|
||||
<wd-cell title="发票类别" title-width="180rpx" center>
|
||||
<wd-radio-group v-model="formData.invoiceType" shape="button">
|
||||
<wd-radio :value="1">
|
||||
增值税普通发票
|
||||
</wd-radio>
|
||||
<wd-radio :value="2">
|
||||
增值税专用发票
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</wd-cell>
|
||||
<wd-cell title="运费承担方" title-width="180rpx" center>
|
||||
<wd-radio-group v-model="formData.freightPayer" shape="button">
|
||||
<wd-radio :value="1">
|
||||
卖方承担
|
||||
</wd-radio>
|
||||
<wd-radio :value="2">
|
||||
买方承担
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</wd-cell>
|
||||
<wd-cell title="结算方式" title-width="180rpx" center>
|
||||
<wd-radio-group v-model="formData.settlementMethod" shape="button">
|
||||
<wd-radio :value="1">
|
||||
款到发货
|
||||
</wd-radio>
|
||||
<wd-radio :value="2">
|
||||
货到票到付款
|
||||
</wd-radio>
|
||||
<wd-radio :value="3">
|
||||
预付部分货到付清
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="其他信息" border>
|
||||
<wd-input
|
||||
v-model="formData.discountPercent"
|
||||
label="优惠率(%)"
|
||||
label-width="180rpx"
|
||||
type="number"
|
||||
placeholder="请输入优惠率"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.depositPrice"
|
||||
label="定金金额"
|
||||
label-width="180rpx"
|
||||
type="number"
|
||||
placeholder="请输入定金金额"
|
||||
clearable
|
||||
/>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<!-- 订单明细 -->
|
||||
<view class="mx-24rpx mt-24rpx pb-180rpx">
|
||||
<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
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="index"
|
||||
class="mb-16rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
>
|
||||
<view class="flex items-center justify-between bg-[#f8f8f8] px-24rpx py-12rpx">
|
||||
<text class="text-28rpx text-[#333] font-semibold">产品 #{{ index + 1 }} {{ item.productName || '' }}</text>
|
||||
<wd-button size="small" type="error" plain @click="handleRemoveItem(index)">
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
<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 class="flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">供应商</text>
|
||||
<text class="text-[#333]">{{ item.supplierName || '-' }}</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
|
||||
/>
|
||||
</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
|
||||
/>
|
||||
</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
|
||||
/>
|
||||
</view>
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">金额</text>
|
||||
<text class="block pt-16rpx text-28rpx text-[#333]">{{ calcTotalPrice(item) }}</text>
|
||||
</view>
|
||||
</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>
|
||||
</view>
|
||||
|
||||
<!-- 底部保存按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
type="primary"
|
||||
block
|
||||
:loading="formLoading"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
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 { 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 { 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<PurchaseOrder>({
|
||||
id: undefined,
|
||||
supplierId: undefined,
|
||||
orderTime: undefined,
|
||||
discountPercent: undefined,
|
||||
depositPrice: undefined,
|
||||
invoiceType: undefined,
|
||||
freightPayer: undefined,
|
||||
settlementMethod: undefined,
|
||||
remark: '',
|
||||
items: [],
|
||||
})
|
||||
const formRules = {
|
||||
supplierId: [{ required: true, message: '供应商不能为空' }],
|
||||
orderTime: [{ required: true, message: '采购时间不能为空' }],
|
||||
}
|
||||
const formRef = ref<FormInstance>()
|
||||
const supplierList = ref<SupplierSimple[]>([])
|
||||
const productList = ref<ProductSimple[]>([])
|
||||
|
||||
/** 供应商下拉列 */
|
||||
const supplierColumns = computed(() => [
|
||||
supplierList.value.map(s => ({ value: s.id, label: s.name })),
|
||||
])
|
||||
|
||||
/** 产品下拉列 */
|
||||
const productColumns = computed(() => [
|
||||
productList.value.map(p => ({ value: p.id, label: p.name })),
|
||||
])
|
||||
|
||||
/** 供应商选择回调 */
|
||||
function onSupplierConfirm({ value }: any) {
|
||||
formData.value.supplierId = value?.[0]
|
||||
}
|
||||
|
||||
/** 产品选择回调:自动填充规格/单位/条码/单价/供应商 */
|
||||
function onProductConfirm({ value }: any, index: number) {
|
||||
const productId = value?.[0]
|
||||
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)
|
||||
if (product) {
|
||||
item.productName = product.name
|
||||
item.productSpec = product.standard || ''
|
||||
item.productUnitName = product.unitName || ''
|
||||
item.productUnitId = product.unitId as any
|
||||
item.productBarCode = product.barCode || ''
|
||||
item.productPrice = product.purchasePrice
|
||||
item.supplierId = product.supplierId
|
||||
item.supplierName = product.supplierName || ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 计算行项金额 */
|
||||
function calcTotalPrice(item: PurchaseOrderItem) {
|
||||
if (item.productPrice && item.count) {
|
||||
const total = Number(item.productPrice) * Number(item.count)
|
||||
return `¥${total.toFixed(2)}`
|
||||
}
|
||||
return '-'
|
||||
}
|
||||
|
||||
/** 加载下拉列表数据 */
|
||||
async function loadDropdownData() {
|
||||
try {
|
||||
const [suppliers, products] = await Promise.all([
|
||||
getSupplierSimpleList(),
|
||||
getProductSimpleList(),
|
||||
])
|
||||
supplierList.value = suppliers || []
|
||||
productList.value = products || []
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/purchase-order/index')
|
||||
}
|
||||
|
||||
/** 添加订单明细行 */
|
||||
function handleAddItem() {
|
||||
if (!formData.value.items) {
|
||||
formData.value.items = []
|
||||
}
|
||||
formData.value.items.push({
|
||||
productId: undefined as any,
|
||||
productName: undefined as any,
|
||||
productUnitId: undefined as any,
|
||||
productUnitName: undefined as any,
|
||||
productPrice: undefined,
|
||||
productSpec: undefined as any,
|
||||
productBarCode: undefined as any,
|
||||
count: 1 as any,
|
||||
taxPercent: undefined,
|
||||
supplierId: undefined,
|
||||
supplierName: undefined as any,
|
||||
remark: '',
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除订单明细行 */
|
||||
function handleRemoveItem(index: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `确定要删除第 ${index + 1} 项产品吗?`,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
formData.value.items?.splice(index, 1)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
formData.value = await getPurchaseOrder(props.id)
|
||||
}
|
||||
|
||||
/** 提交表单 */
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formRef.value!.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
// 校验订单明细
|
||||
if (!formData.value.items || formData.value.items.length === 0) {
|
||||
toast.warning('请至少添加一项产品明细')
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < formData.value.items.length; i++) {
|
||||
const item = formData.value.items[i]
|
||||
if (!item.productId) {
|
||||
toast.warning(`第 ${i + 1} 项产品ID不能为空`)
|
||||
return
|
||||
}
|
||||
if (!item.count) {
|
||||
toast.warning(`第 ${i + 1} 项产品数量不能为空`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
formLoading.value = true
|
||||
try {
|
||||
if (props.id) {
|
||||
await updatePurchaseOrder(formData.value)
|
||||
toast.success('修改成功')
|
||||
} else {
|
||||
await createPurchaseOrder(formData.value)
|
||||
toast.success('新增成功')
|
||||
}
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
await loadDropdownData()
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
344
src/pages-erp/purchase-order/index.vue
Normal file
344
src/pages-erp/purchase-order/index.vue
Normal file
@@ -0,0 +1,344 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="采购订单"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 搜索组件 -->
|
||||
<SearchForm @search="handleQuery" @reset="handleReset" />
|
||||
|
||||
<!-- 状态快速筛选 -->
|
||||
<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="activeStatus === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
|
||||
@click="handleQuickFilter(tab.value)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
<view
|
||||
v-if="activeStatus === 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="handleCardClick(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<!-- 头部:单号 + 状态 -->
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">
|
||||
{{ item.no }}
|
||||
</view>
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(item.status)"
|
||||
>
|
||||
{{ getStatusText(item.status) }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 供应商 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">供应商</text>
|
||||
<text>{{ item.supplierName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 产品 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text class="ml-16rpx line-clamp-1 text-right" style="max-width: 400rpx;">{{ item.productNames || '-' }}</text>
|
||||
</view>
|
||||
<!-- 订单时间 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">订单时间</text>
|
||||
<text>{{ formatDate(item.orderTime) }}</text>
|
||||
</view>
|
||||
<!-- 创建人 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">创建人</text>
|
||||
<text>{{ item.creatorName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 数量金额区域 -->
|
||||
<view class="flex items-center justify-around mt-12rpx pt-16rpx border-t border-[#f0f0f0]">
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">总数量</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#52c41a] font-semibold">{{ item.inCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">已入库</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#e6a23c] font-semibold">¥{{ item.totalPrice || 0 }}</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-order:query'])"
|
||||
size="small" plain @click="handleDetail(item)"
|
||||
>
|
||||
详情
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-order:update']) && item.status !== 20"
|
||||
size="small" type="primary" plain @click="handleEdit(item)"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-order:update-status']) && item.status === 10"
|
||||
size="small" type="success" plain @click="handleUpdateStatus(item.id!, 20)"
|
||||
>
|
||||
审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-order:update-status']) && item.status === 20"
|
||||
size="small" type="error" plain @click="handleUpdateStatus(item.id!, 10)"
|
||||
>
|
||||
反审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-order:delete']) && item.status !== 20"
|
||||
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-order:create'])"
|
||||
position="right-bottom"
|
||||
type="primary"
|
||||
:expandable="false"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PurchaseOrder } from '@/api/erp/purchase-order'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deletePurchaseOrder, getPurchaseOrderPage, updatePurchaseOrderStatus } from '@/api/erp/purchase-order'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import SearchForm from './components/search-form.vue'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const total = ref(0)
|
||||
const list = ref<PurchaseOrder[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const activeStatus = ref<number | undefined>(undefined)
|
||||
const queryParams = ref<Record<string, any>>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
|
||||
const statusTabs = [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '待审核', value: 10 },
|
||||
{ label: '已审核', value: 20 },
|
||||
]
|
||||
|
||||
/** 格式化日期 */
|
||||
function formatDate(date?: string) {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
/** 获取状态文本 */
|
||||
function getStatusText(status?: number) {
|
||||
switch (status) {
|
||||
case 10: return '未审批'
|
||||
case 20: return '已审批'
|
||||
case 30: return '已驳回'
|
||||
default: return '未知'
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number) {
|
||||
switch (status) {
|
||||
case 10: return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
case 20: return 'bg-[#f6ffed] text-[#52c41a]'
|
||||
case 30: return 'bg-[#fff1f0] text-[#f5222d]'
|
||||
default: return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
/** 查询采购订单列表 */
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const params = { ...queryParams.value }
|
||||
const data = await getPurchaseOrderPage(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 handleQuickFilter(status?: number) {
|
||||
activeStatus.value = status
|
||||
queryParams.value.status = status
|
||||
queryParams.value.pageNo = 1
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
function handleQuery(data?: Record<string, any>) {
|
||||
queryParams.value = {
|
||||
...data,
|
||||
status: activeStatus.value,
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
function handleReset() {
|
||||
activeStatus.value = undefined
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
/** 加载更多 */
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished') {
|
||||
return
|
||||
}
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 卡片点击 — 已审核打开详情,未审核打开编辑 */
|
||||
function handleCardClick(item: PurchaseOrder) {
|
||||
if (item.status === 20) {
|
||||
handleDetail(item)
|
||||
} else if (item.status === 10) {
|
||||
handleEdit(item)
|
||||
}
|
||||
}
|
||||
|
||||
/** 新增采购订单 */
|
||||
function handleAdd() {
|
||||
uni.navigateTo({
|
||||
url: '/pages-erp/purchase-order/form/index',
|
||||
})
|
||||
}
|
||||
|
||||
/** 查看详情 */
|
||||
function handleDetail(item: PurchaseOrder) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/purchase-order/detail/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(item: PurchaseOrder) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/purchase-order/form/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 审批/反审批 */
|
||||
function handleUpdateStatus(id: number, status: number) {
|
||||
const text = status === 20 ? '审批' : '反审批'
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `确定${text}该订单吗?`,
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePurchaseOrderStatus(id, status)
|
||||
toast.success(`${text}成功`)
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
function handleDelete(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该采购订单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deletePurchaseOrder([id])
|
||||
toast.success('删除成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 触底加载更多 */
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
Reference in New Issue
Block a user