李红攀:V2.6.969,销售出库管理
This commit is contained in:
21
src/api/erp/approval-record/index.ts
Normal file
21
src/api/erp/approval-record/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { http } from '@/http/http'
|
||||
|
||||
/** 审批记录 */
|
||||
export interface ApprovalRecord {
|
||||
id?: number
|
||||
bizId?: string
|
||||
bizTableName?: string
|
||||
applicant?: string
|
||||
applicantName?: string
|
||||
approver?: string
|
||||
approverName?: string
|
||||
approvalStatus?: number
|
||||
approvalLevel?: number
|
||||
reason?: string
|
||||
createTime?: string | number
|
||||
}
|
||||
|
||||
/** 根据业务单据获取审批记录列表 */
|
||||
export function getApprovalRecordListByBiz(bizId: string | number, bizTableName: string) {
|
||||
return http.get<ApprovalRecord[]>('/erp/approval-record/list-by-biz', { bizId, bizTableName })
|
||||
}
|
||||
@@ -11,11 +11,18 @@ export interface SaleOrderItem {
|
||||
totalCount?: number
|
||||
unitPrice?: number
|
||||
productPrice?: number
|
||||
productUnitId?: number
|
||||
productUnitName?: string
|
||||
productBarCode?: string
|
||||
productSpec?: string
|
||||
taxPrice?: number
|
||||
totalPrice?: number
|
||||
totalProductPrice?: number
|
||||
taxPercent?: number
|
||||
taxAmount?: number
|
||||
remark?: string
|
||||
outCount?: number
|
||||
stockCount?: number
|
||||
}
|
||||
|
||||
/** 销售订单信息 */
|
||||
@@ -55,8 +62,9 @@ export function getSaleOrderPage(params: PageParam & {
|
||||
orderTime?: string[]
|
||||
status?: number
|
||||
creator?: number
|
||||
outStatus?: string
|
||||
returnStatus?: string
|
||||
outStatus?: string | number
|
||||
returnStatus?: string | number
|
||||
outEnable?: boolean
|
||||
}) {
|
||||
return http.get<PageResult<SaleOrder>>('/erp/sale-order/page', params)
|
||||
}
|
||||
|
||||
94
src/api/erp/sale-out/index.ts
Normal file
94
src/api/erp/sale-out/index.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import type { PageParam, PageResult } from '@/http/types'
|
||||
import { http } from '@/http/http'
|
||||
|
||||
/** 销售出库明细 */
|
||||
export interface SaleOutItem {
|
||||
id?: number
|
||||
orderItemId?: number
|
||||
warehouseId?: number
|
||||
warehouseName?: string
|
||||
productId?: number
|
||||
productName?: string
|
||||
productBarCode?: string
|
||||
productUnitId?: number
|
||||
productUnitName?: string
|
||||
productPrice?: number
|
||||
count?: number
|
||||
totalCount?: number
|
||||
totalPrice?: number
|
||||
taxPercent?: number
|
||||
taxPrice?: number
|
||||
batchNo?: string
|
||||
remark?: string
|
||||
stockCount?: number
|
||||
stockUnitPrice?: number
|
||||
stockValue?: number
|
||||
grossProfit?: number
|
||||
totalProductPrice?: number
|
||||
outCount?: number
|
||||
}
|
||||
|
||||
/** 销售出库 */
|
||||
export interface SaleOut {
|
||||
id?: number
|
||||
no?: string
|
||||
customerId?: number
|
||||
customerName?: string
|
||||
accountId?: number
|
||||
saleUserId?: number
|
||||
saleUserName?: string
|
||||
outTime?: string | number
|
||||
orderId?: number
|
||||
orderNo?: string
|
||||
totalCount?: number
|
||||
totalPrice?: number
|
||||
receiptPrice?: number
|
||||
totalProductPrice?: number
|
||||
totalTaxPrice?: number
|
||||
discountPercent?: number
|
||||
discountPrice?: number
|
||||
otherPrice?: number
|
||||
fileUrl?: string
|
||||
status?: number
|
||||
remark?: string
|
||||
creator?: string
|
||||
creatorName?: string
|
||||
createTime?: string | number
|
||||
productNames?: string
|
||||
hasApprovalRecords?: boolean
|
||||
items?: SaleOutItem[]
|
||||
}
|
||||
|
||||
/** 获取销售出库分页列表 */
|
||||
export function getSaleOutPage(params: PageParam & {
|
||||
no?: string
|
||||
customerId?: number
|
||||
status?: number
|
||||
}) {
|
||||
return http.get<PageResult<SaleOut>>('/erp/sale-out/page', params)
|
||||
}
|
||||
|
||||
/** 获取销售出库详情 */
|
||||
export function getSaleOut(id: number) {
|
||||
return http.get<SaleOut>(`/erp/sale-out/get?id=${id}`)
|
||||
}
|
||||
|
||||
/** 创建销售出库 */
|
||||
export function createSaleOut(data: SaleOut) {
|
||||
return http.post<number>('/erp/sale-out/create', data)
|
||||
}
|
||||
|
||||
/** 更新销售出库 */
|
||||
export function updateSaleOut(data: SaleOut) {
|
||||
return http.put<boolean>('/erp/sale-out/update', data)
|
||||
}
|
||||
|
||||
/** 更新销售出库状态 */
|
||||
export function updateSaleOutStatus(id: number, status: number) {
|
||||
return http.put<boolean>('/erp/sale-out/update-status', undefined, { id, status })
|
||||
}
|
||||
|
||||
/** 删除销售出库 */
|
||||
export function deleteSaleOut(ids: number[]) {
|
||||
return http.delete<boolean>('/erp/sale-out/delete', undefined, { ids: ids.join(',') })
|
||||
}
|
||||
382
src/pages-erp/sale-out/detail/index.vue
Normal file
382
src/pages-erp/sale-out/detail/index.vue
Normal file
@@ -0,0 +1,382 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
title="销售出库详情"
|
||||
left-arrow
|
||||
placeholder
|
||||
safe-area-inset-top
|
||||
fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<view class="p-24rpx pb-180rpx" :class="{ 'opacity-60': loading }">
|
||||
<view class="section-card">
|
||||
<view class="section-title">
|
||||
基本信息
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">出库单号</text>
|
||||
<text class="info-value">{{ detail.no || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">客户</text>
|
||||
<text class="info-value">{{ detail.customerName || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">出库时间</text>
|
||||
<text class="info-value">{{ formatDate(detail.outTime) }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">关联订单</text>
|
||||
<text class="info-value">{{ detail.orderNo || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">销售人员</text>
|
||||
<text class="info-value">{{ getSaleUserName() }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">状态</text>
|
||||
<view :class="getStatusClass(detail.status)">
|
||||
{{ getStatusText(detail.status) }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">备注</text>
|
||||
<text class="info-value max-w-[420rpx] text-right">{{ detail.remark || '-' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section-card">
|
||||
<view class="section-title">
|
||||
金额信息
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">总数量</text>
|
||||
<text class="info-value">{{ formatCount(detail.totalCount) }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">应收金额</text>
|
||||
<text class="info-value text-[#409eff]">¥{{ formatPrice(detail.totalPrice) }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">已收金额</text>
|
||||
<text class="info-value text-[#52c41a]">¥{{ formatPrice(detail.receiptPrice) }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">未收金额</text>
|
||||
<text class="info-value text-[#f5222d]">¥{{ formatPrice(unreceivedPrice) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section-card">
|
||||
<view class="section-title">
|
||||
出库明细
|
||||
</view>
|
||||
<view v-if="!detail.items || detail.items.length === 0" class="py-40rpx text-center text-[#999]">
|
||||
暂无产品数据
|
||||
</view>
|
||||
<view
|
||||
v-for="(item, index) in detail.items"
|
||||
:key="item.id || index"
|
||||
class="item-card"
|
||||
>
|
||||
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
|
||||
{{ item.productName || '-' }}
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">仓库</text>
|
||||
<text class="info-value">{{ item.warehouseName || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">单位</text>
|
||||
<text class="info-value">{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">数量</text>
|
||||
<text class="info-value">{{ formatCount(item.count) }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">单价</text>
|
||||
<text class="info-value">¥{{ formatPrice(item.productPrice) }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">金额</text>
|
||||
<text class="info-value text-[#409eff]">¥{{ formatPrice(item.totalPrice) }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">批次</text>
|
||||
<text class="info-value">{{ item.batchNo || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">备注</text>
|
||||
<text class="info-value max-w-[420rpx] text-right">{{ item.remark || '-' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
v-if="canEdit"
|
||||
type="primary"
|
||||
plain
|
||||
@click="handleEdit"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="canApprove"
|
||||
type="success"
|
||||
@click="handleApprove"
|
||||
>
|
||||
审核
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="canDelete"
|
||||
type="error"
|
||||
@click="handleDelete"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { SaleOut } from '@/api/erp/sale-out'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { getApprovalRecordListByBiz } from '@/api/erp/approval-record'
|
||||
import { deleteSaleOut, getSaleOut, updateSaleOutStatus } from '@/api/erp/sale-out'
|
||||
import { getSimpleUserList } from '@/api/system/user'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | string
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const loading = ref(false)
|
||||
const detail = ref<SaleOut>({})
|
||||
const userList = ref<{ id?: number, nickname?: string }[]>([])
|
||||
|
||||
const unreceivedPrice = computed(() => {
|
||||
const totalPrice = Number(detail.value.totalPrice || 0)
|
||||
const receiptPrice = Number(detail.value.receiptPrice || 0)
|
||||
return Math.max(totalPrice - receiptPrice, 0)
|
||||
})
|
||||
|
||||
const canEdit = computed(() => {
|
||||
return hasAccessByCodes(['erp:sale-out:update']) && detail.value.status === 10 && !detail.value.hasApprovalRecords
|
||||
})
|
||||
|
||||
const canApprove = computed(() => {
|
||||
return hasAccessByCodes(['erp:sale-out:update-status']) && detail.value.status === 10
|
||||
})
|
||||
|
||||
const canDelete = computed(() => {
|
||||
return hasAccessByCodes(['erp:sale-out:delete']) && !detail.value.hasApprovalRecords
|
||||
})
|
||||
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/sale-out/index')
|
||||
}
|
||||
|
||||
function getStatusClass(status?: number) {
|
||||
switch (status) {
|
||||
case 10:
|
||||
return 'status-tag bg-[#fffbe6] text-[#faad14]'
|
||||
case 20:
|
||||
return 'status-tag bg-[#f6ffed] text-[#52c41a]'
|
||||
default:
|
||||
return 'status-tag bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusText(status?: number) {
|
||||
switch (status) {
|
||||
case 10:
|
||||
return '未审核'
|
||||
case 20:
|
||||
return '已审核'
|
||||
default:
|
||||
return '-'
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(value?: string | number) {
|
||||
if (!value)
|
||||
return '-'
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime()))
|
||||
return String(value).slice(0, 10)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
function formatCount(value?: number) {
|
||||
if (value === undefined || value === null)
|
||||
return '0.00'
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
|
||||
function formatPrice(value?: number) {
|
||||
if (value === undefined || value === null)
|
||||
return '0.00'
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
|
||||
function getSaleUserName() {
|
||||
if (detail.value.saleUserName)
|
||||
return detail.value.saleUserName
|
||||
const matched = userList.value.find(item => item.id === detail.value.saleUserId)
|
||||
return matched?.nickname || '-'
|
||||
}
|
||||
|
||||
async function loadUserList() {
|
||||
try {
|
||||
userList.value = await getSimpleUserList()
|
||||
} catch {
|
||||
userList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
async function appendApprovalFlag() {
|
||||
if (!detail.value.id)
|
||||
return
|
||||
try {
|
||||
const approvalList = await getApprovalRecordListByBiz(detail.value.id, 'erp_sale_out')
|
||||
detail.value.hasApprovalRecords = approvalList.length > 0
|
||||
} catch {
|
||||
detail.value.hasApprovalRecords = false
|
||||
}
|
||||
}
|
||||
|
||||
async function getDetail() {
|
||||
if (!props.id)
|
||||
return
|
||||
loading.value = true
|
||||
try {
|
||||
detail.value = await getSaleOut(Number(props.id))
|
||||
await appendApprovalFlag()
|
||||
} catch {
|
||||
toast.error('加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleEdit() {
|
||||
uni.navigateTo({ url: `/pages-erp/sale-out/form/index?id=${props.id}` })
|
||||
}
|
||||
|
||||
function handleApprove() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定审核该销售出库单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm || !props.id)
|
||||
return
|
||||
try {
|
||||
await updateSaleOutStatus(Number(props.id), 20)
|
||||
toast.success('审核成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function handleDelete() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定删除该销售出库单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm || !props.id)
|
||||
return
|
||||
try {
|
||||
await deleteSaleOut([Number(props.id)])
|
||||
toast.success('删除成功')
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} catch {
|
||||
// handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserList()
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.section-card {
|
||||
margin-bottom: 24rpx;
|
||||
border-radius: 12rpx;
|
||||
background: #fff;
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin-bottom: 24rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16rpx 0;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.info-label {
|
||||
flex-shrink: 0;
|
||||
color: #999;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #333;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.status-tag {
|
||||
padding: 4rpx 16rpx;
|
||||
border-radius: 8rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.item-card {
|
||||
margin-bottom: 16rpx;
|
||||
border-radius: 8rpx;
|
||||
background: #fafafa;
|
||||
padding: 16rpx;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
643
src/pages-erp/sale-out/form/index.vue
Normal file
643
src/pages-erp/sale-out/form/index.vue
Normal file
@@ -0,0 +1,643 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
:title="pageTitle"
|
||||
left-arrow
|
||||
placeholder
|
||||
safe-area-inset-top
|
||||
fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<view class="pb-180rpx">
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="出库单号" :value="formData.no || '保存后自动生成'" />
|
||||
<wd-cell title="客户" :value="formData.customerName || '-'" />
|
||||
<wd-cell
|
||||
title="关联订单"
|
||||
:value="formData.orderNo || '点击选择'"
|
||||
is-link
|
||||
@click="handlePickOrder"
|
||||
/>
|
||||
<wd-cell title="出库时间" title-width="180rpx" prop="outTime" center>
|
||||
<wd-datetime-picker
|
||||
v-model="formData.outTime"
|
||||
type="date"
|
||||
label=""
|
||||
placeholder="请选择出库时间"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-picker
|
||||
v-model="formData.saleUserId"
|
||||
label="销售人员"
|
||||
label-width="180rpx"
|
||||
:columns="userColumns"
|
||||
placeholder="请选择销售人员"
|
||||
clearable
|
||||
/>
|
||||
<wd-picker
|
||||
v-model="formData.accountId"
|
||||
label="结算账户"
|
||||
label-width="180rpx"
|
||||
:columns="accountColumns"
|
||||
placeholder="请选择结算账户"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.discountPercent"
|
||||
label="优惠率(%)"
|
||||
label-width="180rpx"
|
||||
type="digit"
|
||||
placeholder="请输入优惠率"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.otherPrice"
|
||||
label="其他费用"
|
||||
label-width="180rpx"
|
||||
type="digit"
|
||||
placeholder="请输入其他费用"
|
||||
clearable
|
||||
/>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="出库明细" border>
|
||||
<view
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="item.id || `${item.productId}-${index}`"
|
||||
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
|
||||
>
|
||||
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
|
||||
{{ item.productName || `产品${index + 1}` }}
|
||||
</view>
|
||||
<view class="mb-12rpx flex justify-between text-24rpx text-[#999]">
|
||||
<text>产品编码</text>
|
||||
<text class="text-[#333]">{{ item.productBarCode || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-12rpx flex justify-between text-24rpx text-[#999]">
|
||||
<text>单位</text>
|
||||
<text class="text-[#333]">{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-12rpx flex justify-between text-24rpx text-[#999]">
|
||||
<text>订单可出</text>
|
||||
<text class="text-[#333]">{{ formatCount(getOrderAvailableCount(item)) }}</text>
|
||||
</view>
|
||||
<view class="mb-12rpx flex justify-between text-24rpx text-[#999]">
|
||||
<text>可用库存</text>
|
||||
<text class="text-[#333]">{{ formatCount(item.stockCount) }}</text>
|
||||
</view>
|
||||
|
||||
<wd-picker
|
||||
v-model="item.warehouseId"
|
||||
class="mb-12rpx"
|
||||
label="仓库"
|
||||
label-width="120rpx"
|
||||
:columns="warehouseColumns"
|
||||
placeholder="请选择仓库"
|
||||
clearable
|
||||
@confirm="(e: any) => onWarehouseConfirm(e, index)"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="item.count"
|
||||
class="mb-12rpx"
|
||||
label="数量"
|
||||
label-width="120rpx"
|
||||
type="digit"
|
||||
placeholder="请输入数量"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="item.productPrice"
|
||||
class="mb-12rpx"
|
||||
label="单价"
|
||||
label-width="120rpx"
|
||||
type="digit"
|
||||
placeholder="请输入单价"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="item.taxPercent"
|
||||
class="mb-12rpx"
|
||||
label="税率(%)"
|
||||
label-width="120rpx"
|
||||
type="digit"
|
||||
placeholder="请输入税率"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="item.batchNo"
|
||||
class="mb-12rpx"
|
||||
label="批次号"
|
||||
label-width="120rpx"
|
||||
placeholder="请输入批次号"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="item.remark"
|
||||
label="备注"
|
||||
label-width="120rpx"
|
||||
placeholder="请输入备注"
|
||||
clearable
|
||||
/>
|
||||
|
||||
<view class="mt-12rpx flex justify-between text-26rpx">
|
||||
<text class="text-[#999]">金额</text>
|
||||
<text class="text-[#409eff] font-semibold">¥{{ formatPrice(calculateItemTotal(item)) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="!formData.items?.length" class="py-40rpx text-center text-[#999]">
|
||||
请先选择可出库销售订单
|
||||
</view>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="汇总信息" border>
|
||||
<wd-cell title="总数量" :value="formatCount(totalCount)" />
|
||||
<wd-cell title="商品金额" :value="`¥${formatPrice(totalProductPrice)}`" />
|
||||
<wd-cell title="税额合计" :value="`¥${formatPrice(totalTaxPrice)}`" />
|
||||
<wd-cell title="应收金额" :value="`¥${formatPrice(totalPrice)}`" />
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button type="primary" block :loading="formLoading" @click="handleSubmit">
|
||||
保存
|
||||
</wd-button>
|
||||
</view>
|
||||
|
||||
<wd-popup v-model="orderPickerVisible" position="right" custom-style="width: 100%; height: 100%;">
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
title="选择销售订单"
|
||||
left-arrow
|
||||
placeholder
|
||||
safe-area-inset-top
|
||||
fixed
|
||||
@click-left="orderPickerVisible = false"
|
||||
/>
|
||||
|
||||
<wd-search
|
||||
v-model="orderQueryParams.no"
|
||||
placeholder="搜索订单单号"
|
||||
@search="getOrderList"
|
||||
@clear="getOrderList"
|
||||
/>
|
||||
|
||||
<view class="px-24rpx pb-180rpx">
|
||||
<view
|
||||
v-for="item in orderList"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
:class="{ 'border-2 border-[#1890ff]': selectedOrderId === item.id }"
|
||||
@click="handleSelectOrder(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<view class="mb-12rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">
|
||||
{{ item.no }}
|
||||
</view>
|
||||
<wd-icon
|
||||
v-if="selectedOrderId === item.id"
|
||||
name="check"
|
||||
color="#1890ff"
|
||||
size="40rpx"
|
||||
/>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">客户</text>
|
||||
<text>{{ item.customerName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text class="line-clamp-1 ml-16rpx max-w-[420rpx] text-right">{{ item.productNames || '-' }}</text>
|
||||
</view>
|
||||
<view class="mt-12rpx flex justify-around border-t border-[#f0f0f0] pt-12rpx">
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#333] font-semibold">
|
||||
{{ formatCount(item.totalCount) }}
|
||||
</view>
|
||||
<view class="text-22rpx text-[#999]">
|
||||
总数量
|
||||
</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#52c41a] font-semibold">
|
||||
{{ formatCount(item.outCount) }}
|
||||
</view>
|
||||
<view class="text-22rpx text-[#999]">
|
||||
已出库
|
||||
</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#409eff] font-semibold">
|
||||
¥{{ formatPrice(item.totalPrice) }}
|
||||
</view>
|
||||
<view class="text-22rpx text-[#999]">
|
||||
金额
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="orderList.length === 0 && orderLoadMoreState !== 'loading'" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无可出库订单" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="orderList.length > 0"
|
||||
:state="orderLoadMoreState"
|
||||
@reload="loadMoreOrders"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button type="primary" block :disabled="!selectedOrderId" @click="confirmSelectOrder">
|
||||
确认选择
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
|
||||
import type { SaleOrder, SaleOrderItem } from '@/api/erp/sale-order'
|
||||
import type { SaleOut, SaleOutItem } from '@/api/erp/sale-out'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { getAccountSimpleList } from '@/api/erp/account'
|
||||
import { getApprovalRecordListByBiz } from '@/api/erp/approval-record'
|
||||
import { getSaleOrder, getSaleOrderPage } from '@/api/erp/sale-order'
|
||||
import { createSaleOut, getSaleOut, updateSaleOut } from '@/api/erp/sale-out'
|
||||
import { getWarehouseSimpleList } from '@/api/erp/warehouse'
|
||||
import { getSimpleUserList } from '@/api/system/user'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | string
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
const formLoading = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const warehouseList = ref<{ id?: number, name?: string }[]>([])
|
||||
const userList = ref<{ id?: number, nickname?: string }[]>([])
|
||||
const accountList = ref<{ id?: number, name?: string }[]>([])
|
||||
const orderPickerVisible = ref(false)
|
||||
const orderList = ref<SaleOrder[]>([])
|
||||
const selectedOrderId = ref<number>()
|
||||
const orderLoadMoreState = ref<LoadMoreState>('loading')
|
||||
const orderTotal = ref(0)
|
||||
const formData = ref<SaleOut>({
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
customerId: undefined,
|
||||
customerName: undefined,
|
||||
accountId: undefined,
|
||||
saleUserId: undefined,
|
||||
outTime: Date.now(),
|
||||
orderId: undefined,
|
||||
orderNo: undefined,
|
||||
discountPercent: 0,
|
||||
otherPrice: 0,
|
||||
remark: undefined,
|
||||
items: [],
|
||||
})
|
||||
|
||||
const orderQueryParams = ref({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
no: undefined as string | undefined,
|
||||
outEnable: true,
|
||||
})
|
||||
|
||||
const isEdit = computed(() => !!props.id)
|
||||
const pageTitle = computed(() => (isEdit.value ? '编辑销售出库' : '新增销售出库'))
|
||||
|
||||
const formRules = {
|
||||
outTime: [{ required: true, message: '请选择出库时间' }],
|
||||
}
|
||||
|
||||
const warehouseColumns = computed(() => warehouseList.value.map(item => ({ label: item.name, value: item.id })))
|
||||
const userColumns = computed(() => userList.value.map(item => ({ label: item.nickname, value: item.id })))
|
||||
const accountColumns = computed(() => accountList.value.map(item => ({ label: item.name, value: item.id })))
|
||||
|
||||
const totalCount = computed(() => {
|
||||
return (formData.value.items || []).reduce((sum, item) => sum + Number(item.count || 0), 0)
|
||||
})
|
||||
|
||||
const totalProductPrice = computed(() => {
|
||||
return (formData.value.items || []).reduce((sum, item) => {
|
||||
const count = Number(item.count || 0)
|
||||
const price = Number(item.productPrice || 0)
|
||||
return sum + count * price
|
||||
}, 0)
|
||||
})
|
||||
|
||||
const totalTaxPrice = computed(() => {
|
||||
return (formData.value.items || []).reduce((sum, item) => {
|
||||
const subtotal = Number(item.count || 0) * Number(item.productPrice || 0)
|
||||
const taxPercent = Number(item.taxPercent || 0)
|
||||
return sum + subtotal * taxPercent / 100
|
||||
}, 0)
|
||||
})
|
||||
|
||||
const totalPrice = computed(() => {
|
||||
const discountPercent = Number(formData.value.discountPercent || 0)
|
||||
const discountPrice = totalProductPrice.value * discountPercent / 100
|
||||
return totalProductPrice.value + totalTaxPrice.value - discountPrice + Number(formData.value.otherPrice || 0)
|
||||
})
|
||||
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/sale-out/index')
|
||||
}
|
||||
|
||||
function formatCount(value?: number) {
|
||||
if (value === undefined || value === null)
|
||||
return '0.00'
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
|
||||
function formatPrice(value?: number) {
|
||||
if (value === undefined || value === null)
|
||||
return '0.00'
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
|
||||
function calculateItemTotal(item: SaleOutItem) {
|
||||
const count = Number(item.count || 0)
|
||||
const price = Number(item.productPrice || 0)
|
||||
const taxPercent = Number(item.taxPercent || 0)
|
||||
const subtotal = count * price
|
||||
return subtotal + subtotal * taxPercent / 100
|
||||
}
|
||||
|
||||
function getOrderAvailableCount(item: SaleOutItem) {
|
||||
const totalCount = Number(item.totalCount || 0)
|
||||
const outCount = Number(item.outCount || 0)
|
||||
return Math.max(totalCount - outCount, 0)
|
||||
}
|
||||
|
||||
function onWarehouseConfirm({ value }: any, index: number) {
|
||||
const current = formData.value.items?.[index]
|
||||
if (!current)
|
||||
return
|
||||
current.warehouseId = value?.[0]
|
||||
const warehouse = warehouseList.value.find(item => item.id === current.warehouseId)
|
||||
current.warehouseName = warehouse?.name
|
||||
}
|
||||
|
||||
async function loadOptions() {
|
||||
const [warehouses, users, accounts] = await Promise.allSettled([
|
||||
getWarehouseSimpleList(),
|
||||
getSimpleUserList(),
|
||||
getAccountSimpleList(),
|
||||
])
|
||||
warehouseList.value = warehouses.status === 'fulfilled' ? (warehouses.value || []) : []
|
||||
userList.value = users.status === 'fulfilled' ? (users.value || []) : []
|
||||
accountList.value = accounts.status === 'fulfilled' ? (accounts.value || []) : []
|
||||
}
|
||||
|
||||
async function ensureEditable() {
|
||||
if (!formData.value.id)
|
||||
return true
|
||||
if (formData.value.status === 20) {
|
||||
toast.warning('已审核单据不可编辑')
|
||||
setTimeout(() => handleBack(), 300)
|
||||
return false
|
||||
}
|
||||
try {
|
||||
const approvalList = await getApprovalRecordListByBiz(formData.value.id, 'erp_sale_out')
|
||||
if (approvalList.length > 0) {
|
||||
toast.warning('已有审批记录的单据不可编辑')
|
||||
setTimeout(() => handleBack(), 300)
|
||||
return false
|
||||
}
|
||||
} catch {
|
||||
// ignore approval query failure here
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function getDetail() {
|
||||
if (!props.id)
|
||||
return
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getSaleOut(Number(props.id))
|
||||
const editable = await ensureEditable()
|
||||
if (!editable)
|
||||
return
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
function handlePickOrder() {
|
||||
if (isEdit.value && formData.value.orderId) {
|
||||
toast.warning('编辑模式不支持更换关联订单')
|
||||
return
|
||||
}
|
||||
orderPickerVisible.value = true
|
||||
orderQueryParams.value.pageNo = 1
|
||||
orderList.value = []
|
||||
selectedOrderId.value = formData.value.orderId
|
||||
getOrderList()
|
||||
}
|
||||
|
||||
async function getOrderList() {
|
||||
orderLoadMoreState.value = 'loading'
|
||||
try {
|
||||
const data = await getSaleOrderPage({ ...orderQueryParams.value })
|
||||
orderList.value = orderQueryParams.value.pageNo === 1 ? data.list : [...orderList.value, ...data.list]
|
||||
orderTotal.value = data.total
|
||||
orderLoadMoreState.value = orderList.value.length >= orderTotal.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
orderQueryParams.value.pageNo = orderQueryParams.value.pageNo > 1 ? orderQueryParams.value.pageNo - 1 : 1
|
||||
orderLoadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
function loadMoreOrders() {
|
||||
if (orderLoadMoreState.value === 'finished')
|
||||
return
|
||||
orderQueryParams.value.pageNo++
|
||||
getOrderList()
|
||||
}
|
||||
|
||||
function handleSelectOrder(item: SaleOrder) {
|
||||
selectedOrderId.value = item.id
|
||||
}
|
||||
|
||||
function mapSaleOrderItemToSaleOutItem(item: SaleOrderItem, defaultWarehouseId?: number, defaultWarehouseName?: string): SaleOutItem {
|
||||
const totalCount = Number(item.totalCount ?? item.count ?? 0)
|
||||
const outCount = Number(item.outCount || 0)
|
||||
const availableCount = Math.max(totalCount - outCount, 0)
|
||||
|
||||
return {
|
||||
id: undefined,
|
||||
orderItemId: item.id,
|
||||
warehouseId: defaultWarehouseId,
|
||||
warehouseName: defaultWarehouseName,
|
||||
productId: item.productId,
|
||||
productName: item.productName,
|
||||
productBarCode: item.productBarCode,
|
||||
productUnitId: item.productUnitId,
|
||||
productUnitName: item.productUnitName,
|
||||
productPrice: item.productPrice ?? item.unitPrice,
|
||||
count: availableCount,
|
||||
totalCount,
|
||||
totalPrice: item.totalPrice,
|
||||
taxPercent: item.taxPercent,
|
||||
taxPrice: item.taxPrice,
|
||||
batchNo: undefined,
|
||||
remark: item.remark,
|
||||
stockCount: item.stockCount,
|
||||
totalProductPrice: item.totalProductPrice,
|
||||
outCount,
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmSelectOrder() {
|
||||
if (!selectedOrderId.value)
|
||||
return
|
||||
try {
|
||||
toast.loading('加载订单详情...')
|
||||
const orderDetail = await getSaleOrder(selectedOrderId.value)
|
||||
const defaultWarehouse = warehouseList.value[0]
|
||||
const items = (orderDetail.items || [])
|
||||
.map(item => mapSaleOrderItemToSaleOutItem(item, defaultWarehouse?.id, defaultWarehouse?.name))
|
||||
.filter(item => Number(item.count || 0) > 0)
|
||||
|
||||
if (items.length === 0) {
|
||||
toast.warning('该订单没有可出库明细')
|
||||
return
|
||||
}
|
||||
|
||||
formData.value = {
|
||||
...formData.value,
|
||||
customerId: orderDetail.customerId,
|
||||
customerName: orderDetail.customerName,
|
||||
accountId: orderDetail.accountId,
|
||||
saleUserId: orderDetail.saleUserId,
|
||||
orderId: orderDetail.id,
|
||||
orderNo: orderDetail.no,
|
||||
discountPercent: orderDetail.discountPercent || 0,
|
||||
remark: formData.value.remark || orderDetail.remark,
|
||||
items,
|
||||
}
|
||||
orderPickerVisible.value = false
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
function buildSubmitData() {
|
||||
return {
|
||||
id: formData.value.id,
|
||||
accountId: formData.value.accountId,
|
||||
saleUserId: formData.value.saleUserId,
|
||||
outTime: formData.value.outTime,
|
||||
orderId: formData.value.orderId,
|
||||
deliveryNoticeId: (formData.value as any).deliveryNoticeId,
|
||||
discountPercent: Number(formData.value.discountPercent || 0),
|
||||
otherPrice: Number(formData.value.otherPrice || 0),
|
||||
fileUrl: formData.value.fileUrl,
|
||||
remark: formData.value.remark,
|
||||
items: (formData.value.items || []).map(item => ({
|
||||
id: item.id,
|
||||
orderItemId: item.orderItemId,
|
||||
warehouseId: item.warehouseId,
|
||||
productId: item.productId,
|
||||
productUnitId: item.productUnitId,
|
||||
productPrice: Number(item.productPrice || 0),
|
||||
count: Number(item.count || 0),
|
||||
taxPercent: Number(item.taxPercent || 0),
|
||||
batchNo: item.batchNo,
|
||||
remark: item.remark,
|
||||
stockUnitPrice: item.stockUnitPrice,
|
||||
stockValue: item.stockValue,
|
||||
grossProfit: item.grossProfit,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formRef.value!.validate()
|
||||
if (!valid)
|
||||
return
|
||||
if (!formData.value.orderId) {
|
||||
toast.warning('请先选择关联订单')
|
||||
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.orderItemId || !item.productId || !item.productUnitId) {
|
||||
toast.warning(`第 ${i + 1} 项明细缺少关联字段`)
|
||||
return
|
||||
}
|
||||
if (!item.warehouseId) {
|
||||
toast.warning(`第 ${i + 1} 项请选择仓库`)
|
||||
return
|
||||
}
|
||||
if (!item.count || Number(item.count) <= 0) {
|
||||
toast.warning(`第 ${i + 1} 项数量必须大于 0`)
|
||||
return
|
||||
}
|
||||
if (Number(item.count) > getOrderAvailableCount(item)) {
|
||||
toast.warning(`第 ${i + 1} 项数量不能超过订单可出数量`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
formLoading.value = true
|
||||
try {
|
||||
const submitData = buildSubmitData() as SaleOut
|
||||
if (isEdit.value) {
|
||||
await updateSaleOut(submitData)
|
||||
toast.success('保存成功')
|
||||
} else {
|
||||
await createSaleOut(submitData)
|
||||
toast.success('新增成功')
|
||||
}
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadOptions()
|
||||
await getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
552
src/pages-erp/sale-out/index.vue
Normal file
552
src/pages-erp/sale-out/index.vue
Normal file
@@ -0,0 +1,552 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
title="销售出库"
|
||||
left-arrow
|
||||
placeholder
|
||||
safe-area-inset-top
|
||||
fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<view @click="searchVisible = true">
|
||||
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
|
||||
</view>
|
||||
|
||||
<view class="status-tabs">
|
||||
<view
|
||||
class="status-tabs__item" :class="[{ 'is-active': queryParams.status === undefined }]"
|
||||
@click="onStatusTabChange(undefined)"
|
||||
>
|
||||
全部
|
||||
</view>
|
||||
<view
|
||||
class="status-tabs__item" :class="[{ 'is-active': queryParams.status === 10 }]"
|
||||
@click="onStatusTabChange(10)"
|
||||
>
|
||||
未审核
|
||||
</view>
|
||||
<view
|
||||
class="status-tabs__item" :class="[{ 'is-active': queryParams.status === 20 }]"
|
||||
@click="onStatusTabChange(20)"
|
||||
>
|
||||
已审核
|
||||
</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"
|
||||
>
|
||||
<view class="p-24rpx" @click="handleDetail(item)">
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-28rpx 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="info-row">
|
||||
<text class="info-label">客户</text>
|
||||
<text class="info-value">{{ item.customerName || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">产品</text>
|
||||
<text class="info-value line-clamp-1 max-w-[420rpx] text-right">{{ item.productNames || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">批次</text>
|
||||
<text class="info-value line-clamp-1 max-w-[420rpx] text-right">{{ formatItemBatchNos(item) || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">出库时间</text>
|
||||
<text class="info-value">{{ formatDate(item.outTime) }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">创建人</text>
|
||||
<text class="info-value">{{ item.creatorName || '-' }}</text>
|
||||
</view>
|
||||
|
||||
<view class="mt-16rpx flex justify-around border-t border-[#f0f0f0] pt-16rpx">
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#333] font-semibold">
|
||||
{{ formatCount(item.totalCount) }}
|
||||
</view>
|
||||
<view class="text-22rpx text-[#999]">
|
||||
总数量
|
||||
</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#409eff] font-semibold">
|
||||
¥{{ formatPrice(item.totalPrice) }}
|
||||
</view>
|
||||
<view class="text-22rpx text-[#999]">
|
||||
应收
|
||||
</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#52c41a] font-semibold">
|
||||
¥{{ formatPrice(item.receiptPrice) }}
|
||||
</view>
|
||||
<view class="text-22rpx text-[#999]">
|
||||
已收
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
|
||||
<wd-button size="small" plain @click="handleDetail(item)">
|
||||
详情
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="canEdit(item)"
|
||||
size="small"
|
||||
type="primary"
|
||||
plain
|
||||
@click="handleEdit(item)"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-out:update-status']) && item.status === 10"
|
||||
size="small"
|
||||
type="success"
|
||||
plain
|
||||
@click="handleApprove(item.id!)"
|
||||
>
|
||||
审核
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="canDelete(item)"
|
||||
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:sale-out:create'])"
|
||||
position="right-bottom"
|
||||
type="primary"
|
||||
:expandable="false"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
|
||||
<wd-popup v-model="searchVisible" position="top" @close="searchVisible = false">
|
||||
<view class="yd-search-form-container">
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
出库单号
|
||||
</view>
|
||||
<wd-input v-model="searchForm.no" placeholder="请输入出库单号" clearable />
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
客户
|
||||
</view>
|
||||
<wd-picker
|
||||
v-model="searchForm.customerId"
|
||||
:columns="customerColumns"
|
||||
placeholder="请选择客户"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
审核状态
|
||||
</view>
|
||||
<view class="yd-search-form-radio-group">
|
||||
<view
|
||||
v-for="opt in statusOptions"
|
||||
:key="String(opt.value)"
|
||||
class="yd-search-form-radio"
|
||||
:class="{ 'yd-search-form-radio--active': searchForm.status === opt.value }"
|
||||
@click="searchForm.status = opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</view>
|
||||
</view>
|
||||
</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>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { SaleOut } from '@/api/erp/sale-out'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { getApprovalRecordListByBiz } from '@/api/erp/approval-record'
|
||||
import { getCustomerSimpleList } from '@/api/erp/customer'
|
||||
import { deleteSaleOut, getSaleOutPage, updateSaleOutStatus } from '@/api/erp/sale-out'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const total = ref(0)
|
||||
const list = ref<SaleOut[]>([])
|
||||
const customerList = ref<{ id: number, name: string }[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const searchVisible = ref(false)
|
||||
const queryParams = ref<{
|
||||
pageNo: number
|
||||
pageSize: number
|
||||
no?: string
|
||||
customerId?: number
|
||||
status?: number
|
||||
}>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
status: undefined,
|
||||
})
|
||||
const searchForm = reactive<{
|
||||
no?: string
|
||||
customerId?: number
|
||||
status?: number
|
||||
}>({
|
||||
no: undefined,
|
||||
customerId: undefined,
|
||||
status: undefined,
|
||||
})
|
||||
|
||||
const statusOptions = [
|
||||
{ value: undefined, label: '全部' },
|
||||
{ value: 10, label: '未审核' },
|
||||
{ value: 20, label: '已审核' },
|
||||
]
|
||||
|
||||
const customerColumns = computed(() => customerList.value.map(v => ({ label: v.name, value: v.id })))
|
||||
|
||||
const searchPlaceholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (searchForm.no)
|
||||
conditions.push(`单号:${searchForm.no}`)
|
||||
if (searchForm.customerId) {
|
||||
const customer = customerList.value.find(item => item.id === searchForm.customerId)
|
||||
if (customer?.name)
|
||||
conditions.push(`客户:${customer.name}`)
|
||||
}
|
||||
if (searchForm.status !== undefined) {
|
||||
const statusLabel = statusOptions.find(item => item.value === searchForm.status)?.label
|
||||
if (statusLabel && statusLabel !== '全部')
|
||||
conditions.push(`状态:${statusLabel}`)
|
||||
}
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索销售出库'
|
||||
})
|
||||
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
function getStatusClass(status?: number) {
|
||||
switch (status) {
|
||||
case 10:
|
||||
return 'bg-[#fffbe6] text-[#faad14]'
|
||||
case 20:
|
||||
return 'bg-[#f6ffed] text-[#52c41a]'
|
||||
default:
|
||||
return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusText(status?: number) {
|
||||
switch (status) {
|
||||
case 10:
|
||||
return '未审核'
|
||||
case 20:
|
||||
return '已审核'
|
||||
default:
|
||||
return '-'
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(value?: string | number) {
|
||||
if (!value)
|
||||
return '-'
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime()))
|
||||
return String(value).slice(0, 10)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
function formatCount(value?: number) {
|
||||
if (value === undefined || value === null)
|
||||
return '0'
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
|
||||
function formatPrice(value?: number) {
|
||||
if (value === undefined || value === null)
|
||||
return '0.00'
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
|
||||
function formatItemBatchNos(row: SaleOut) {
|
||||
const items = row.items || []
|
||||
const batchCountMap = new Map<string, number>()
|
||||
items.forEach((item) => {
|
||||
const batchNo = (item.batchNo || '').trim()
|
||||
if (!batchNo)
|
||||
return
|
||||
const count = Number(item.count || 0)
|
||||
batchCountMap.set(batchNo, (batchCountMap.get(batchNo) || 0) + count)
|
||||
})
|
||||
if (!batchCountMap.size)
|
||||
return ''
|
||||
return Array.from(batchCountMap.entries())
|
||||
.map(([batchNo, count]) => `${batchNo}[${count}]`)
|
||||
.join(',')
|
||||
}
|
||||
|
||||
async function appendApprovalFlags(records: SaleOut[]) {
|
||||
const approvalResults = await Promise.allSettled(
|
||||
records.map(async (item) => {
|
||||
if (!item.id)
|
||||
return false
|
||||
const approvalList = await getApprovalRecordListByBiz(item.id, 'erp_sale_out')
|
||||
return approvalList.length > 0
|
||||
}),
|
||||
)
|
||||
|
||||
return records.map((item, index) => ({
|
||||
...item,
|
||||
hasApprovalRecords: approvalResults[index]?.status === 'fulfilled'
|
||||
? approvalResults[index].value
|
||||
: false,
|
||||
}))
|
||||
}
|
||||
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const data = await getSaleOutPage({ ...queryParams.value })
|
||||
const pageList = await appendApprovalFlags(data.list || [])
|
||||
list.value = queryParams.value.pageNo === 1 ? pageList : [...list.value, ...pageList]
|
||||
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 onStatusTabChange(status?: number) {
|
||||
queryParams.value.status = status
|
||||
queryParams.value.pageNo = 1
|
||||
searchForm.status = status
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
searchVisible.value = false
|
||||
queryParams.value = {
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
no: searchForm.no,
|
||||
customerId: searchForm.customerId,
|
||||
status: searchForm.status,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
searchForm.no = undefined
|
||||
searchForm.customerId = undefined
|
||||
searchForm.status = queryParams.value.status
|
||||
searchVisible.value = false
|
||||
queryParams.value = {
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
status: queryParams.value.status,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished')
|
||||
return
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
uni.navigateTo({ url: '/pages-erp/sale-out/form/index' })
|
||||
}
|
||||
|
||||
function handleDetail(item: SaleOut) {
|
||||
uni.navigateTo({ url: `/pages-erp/sale-out/detail/index?id=${item.id}` })
|
||||
}
|
||||
|
||||
function handleEdit(item: SaleOut) {
|
||||
uni.navigateTo({ url: `/pages-erp/sale-out/form/index?id=${item.id}` })
|
||||
}
|
||||
|
||||
function canEdit(item: SaleOut) {
|
||||
return hasAccessByCodes(['erp:sale-out:update']) && item.status === 10 && !item.hasApprovalRecords
|
||||
}
|
||||
|
||||
function canDelete(item: SaleOut) {
|
||||
return hasAccessByCodes(['erp:sale-out:delete']) && !item.hasApprovalRecords
|
||||
}
|
||||
|
||||
function handleApprove(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定审核该销售出库单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm)
|
||||
return
|
||||
try {
|
||||
await updateSaleOutStatus(id, 20)
|
||||
toast.success('审核成功')
|
||||
queryParams.value.pageNo = 1
|
||||
list.value = []
|
||||
getList()
|
||||
} catch {
|
||||
// handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function handleDelete(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定删除该销售出库单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm)
|
||||
return
|
||||
try {
|
||||
await deleteSaleOut([id])
|
||||
toast.success('删除成功')
|
||||
queryParams.value.pageNo = 1
|
||||
list.value = []
|
||||
getList()
|
||||
} catch {
|
||||
// handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async function loadCustomers() {
|
||||
try {
|
||||
customerList.value = await getCustomerSimpleList()
|
||||
} catch {
|
||||
customerList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
await loadCustomers()
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.status-tabs {
|
||||
display: flex;
|
||||
margin: 0 24rpx 16rpx;
|
||||
background: #fff;
|
||||
border-radius: 8rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
|
||||
|
||||
&__item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 20rpx 0;
|
||||
font-size: 28rpx;
|
||||
color: #606266;
|
||||
position: relative;
|
||||
|
||||
&.is-active {
|
||||
color: #018d71;
|
||||
font-weight: 600;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 25%;
|
||||
width: 50%;
|
||||
height: 4rpx;
|
||||
background: #018d71;
|
||||
border-radius: 2rpx;
|
||||
}
|
||||
}
|
||||
|
||||
&:not(:last-child) {
|
||||
border-right: 1rpx solid #f0f0f0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8rpx;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #999;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #666;
|
||||
}
|
||||
</style>
|
||||
@@ -107,6 +107,14 @@ const menuGroupsData: MenuGroup[] = [
|
||||
url: '/pages-erp/sale-order/index',
|
||||
iconColor: '#1890ff',
|
||||
permission: 'erp:sale-order:query',
|
||||
},
|
||||
{
|
||||
key: 'saleOut',
|
||||
name: '销售出库',
|
||||
icon: 'arrow-right',
|
||||
url: '/pages-erp/sale-out/index',
|
||||
iconColor: '#52c41a',
|
||||
permission: 'erp:sale-out:query',
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user