17 Commits

Author SHA1 Message Date
69c54cbeae 李红攀:V2.6.975,添加采购询比、采购统计 2026-07-11 18:01:54 +08:00
f3db15ab74 李红攀:V2.6.976,添加采购询比、采购统计 2026-07-11 17:55:50 +08:00
69083ba8db 李红攀:V2.6.975,采购询比分享链接给供应商进行报价,而且还能生成请购单 2026-07-07 15:20:03 +08:00
0614605ad8 李红攀:V2.6.969,销售计划管理 2026-06-22 19:44:06 +08:00
800d8c1ae9 李红攀:V2.6.969,销售退货管理管理 2026-06-22 19:15:41 +08:00
617d293dc3 李红攀:V2.6.969,销售出库管理 2026-06-22 17:09:31 +08:00
d0ce2f2b55 李红攀:V2.6.969,客户管理、销售订单 2026-06-18 17:51:39 +08:00
4c09ffdf00 李红攀:V2.6.969,请购单BUG修复 2026-06-18 15:58:24 +08:00
e404898a78 李红攀:V2.6.969,扫码出库 2026-06-16 18:35:19 +08:00
73efc21c19 李红攀:V2.6.969,扫码出库 2026-06-16 18:24:08 +08:00
794348a167 李红攀:V2.6.970,扫码枪入库 2026-06-16 17:31:21 +08:00
0f5d94ead2 李红攀:V2.6.964,添加设备维修单 2026-06-13 18:03:04 +08:00
66f47cdde4 李红攀:V2.0.001采购订单添加税率 2026-04-25 10:57:12 +08:00
6f1f32df62 李红攀:V2.0.001小程序的农业溯源 2026-04-23 19:57:52 +08:00
505fda77f0 李红攀:V2.0.001仓库管理 2026-04-21 17:12:43 +08:00
5586e8e39a 李红攀:V2.0.001小程序的采购管理 2026-04-21 15:55:26 +08:00
45eb9232d7 李红攀:V2.0.001小程序的采摘管理 2026-04-17 19:40:30 +08:00
114 changed files with 28153 additions and 425 deletions

12
env/.env vendored
View File

@@ -1,7 +1,7 @@
VITE_APP_TITLE = '芋道管理系统'
VITE_APP_TITLE = '亚为mom小程序'
VITE_APP_PORT = 9000
VITE_UNI_APPID = '__UNI__D1E5001'
VITE_UNI_APPID = '__UNI__2EB12DE'
VITE_WX_APPID = 'wx1a832d51073d3a35'
# h5部署网站的base配置到 manifest.config.ts 里的 h5.router.base
@@ -10,8 +10,8 @@ VITE_WX_APPID = 'wx1a832d51073d3a35'
VITE_APP_PUBLIC_BASE=/
# 后台请求地址
VITE_SERVER_BASEURL = 'http://localhost:48080/admin-api'
VITE_UPLOAD_BASEURL = 'http://localhost:48080/upload'
VITE_SERVER_BASEURL = 'http://192.168.1.107:48080/admin-api'
VITE_UPLOAD_BASEURL = 'http://192.168.1.107:48080/upload'
# 备注如果后台带统一前缀则也要加到后面eg: https://ukw0y1.laf.run/api
# 注意,如果是微信小程序,还有一套请求地址的配置,根据 develop、trial、release 分别设置上传地址,见 `src/utils/index.ts`。
@@ -39,8 +39,8 @@ VITE_APP_TENANT_ENABLE=true
VITE_APP_CAPTCHA_ENABLE=false
# 默认账户密码
VITE_APP_DEFAULT_LOGIN_TENANT_ID = 1
VITE_APP_DEFAULT_LOGIN_USERNAME = admin
VITE_APP_DEFAULT_LOGIN_PASSWORD = admin123
VITE_APP_DEFAULT_LOGIN_USERNAME = YAVII
VITE_APP_DEFAULT_LOGIN_PASSWORD = yavii123
# API 加解密
VITE_APP_API_ENCRYPT_ENABLE = true

View File

@@ -6,4 +6,4 @@ VITE_DELETE_CONSOLE = false
VITE_SHOW_SOURCEMAP = false
# 后台请求地址
# VITE_SERVER_BASEURL = 'http://localhost:48080'
# VITE_SERVER_BASEURL = 'http://192.168.1.107:48080'

View File

@@ -82,33 +82,33 @@ export default defineManifestConfig({
/* 图标配置 */
icons: {
android: {
hdpi: 'static/app/icons/72x72.png',
xhdpi: 'static/app/icons/96x96.png',
xxhdpi: 'static/app/icons/144x144.png',
xxxhdpi: 'static/app/icons/192x192.png',
hdpi: 'src/static/app/icons/72x72.png',
xhdpi: 'src/static/app/icons/96x96.png',
xxhdpi: 'src/static/app/icons/144x144.png',
xxxhdpi: 'src/static/app/icons/192x192.png',
},
ios: {
appstore: 'static/app/icons/1024x1024.png',
appstore: 'src/static/app/icons/1024x1024.png',
ipad: {
'app': 'static/app/icons/76x76.png',
'app@2x': 'static/app/icons/152x152.png',
'notification': 'static/app/icons/20x20.png',
'notification@2x': 'static/app/icons/40x40.png',
'proapp@2x': 'static/app/icons/167x167.png',
'settings': 'static/app/icons/29x29.png',
'settings@2x': 'static/app/icons/58x58.png',
'spotlight': 'static/app/icons/40x40.png',
'spotlight@2x': 'static/app/icons/80x80.png',
'app': 'src/static/app/icons/76x76.png',
'app@2x': 'src/static/app/icons/152x152.png',
'notification': 'src/static/app/icons/20x20.png',
'notification@2x': 'src/static/app/icons/40x40.png',
'proapp@2x': 'src/static/app/icons/167x167.png',
'settings': 'src/static/app/icons/29x29.png',
'settings@2x': 'src/static/app/icons/58x58.png',
'spotlight': 'src/static/app/icons/40x40.png',
'spotlight@2x': 'src/static/app/icons/80x80.png',
},
iphone: {
'app@2x': 'static/app/icons/120x120.png',
'app@3x': 'static/app/icons/180x180.png',
'notification@2x': 'static/app/icons/40x40.png',
'notification@3x': 'static/app/icons/60x60.png',
'settings@2x': 'static/app/icons/58x58.png',
'settings@3x': 'static/app/icons/87x87.png',
'spotlight@2x': 'static/app/icons/80x80.png',
'spotlight@3x': 'static/app/icons/120x120.png',
'app@2x': 'src/static/app/icons/120x120.png',
'app@3x': 'src/static/app/icons/180x180.png',
'notification@2x': 'src/static/app/icons/40x40.png',
'notification@3x': 'src/static/app/icons/60x60.png',
'settings@2x': 'src/static/app/icons/58x58.png',
'settings@3x': 'src/static/app/icons/87x87.png',
'spotlight@2x': 'src/static/app/icons/80x80.png',
'spotlight@3x': 'src/static/app/icons/120x120.png',
},
},
},

74
src/api/agri/biz/flow.ts Normal file
View File

@@ -0,0 +1,74 @@
import { http } from '@/http/http'
export interface AgriHarvestSubmitReqVO {
batchType: string
productId?: number
productName?: string
plotId?: number
plotName?: string
farmerId?: number
quantity?: number
unit?: string
harvestTime?: string
remark?: string
}
export interface AgriSortingSubmitReqVO {
batchId: number
weightResult?: number
unqualifiedCategory?: string
imageUrl?: string
remark?: string
}
export interface AgriPackingSubmitReqVO {
batchId: number
netWeight?: number
labelCode?: string
packingTime?: string
remark?: string
}
export interface AgriWarehouseInReqVO {
batchId: number
inMode?: string
warehouseTime?: string
remark?: string
}
export interface AgriShipmentDispatchReqVO {
batchId: number
vehicleNo: string
boxCount?: number
shipmentTime?: string
remark?: string
}
export interface AgriShipmentSignReqVO {
batchId: number
remark?: string
}
export function submitHarvest(data: AgriHarvestSubmitReqVO) {
return http.post<number>('/agri/biz/flow/harvest', data)
}
export function submitSorting(data: AgriSortingSubmitReqVO) {
return http.post<void>('/agri/biz/flow/sorting', data)
}
export function submitPacking(data: AgriPackingSubmitReqVO) {
return http.post<void>('/agri/biz/flow/packing', data)
}
export function submitWarehouseIn(data: AgriWarehouseInReqVO) {
return http.post<void>('/agri/biz/flow/warehouse-in', data)
}
export function dispatchShipment(data: AgriShipmentDispatchReqVO) {
return http.post<void>('/agri/biz/flow/shipment-dispatch', data)
}
export function signShipment(data: AgriShipmentSignReqVO) {
return http.post<void>('/agri/biz/flow/shipment-sign', data)
}

View File

@@ -0,0 +1,45 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
export interface AgriTraceSnapshotVO {
id: number
traceCode: string
batchId: number
batchNo: string
productName?: string
plotName?: string
harvestTime?: string
harvestOperatorId?: number
harvestOperatorName?: string
packingTime?: string
packingOperatorId?: number
packingOperatorName?: string
warehouseTime?: string
warehouseOperatorId?: number
warehouseOperatorName?: string
shipmentTime?: string
shipmentOperatorId?: number
shipmentOperatorName?: string
vehicleNo?: string
invoiceStatus?: string
snapshotJson?: string
}
export interface AgriTraceSnapshotPageReqVO extends PageParam {
batchId?: number
batchNo?: string
traceCode?: string
productName?: string
}
export function getAgriTraceSnapshotPage(params: AgriTraceSnapshotPageReqVO) {
return http.get<PageResult<AgriTraceSnapshotVO>>('/agri/trace/snapshot/page', params)
}
export function getAgriTraceSnapshot(id: number) {
return http.get<AgriTraceSnapshotVO>(`/agri/trace/snapshot/get?id=${id}`)
}
export function getAgriTraceSnapshotByTraceCode(traceCode: string) {
return http.get<AgriTraceSnapshotVO>('/agri/trace/snapshot/get-by-trace-code', { traceCode })
}

View File

@@ -0,0 +1,13 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 账户信息 */
export interface Account {
id?: number
name?: string
}
/** 获取账户精简列表 */
export function getAccountSimpleList() {
return http.get<Account[]>('/erp/account/simple-list')
}

View 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 })
}

13
src/api/erp/box/index.ts Normal file
View File

@@ -0,0 +1,13 @@
import { http } from '@/http/http'
/** 框管理记录 */
export interface Box {
id?: number
boxNumber: string
[key: string]: any
}
/** 获取框管理分页列表(用于提取框编号) */
export function getBoxPage(params?: Record<string, any>) {
return http.get<{ list: Box[], total: number }>('/erp/box/page', { pageNo: 1, pageSize: 100, ...params })
}

View File

@@ -0,0 +1,96 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 客户信息 */
export interface Customer {
id?: number
name?: string
contact?: string
mobile?: string
telephone?: string
email?: string
fax?: string
remark?: string
status?: number
sort?: number
taxNo?: string
taxPercent?: number
bankName?: string
bankAccount?: string
bankAddress?: string
tags?: string
companyType?: number
businessScale?: string
annualPurchaseVolume?: number
annualPurchaseAmount?: number
annualOrderNums?: number
annualOrderAmounts?: number
annualReceivedAmounts?: number
totalUnreceivedAmounts?: number
preferredProducts?: string
preferredPackaging?: string
qualityCertRequirements?: string
deliveryCyclePrefer?: string
paymentTerms?: string
lastDeliveryTime?: number
deliveryAddress?: string
businessLicenseNo?: string
licenseValidity?: number
riskLevel?: number
logisticsPartner?: string
requiresColdChain?: boolean
serviceRegion?: string
relationshipLevel?: number
leadSourceType?: number
leadSourceDetail?: string
leadScore?: number
potentialLevel?: number
expectedAnnualVolume?: number
expectedAnnualAmount?: number
purchaseCycle?: string
}
/** 客户精简信息 */
export interface CustomerSimple {
id: number
name: string
}
/** 获取客户分页列表 */
export function getCustomerPage(params: PageParam & {
name?: string
mobile?: string
telephone?: string
}) {
return http.get<PageResult<Customer>>('/erp/customer/page', params)
}
/** 获取客户详情 */
export function getCustomer(id: number) {
return http.get<Customer>(`/erp/customer/get?id=${id}`)
}
/** 创建客户 */
export function createCustomer(data: Customer) {
return http.post<number>('/erp/customer/create', data)
}
/** 更新客户 */
export function updateCustomer(data: Customer) {
return http.put<boolean>('/erp/customer/update', data)
}
/** 删除客户 */
export function deleteCustomer(id: number) {
return http.delete<boolean>(`/erp/customer/delete?id=${id}`)
}
/** 获取客户精简列表 */
export function getCustomerSimpleList() {
return http.get<CustomerSimple[]>('/erp/customer/simple-list')
}
/** 导出客户 */
export function exportCustomer(params: PageParam) {
return http.get<string>('/erp/customer/export', params)
}

View File

@@ -0,0 +1,73 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 农户信息 */
export interface Farmer {
id?: number
name?: string
idCardNumber?: string
mobile?: string
address?: string
plantingBase?: string
contractNumber?: string
contractedArea?: number
orderQuantity?: number
actualArea?: number
transplantTime?: string
transplantQuantity?: number
maturityTime?: string
expectedHarvestTime?: string
usedVariety?: string
plantingMethod?: string
adminName?: string
contact?: string
telephone?: string
email?: string
fax?: string
remark?: string
status?: number
sort?: number
taxNo?: string
taxPercent?: number
bankName?: string
bankAccount?: string
bankAddress?: string
}
/** 品种选项 */
export const VARIETY_OPTIONS = [
{ value: '红宝石', label: '红宝石' },
{ value: '1401', label: '1401' },
{ value: '1501', label: '1501' },
{ value: '3366', label: '3366' },
]
/** 获取农户分页列表 */
export function getFarmerPage(params: PageParam) {
return http.get<PageResult<Farmer>>('/erp/farmer/page', { ...params, type: 2 })
}
/** 获取农户详情 */
export function getFarmer(id: number) {
return http.get<Farmer>(`/erp/farmer/get?id=${id}`)
}
/** 创建农户 */
export function createFarmer(data: Farmer) {
return http.post<number>('/erp/farmer/create', data)
}
/** 更新农户 */
export function updateFarmer(data: Farmer) {
return http.put<boolean>('/erp/farmer/update', data)
}
/** 删除农户 */
export function deleteFarmer(id: number) {
return http.delete<boolean>(`/erp/farmer/delete?id=${id}`)
}
/** 获取农户精简列表 */
export function getFarmerSimpleList() {
return http.get<Farmer[]>('/erp/farmer/simple-list')
}

View File

@@ -0,0 +1,13 @@
import { http } from '@/http/http'
/** 田间管理记录 */
export interface FarmingManagement {
id?: number
code: string
[key: string]: any
}
/** 获取田间管理分页列表(用于提取田间编号) */
export function getFarmingManagementPage(params?: Record<string, any>) {
return http.get<{ list: FarmingManagement[], total: number }>('/erp/farming-management/page', { pageNo: 1, pageSize: 100, ...params })
}

View File

@@ -0,0 +1,85 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 西兰花采摘记录信息 */
export interface PickBroccoli {
id?: number
pickCode?: string
userId?: number
userName?: string
fieldCode?: string
fieldName?: string
basketCode?: string
basketWeight?: number
licensePlate?: string
pickTime?: string
loadTime?: string
loaderId?: number
loaderName?: string
status?: number
unloadTime?: string
unloaderId?: number
unloaderName?: string
warehouseId?: string
warehouseName?: string
unloadBatch?: string
productId?: number
productName?: string
remark?: string
createTime?: string
}
/** 获取采摘记录分页列表 */
export function getPickBroccoliPage(params: PageParam) {
return http.get<PageResult<PickBroccoli>>('/erp/pick-broccoli/page', params)
}
/** 获取采摘记录详情 */
export function getPickBroccoli(id: number) {
return http.get<PickBroccoli>(`/erp/pick-broccoli/get?id=${id}`)
}
/** 创建采摘记录 */
export function createPickBroccoli(data: PickBroccoli) {
return http.post<number>('/erp/pick-broccoli/create', data)
}
/** 更新采摘记录 */
export function updatePickBroccoli(data: PickBroccoli) {
return http.put<boolean>('/erp/pick-broccoli/update', data)
}
/** 删除采摘记录 */
export function deletePickBroccoli(id: number) {
return http.delete<boolean>(`/erp/pick-broccoli/delete?id=${id}`)
}
/** 更新采摘记录状态 */
export function updatePickBroccoliStatus(id: number, status: number) {
return http.put<boolean>(`/erp/pick-broccoli/update-status?id=${id}&status=${status}`)
}
/** 装车操作 */
export function loadTruck(id: number, licensePlate: string, loaderId: number, loaderName: string) {
return http.put<boolean>(`/erp/pick-broccoli/load-truck?id=${id}&licensePlate=${licensePlate}&loaderId=${loaderId}&loaderName=${loaderName}`)
}
/** 卸车入库操作 */
export function unloadTruck(licensePlate: string, unloaderId: number, unloaderName: string, warehouseId: string, warehouseName: string) {
return http.put<boolean>(`/erp/pick-broccoli/unload-truck?licensePlate=${licensePlate}&unloaderId=${unloaderId}&unloaderName=${unloaderName}&warehouseId=${warehouseId}&warehouseName=${warehouseName}`)
}
/** 获取已装车车辆列表 */
export function getLoadedTrucks() {
return http.get<any[]>('/erp/pick-broccoli/list-loaded-trucks')
}
/** 卸车预览 */
export function getUnloadPreview(licensePlate: string) {
return http.get<any>(`/erp/pick-broccoli/unload-preview?licensePlate=${licensePlate}`)
}
/** 生成采摘编号 */
export function generatePickCode() {
return http.get<{ code: string }>('/erp/pick-broccoli/generate-code')
}

View File

@@ -0,0 +1,42 @@
import { http } from '@/http/http'
/** 产品精简信息 */
export interface ProductSimple {
id: number
name: string
barCode?: string
unitId?: number
unitName?: string
standard?: string
purchasePrice?: number
salePrice?: number
minPrice?: number
supplierId?: number
supplierName?: string
weight?: number
}
/** 获取产品精简列表 */
export function getProductSimpleList() {
return http.get<ProductSimple[]>('/erp/product/simple-list')
}
/** 通过产品条码获得产品(响应 VO */
export interface ProductByBarCode {
id?: number
name?: string
barCode?: string
standard?: string
unitId?: number
unitName?: string
categoryId?: number
categoryName?: string
purchasePrice?: number
salePrice?: number
minPrice?: number
}
/** 通过产品条码获得产品 */
export function getProductByBarCode(barCode: string) {
return http.get<ProductByBarCode>(`/erp/product/get-by-bar-code?barCode=${encodeURIComponent(barCode)}`)
}

View File

@@ -0,0 +1,110 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 采购入库项 */
export interface PurchaseInItem {
id?: number
productId: number
productUnitId: number
productPrice?: number
count: number
taxPercent?: number
taxPrice?: number
remark?: string
warehouseId?: number
warehouseName?: string
productName?: string
productBarCode?: string
productUnitName?: string
productSpec?: string
productCategoryName?: string
stockCount?: number
totalCount?: number
inCount?: number
totalPrice?: number
totalProductPrice?: number
orderItemId?: number
}
/** 采购入库信息 */
export interface PurchaseIn {
id?: number
no?: string
status?: number
supplierId?: number
supplierName?: string
accountId?: number
accountName?: string
inTime?: string
totalCount?: number
totalPrice?: number
totalProductPrice?: number
totalTaxPrice?: number
discountPercent?: number
discountPrice?: number
otherPrice?: number
paymentPrice?: number
fileUrl?: string
remark?: string
creator?: string
creatorName?: string
createTime?: string
items?: PurchaseInItem[]
productNames?: string
orderId?: number
orderNo?: string
isQualified?: boolean
returnType?: string | null
returnRemark?: string
}
/** 审核表单数据 */
export interface AuditFormData {
id: number
isQualified: boolean
returnType?: string
returnRemark?: string
status: number
}
/** 返回方式枚举 */
export const RETURN_TYPE_ENUM = {
RETURN_BACK: 'return_back',
DESTROY: 'destroy',
}
/** 返回方式选项 */
export const RETURN_TYPE_OPTIONS = [
{ label: '原路返回', value: RETURN_TYPE_ENUM.RETURN_BACK },
{ label: '就地销毁', value: RETURN_TYPE_ENUM.DESTROY },
]
/** 获取采购入库分页列表 */
export function getPurchaseInPage(params: PageParam) {
return http.get<PageResult<PurchaseIn>>('/erp/purchase-in/page', params)
}
/** 获取采购入库详情 */
export function getPurchaseIn(id: number) {
return http.get<PurchaseIn>(`/erp/purchase-in/get?id=${id}`)
}
/** 创建采购入库 */
export function createPurchaseIn(data: PurchaseIn) {
return http.post<number>('/erp/purchase-in/create', data)
}
/** 更新采购入库 */
export function updatePurchaseIn(data: PurchaseIn) {
return http.put<boolean>('/erp/purchase-in/update', data)
}
/** 更新采购入库状态 */
export function updatePurchaseInStatus(data: AuditFormData) {
return http.put<boolean>('/erp/purchase-in/update-status', data)
}
/** 删除采购入库 */
export function deletePurchaseIn(ids: number[]) {
return http.delete<boolean>(`/erp/purchase-in/delete?ids=${ids.join(',')}`)
}

View File

@@ -0,0 +1,171 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
export interface PurchaseInquiryQuote {
id?: number
inquiryId?: number
invitationId?: number
supplierId?: number
supplierName?: string
contactName?: string
contactPhone?: string
quoteDate?: string | number | Date
unitPrice?: number
totalPrice?: number
paymentTerms?: string
deliveryCycle?: number
expectedArrivalDate?: string | number | Date
qualificationFile?: string
remark?: string
isSelected?: boolean
quoteStatus?: number
submitSource?: string
priceScore?: number
qualityScore?: number
deliveryScore?: number
serviceScore?: number
totalScore?: number
}
export interface PurchaseInquiry {
id?: number
no?: string
productId?: number
productName?: string
requireCount?: number
budgetPrice?: number
inquiryTime?: string | number | Date
deadline?: string | number | Date
status?: number
remark?: string
selectedQuoteId?: number
creatorName?: string
creator?: number
quoteCount?: number
minQuotePrice?: number
quotes?: PurchaseInquiryQuote[]
}
export interface PurchaseInquiryPublishReq {
inquiryId: number
supplierIds: number[]
linkExpireTime?: string | number | Date
}
export interface PurchaseInquiryInvitation {
id?: number
inquiryId?: number
supplierId?: number
supplierName?: string
status?: number
accessToken?: string
portalUrl?: string
linkExpireTime?: string | number | Date
firstViewTime?: string | number | Date
lastViewTime?: string | number | Date
submitTime?: string | number | Date
sendTime?: string | number | Date
quoteId?: number
quoteDate?: string | number | Date
unitPrice?: number
totalPrice?: number
paymentTerms?: string
deliveryCycle?: number
expectedArrivalDate?: string | number | Date
qualificationFile?: string
remark?: string
submitSource?: string
contactName?: string
contactPhone?: string
}
export interface PurchaseInquiryCompareReq {
inquiryId: number
priceWeight: number
qualityWeight: number
deliveryWeight: number
serviceWeight: number
quotes?: {
quoteId: number
qualityScore?: number
serviceScore?: number
}[]
}
export interface PurchaseInquiryCompareQuote {
quoteId: number
supplierId: number
supplierName?: string
unitPrice?: number
totalPrice?: number
deliveryCycle?: number
expectedArrivalDate?: string | number | Date
qualificationFile?: string
priceScore?: number
qualityScore?: number
deliveryScore?: number
serviceScore?: number
totalScore?: number
historicalAvgTotalScore?: number
historicalEvaluationCount?: number
attachmentProvided?: boolean
recommended?: boolean
recommendationReasons?: string[]
riskTips?: string[]
}
export interface PurchaseInquiryCompareResp {
inquiryId: number
inquiryNo?: string
productName?: string
requireCount?: number
budgetPrice?: number
recommendedQuoteId?: number
recommendedSupplierId?: number
recommendedSupplierName?: string
recommendedTotalScore?: number
analysisSummary?: string
analysisTime?: string | number | Date
riskTips?: string[]
quotes: PurchaseInquiryCompareQuote[]
}
export function getPurchaseInquiryPage(params: PageParam) {
return http.get<PageResult<PurchaseInquiry>>('/erp/purchase-inquiry/page', params)
}
export function getPurchaseInquiry(id: number) {
return http.get<PurchaseInquiry>(`/erp/purchase-inquiry/get?id=${id}`)
}
export function createPurchaseInquiry(data: PurchaseInquiry) {
return http.post<number>('/erp/purchase-inquiry/create', data)
}
export function updatePurchaseInquiry(data: PurchaseInquiry) {
return http.put<boolean>('/erp/purchase-inquiry/update', data)
}
export function updatePurchaseInquiryStatus(id: number, status: number) {
return http.put<boolean>(`/erp/purchase-inquiry/update-status?id=${id}&status=${status}`)
}
export function publishPurchaseInquiry(data: PurchaseInquiryPublishReq) {
return http.post<boolean>('/erp/purchase-inquiry/publish', data)
}
export function comparePurchaseInquiry(data: PurchaseInquiryCompareReq) {
return http.post<PurchaseInquiryCompareResp>('/erp/purchase-inquiry/compare-recommend', data)
}
export function getPurchaseInquiryInvitationList(inquiryId: number) {
return http.get<PurchaseInquiryInvitation[]>(`/erp/purchase-inquiry/invitation-list?inquiryId=${inquiryId}`)
}
export function selectPurchaseInquiryQuote(inquiryId: number, quoteId: number) {
return http.put<boolean>(`/erp/purchase-inquiry/select-quote?inquiryId=${inquiryId}&quoteId=${quoteId}`)
}
export function deletePurchaseInquiry(ids: number[]) {
return http.delete<boolean>(`/erp/purchase-inquiry/delete?ids=${ids.join(',')}`)
}

View File

@@ -0,0 +1,90 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 采购订单项 */
export interface PurchaseOrderItem {
id?: number
productId: number
productUnitId: number
productPrice?: number
count: number
taxPercent?: number
taxPrice?: number
remark?: string
inCount?: number
returnCount?: number
supplierId?: number
supplierName?: string
productName?: string
productBarCode?: string
productUnitName?: string
stockCount?: number
productSpec?: string
}
/** 采购订单信息 */
export interface PurchaseOrder {
id?: number
no?: string
status?: number
supplierId?: number
supplierName?: string
accountId?: number
orderTime?: string
totalCount?: number
totalPrice?: number
totalProductPrice?: number
totalTaxPrice?: number
discountPercent?: number
discountPrice?: number
depositPrice?: number
fileUrl?: string
remark?: string
creator?: string
creatorName?: string
createTime?: string
items?: PurchaseOrderItem[]
productNames?: string
inCount?: number
returnCount?: number
auditorId?: number
auditorName?: string
purchaseRequisitionId?: number
purchaseRequisitionNo?: string
invoiceType?: number
invoiceTypeName?: string
freightPayer?: number
freightPayerName?: string
settlementMethod?: number
settlementMethodName?: string
}
/** 获取采购订单分页列表 */
export function getPurchaseOrderPage(params: PageParam) {
return http.get<PageResult<PurchaseOrder>>('/erp/purchase-order/page', params)
}
/** 获取采购订单详情 */
export function getPurchaseOrder(id: number) {
return http.get<PurchaseOrder>(`/erp/purchase-order/get?id=${id}`)
}
/** 创建采购订单 */
export function createPurchaseOrder(data: PurchaseOrder) {
return http.post<number>('/erp/purchase-order/create', data)
}
/** 更新采购订单 */
export function updatePurchaseOrder(data: PurchaseOrder) {
return http.put<boolean>('/erp/purchase-order/update', data)
}
/** 更新采购订单状态 */
export function updatePurchaseOrderStatus(id: number, status: number) {
return http.put<boolean>(`/erp/purchase-order/update-status?id=${id}&status=${status}`)
}
/** 删除采购订单 */
export function deletePurchaseOrder(ids: number[]) {
return http.delete<boolean>(`/erp/purchase-order/delete?ids=${ids.join(',')}`)
}

View File

@@ -0,0 +1,126 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 请购单明细信息 */
export interface PurchaseRequisitionItem {
id?: number
requisitionId?: number
productId?: number
productName?: string
productUnitId?: number
productUnitName?: string
productSpec?: string
productBarCode?: string
productPrice?: number
count?: number
totalProductPrice?: number
taxPercent?: number
taxPrice?: number
totalPrice?: number
purpose?: string
brandId?: number
brandName?: string
supplierId?: number
supplierName?: string
approveCount?: number
purchaseCount?: number
remark?: string
createTime?: string
saleOrderId?: number
saleOrderNo?: string
}
/** 请购单信息 */
export interface PurchaseRequisition {
id?: number
no?: string
type?: number
priority?: number
status?: number
requesterId?: number
requesterName?: string
requesterNickname?: string
requesterDeptId?: number
requesterDeptName?: string
requestTime?: string
expectedTime?: string
approverId?: number
approverName?: string
approveTime?: string
approveRemark?: string
totalCount?: number
totalProductPrice?: number
totalTaxPrice?: number
totalPrice?: number
additionalFee?: number
emergencyDegree?: number
fileUrl?: string
remark?: string
supplierId?: number
supplierName?: string
items?: PurchaseRequisitionItem[]
hasApprovalRecords?: boolean
createTime?: number
}
/** 获取请购单分页列表 */
export function getPurchaseRequisitionPage(params: PageParam) {
return http.get<PageResult<PurchaseRequisition>>('/erp/purchase-requisition/page', params)
}
/** 获取请购单详情 */
export function getPurchaseRequisition(id: number) {
return http.get<PurchaseRequisition>(`/erp/purchase-requisition/get?id=${id}`)
}
/** 创建请购单 */
export function createPurchaseRequisition(data: PurchaseRequisition) {
return http.post<number>('/erp/purchase-requisition/create', data)
}
/** 更新请购单 */
export function updatePurchaseRequisition(data: PurchaseRequisition) {
return http.put<boolean>('/erp/purchase-requisition/update', data)
}
/** 删除请购单 */
export function deletePurchaseRequisition(id: number) {
return http.delete<boolean>(`/erp/purchase-requisition/delete?id=${id}`)
}
/** 更新请购单状态 */
export function updatePurchaseRequisitionStatus(id: number, status: number) {
return http.put<boolean>(`/erp/purchase-requisition/update-status?id=${id}&status=${status}`)
}
/** 请购类型选项 */
export const REQUISITION_TYPE_OPTIONS = [
{ value: 1, label: '请购' },
{ value: 2, label: '补货' },
{ value: 3, label: '其他' },
]
/** 优先级选项 */
export const PRIORITY_OPTIONS = [
{ value: 1, label: '低' },
{ value: 2, label: '中' },
{ value: 3, label: '高' },
{ value: 4, label: '紧急' },
]
/** 状态选项 */
export const STATUS_OPTIONS = [
{ value: 1, label: '待审核' },
{ value: 2, label: '已审核' },
{ value: 3, label: '已驳回' },
{ value: 4, label: '已取消' },
{ value: 5, label: '已采购' },
]
/** 紧急程度选项 */
export const EMERGENCY_OPTIONS = [
{ value: 1, label: '普通' },
{ value: 2, label: '较急' },
{ value: 3, label: '紧急' },
{ value: 4, label: '特急' },
]

View File

@@ -0,0 +1,87 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 采购退货项 */
export interface PurchaseReturnItem {
id?: number
productId: number
productUnitId: number
productPrice?: number
count: number
taxPercent?: number
taxPrice?: number
remark?: string
warehouseId?: number
warehouseName?: string
productName?: string
productBarCode?: string
productUnitName?: string
productSpec?: string
productCategoryName?: string
stockCount?: number
totalCount?: number
totalPrice?: number
totalProductPrice?: number
orderItemId?: number
inCount?: number
returnCount?: number
}
/** 采购退货信息 */
export interface PurchaseReturn {
id?: number
no?: string
status?: number
supplierId?: number
supplierName?: string
accountId?: number
accountName?: string
returnTime?: string
totalCount?: number
totalPrice?: number
totalProductPrice?: number
totalTaxPrice?: number
discountPercent?: number
discountPrice?: number
otherPrice?: number
refundPrice?: number
fileUrl?: string
remark?: string
creator?: string
creatorName?: string
createTime?: string
items?: PurchaseReturnItem[]
productNames?: string
orderId?: number
orderNo?: string
}
/** 获取采购退货分页列表 */
export function getPurchaseReturnPage(params: PageParam) {
return http.get<PageResult<PurchaseReturn>>('/erp/purchase-return/page', params)
}
/** 获取采购退货详情 */
export function getPurchaseReturn(id: number) {
return http.get<PurchaseReturn>(`/erp/purchase-return/get?id=${id}`)
}
/** 创建采购退货 */
export function createPurchaseReturn(data: PurchaseReturn) {
return http.post<number>('/erp/purchase-return/create', data)
}
/** 更新采购退货 */
export function updatePurchaseReturn(data: PurchaseReturn) {
return http.put<boolean>('/erp/purchase-return/update', data)
}
/** 更新采购退货状态 */
export function updatePurchaseReturnStatus(id: number, status: number) {
return http.put<boolean>(`/erp/purchase-return/update-status?id=${id}&status=${status}`)
}
/** 删除采购退货 */
export function deletePurchaseReturn(ids: number[]) {
return http.delete<boolean>(`/erp/purchase-return/delete?ids=${ids.join(',')}`)
}

View File

@@ -0,0 +1,75 @@
import { http } from '@/http/http'
export interface PurchaseSummary {
todayPrice: number
yesterdayPrice: number
monthPrice: number
yearPrice: number
}
export interface PurchaseTimeSummary {
time: string
price: number
}
export interface PurchaseTrend {
time: string
price: number
count: number
}
export interface PurchaseProductRank {
productId: number
productName: string
count: number
price: number
inCount: number
returnCount: number
inPrice: number
returnPrice: number
orderCount: number
avgPrice: number
shareRate: number
}
export interface PurchaseSupplierRank {
supplierId: number
supplierName: string
count: number
price: number
inCount: number
returnCount: number
inPrice: number
returnPrice: number
orderCount: number
avgPrice: number
shareRate: number
}
export function getPurchaseSummary() {
return http.get<PurchaseSummary>('/erp/purchase-statistics/summary')
}
export function getPurchaseTimeSummary() {
return http.get<PurchaseTimeSummary[]>('/erp/purchase-statistics/time-summary')
}
export function getPurchaseTrendByWeek(count: number = 12) {
return http.get<PurchaseTrend[]>(`/erp/purchase-statistics/trend-by-week?count=${count}`)
}
export function getPurchaseTrendByMonth(count: number = 12) {
return http.get<PurchaseTrend[]>(`/erp/purchase-statistics/trend-by-month?count=${count}`)
}
export function getPurchaseProductRank(beginTime: string, endTime: string, limit: number = 10, sortBy: 'price' | 'count' = 'price') {
return http.get<PurchaseProductRank[]>('/erp/purchase-statistics/product-rank', { beginTime, endTime, limit, sortBy })
}
export function getPurchaseSupplierRank(beginTime: string, endTime: string, limit: number = 10, sortBy: 'price' | 'count' = 'price') {
return http.get<PurchaseSupplierRank[]>('/erp/purchase-statistics/supplier-rank', { beginTime, endTime, limit, sortBy })
}
export function analyzePurchaseStatistics(data: Record<string, any>) {
return http.post<any>('/erp/purchase-statistics/ai-analysis', data)
}

View File

@@ -0,0 +1,101 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 销售订单项 */
export interface SaleOrderItem {
id?: number
productId?: number
productName?: string
productNo?: string
count?: number
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
returnCount?: number
stockCount?: number
}
/** 销售订单信息 */
export interface SaleOrder {
id?: number
no?: string
customerId?: number
customerName?: string
orderTime?: number | string
totalCount?: number
totalProductPrice?: number
discountPercent?: number
discountPrice?: number
totalPrice?: number
depositPrice?: number
accountId?: number
status?: number
remark?: string
fileUrl?: string
items?: SaleOrderItem[]
saleUserId?: number
saleUserName?: string
paymentCondition?: number
paymentMethod?: number
outCount?: number
returnCount?: number
productNames?: string
creatorName?: string
hasApprovalRecords?: boolean
}
/** 获取销售订单分页列表 */
export function getSaleOrderPage(params: PageParam & {
no?: string
customerId?: number
productId?: number
orderTime?: string[]
status?: number
creator?: number
outStatus?: string | number
returnStatus?: string | number
outEnable?: boolean
}) {
return http.get<PageResult<SaleOrder>>('/erp/sale-order/page', params)
}
/** 获取销售订单详情 */
export function getSaleOrder(id: number) {
return http.get<SaleOrder>(`/erp/sale-order/get?id=${id}`)
}
/** 创建销售订单 */
export function createSaleOrder(data: SaleOrder) {
return http.post<number>('/erp/sale-order/create', data)
}
/** 更新销售订单 */
export function updateSaleOrder(data: SaleOrder) {
return http.put<boolean>('/erp/sale-order/update', data)
}
/** 更新销售订单状态 */
export function updateSaleOrderStatus(id: number, status: number) {
return http.put<boolean>('/erp/sale-order/update-status', undefined, { id, status })
}
/** 删除销售订单 */
export function deleteSaleOrder(ids: number[]) {
return http.delete<boolean>(`/erp/sale-order/delete?ids=${ids.join(',')}`)
}
/** 导出销售订单 */
export function exportSaleOrder(params: PageParam) {
return http.get<string>('/erp/sale-order/export-excel', params)
}

View 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(',') })
}

View File

@@ -0,0 +1,81 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 销售计划明细 */
export interface SalePlanItem {
id?: number
planId?: number
productId?: number
productName?: string
productUnitName?: string
planCount?: number
productPrice?: number
totalPrice?: number
completedAmount?: number
progress?: number
remark?: string
}
/** 销售计划 */
export interface SalePlan {
id?: number
no?: string
name?: string
customerId?: number
customerName?: string
targetAmount?: number
startTime?: number | string
endTime?: number | string
status?: number
approverId?: number
approverName?: string
remark?: string
items?: SalePlanItem[]
completedAmount?: number
progress?: number
completionStatus?: number
creatorName?: string
createTime?: number | string
}
/** 获取销售计划分页 */
export function getSalePlanPage(params: PageParam & {
no?: string
name?: string
customerId?: number
status?: number
creator?: number
planTime?: string[]
}) {
return http.get<PageResult<SalePlan>>('/erp/sale-plan/page', params)
}
/** 获取销售计划详情 */
export function getSalePlan(id: number) {
return http.get<SalePlan>(`/erp/sale-plan/get?id=${id}`)
}
/** 创建销售计划 */
export function createSalePlan(data: SalePlan) {
return http.post<number>('/erp/sale-plan/create', data)
}
/** 更新销售计划 */
export function updateSalePlan(data: SalePlan) {
return http.put<boolean>('/erp/sale-plan/update', data)
}
/** 更新销售计划状态 */
export function updateSalePlanStatus(id: number, status: number) {
return http.put<boolean>('/erp/sale-plan/update-status', undefined, { id, status })
}
/** 删除销售计划 */
export function deleteSalePlan(ids: number[]) {
return http.delete<boolean>('/erp/sale-plan/delete', undefined, { ids: ids.join(',') })
}
/** 获取销售计划简列表 */
export function getSalePlanSimpleList() {
return http.get<SalePlan[]>('/erp/sale-plan/simple-list')
}

View File

@@ -0,0 +1,92 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 销售退货明细 */
export interface SaleReturnItem {
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
remark?: string
stockCount?: number
totalProductPrice?: number
outCount?: number
returnCount?: number
productSpec?: string
}
/** 销售退货 */
export interface SaleReturn {
id?: number
no?: string
customerId?: number
customerName?: string
accountId?: number
accountName?: string
saleUserId?: number
saleUserName?: string
returnTime?: string | number
orderId?: number
orderNo?: string
totalCount?: number
totalPrice?: number
refundPrice?: 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
items?: SaleReturnItem[]
}
/** 获取销售退货分页列表 */
export function getSaleReturnPage(params: PageParam & {
no?: string
customerId?: number
status?: number
}) {
return http.get<PageResult<SaleReturn>>('/erp/sale-return/page', params)
}
/** 获取销售退货详情 */
export function getSaleReturn(id: number) {
return http.get<SaleReturn>(`/erp/sale-return/get?id=${id}`)
}
/** 创建销售退货 */
export function createSaleReturn(data: SaleReturn) {
return http.post<number>('/erp/sale-return/create', data)
}
/** 更新销售退货 */
export function updateSaleReturn(data: SaleReturn) {
return http.put<boolean>('/erp/sale-return/update', data)
}
/** 更新销售退货状态 */
export function updateSaleReturnStatus(id: number, status: number) {
return http.put<boolean>('/erp/sale-return/update-status', undefined, { id, status })
}
/** 删除销售退货 */
export function deleteSaleReturn(ids: number[]) {
return http.delete<boolean>('/erp/sale-return/delete', undefined, { ids: ids.join(',') })
}

View File

@@ -0,0 +1,64 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 盘点单项 */
export interface StockCheckItem {
id?: number
stockCheckId?: number
warehouseId?: number
warehouseName?: string
productId?: number
productName?: string
productUnitName?: string
stockCount?: number
actualCount?: number
count?: number
productPrice?: number
totalPrice?: number
remark?: string
}
/** 盘点单信息 */
export interface StockCheck {
id?: number
no?: string
checkTime?: string
totalCount?: number
totalPrice?: number
status?: number
remark?: string
items?: StockCheckItem[]
productNames?: string
creatorName?: string
createTime?: number
}
/** 获取盘点单分页列表 */
export function getStockCheckPage(params: PageParam) {
return http.get<PageResult<StockCheck>>('/erp/stock-check/page', params)
}
/** 获取盘点单详情 */
export function getStockCheck(id: number) {
return http.get<StockCheck>(`/erp/stock-check/get?id=${id}`)
}
/** 创建盘点单 */
export function createStockCheck(data: StockCheck) {
return http.post<number>('/erp/stock-check/create', data)
}
/** 更新盘点单 */
export function updateStockCheck(data: StockCheck) {
return http.put<boolean>('/erp/stock-check/update', data)
}
/** 更新盘点单状态 */
export function updateStockCheckStatus(id: number, status: number) {
return http.put<boolean>('/erp/stock-check/update-status', undefined, { id, status })
}
/** 删除盘点单 */
export function deleteStockCheck(ids: number[]) {
return http.delete<boolean>('/erp/stock-check/delete', undefined, { ids: ids.join(',') })
}

View File

@@ -0,0 +1,63 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 报溢单项 */
export interface StockGainItem {
id?: number
stockGainId?: number
warehouseId?: number
warehouseName?: string
productId?: number
productName?: string
productUnitName?: string
count?: number
productPrice?: number
totalPrice?: number
remark?: string
}
/** 报溢单信息 */
export interface StockGain {
id?: number
no?: string
gainTime?: string
totalCount?: number
totalPrice?: number
status?: number
reason?: string
remark?: string
items?: StockGainItem[]
productNames?: string
creatorName?: string
createTime?: number
}
/** 获取报溢单分页列表 */
export function getStockGainPage(params: PageParam) {
return http.get<PageResult<StockGain>>('/erp/stock-gain/page', params)
}
/** 获取报溢单详情 */
export function getStockGain(id: number) {
return http.get<StockGain>(`/erp/stock-gain/get?id=${id}`)
}
/** 创建报溢单 */
export function createStockGain(data: StockGain) {
return http.post<number>('/erp/stock-gain/create', data)
}
/** 更新报溢单 */
export function updateStockGain(data: StockGain) {
return http.put<boolean>('/erp/stock-gain/update', data)
}
/** 更新报溢单状态 */
export function updateStockGainStatus(id: number, status: number) {
return http.put<boolean>('/erp/stock-gain/update-status', undefined, { id, status })
}
/** 删除报溢单 */
export function deleteStockGain(ids: number[]) {
return http.delete<boolean>('/erp/stock-gain/delete', undefined, { ids: ids.join(',') })
}

View File

@@ -0,0 +1,64 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 其他入库单项 */
export interface StockInItem {
id?: number
stockInId?: number
warehouseId?: number
warehouseName?: string
productId?: number
productName?: string
productUnitName?: string
count?: number
productPrice?: number
totalPrice?: number
remark?: string
}
/** 其他入库单信息 */
export interface StockIn {
id?: number
no?: string
supplierId?: number
supplierName?: string
inTime?: string
totalCount?: number
totalPrice?: number
status?: number
remark?: string
items?: StockInItem[]
productNames?: string
creatorName?: string
createTime?: number
}
/** 获取其他入库单分页列表 */
export function getStockInPage(params: PageParam) {
return http.get<PageResult<StockIn>>('/erp/stock-in/page', params)
}
/** 获取其他入库单详情 */
export function getStockIn(id: number) {
return http.get<StockIn>(`/erp/stock-in/get?id=${id}`)
}
/** 创建其他入库单 */
export function createStockIn(data: StockIn) {
return http.post<number>('/erp/stock-in/create', data)
}
/** 更新其他入库单 */
export function updateStockIn(data: StockIn) {
return http.put<boolean>('/erp/stock-in/update', data)
}
/** 更新其他入库单状态 */
export function updateStockInStatus(id: number, status: number) {
return http.put<boolean>('/erp/stock-in/update-status', undefined, { id, status })
}
/** 删除其他入库单 */
export function deleteStockIn(ids: number[]) {
return http.delete<boolean>('/erp/stock-in/delete', undefined, { ids: ids.join(',') })
}

View File

@@ -0,0 +1,63 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 报损单项 */
export interface StockLossItem {
id?: number
stockLossId?: number
warehouseId?: number
warehouseName?: string
productId?: number
productName?: string
productUnitName?: string
count?: number
productPrice?: number
totalPrice?: number
remark?: string
}
/** 报损单信息 */
export interface StockLoss {
id?: number
no?: string
lossTime?: string
totalCount?: number
totalPrice?: number
status?: number
reason?: string
remark?: string
items?: StockLossItem[]
productNames?: string
creatorName?: string
createTime?: number
}
/** 获取报损单分页列表 */
export function getStockLossPage(params: PageParam) {
return http.get<PageResult<StockLoss>>('/erp/stock-loss/page', params)
}
/** 获取报损单详情 */
export function getStockLoss(id: number) {
return http.get<StockLoss>(`/erp/stock-loss/get?id=${id}`)
}
/** 创建报损单 */
export function createStockLoss(data: StockLoss) {
return http.post<number>('/erp/stock-loss/create', data)
}
/** 更新报损单 */
export function updateStockLoss(data: StockLoss) {
return http.put<boolean>('/erp/stock-loss/update', data)
}
/** 更新报损单状态 */
export function updateStockLossStatus(id: number, status: number) {
return http.put<boolean>('/erp/stock-loss/update-status', undefined, { id, status })
}
/** 删除报损单 */
export function deleteStockLoss(ids: number[]) {
return http.delete<boolean>('/erp/stock-loss/delete', undefined, { ids: ids.join(',') })
}

View File

@@ -0,0 +1,64 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 调拨单项 */
export interface StockMoveItem {
id?: number
stockMoveId?: number
fromWarehouseId?: number
fromWarehouseName?: string
toWarehouseId?: number
toWarehouseName?: string
productId?: number
productName?: string
productUnitName?: string
count?: number
productPrice?: number
totalPrice?: number
remark?: string
}
/** 调拨单信息 */
export interface StockMove {
id?: number
no?: string
moveTime?: string
totalCount?: number
totalPrice?: number
status?: number
remark?: string
items?: StockMoveItem[]
productNames?: string
creatorName?: string
createTime?: number
}
/** 获取调拨单分页列表 */
export function getStockMovePage(params: PageParam) {
return http.get<PageResult<StockMove>>('/erp/stock-move/page', params)
}
/** 获取调拨单详情 */
export function getStockMove(id: number) {
return http.get<StockMove>(`/erp/stock-move/get?id=${id}`)
}
/** 创建调拨单 */
export function createStockMove(data: StockMove) {
return http.post<number>('/erp/stock-move/create', data)
}
/** 更新调拨单 */
export function updateStockMove(data: StockMove) {
return http.put<boolean>('/erp/stock-move/update', data)
}
/** 更新调拨单状态 */
export function updateStockMoveStatus(id: number, status: number) {
return http.put<boolean>('/erp/stock-move/update-status', undefined, { id, status })
}
/** 删除调拨单 */
export function deleteStockMove(ids: number[]) {
return http.delete<boolean>('/erp/stock-move/delete', undefined, { ids: ids.join(',') })
}

View File

@@ -0,0 +1,64 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 其他出库单项 */
export interface StockOutItem {
id?: number
stockOutId?: number
warehouseId?: number
warehouseName?: string
productId?: number
productName?: string
productUnitName?: string
count?: number
productPrice?: number
totalPrice?: number
remark?: string
}
/** 其他出库单信息 */
export interface StockOut {
id?: number
no?: string
customerId?: number
customerName?: string
outTime?: string
totalCount?: number
totalPrice?: number
status?: number
remark?: string
items?: StockOutItem[]
productNames?: string
creatorName?: string
createTime?: number
}
/** 获取其他出库单分页列表 */
export function getStockOutPage(params: PageParam) {
return http.get<PageResult<StockOut>>('/erp/stock-out/page', params)
}
/** 获取其他出库单详情 */
export function getStockOut(id: number) {
return http.get<StockOut>(`/erp/stock-out/get?id=${id}`)
}
/** 创建其他出库单 */
export function createStockOut(data: StockOut) {
return http.post<number>('/erp/stock-out/create', data)
}
/** 更新其他出库单 */
export function updateStockOut(data: StockOut) {
return http.put<boolean>('/erp/stock-out/update', data)
}
/** 更新其他出库单状态 */
export function updateStockOutStatus(id: number, status: number) {
return http.put<boolean>('/erp/stock-out/update-status', undefined, { id, status })
}
/** 删除其他出库单 */
export function deleteStockOut(ids: number[]) {
return http.delete<boolean>('/erp/stock-out/delete', undefined, { ids: ids.join(',') })
}

View File

@@ -0,0 +1,45 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 产品库存明细信息 */
export interface StockRecord {
id?: number
productId?: number
productName?: string
unitName?: string
categoryName?: string
warehouseId?: number
warehouseName?: string
count?: number
totalCount?: number
bizType?: number
bizId?: number
bizItemId?: number
bizNo?: string
unitPrice?: number
stockValue?: number
creatorName?: string
createTime?: number
}
/** 业务类型选项 */
export const BIZ_TYPE_OPTIONS = [
{ value: 1, label: '采购入库' },
{ value: 2, label: '采购退货' },
{ value: 3, label: '销售出库' },
{ value: 4, label: '销售退货' },
{ value: 10, label: '其他入库' },
{ value: 11, label: '其他出库' },
{ value: 12, label: '库存调拨' },
{ value: 13, label: '库存盘点' },
]
/** 获取产品库存明细分页列表 */
export function getStockRecordPage(params: PageParam) {
return http.get<PageResult<StockRecord>>('/erp/stock-record/page', params)
}
/** 获取产品库存明细详情 */
export function getStockRecord(id: number) {
return http.get<StockRecord>(`/erp/stock-record/get?id=${id}`)
}

View File

@@ -0,0 +1,40 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 产品库存信息 */
export interface Stock {
id?: number
productId?: number
productName?: string
unitName?: string
categoryName?: string
warehouseId?: number
warehouseName?: string
count?: number
unitPrice?: number
stockValue?: number
}
/** 获取产品库存分页列表 */
export function getStockPage(params: PageParam) {
return http.get<PageResult<Stock>>('/erp/stock/page', params)
}
/** 获取产品库存详情 */
export function getStock(id: number) {
return http.get<Stock>(`/erp/stock/get?id=${id}`)
}
/** 获取产品库存详情通过产品ID和仓库ID */
export function getStock2(productId: number, warehouseId: number) {
return http.get<Stock>('/erp/stock/get', { productId, warehouseId })
}
/** 获取产品库存数量 */
export function getStockCount(productId: number, warehouseId?: number) {
const params: Record<string, any> = { productId }
if (warehouseId) {
params.warehouseId = warehouseId
}
return http.get<number>('/erp/stock/get-count', params)
}

View File

@@ -0,0 +1,57 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 供应商信息 */
export interface Supplier {
id?: number
name?: string
contact?: string
mobile?: string
telephone?: string
email?: string
fax?: string
remark?: string
status?: number
sort?: number
taxNo?: string
taxPercent?: number
bankName?: string
bankAccount?: string
bankAddress?: string
}
/** 供应商精简信息 */
export interface SupplierSimple {
id: number
name: string
}
/** 获取供应商分页列表 */
export function getSupplierPage(params: PageParam) {
return http.get<PageResult<Supplier>>('/erp/supplier/page', { ...params, type: 1 })
}
/** 获取供应商详情 */
export function getSupplier(id: number) {
return http.get<Supplier>(`/erp/supplier/get?id=${id}`)
}
/** 创建供应商 */
export function createSupplier(data: Supplier) {
return http.post<number>('/erp/supplier/create', data)
}
/** 更新供应商 */
export function updateSupplier(data: Supplier) {
return http.put<boolean>('/erp/supplier/update', data)
}
/** 删除供应商 */
export function deleteSupplier(id: number) {
return http.delete<boolean>(`/erp/supplier/delete?id=${id}`)
}
/** 获取供应商精简列表 */
export function getSupplierSimpleList() {
return http.get<SupplierSimple[]>('/erp/supplier/simple-list')
}

View File

@@ -0,0 +1,69 @@
import type { PageParam, PageResult } from '@/http/types'
import { http } from '@/http/http'
/** 仓库信息 */
export interface Warehouse {
id?: number
name?: string
address?: string
sort?: number
remark?: string
principal?: string
warehousePrice?: number
truckagePrice?: number
status?: number
defaultStatus?: boolean
createTime?: number
}
/** 获取仓库分页列表 */
export function getWarehousePage(params: PageParam) {
return http.get<PageResult<Warehouse>>('/erp/warehouse/page', params)
}
/** 获取仓库详情 */
export function getWarehouse(id: number) {
return http.get<Warehouse>(`/erp/warehouse/get?id=${id}`)
}
/** 创建仓库 */
export function createWarehouse(data: Warehouse) {
return http.post<number>('/erp/warehouse/create', data)
}
/** 更新仓库 */
export function updateWarehouse(data: Warehouse) {
return http.put<boolean>('/erp/warehouse/update', data)
}
/** 更新仓库默认状态 */
export function updateWarehouseDefaultStatus(id: number, defaultStatus: boolean) {
return http.put<boolean>('/erp/warehouse/update-default-status', undefined, { id, defaultStatus })
}
/** 删除仓库 */
export function deleteWarehouse(id: number) {
return http.delete<boolean>(`/erp/warehouse/delete?id=${id}`)
}
/** 仓库精简信息 */
export interface WarehouseSimple {
id?: number
name?: string
}
/** 获取仓库精简列表 */
export function getWarehouseSimpleList() {
return http.get<Warehouse[]>('/erp/warehouse/simple-list')
}
/** 仓库条码信息 */
export interface WarehouseByBarCode {
id?: number
name?: string
}
/** 通过仓库条码获取仓库 */
export function getWarehouseByBarCode(barCode: string) {
return http.get<WarehouseByBarCode>(`/erp/warehouse/get-by-bar-code?barCode=${encodeURIComponent(barCode)}`)
}

View File

@@ -0,0 +1,437 @@
<template>
<view class="yd-page-container">
<!-- 顶部导航栏 -->
<wd-navbar
title="闭环操作台"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 流程说明 -->
<view class="mx-24rpx mt-20rpx mb-16rpx px-24rpx py-16rpx rounded-12rpx bg-[#e6f7ff] text-24rpx text-[#1890ff]">
最小闭环操作台采收 分拣 装箱 入库 发运 签收
</view>
<!-- 数量/重量看板 -->
<view class="mx-24rpx mb-20rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
<view class="px-24rpx py-20rpx border-b border-[#f0f0f0] text-28rpx text-[#333] font-semibold">
数量 / 重量看板
</view>
<view class="p-24rpx">
<view class="flex flex-wrap">
<view class="w-1/2 mb-16rpx">
<text class="text-24rpx text-[#999]">当前批次ID</text>
<text class="ml-12rpx text-26rpx text-[#333]">{{ metricPanel.batchId ?? '-' }}</text>
</view>
<view class="w-1/2 mb-16rpx">
<text class="text-24rpx text-[#999]">最近更新</text>
<text class="ml-12rpx text-26rpx text-[#333]">{{ metricPanel.updatedAt || '-' }}</text>
</view>
<view class="w-1/2 mb-16rpx">
<text class="text-24rpx text-[#999]">采收数量</text>
<text class="ml-12rpx text-26rpx text-[#333]">{{ formatMetric(metricPanel.harvestQuantity, metricPanel.harvestUnit) }}</text>
</view>
<view class="w-1/2 mb-16rpx">
<text class="text-24rpx text-[#999]">分拣称重</text>
<text class="ml-12rpx text-26rpx text-[#333]">{{ formatMetric(metricPanel.sortingWeight, 'kg') }}</text>
</view>
<view class="w-1/2">
<text class="text-24rpx text-[#999]">装箱净重</text>
<text class="ml-12rpx text-26rpx text-[#333]">{{ formatMetric(metricPanel.packingNetWeight, 'kg') }}</text>
</view>
<view class="w-1/2">
<text class="text-24rpx text-[#999]">发运箱数</text>
<text class="ml-12rpx text-26rpx text-[#333]">{{ formatMetric(metricPanel.shipmentBoxCount, '箱') }}</text>
</view>
</view>
</view>
</view>
<!-- 扫码按钮 -->
<view class="mx-24rpx mb-20rpx flex items-center justify-between">
<view class="text-28rpx text-[#333]">快捷操作</view>
<wd-button size="small" type="info" plain icon="scan" @click="handleScanCode">
扫码填充批次ID
</wd-button>
</view>
<!-- 操作步骤 Tab -->
<view class="mx-24rpx mb-20rpx">
<wd-tabs v-model="activeTab">
<wd-tab title="采收" name="harvest" />
<wd-tab title="分拣" name="sorting" />
<wd-tab title="装箱" name="packing" />
<wd-tab title="入库" name="warehouse" />
<wd-tab title="发运" name="shipment" />
<wd-tab title="签收" name="sign" />
</wd-tabs>
</view>
<!-- 采收表单 -->
<view v-show="activeTab === 'harvest'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
<view class="p-24rpx">
<wd-cell-group border>
<wd-picker
v-model="harvestForm.batchType"
label="批次类型"
:columns="batchTypeColumns"
label-width="200rpx"
/>
<wd-input v-model="harvestForm.productName" label="产品名称" label-width="200rpx" placeholder="请输入产品名称" />
<wd-input v-model="harvestForm.plotName" label="地块名称" label-width="200rpx" placeholder="请输入地块名称" />
<wd-input
v-model="harvestForm.quantity"
label="数量"
label-width="200rpx"
placeholder="请输入数量"
type="number"
/>
<wd-input v-model="harvestForm.unit" label="单位" label-width="200rpx" placeholder="kg" />
</wd-cell-group>
<view class="mt-32rpx">
<wd-button type="primary" block @click="onHarvest">提交采收</wd-button>
</view>
</view>
</view>
<!-- 分拣表单 -->
<view v-show="activeTab === 'sorting'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
<view class="p-24rpx">
<wd-cell-group border>
<wd-input
v-model="sortingForm.batchId"
label="批次ID"
label-width="200rpx"
placeholder="请输入批次ID"
type="number"
/>
<wd-input
v-model="sortingForm.weightResult"
label="称重结果"
label-width="200rpx"
placeholder="请输入称重结果"
type="digit"
/>
<wd-input v-model="sortingForm.unqualifiedCategory" label="不合格分类" label-width="200rpx" placeholder="请输入不合格分类" />
</wd-cell-group>
<view class="mt-32rpx">
<wd-button type="primary" block @click="onSorting">提交分拣</wd-button>
</view>
</view>
</view>
<!-- 装箱表单 -->
<view v-show="activeTab === 'packing'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
<view class="p-24rpx">
<wd-cell-group border>
<wd-input
v-model="packingForm.batchId"
label="批次ID"
label-width="200rpx"
placeholder="请输入批次ID"
type="number"
/>
<wd-input
v-model="packingForm.netWeight"
label="净重"
label-width="200rpx"
placeholder="请输入净重"
type="digit"
/>
<wd-input v-model="packingForm.labelCode" label="标签编码" label-width="200rpx" placeholder="请输入标签编码" />
</wd-cell-group>
<view class="mt-32rpx">
<wd-button type="primary" block @click="onPacking">提交装箱</wd-button>
</view>
</view>
</view>
<!-- 入库表单 -->
<view v-show="activeTab === 'warehouse'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
<view class="p-24rpx">
<wd-cell-group border>
<wd-input
v-model="warehouseForm.batchId"
label="批次ID"
label-width="200rpx"
placeholder="请输入批次ID"
type="number"
/>
<wd-picker
v-model="warehouseForm.inMode"
label="入库模式"
:columns="inModeColumns"
label-width="200rpx"
/>
</wd-cell-group>
<view class="mt-32rpx">
<wd-button type="primary" block @click="onWarehouseIn">提交入库</wd-button>
</view>
</view>
</view>
<!-- 发运表单 -->
<view v-show="activeTab === 'shipment'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
<view class="p-24rpx">
<wd-cell-group border>
<wd-input
v-model="shipmentForm.batchId"
label="批次ID"
label-width="200rpx"
placeholder="请输入批次ID"
type="number"
/>
<wd-input v-model="shipmentForm.vehicleNo" label="车牌号" label-width="200rpx" placeholder="请输入车牌号" />
<wd-input
v-model="shipmentForm.boxCount"
label="箱数"
label-width="200rpx"
placeholder="请输入箱数"
type="number"
/>
</wd-cell-group>
<view class="mt-32rpx">
<wd-button type="primary" block @click="onDispatch">提交发运</wd-button>
</view>
</view>
</view>
<!-- 签收表单 -->
<view v-show="activeTab === 'sign'" class="mx-24rpx rounded-12rpx bg-white shadow-sm overflow-hidden">
<view class="p-24rpx">
<wd-cell-group border>
<wd-input
v-model="signForm.batchId"
label="批次ID"
label-width="200rpx"
placeholder="请输入批次ID"
type="number"
/>
<wd-input v-model="signForm.remark" label="备注" label-width="200rpx" placeholder="请输入备注" />
</wd-cell-group>
<view class="mt-32rpx">
<wd-button type="primary" block @click="onSign">提交签收</wd-button>
</view>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import { computed, reactive, ref } from 'vue'
import {
dispatchShipment,
signShipment,
submitHarvest,
submitPacking,
submitSorting,
submitWarehouseIn
} from '@/api/agri/biz/flow'
import { BATCH_TYPE_OPTIONS, IN_MODE_OPTIONS } from '@/utils/agriTraceDict'
import { navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const activeTab = ref('harvest')
const harvestForm = reactive({
batchType: 'HARVEST',
productName: '',
plotName: '',
quantity: '' as string | number,
unit: 'kg'
})
const sortingForm = reactive({
batchId: '' as string | number,
weightResult: '' as string | number,
unqualifiedCategory: ''
})
const packingForm = reactive({
batchId: '' as string | number,
netWeight: '' as string | number,
labelCode: ''
})
const warehouseForm = reactive({
batchId: '' as string | number,
inMode: 'BOX'
})
const shipmentForm = reactive({
batchId: '' as string | number,
vehicleNo: '',
boxCount: '' as string | number
})
const signForm = reactive({
batchId: '' as string | number,
remark: ''
})
const metricPanel = reactive({
batchId: undefined as number | undefined,
harvestQuantity: undefined as number | undefined,
harvestUnit: 'kg',
sortingWeight: undefined as number | undefined,
packingNetWeight: undefined as number | undefined,
shipmentBoxCount: undefined as number | undefined,
updatedAt: ''
})
/** 批次类型下拉列 */
const batchTypeColumns = computed(() => [
BATCH_TYPE_OPTIONS.map(v => ({ value: v.value, label: v.label }))
])
/** 入库模式下拉列 */
const inModeColumns = computed(() => [
IN_MODE_OPTIONS.map(v => ({ value: v.value, label: v.label }))
])
const formatMetric = (value?: number, unit?: string) => {
if (value === undefined || value === null) {
return '-'
}
return unit ? `${value} ${unit}` : `${value}`
}
const refreshMetricPanel = (patch: Partial<typeof metricPanel>) => {
Object.assign(metricPanel, patch, {
updatedAt: new Date().toLocaleString()
})
}
const syncBatchIdToFollowUpForms = (batchId: number) => {
sortingForm.batchId = batchId
packingForm.batchId = batchId
warehouseForm.batchId = batchId
shipmentForm.batchId = batchId
signForm.batchId = batchId
}
function handleBack() {
navigateBackPlus()
}
const onHarvest = async () => {
const id = await submitHarvest({
...harvestForm,
quantity: harvestForm.quantity ? Number(harvestForm.quantity) : undefined
})
refreshMetricPanel({
batchId: id,
harvestQuantity: harvestForm.quantity ? Number(harvestForm.quantity) : undefined,
harvestUnit: harvestForm.unit || 'kg'
})
syncBatchIdToFollowUpForms(id)
uni.showToast({ title: `采收成功批次ID${id}`, icon: 'none' })
activeTab.value = 'sorting'
}
const onSorting = async () => {
await submitSorting({
batchId: Number(sortingForm.batchId),
weightResult: sortingForm.weightResult ? Number(sortingForm.weightResult) : undefined,
unqualifiedCategory: sortingForm.unqualifiedCategory || undefined
})
refreshMetricPanel({
batchId: Number(sortingForm.batchId),
sortingWeight: sortingForm.weightResult ? Number(sortingForm.weightResult) : undefined
})
uni.showToast({ title: '分拣成功', icon: 'success' })
activeTab.value = 'packing'
}
const onPacking = async () => {
await submitPacking({
batchId: Number(packingForm.batchId),
netWeight: packingForm.netWeight ? Number(packingForm.netWeight) : undefined,
labelCode: packingForm.labelCode || undefined
})
refreshMetricPanel({
batchId: Number(packingForm.batchId),
packingNetWeight: packingForm.netWeight ? Number(packingForm.netWeight) : undefined
})
uni.showToast({ title: '装箱成功', icon: 'success' })
activeTab.value = 'warehouse'
}
const onWarehouseIn = async () => {
await submitWarehouseIn({
batchId: Number(warehouseForm.batchId),
inMode: warehouseForm.inMode || undefined
})
uni.showToast({ title: '入库成功', icon: 'success' })
activeTab.value = 'shipment'
}
const onDispatch = async () => {
await dispatchShipment({
batchId: Number(shipmentForm.batchId),
vehicleNo: shipmentForm.vehicleNo,
boxCount: shipmentForm.boxCount ? Number(shipmentForm.boxCount) : undefined
})
refreshMetricPanel({
batchId: Number(shipmentForm.batchId),
shipmentBoxCount: shipmentForm.boxCount ? Number(shipmentForm.boxCount) : undefined
})
uni.showToast({ title: '发运成功', icon: 'success' })
activeTab.value = 'sign'
}
const onSign = async () => {
await signShipment({
batchId: Number(signForm.batchId),
remark: signForm.remark || undefined
})
uni.showToast({ title: '签收成功', icon: 'success' })
}
/** 扫码填充批次ID */
const handleScanCode = () => {
// #ifdef MP-WEIXIN
uni.scanCode({
onlyFromCamera: false,
scanType: ['qrCode', 'barCode'],
success: (res) => {
const result = res.result
// 尝试解析批次ID支持纯数字或JSON格式
let batchId: number | undefined
try {
const parsed = JSON.parse(result)
batchId = parsed.batchId || parsed.id
} catch {
// 如果不是JSON尝试直接解析为数字
const num = Number(result)
if (!isNaN(num) && num > 0) {
batchId = num
}
}
if (batchId) {
syncBatchIdToFollowUpForms(batchId)
refreshMetricPanel({ batchId })
uni.showToast({ title: `已填充批次ID: ${batchId}`, icon: 'none' })
} else {
uni.showToast({ title: '无法识别批次ID', icon: 'none' })
}
},
fail: () => {
uni.showToast({ title: '扫码取消或失败', icon: 'none' })
}
})
// #endif
// #ifndef MP-WEIXIN
uni.showToast({ title: '当前环境不支持扫码', icon: 'none' })
// #endif
}
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,334 @@
<template>
<view class="yd-page-container">
<!-- 顶部导航栏 -->
<wd-navbar
title="溯源快照"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 搜索组件 -->
<view class="flex items-center px-24rpx">
<view class="flex-1" @click="searchVisible = true">
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
</view>
<wd-button size="small" type="primary" icon="scan" class="ml-16rpx" @click="handleScanQuery">
扫码
</wd-button>
</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="handleDetail(item)"
>
<view class="p-24rpx">
<!-- 头部溯源码 + 批次号 -->
<view class="mb-16rpx flex items-center justify-between">
<view class="text-28rpx text-[#333] font-semibold flex-1 truncate">
{{ item.traceCode || '-' }}
</view>
<view class="text-24rpx text-[#1890ff] ml-12rpx">
{{ item.batchNo || '' }}
</view>
</view>
<!-- 产品名 + 地块名 -->
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">产品</text>
<text>{{ item.productName || '-' }}</text>
</view>
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">地块</text>
<text>{{ item.plotName || '-' }}</text>
</view>
<!-- 采收信息 -->
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">采收</text>
<text>{{ item.harvestOperatorName || '-' }} / {{ formatTime(item.harvestTime) }}</text>
</view>
<!-- 装箱信息 -->
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">装箱</text>
<text>{{ item.packingOperatorName || '-' }} / {{ formatTime(item.packingTime) }}</text>
</view>
<!-- 入库信息 -->
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">入库</text>
<text>{{ item.warehouseOperatorName || '-' }} / {{ formatTime(item.warehouseTime) }}</text>
</view>
<!-- 发运信息 -->
<view class="flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">发运</text>
<text>{{ item.shipmentOperatorName || '-' }} / {{ item.vehicleNo || '-' }}</text>
</view>
</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-popup v-model="searchVisible" position="top" @close="searchVisible = 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="searchForm.batchNo" placeholder="请输入批次号" no-border />
</view>
<view class="yd-search-form-item">
<view class="yd-search-form-label">溯源码</view>
<wd-input v-model="searchForm.traceCode" placeholder="请输入溯源码" no-border />
</view>
<view class="yd-search-form-item">
<view class="yd-search-form-label">产品名</view>
<wd-input v-model="searchForm.productName" placeholder="请输入产品名称" no-border />
</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 class="mt-20rpx">
<wd-button type="info" block plain @click="handleTraceCodeQuery">按溯源码查单条</wd-button>
</view>
</view>
</wd-popup>
<!-- 详情弹窗 -->
<wd-popup v-model="detailVisible" position="bottom" custom-style="height: 70%;">
<view class="p-24rpx">
<view class="text-32rpx text-[#333] font-semibold mb-24rpx">溯源详情</view>
<view v-if="currentDetail" class="text-26rpx text-[#666]">
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">ID</text><text>{{ currentDetail.id }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">溯源码</text><text class="flex-1 break-all">{{ currentDetail.traceCode }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">批次号</text><text>{{ currentDetail.batchNo }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">产品名</text><text>{{ currentDetail.productName || '-' }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">地块名</text><text>{{ currentDetail.plotName || '-' }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">采收操作人</text><text>{{ currentDetail.harvestOperatorName || '-' }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">采收时间</text><text>{{ formatTime(currentDetail.harvestTime) }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">装箱操作人</text><text>{{ currentDetail.packingOperatorName || '-' }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">装箱时间</text><text>{{ formatTime(currentDetail.packingTime) }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">入库操作人</text><text>{{ currentDetail.warehouseOperatorName || '-' }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">入库时间</text><text>{{ formatTime(currentDetail.warehouseTime) }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">发运操作人</text><text>{{ currentDetail.shipmentOperatorName || '-' }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">发运时间</text><text>{{ formatTime(currentDetail.shipmentTime) }}</text></view>
<view class="mb-16rpx flex"><text class="text-[#999] w-160rpx">车牌号</text><text>{{ currentDetail.vehicleNo || '-' }}</text></view>
</view>
<wd-button type="primary" block class="mt-32rpx" @click="detailVisible = false">关闭</wd-button>
</view>
</wd-popup>
</view>
</template>
<script lang="ts" setup>
import type { AgriTraceSnapshotVO } from '@/api/agri/trace/snapshot'
import type { LoadMoreState } from '@/http/types'
import { onReachBottom } from '@dcloudio/uni-app'
import { computed, onMounted, reactive, ref } from 'vue'
import {
getAgriTraceSnapshotByTraceCode,
getAgriTraceSnapshotPage
} from '@/api/agri/trace/snapshot'
import { getNavbarHeight, navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const total = ref(0)
const list = ref<AgriTraceSnapshotVO[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<Record<string, any>>({
pageNo: 1,
pageSize: 10,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
batchNo: '',
traceCode: '',
productName: ''
})
// 详情弹窗
const detailVisible = ref(false)
const currentDetail = ref<AgriTraceSnapshotVO | null>(null)
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.batchNo) conditions.push(`批次:${searchForm.batchNo}`)
if (searchForm.traceCode) conditions.push(`溯源码:${searchForm.traceCode}`)
if (searchForm.productName) conditions.push(`产品:${searchForm.productName}`)
return conditions.length > 0 ? conditions.join(' | ') : '搜索溯源快照'
})
/** 格式化时间 */
function formatTime(time?: string | number) {
if (!time) return '-'
// 如果是时间戳(数字),转换为日期字符串
if (typeof time === 'number') {
const date = new Date(time)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}`
}
// 如果是字符串,处理 ISO 格式
if (typeof time === 'string') {
return time.replace('T', ' ').substring(0, 16)
}
return '-'
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 查询列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params: Record<string, any> = { ...queryParams.value }
if (searchForm.batchNo) params.batchNo = searchForm.batchNo
if (searchForm.traceCode) params.traceCode = searchForm.traceCode
if (searchForm.productName) params.productName = searchForm.productName
const data = await getAgriTraceSnapshotPage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
pageNo: 1,
pageSize: queryParams.value.pageSize,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.batchNo = ''
searchForm.traceCode = ''
searchForm.productName = ''
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10 }
list.value = []
getList()
}
/** 按溯源码查单条 */
async function handleTraceCodeQuery() {
if (!searchForm.traceCode) {
uni.showToast({ title: '请先输入溯源码', icon: 'none' })
return
}
searchVisible.value = false
loadMoreState.value = 'loading'
try {
const data = await getAgriTraceSnapshotByTraceCode(searchForm.traceCode)
list.value = data ? [data] : []
total.value = list.value.length
loadMoreState.value = 'finished'
} catch {
loadMoreState.value = 'error'
}
}
/** 查看详情 */
function handleDetail(item: AgriTraceSnapshotVO) {
currentDetail.value = item
detailVisible.value = true
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 扫码查询 */
function handleScanQuery() {
// #ifdef MP-WEIXIN
uni.scanCode({
onlyFromCamera: false,
scanType: ['qrCode', 'barCode'],
success: async (res) => {
const result = res.result
// 尝试解析溯源码支持纯字符串或JSON格式
let traceCode: string | undefined
try {
const parsed = JSON.parse(result)
traceCode = parsed.traceCode || parsed.code
} catch {
// 如果不是JSON直接使用扫码结果
traceCode = result
}
if (traceCode) {
loadMoreState.value = 'loading'
try {
const data = await getAgriTraceSnapshotByTraceCode(traceCode)
list.value = data ? [data] : []
total.value = list.value.length
loadMoreState.value = 'finished'
if (data) {
uni.showToast({ title: '查询成功', icon: 'success' })
} else {
uni.showToast({ title: '未找到该溯源码', icon: 'none' })
}
} catch {
loadMoreState.value = 'error'
uni.showToast({ title: '查询失败', icon: 'none' })
}
} else {
uni.showToast({ title: '无法识别溯源码', icon: 'none' })
}
},
fail: () => {
uni.showToast({ title: '扫码取消或失败', icon: 'none' })
}
})
// #endif
// #ifndef MP-WEIXIN
uni.showToast({ title: '当前环境不支持扫码', icon: 'none' })
// #endif
}
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,372 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<!-- 基础信息 -->
<wd-cell-group title="基础信息" border>
<wd-input
v-model="formData.name"
label="名称"
label-width="180rpx"
placeholder="请输入客户名称"
prop="name"
clearable
/>
<wd-input
v-model="formData.contact"
label="联系人"
label-width="180rpx"
placeholder="请输入联系人"
clearable
/>
<wd-input
v-model="formData.mobile"
label="手机号码"
label-width="180rpx"
placeholder="请输入手机号码"
type="number"
clearable
/>
<wd-input
v-model="formData.telephone"
label="联系电话"
label-width="180rpx"
placeholder="请输入联系电话"
clearable
/>
<wd-input
v-model="formData.email"
label="电子邮箱"
label-width="180rpx"
placeholder="请输入电子邮箱"
clearable
/>
<wd-cell title="企业类型" title-width="180rpx" center>
<wd-picker
v-model="formData.companyType"
:columns="companyTypeColumns"
label=""
placeholder="请选择企业类型"
@confirm="onCompanyTypeConfirm"
/>
</wd-cell>
<wd-input
v-model="formData.businessScale"
label="企业规模"
label-width="180rpx"
placeholder="请输入企业规模"
clearable
/>
<wd-cell title="客户来源" title-width="180rpx" center>
<wd-picker
v-model="formData.leadSourceType"
:columns="leadSourceTypeColumns"
label=""
placeholder="请选择来源类型"
@confirm="onLeadSourceTypeConfirm"
/>
</wd-cell>
</wd-cell-group>
<!-- 财务信息 -->
<wd-cell-group title="财务信息" border>
<wd-input
v-model="formData.taxNo"
label="纳税人识别号"
label-width="180rpx"
placeholder="请输入纳税人识别号"
clearable
/>
<wd-input
v-model="formData.bankName"
label="开户行"
label-width="180rpx"
placeholder="请输入开户行"
clearable
/>
<wd-input
v-model="formData.bankAccount"
label="开户账号"
label-width="180rpx"
placeholder="请输入开户账号"
clearable
/>
<wd-input
v-model="formData.bankAddress"
label="开户地址"
label-width="180rpx"
placeholder="请输入开户地址"
clearable
/>
</wd-cell-group>
<!-- 偏好信息 -->
<wd-cell-group title="偏好信息" border>
<wd-input
v-model="formData.preferredProducts"
label="偏好产品"
label-width="180rpx"
placeholder="请输入偏好产品或品类"
clearable
/>
<wd-input
v-model="formData.preferredPackaging"
label="偏好包装"
label-width="180rpx"
placeholder="请输入偏好包装形式"
clearable
/>
<wd-input
v-model="formData.deliveryCyclePrefer"
label="偏好交期"
label-width="180rpx"
placeholder="请输入偏好交期/周期"
clearable
/>
</wd-cell-group>
<!-- 统计信息 -->
<wd-cell-group title="统计信息" border>
<wd-input
:model-value="formatInteger(formData.annualOrderNums)"
label="年度订单数"
label-width="180rpx"
placeholder="系统自动生成"
disabled
/>
<wd-input
:model-value="formatAmount(formData.annualOrderAmounts)"
label="年度订单额"
label-width="180rpx"
placeholder="系统自动生成"
disabled
/>
<wd-input
:model-value="formatAmount(formData.annualReceivedAmounts)"
label="年度已收款"
label-width="180rpx"
placeholder="系统自动生成"
disabled
/>
<wd-input
:model-value="formatAmount(formData.totalUnreceivedAmounts)"
label="累计未收款"
label-width="180rpx"
placeholder="系统自动生成"
disabled
/>
</wd-cell-group>
<!-- 其他信息 -->
<wd-cell-group title="其他信息" border>
<wd-cell title="开启状态" title-width="180rpx" center>
<wd-switch v-model="statusEnabled" />
</wd-cell>
<wd-input
v-model="formData.sort"
label="排序"
label-width="180rpx"
placeholder="请输入排序"
type="number"
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="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 { Customer } from '@/api/erp/customer'
import { computed, onMounted, ref, watch } from 'vue'
import { useToast } from 'wot-design-uni'
import { createCustomer, getCustomer, updateCustomer } from '@/api/erp/customer'
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<Customer>({
id: undefined,
name: undefined,
contact: undefined,
mobile: undefined,
telephone: undefined,
email: undefined,
remark: undefined,
status: 0,
sort: 0,
taxNo: undefined,
taxPercent: undefined,
bankName: undefined,
bankAccount: undefined,
bankAddress: undefined,
companyType: undefined,
businessScale: undefined,
leadSourceType: undefined,
preferredProducts: undefined,
preferredPackaging: undefined,
deliveryCyclePrefer: undefined,
annualOrderNums: undefined,
annualOrderAmounts: undefined,
annualReceivedAmounts: undefined,
totalUnreceivedAmounts: undefined,
})
const formRules = {
name: [{ required: true, message: '客户名称不能为空' }],
}
const formRef = ref<FormInstance>()
// 状态开关
const statusEnabled = ref(true)
watch(statusEnabled, (val) => {
formData.value.status = val ? 0 : 1
})
watch(() => formData.value.status, (val) => {
statusEnabled.value = val === 0
})
/** 企业类型选项 */
const companyTypeOptions = [
{ value: 1, label: '餐饮' },
{ value: 2, label: '食品批发' },
{ value: 3, label: '制造' },
{ value: 4, label: '超市' },
{ value: 5, label: '其他' },
]
const companyTypeColumns = computed(() => [
companyTypeOptions.map(v => ({ value: v.value, label: v.label })),
])
function onCompanyTypeConfirm({ value }: any) {
formData.value.companyType = value?.[0]
}
/** 客户来源选项 */
const leadSourceTypeOptions = [
{ value: 1, label: '展会' },
{ value: 2, label: '地推' },
{ value: 3, label: '转介绍' },
{ value: 4, label: '官网' },
{ value: 5, label: '平台' },
{ value: 6, label: '电销' },
{ value: 7, label: '老客户' },
{ value: 99, label: '其他' },
]
const leadSourceTypeColumns = computed(() => [
leadSourceTypeOptions.map(v => ({ value: v.value, label: v.label })),
])
function onLeadSourceTypeConfirm({ value }: any) {
formData.value.leadSourceType = value?.[0]
}
/** 格式化整数 */
const formatInteger = (value?: string | number) => {
if (value === undefined || value === null || value === '') {
return ''
}
const num = Number(value)
if (Number.isNaN(num)) {
return String(value)
}
return String(Math.trunc(num))
}
/** 格式化金额 */
const formatAmount = (value?: string | number) => {
if (value === undefined || value === null || value === '') {
return ''
}
const num = Number(value)
if (Number.isNaN(num)) {
return String(value)
}
return num.toFixed(2)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/customer/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getCustomer(props.id)
} finally {
toast.close()
}
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
formLoading.value = true
try {
if (props.id) {
await updateCustomer(formData.value)
toast.success('修改成功')
} else {
await createCustomer(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,260 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="客户管理"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 搜索组件 -->
<view @click="openSearchForm">
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
</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="handleEdit(item)"
>
<view class="p-24rpx">
<!-- 头部名称 + 状态 -->
<view class="mb-16rpx flex items-center justify-between">
<view class="text-30rpx text-[#333] font-semibold">
{{ item.name || '-' }}
</view>
<view
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
:class="item.status === 0 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff1f0] text-[#f5222d]'"
>
{{ item.status === 0 ? '正常' : '停用' }}
</view>
</view>
<!-- 联系人 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">联系人</text>
<text>{{ item.contact || '-' }}</text>
</view>
<!-- 手机号码 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">手机号码</text>
<text>{{ item.mobile || '-' }}</text>
</view>
<!-- 联系电话 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">联系电话</text>
<text>{{ item.telephone || '-' }}</text>
</view>
<!-- 备注 -->
<view class="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.remark || '无备注' }}</text>
</view>
</view>
<!-- 操作按钮 -->
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
<wd-button
v-if="hasAccessByCodes(['erp:customer:update']) && item.name !== '-'"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:customer:delete']) && item.name !== '-'"
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:customer: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.name" placeholder="请输入客户名称" clearable />
</view>
<view class="yd-search-form-item">
<view class="yd-search-form-label">手机号码</view>
<wd-input v-model="searchForm.mobile" placeholder="请输入手机号码" clearable />
</view>
<view class="yd-search-form-item">
<view class="yd-search-form-label">联系电话</view>
<wd-input v-model="searchForm.telephone" placeholder="请输入联系电话" clearable />
</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 { Customer } from '@/api/erp/customer'
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 { deleteCustomer, getCustomerPage } from '@/api/erp/customer'
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<Customer[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
name: undefined as string | undefined,
mobile: undefined as string | undefined,
telephone: undefined as string | undefined,
})
/** 打开搜索表单 */
function openSearchForm() {
searchVisible.value = true
}
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.name) conditions.push(`名称:${searchForm.name}`)
if (searchForm.mobile) conditions.push(`手机:${searchForm.mobile}`)
if (searchForm.telephone) conditions.push(`电话:${searchForm.telephone}`)
return conditions.length > 0 ? conditions.join(' | ') : '搜索客户'
})
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 查询客户列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
const data = await getCustomerPage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
...searchForm,
pageNo: 1,
pageSize: queryParams.value.pageSize,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.name = undefined
searchForm.mobile = undefined
searchForm.telephone = undefined
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10 }
list.value = []
getList()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
/** 新增客户 */
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/customer/form/index' })
}
/** 编辑 */
function handleEdit(item: Customer) {
if (item.name === '-') return
uni.navigateTo({ url: `/pages-erp/customer/form/index?id=${item.id}` })
}
/** 删除 */
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该客户吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteCustomer(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>

View File

@@ -0,0 +1,298 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-input
v-model="formData.name"
label="户主姓名"
label-width="180rpx"
placeholder="请输入户主姓名"
prop="name"
clearable
/>
<wd-input
v-model="formData.idCardNumber"
label="身份证号"
label-width="180rpx"
placeholder="请输入身份证号"
clearable
/>
<wd-input
v-model="formData.mobile"
label="手机号码"
label-width="180rpx"
placeholder="请输入手机号码"
type="number"
clearable
/>
<wd-input
v-model="formData.address"
label="住址"
label-width="180rpx"
placeholder="请输入住址"
clearable
/>
</wd-cell-group>
<wd-cell-group title="种植信息" border>
<wd-input
v-model="formData.plantingBase"
label="种植基地"
label-width="180rpx"
placeholder="请输入所属种植基地"
clearable
/>
<wd-input
v-model="formData.contractNumber"
label="合同号"
label-width="180rpx"
placeholder="请输入合同号"
clearable
/>
<wd-input
v-model="formData.contractedArea"
label="签订面积"
label-width="180rpx"
placeholder="请输入签订面积"
type="number"
suffix-icon=""
clearable
/>
<wd-input
v-model="formData.orderQuantity"
label="订购数量"
label-width="180rpx"
placeholder="请输入订购数量"
type="number"
suffix-icon=""
clearable
/>
<wd-input
v-model="formData.actualArea"
label="实种面积"
label-width="180rpx"
placeholder="请输入实种面积"
type="number"
suffix-icon=""
clearable
/>
<wd-cell title="移栽时间" title-width="180rpx" center>
<wd-datetime-picker
v-model="formData.transplantTime"
type="date"
label=""
placeholder="请选择移栽时间"
/>
</wd-cell>
<wd-input
v-model="formData.transplantQuantity"
label="移栽数量"
label-width="180rpx"
placeholder="请输入移栽数量"
type="number"
suffix-icon=""
clearable
/>
<wd-cell title="成熟时间" title-width="180rpx" center>
<wd-datetime-picker
v-model="formData.maturityTime"
type="date"
label=""
placeholder="请选择成熟时间"
/>
</wd-cell>
<wd-cell title="预计采收" title-width="180rpx" center>
<wd-datetime-picker
v-model="formData.expectedHarvestTime"
type="date"
label=""
placeholder="请选择预计采收时间"
/>
</wd-cell>
<wd-cell title="使用品种" title-width="180rpx" center>
<wd-picker
v-model="formData.usedVariety"
:columns="varietyColumns"
label=""
placeholder="请选择使用品种"
@confirm="onVarietyConfirm"
/>
</wd-cell>
<wd-input
v-model="formData.plantingMethod"
label="种植方式"
label-width="180rpx"
placeholder="请输入种植方式"
clearable
/>
<wd-input
v-model="formData.adminName"
label="管理员"
label-width="180rpx"
placeholder="请输入管理员姓名"
clearable
/>
</wd-cell-group>
<wd-cell-group title="其他信息" border>
<wd-cell title="开启状态" title-width="180rpx" center>
<wd-switch v-model="statusEnabled" />
</wd-cell>
<wd-input
v-model="formData.sort"
label="排序"
label-width="180rpx"
placeholder="请输入排序"
type="number"
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="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 { Farmer } from '@/api/erp/farmer'
import { computed, onMounted, ref, watch } from 'vue'
import { useToast } from 'wot-design-uni'
import { createFarmer, getFarmer, updateFarmer, VARIETY_OPTIONS } from '@/api/erp/farmer'
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<Farmer>({
id: undefined,
name: undefined,
idCardNumber: undefined,
mobile: undefined,
address: undefined,
plantingBase: undefined,
contractNumber: undefined,
contractedArea: undefined,
orderQuantity: undefined,
actualArea: undefined,
transplantTime: undefined,
transplantQuantity: undefined,
maturityTime: undefined,
expectedHarvestTime: undefined,
usedVariety: undefined,
plantingMethod: undefined,
adminName: undefined,
remark: undefined,
status: 0,
sort: 0,
})
const formRules = {
name: [{ required: true, message: '户主姓名不能为空' }],
}
const formRef = ref<FormInstance>()
// 状态开关
const statusEnabled = ref(true)
watch(statusEnabled, (val) => {
formData.value.status = val ? 0 : 1
})
watch(() => formData.value.status, (val) => {
statusEnabled.value = val === 0
})
/** 品种下拉列 */
const varietyColumns = computed(() => [
VARIETY_OPTIONS.map(v => ({ value: v.value, label: v.label })),
])
/** 品种选择回调 */
function onVarietyConfirm({ value }: any) {
formData.value.usedVariety = value?.[0]
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/farmer/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getFarmer(props.id)
} finally {
toast.close()
}
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
formLoading.value = true
try {
if (props.id) {
await updateFarmer(formData.value)
toast.success('修改成功')
} else {
await createFarmer(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,289 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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="px-24rpx">
<view
v-for="item in list"
:key="item.id"
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
@click="handleEdit(item)"
>
<view class="p-24rpx">
<!-- 头部姓名 + 状态 -->
<view class="mb-16rpx flex items-center justify-between">
<view class="text-30rpx text-[#333] font-semibold">
{{ item.name || '-' }}
</view>
<view
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
:class="item.status === 0 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff1f0] text-[#f5222d]'"
>
{{ item.status === 0 ? '正常' : '停用' }}
</view>
</view>
<!-- 住址 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">住址</text>
<text>{{ item.address || '-' }}</text>
</view>
<!-- 种植基地 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">种植基地</text>
<text>{{ item.plantingBase || '-' }}</text>
</view>
<!-- 合同号 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">合同号</text>
<text>{{ item.contractNumber || '-' }}</text>
</view>
<!-- 使用品种 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">使用品种</text>
<text>{{ item.usedVariety || '-' }}</text>
</view>
<!-- 管理员 -->
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">管理员</text>
<text>{{ item.adminName || '-' }}</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.contractedArea ?? '-' }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">签订面积</view>
</view>
<view class="text-center">
<view class="text-30rpx text-[#333] font-semibold">{{ item.actualArea ?? '-' }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">实种面积</view>
</view>
<view class="text-center">
<view class="text-30rpx text-[#1890ff] font-semibold">{{ item.orderQuantity ?? '-' }}</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:farmer:update'])"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:farmer:delete'])"
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:farmer: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" :style="{ paddingTop: `${getNavbarHeight()}px` }">
<view class="yd-search-form-item">
<view class="yd-search-form-label">户主姓名</view>
<wd-input v-model="searchForm.name" placeholder="请输入户主姓名" clearable />
</view>
<view class="yd-search-form-item">
<view class="yd-search-form-label">种植基地</view>
<wd-input v-model="searchForm.plantingBase" placeholder="请输入种植基地" clearable />
</view>
<view class="yd-search-form-item">
<view class="yd-search-form-label">使用品种</view>
<wd-picker
v-model="searchForm.usedVariety"
:columns="varietyColumns"
placeholder="请选择使用品种"
@confirm="onVarietyConfirm"
/>
</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 { Farmer } from '@/api/erp/farmer'
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 { deleteFarmer, getFarmerPage, VARIETY_OPTIONS } from '@/api/erp/farmer'
import { useAccess } from '@/hooks/useAccess'
import { getNavbarHeight, navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<Farmer[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
name: undefined as string | undefined,
plantingBase: undefined as string | undefined,
usedVariety: undefined as string | undefined,
})
/** 品种下拉列 */
const varietyColumns = computed(() => [
[{ value: '', label: '全部' }, ...VARIETY_OPTIONS.map(v => ({ value: v.value, label: v.label }))],
])
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.name) conditions.push(`姓名:${searchForm.name}`)
if (searchForm.plantingBase) conditions.push(`基地:${searchForm.plantingBase}`)
if (searchForm.usedVariety) conditions.push(`品种:${searchForm.usedVariety}`)
return conditions.length > 0 ? conditions.join(' | ') : '搜索农户'
})
/** 品种选择回调 */
function onVarietyConfirm({ value }: any) {
searchForm.usedVariety = value?.[0] || undefined
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 查询农户列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
const data = await getFarmerPage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
...searchForm,
pageNo: 1,
pageSize: queryParams.value.pageSize,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.name = undefined
searchForm.plantingBase = undefined
searchForm.usedVariety = undefined
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10 }
list.value = []
getList()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
/** 新增农户 */
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/farmer/form/index' })
}
/** 编辑 */
function handleEdit(item: Farmer) {
uni.navigateTo({ url: `/pages-erp/farmer/form/index?id=${item.id}` })
}
/** 删除 */
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该农户吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteFarmer(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>

View File

@@ -0,0 +1,126 @@
<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.pickCode"
placeholder="请输入采摘编号"
clearable
/>
</view>
<view class="yd-search-form-item">
<view class="yd-search-form-label">
采摘人员
</view>
<wd-input
v-model="formData.userName"
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="1">
已采摘
</wd-radio>
<wd-radio :value="2">
已装框
</wd-radio>
<wd-radio :value="3">
已装车
</wd-radio>
<wd-radio :value="4">
已入库
</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({
pickCode: undefined as string | undefined,
userName: undefined as string | undefined,
status: -1,
})
const statusMap: Record<number, string> = {
1: '已采摘',
2: '已装框',
3: '已装车',
4: '已入库',
}
/** 搜索条件 placeholder 拼接 */
const placeholder = computed(() => {
const conditions: string[] = []
if (formData.pickCode) {
conditions.push(`编号:${formData.pickCode}`)
}
if (formData.userName) {
conditions.push(`人员:${formData.userName}`)
}
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.pickCode) {
params.pickCode = formData.pickCode
}
if (formData.userName) {
params.userName = formData.userName
}
if (formData.status !== -1) {
params.status = formData.status
}
emit('search', params)
}
/** 重置 */
function handleReset() {
formData.pickCode = undefined
formData.userName = undefined
formData.status = -1
visible.value = false
emit('reset')
}
</script>

View File

@@ -0,0 +1,237 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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.pickCode" />
<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.productName || '-'" />
<wd-cell title="采摘人员" :value="formData.userName || '-'" />
<wd-cell title="田间编号" :value="formData.fieldCode || '-'" />
<wd-cell title="采摘时间" :value="formatDate(formData.pickTime)" />
<wd-cell title="创建时间" :value="formatDate(formData.createTime)" />
</wd-cell-group>
<!-- 采摘信息 -->
<wd-cell-group title="采摘信息" border>
<wd-cell title="框编号" :value="formData.basketCode || '-'" />
<wd-cell title="每筐重量" :value="formData.basketWeight ? `${formData.basketWeight} kg` : '-'" />
<wd-cell title="车牌号" :value="formData.licensePlate || '-'" />
</wd-cell-group>
<!-- 装车信息 (status >= 3) -->
<wd-cell-group v-if="(formData.status ?? 0) >= 3" title="装车信息" border>
<wd-cell title="装车人员" :value="formData.loaderName || '-'" />
<wd-cell title="装车时间" :value="formatDate(formData.loadTime)" />
</wd-cell-group>
<!-- 卸车入库信息 (status === 4) -->
<wd-cell-group v-if="formData.status === 4" title="卸车入库信息" border>
<wd-cell title="卸车人员" :value="formData.unloaderName || '-'" />
<wd-cell title="卸车时间" :value="formatDate(formData.unloadTime)" />
<wd-cell title="入库仓库" :value="formData.warehouseName || '-'" />
<wd-cell title="卸车批次号" :value="formData.unloadBatch || '-'" />
</wd-cell-group>
<!-- 备注 -->
<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:pick-broccoli:update']) && (formData?.status ?? 0) < 3"
class="flex-1" type="primary" @click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && formData?.status === 1"
class="flex-1" type="success" @click="handleStatusUpdate(2, '装框')"
>
装框
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && formData?.status === 2"
class="flex-1" type="warning" @click="handleLoadTruck"
>
装车
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:pick-broccoli:delete']) && (formData?.status ?? 0) < 3"
class="flex-1" type="error" :loading="deleting" @click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import type { PickBroccoli } from '@/api/erp/pick-broccoli'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deletePickBroccoli, getPickBroccoli, loadTruck, updatePickBroccoliStatus } from '@/api/erp/pick-broccoli'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id?: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const formData = ref<PickBroccoli>()
const deleting = ref(false)
/** 格式化日期 */
function formatDate(date?: string) {
if (!date) return '-'
return new Date(date).toLocaleString('zh-CN')
}
/** 获取状态文本 */
function getStatusText(status?: number) {
switch (status) {
case 1: return '已采摘'
case 2: return '已装框'
case 3: return '已装车'
case 4: return '已卸车入库'
default: return '未知'
}
}
/** 获取状态样式 */
function getStatusClass(status?: number) {
switch (status) {
case 1: return 'bg-[#e6f7ff] text-[#1890ff]'
case 2: return 'bg-[#fff7e6] text-[#fa8c16]'
case 3: return 'bg-[#f9f0ff] text-[#722ed1]'
case 4: return 'bg-[#f6ffed] text-[#52c41a]'
default: return 'bg-[#f5f5f5] text-[#999]'
}
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/pick-broccoli/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) {
return
}
try {
toast.loading('加载中...')
formData.value = await getPickBroccoli(props.id)
} finally {
toast.close()
}
}
/** 编辑 */
function handleEdit() {
uni.navigateTo({
url: `/pages-erp/pick-broccoli/form/index?id=${props.id}`,
})
}
/** 状态更新(装框) */
function handleStatusUpdate(status: number, text: string) {
uni.showModal({
title: '提示',
content: `确认将该记录状态更新为"${text}完成"吗?`,
success: async (res) => {
if (!res.confirm) return
try {
await updatePickBroccoliStatus(props.id, status)
toast.success(`${text}操作成功`)
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 装车操作 */
function handleLoadTruck() {
uni.showModal({
title: '装车',
content: '请输入车牌号',
editable: true,
placeholderText: '车牌号',
success: async (res) => {
if (!res.confirm || !res.content) return
try {
await loadTruck(props.id, res.content, 0, '')
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 deletePickBroccoli(props.id)
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} finally {
deleting.value = false
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,354 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<!-- 基本信息 -->
<wd-cell-group title="基本信息" border>
<wd-input
v-model="formData.pickCode"
label="采摘编号"
label-width="180rpx"
prop="pickCode"
placeholder="自动生成"
:disabled="isLoaded"
readonly
>
<template v-if="!props.id" #suffix>
<wd-button size="small" type="primary" @click="handleGenerateCode">
生成
</wd-button>
</template>
</wd-input>
<wd-cell title="采摘人员" title-width="180rpx" prop="userName" center>
<wd-picker
v-model="formData.userId"
:columns="userColumns"
label=""
placeholder="请选择采摘人员"
:disabled="isLoaded"
@confirm="onUserConfirm"
/>
</wd-cell>
<wd-cell title="关联产品" title-width="180rpx" prop="productName" center>
<wd-picker
v-model="formData.productId"
:columns="productColumns"
label=""
placeholder="请选择产品"
:disabled="isLoaded"
@confirm="onProductConfirm"
/>
</wd-cell>
<wd-cell title="田间编号" title-width="180rpx" prop="fieldCode" center>
<wd-picker
v-model="formData.fieldCode"
:columns="fieldColumns"
label=""
placeholder="请选择田间编号"
:disabled="isLoaded"
/>
</wd-cell>
</wd-cell-group>
<!-- 采摘信息 -->
<wd-cell-group title="采摘信息" border>
<wd-cell title="框编号" title-width="180rpx" prop="basketCode" center>
<wd-picker
v-model="formData.basketCode"
:columns="basketColumns"
label=""
placeholder="请选择框编号"
:disabled="isLoaded"
/>
</wd-cell>
<wd-input
v-model="formData.basketWeight"
label="每筐重量(kg)"
label-width="180rpx"
type="number"
placeholder="请输入每筐重量"
clearable
:disabled="isLoaded"
/>
<wd-input
v-model="formData.licensePlate"
label="车牌号"
label-width="180rpx"
clearable
placeholder="请输入车牌号"
:disabled="isLoaded"
/>
<wd-cell title="采摘时间" title-width="180rpx" prop="pickTime" center>
<wd-datetime-picker
v-model="formData.pickTime"
type="datetime"
label=""
placeholder="请选择采摘时间"
:disabled="isLoaded"
/>
</wd-cell>
</wd-cell-group>
<!-- 状态信息编辑时 -->
<wd-cell-group v-if="formData.id" title="状态信息" border>
<wd-cell title="当前状态" :value="getStatusText(formData.status)" />
<wd-cell v-if="formData.loadTime" title="装车时间" :value="formatDate(formData.loadTime)" />
<wd-cell v-if="formData.loaderName" title="装车人" :value="formData.loaderName" />
<wd-cell v-if="formData.unloadTime" title="卸车时间" :value="formatDate(formData.unloadTime)" />
<wd-cell v-if="formData.unloaderName" title="卸车人员" :value="formData.unloaderName" />
<wd-cell v-if="formData.warehouseName" title="仓库名称" :value="formData.warehouseName" />
<wd-cell v-if="formData.unloadBatch" title="卸车批次号" :value="formData.unloadBatch" />
</wd-cell-group>
<!-- 备注 -->
<wd-cell-group title="其他" border>
<wd-textarea
v-model="formData.remark"
label="备注"
label-width="180rpx"
placeholder="请输入备注信息(可选)"
:maxlength="200"
show-word-limit
clearable
:disabled="isLoaded"
/>
</wd-cell-group>
</wd-form>
</view>
<!-- 底部保存按钮 -->
<view class="yd-detail-footer">
<wd-button
type="primary"
block
:loading="formLoading"
:disabled="isLoaded"
@click="handleSubmit"
>
保存
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { PickBroccoli } from '@/api/erp/pick-broccoli'
import type { User } from '@/api/system/user'
import type { ProductSimple } from '@/api/erp/product'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createPickBroccoli, generatePickCode, getPickBroccoli, updatePickBroccoli } from '@/api/erp/pick-broccoli'
import { getSimpleUserList } from '@/api/system/user'
import { getProductSimpleList } from '@/api/erp/product'
import { getFarmingManagementPage } from '@/api/erp/farming'
import { getBoxPage } from '@/api/erp/box'
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<PickBroccoli>({
id: undefined,
pickCode: '',
userId: undefined,
userName: '',
productId: undefined,
productName: '',
fieldCode: '',
basketCode: '',
basketWeight: undefined,
licensePlate: '',
pickTime: undefined,
status: 1,
remark: '',
})
const formRules = {
pickCode: [{ required: true, message: '采摘编号不能为空' }],
userName: [{ required: true, message: '采摘人员不能为空' }],
productName: [{ required: true, message: '关联产品不能为空' }],
fieldCode: [{ required: true, message: '田间编号不能为空' }],
basketCode: [{ required: true, message: '框编号不能为空' }],
pickTime: [{ required: true, message: '采摘时间不能为空' }],
}
const formRef = ref<FormInstance>()
const userList = ref<User[]>([])
const productList = ref<ProductSimple[]>([])
const fieldList = ref<string[]>([])
const basketList = ref<string[]>([])
/** 采摘人员下拉列 */
const userColumns = computed(() => [
userList.value.map(u => ({ value: u.id, label: u.nickname })),
])
/** 产品下拉列 */
const productColumns = computed(() => [
productList.value.map(p => ({ value: p.id, label: p.name })),
])
/** 田间编号下拉列 */
const fieldColumns = computed(() => [
fieldList.value.map(code => ({ value: code, label: code })),
])
/** 框编号下拉列 */
const basketColumns = computed(() => [
basketList.value.map(code => ({ value: code, label: code })),
])
/** 采摘人员选择回调 */
function onUserConfirm({ value }: any) {
const userId = value?.[0]
formData.value.userId = userId
const user = userList.value.find(u => u.id === userId)
if (user) {
formData.value.userName = user.nickname
}
}
/** 产品选择回调 */
function onProductConfirm({ value }: any) {
const productId = value?.[0]
formData.value.productId = productId
const product = productList.value.find(p => p.id === productId)
if (product) {
formData.value.productName = product.name
}
}
/** 加载下拉列表数据 */
async function loadDropdownData() {
try {
const [users, products, farmingResult, boxResult] = await Promise.all([
getSimpleUserList(),
getProductSimpleList(),
getFarmingManagementPage(),
getBoxPage(),
])
userList.value = users || []
productList.value = products || []
// 提取田间编号
const farmingList = farmingResult?.list || []
fieldList.value = Array.from(new Set(farmingList.filter(f => f.code?.trim()).map(f => f.code)))
// 提取框编号
const boxList = boxResult?.list || []
basketList.value = boxList.filter(b => b.boxNumber?.trim()).map(b => b.boxNumber)
} catch {
// error handled by http
}
}
/** 已装车状态时禁用所有字段 */
const isLoaded = computed(() => (formData.value.status ?? 0) >= 3)
/** 格式化日期 */
function formatDate(date?: string) {
if (!date) return '-'
return new Date(date).toLocaleString('zh-CN')
}
/** 获取状态文本 */
function getStatusText(status?: number) {
switch (status) {
case 1: return '已采摘'
case 2: return '已装框'
case 3: return '已装车'
case 4: return '已卸车入库'
default: return '未知'
}
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/pick-broccoli/index')
}
/** 生成采摘编号 */
async function handleGenerateCode() {
try {
const data = await generatePickCode()
if (data && data.code) {
formData.value.pickCode = data.code
} else {
// 前端生成备用编号
const d = new Date()
const y = d.getFullYear()
const m = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
const rnd = Math.floor(Math.random() * 1000000).toString().padStart(6, '0')
formData.value.pickCode = `CJXL${y}${m}${day}${rnd}`
}
} catch {
// 前端生成备用编号
const d = new Date()
const y = d.getFullYear()
const m = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
const rnd = Math.floor(Math.random() * 1000000).toString().padStart(6, '0')
formData.value.pickCode = `CJXL${y}${m}${day}${rnd}`
}
}
/** 加载详情 */
async function getDetail() {
if (!props.id) {
// 新增时自动生成编号
await handleGenerateCode()
return
}
formData.value = await getPickBroccoli(props.id)
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) {
return
}
formLoading.value = true
try {
if (props.id) {
await updatePickBroccoli(formData.value)
toast.success('修改成功')
} else {
await createPickBroccoli(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
await loadDropdownData()
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,331 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="采摘管理"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 搜索组件 -->
<SearchForm @search="handleQuery" @reset="handleReset" />
<!-- 采摘记录列表 -->
<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.pickCode }}
</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.productName || '-' }}</text>
</view>
<!-- 采摘人员 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">采摘人员</text>
<text>{{ item.userName || '-' }}</text>
</view>
<!-- 田间编号 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">田间编号</text>
<text>{{ item.fieldCode || '-' }}</text>
</view>
<!-- 框编号 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">框编号</text>
<text>{{ item.basketCode || '-' }}</text>
</view>
<!-- 重量 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">重量</text>
<text class="font-semibold">{{ item.basketWeight || 0 }} kg</text>
</view>
<!-- 车牌号 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">车牌号</text>
<text>{{ item.licensePlate || '-' }}</text>
</view>
<!-- 采摘时间 -->
<view class="flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">采摘时间</text>
<text>{{ formatDate(item.pickTime) }}</text>
</view>
</view>
<!-- 操作按钮 -->
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
<wd-button
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && (item.status ?? 0) < 3"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:pick-broccoli:query'])"
size="small" plain @click="handleDetail(item)"
>
详情
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && item.status === 1"
size="small" type="success" plain @click="handleStatusUpdate(item, 2, '装框')"
>
装框
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:pick-broccoli:update']) && item.status === 2"
size="small" type="warning" plain @click="handleLoadTruck(item)"
>
装车
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:pick-broccoli:delete']) && (item.status ?? 0) < 3"
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:pick-broccoli:create'])"
position="right-bottom"
type="primary"
:expandable="false"
@click="handleAdd"
/>
</view>
</template>
<script lang="ts" setup>
import type { PickBroccoli } from '@/api/erp/pick-broccoli'
import type { LoadMoreState } from '@/http/types'
import { onReachBottom } from '@dcloudio/uni-app'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deletePickBroccoli, getPickBroccoliPage, loadTruck, updatePickBroccoliStatus } from '@/api/erp/pick-broccoli'
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<PickBroccoli[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
})
/** 格式化日期 */
function formatDate(date?: string) {
if (!date) return '-'
return new Date(date).toLocaleString('zh-CN')
}
/** 获取状态文本 */
function getStatusText(status?: number) {
switch (status) {
case 1: return '已采摘'
case 2: return '已装框'
case 3: return '已装车'
case 4: return '已入库'
default: return '未知'
}
}
/** 获取状态样式 */
function getStatusClass(status?: number) {
switch (status) {
case 1: return 'bg-[#e6f7ff] text-[#1890ff]'
case 2: return 'bg-[#fff7e6] text-[#fa8c16]'
case 3: return 'bg-[#f9f0ff] text-[#722ed1]'
case 4: return 'bg-[#f6ffed] text-[#52c41a]'
default: return 'bg-[#f5f5f5] text-[#999]'
}
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 查询采摘记录列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
const data = await getPickBroccoliPage(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 handleQuery(data?: Record<string, any>) {
queryParams.value = {
...data,
pageNo: 1,
pageSize: queryParams.value.pageSize,
}
list.value = []
getList()
}
/** 重置按钮操作 */
function handleReset() {
handleQuery()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') {
return
}
queryParams.value.pageNo++
getList()
}
/** 刷新列表 */
function refreshList() {
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 卡片点击 — 打开详情 */
function handleCardClick(item: PickBroccoli) {
handleDetail(item)
}
/** 新增采摘记录 */
function handleAdd() {
uni.navigateTo({
url: '/pages-erp/pick-broccoli/form/index',
})
}
/** 查看详情 */
function handleDetail(item: PickBroccoli) {
uni.navigateTo({
url: `/pages-erp/pick-broccoli/detail/index?id=${item.id}`,
})
}
/** 编辑 */
function handleEdit(item: PickBroccoli) {
uni.navigateTo({
url: `/pages-erp/pick-broccoli/form/index?id=${item.id}`,
})
}
/** 状态更新(装框) */
function handleStatusUpdate(item: PickBroccoli, status: number, text: string) {
uni.showModal({
title: '提示',
content: `确认将该记录状态更新为"${text}完成"吗?`,
success: async (res) => {
if (!res.confirm) return
try {
await updatePickBroccoliStatus(item.id!, status)
toast.success(`${text}操作成功`)
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 装车操作 — 简易输入车牌号 + 装车人 */
function handleLoadTruck(item: PickBroccoli) {
// 小程序端用简化方式:直接输入车牌号
uni.showModal({
title: '装车',
content: '请输入车牌号',
editable: true,
placeholderText: '车牌号',
success: async (res) => {
if (!res.confirm || !res.content) return
try {
// 使用当前用户作为装车人(简化处理)
await loadTruck(item.id!, res.content, 0, '')
toast.success('装车操作成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该采摘记录吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deletePickBroccoli(id)
toast.success('删除成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
</style>

View 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>

View File

@@ -0,0 +1,395 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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, formData.isQualified)"
>
{{ getStatusText(formData.status, formData.isQualified) }}
</view>
</wd-cell>
<wd-cell title="供应商" :value="formData.supplierName || '-'" />
<wd-cell title="入库时间" :value="formatDateTime(formData.inTime)" />
<wd-cell title="关联订单" :value="formData.orderNo || '-'" />
<wd-cell title="创建人" :value="formData.creatorName || '-'" />
<wd-cell title="创建时间" :value="formatDateTime(formData.createTime)" />
</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.otherPrice || 0}`" />
<wd-cell title="应付金额">
<text class="text-[#e6a23c] font-semibold">¥{{ formData.totalPrice || 0 }}</text>
</wd-cell>
<wd-cell title="已付金额">
<text class="text-[#52c41a] font-semibold">¥{{ formData.paymentPrice || 0 }}</text>
</wd-cell>
<wd-cell title="未付金额">
<text
class="font-semibold"
:class="(formData.totalPrice || 0) - (formData.paymentPrice || 0) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
>
¥{{ (formData.totalPrice || 0) - (formData.paymentPrice || 0) }}
</text>
</wd-cell>
</wd-cell-group>
<!-- 不合格信息 -->
<wd-cell-group v-if="formData.status !== 10 && !formData.isQualified" title="不合格信息" border>
<wd-cell title="返回方式" :value="getReturnTypeLabel(formData.returnType)" />
<wd-cell v-if="formData.returnRemark" title="返回备注" :value="formData.returnRemark" />
</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.warehouseName" class="text-24rpx text-[#1890ff]">{{ item.warehouseName }}</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 class="text-[#e6a23c]">¥{{ item.totalPrice || 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-in:update']) && formData?.status === 10"
class="flex-1" type="warning" @click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-in:update-status']) && formData?.status === 10"
class="flex-1" type="success" @click="handleAudit"
>
审核
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-in:update-status']) && (formData?.status === 20 || formData?.status === 30)"
class="flex-1" type="warning" @click="handleReverseAudit"
>
反审核
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-in:delete']) && formData?.status === 10"
class="flex-1" type="error" :loading="deleting" @click="handleDelete"
>
删除
</wd-button>
</view>
</view>
<!-- 审核弹窗 -->
<wd-popup v-model="auditVisible" position="bottom" closable @close="auditVisible = false">
<view class="p-32rpx">
<view class="text-32rpx text-[#333] font-semibold mb-32rpx text-center">
采购入库审核
</view>
<view class="mb-24rpx">
<view class="text-26rpx text-[#666] mb-12rpx">是否合格</view>
<wd-switch v-model="auditForm.isQualified" @change="handleQualifiedChange" />
</view>
<view v-if="!auditForm.isQualified" class="mb-24rpx">
<view class="text-26rpx text-[#666] mb-12rpx">返回方式</view>
<wd-radio-group v-model="auditForm.returnType" shape="button">
<wd-radio
v-for="opt in RETURN_TYPE_OPTIONS"
:key="opt.value"
:value="opt.value"
>
{{ opt.label }}
</wd-radio>
</wd-radio-group>
</view>
<view v-if="!auditForm.isQualified" class="mb-24rpx">
<view class="text-26rpx text-[#666] mb-12rpx">返回备注</view>
<wd-textarea
v-model="auditForm.returnRemark"
placeholder="请输入返回方式备注"
:maxlength="200"
/>
</view>
<view class="flex gap-24rpx mt-32rpx">
<wd-button class="flex-1" plain @click="auditVisible = false">
取消
</wd-button>
<wd-button class="flex-1" type="primary" :loading="auditLoading" @click="submitAudit">
确定
</wd-button>
</view>
</view>
</wd-popup>
</view>
</template>
<script lang="ts" setup>
import type { PurchaseIn } from '@/api/erp/purchase-in'
import { onMounted, reactive, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deletePurchaseIn, getPurchaseIn, RETURN_TYPE_OPTIONS, updatePurchaseInStatus } from '@/api/erp/purchase-in'
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<PurchaseIn>()
const deleting = ref(false)
// 审核相关
const auditVisible = ref(false)
const auditLoading = ref(false)
const auditForm = reactive({
isQualified: true,
returnType: undefined as string | undefined,
returnRemark: undefined as string | undefined,
})
/** 获取状态文本 */
function getStatusText(status?: number, isQualified?: boolean) {
if (status === 10) return '未审核'
if (status === 20) return isQualified ? '已审核' : '不合格'
if (status === 30) return '不合格'
return '未知'
}
/** 获取状态样式 */
function getStatusClass(status?: number, isQualified?: boolean) {
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
if (status === 20) return isQualified ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff1f0] text-[#f5222d]'
if (status === 30) return 'bg-[#fff1f0] text-[#f5222d]'
return 'bg-[#f5f5f5] text-[#999]'
}
/** 获取返回方式标签 */
function getReturnTypeLabel(value?: string | null) {
if (!value) return '-'
const option = RETURN_TYPE_OPTIONS.find(opt => opt.value === value)
return option ? option.label : value
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/purchase-in/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) {
return
}
try {
toast.loading('加载中...')
formData.value = await getPurchaseIn(props.id)
} finally {
toast.close()
}
}
/** 编辑操作 */
function handleEdit() {
uni.navigateTo({
url: `/pages-erp/purchase-in/form/index?id=${props.id}`,
})
}
/** 打开审核弹窗 */
function handleAudit() {
auditForm.isQualified = true
auditForm.returnType = undefined
auditForm.returnRemark = undefined
auditVisible.value = true
}
/** 合格状态变化 */
function handleQualifiedChange(val: boolean) {
if (val) {
auditForm.returnType = undefined
auditForm.returnRemark = undefined
}
}
/** 提交审核 */
async function submitAudit() {
if (!props.id) return
if (!auditForm.isQualified && !auditForm.returnType) {
toast.warning('请选择返回方式')
return
}
auditLoading.value = true
try {
await updatePurchaseInStatus({
id: props.id,
isQualified: auditForm.isQualified,
returnType: auditForm.returnType,
returnRemark: auditForm.returnRemark,
status: auditForm.isQualified ? 20 : 30,
})
toast.success('审核成功')
auditVisible.value = false
getDetail()
} finally {
auditLoading.value = false
}
}
/** 反审核操作 */
function handleReverseAudit() {
if (!props.id) {
return
}
uni.showModal({
title: '提示',
content: '确定要反审核该入库单吗?',
success: async (res) => {
if (!res.confirm) {
return
}
try {
await updatePurchaseInStatus({
id: props.id,
isQualified: false,
status: 10,
})
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 deletePurchaseIn([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} finally {
deleting.value = false
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,612 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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" center>
<wd-input
v-model="formData.no"
placeholder="不填则自动生成"
:disabled="!!props.id"
/>
</wd-cell>
<wd-cell title="入库时间" title-width="180rpx" prop="inTime" center>
<wd-datetime-picker
v-model="formData.inTime"
type="date"
label=""
placeholder="请选择入库时间"
/>
</wd-cell>
<wd-cell title="关联订单" title-width="180rpx" center is-link @click="openOrderSelect">
<text v-if="formData.orderNo" class="text-[#1890ff]">{{ formData.orderNo }}</text>
<text v-else class="text-[#999]">点击选择采购订单</text>
</wd-cell>
<wd-cell title="供应商" title-width="180rpx" center>
<text>{{ getSupplierName() || '-' }}</text>
</wd-cell>
<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>
<wd-input
v-model="formData.discountPercent"
label="优惠率(%)"
label-width="180rpx"
type="number"
placeholder="请输入优惠率"
clearable
/>
<wd-cell title="付款优惠" title-width="180rpx" center>
<text>¥{{ formData.discountPrice || 0 }}</text>
</wd-cell>
<wd-input
v-model="formData.otherPrice"
label="其他费用"
label-width="180rpx"
type="number"
placeholder="请输入其他费用"
clearable
/>
<wd-cell title="优惠后金额" title-width="180rpx" center>
<text>¥{{ (formData.totalPrice || 0) - (formData.otherPrice || 0) }}</text>
</wd-cell>
<wd-cell title="结算账户" title-width="180rpx" prop="accountId" center>
<wd-picker
v-model="formData.accountId"
:columns="accountColumns"
label=""
placeholder="请选择结算账户"
@confirm="onAccountConfirm"
/>
</wd-cell>
<wd-cell title="应付金额" title-width="180rpx" center>
<text class="text-[#e6a23c] font-semibold">¥{{ formData.totalPrice || 0 }}</text>
</wd-cell>
</wd-cell-group>
</wd-form>
</view>
<!-- 入库明细 -->
<view class="erp-form-body">
<view class="erp-form-section-heading">
<view class="text-32rpx text-[#333] font-semibold">
入库明细{{ formData.items?.length || 0 }}
</view>
</view>
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card"
>
<view class="erp-form-item-card__header">
<text class="text-28rpx text-[#333] font-semibold">产品 #{{ index + 1 }} {{ item.productName || '' }}</text>
<wd-button
v-if="formData.items && formData.items.length > 1"
size="small" type="error" plain @click="handleRemoveItem(index)"
>
删除
</wd-button>
</view>
<view class="erp-form-item-list">
<!-- 仓库选择 -->
<view class="mb-16rpx">
<text class="mb-8rpx block text-24rpx text-[#999]">仓库</text>
<wd-picker
v-model="item.warehouseId"
:columns="warehouseColumns"
placeholder="请选择仓库"
@confirm="(e: any) => onWarehouseConfirm(e, index)"
/>
</view>
<!-- 自动填充的产品信息只读 -->
<view v-if="item.productId" class="erp-form-info-card">
<view class="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">产品名称</text>
<text class="text-[#333]">{{ item.productName || '-' }}</text>
</view>
<view v-if="item.productSpec" 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="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">库存</text>
<text class="text-[#333]">{{ item.stockCount || 0 }}</text>
</view>
<view v-if="item.totalCount != null" class="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">原数量</text>
<text class="text-[#333]">{{ item.totalCount }}</text>
</view>
<view v-if="item.inCount != null" class="flex justify-between text-24rpx">
<text class="text-[#999]">已入库</text>
<text class="text-[#333]">{{ item.inCount }}</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>
<!-- 采购订单选择弹窗 -->
<wd-popup v-model="orderSelectVisible" position="right" custom-style="width: 100%; height: 100%;">
<view class="yd-page-container erp-page">
<wd-navbar
title="选择采购订单"
left-arrow placeholder safe-area-inset-top fixed
@click-left="orderSelectVisible = false"
/>
<wd-search
v-model="orderQueryParams.no"
placeholder="搜索订单单号"
@search="getOrderList"
@clear="getOrderList"
/>
<view class="px-24rpx">
<view
v-for="item in orderList"
:key="item.id"
class="erp-form-item-card"
:class="{ 'border-2 border-[#1890ff]': selectedOrderId === item.id }"
@click="handleSelectOrder(item)"
>
<view class="erp-form-item-list">
<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.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="flex items-center justify-around mt-12rpx pt-12rpx border-t border-[#f0f0f0]">
<view class="text-center">
<view class="text-28rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
<view class="text-22rpx text-[#999]">总数量</view>
</view>
<view class="text-center">
<view class="text-28rpx text-[#52c41a] font-semibold">{{ item.inCount || 0 }}</view>
<view class="text-22rpx text-[#999]">已入库</view>
</view>
<view class="text-center">
<view class="text-28rpx text-[#e6a23c] font-semibold">¥{{ item.totalPrice || 0 }}</view>
<view class="text-22rpx text-[#999]">含税金额</view>
</view>
</view>
</view>
</view>
<view v-if="orderList.length === 0" 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 { PurchaseIn, PurchaseInItem } from '@/api/erp/purchase-in'
import type { PurchaseOrder } from '@/api/erp/purchase-order'
import type { LoadMoreState } from '@/http/types'
import { computed, onMounted, ref, watch } from 'vue'
import { useToast } from 'wot-design-uni'
import { createPurchaseIn, getPurchaseIn, updatePurchaseIn } from '@/api/erp/purchase-in'
import { getPurchaseOrder, getPurchaseOrderPage } from '@/api/erp/purchase-order'
import { navigateBackPlus } from '@/utils'
/** 账户简单信息 */
interface AccountSimple {
id: number
name: string
defaultStatus?: boolean
}
/** 仓库简单信息 */
interface WarehouseSimple {
id: number
name: string
defaultStatus?: boolean
}
/** 供应商简单信息 */
interface SupplierSimple {
id: number
name: string
}
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<PurchaseIn>({
id: undefined,
no: undefined,
supplierId: undefined,
accountId: undefined,
inTime: undefined,
orderId: undefined,
orderNo: undefined,
discountPercent: 0,
discountPrice: 0,
otherPrice: 0,
totalPrice: 0,
remark: '',
items: [],
})
const formRules = {
inTime: [{ required: true, message: '入库时间不能为空' }],
}
const formRef = ref<FormInstance>()
const supplierList = ref<SupplierSimple[]>([])
const accountList = ref<AccountSimple[]>([])
const warehouseList = ref<WarehouseSimple[]>([])
const defaultWarehouse = ref<WarehouseSimple>()
// 采购订单选择相关
const orderSelectVisible = ref(false)
const orderList = ref<PurchaseOrder[]>([])
const orderLoadMoreState = ref<LoadMoreState>('loading')
const orderQueryParams = ref({
pageNo: 1,
pageSize: 10,
no: undefined as string | undefined,
inEnable: true,
})
const orderTotal = ref(0)
const selectedOrderId = ref<number>()
/** 账户下拉列 */
const accountColumns = computed(() => [
accountList.value.map(a => ({ value: a.id, label: a.name })),
])
/** 仓库下拉列 */
const warehouseColumns = computed(() => [
warehouseList.value.map(w => ({ value: w.id, label: w.name })),
])
/** 获取供应商名称 */
function getSupplierName() {
if (!formData.value.supplierId) return ''
const supplier = supplierList.value.find(s => s.id === formData.value.supplierId)
return supplier?.name || formData.value.supplierName || ''
}
/** 账户选择回调 */
function onAccountConfirm({ value }: any) {
formData.value.accountId = value?.[0]
}
/** 仓库选择回调 */
function onWarehouseConfirm({ value }: any, index: number) {
if (formData.value.items && formData.value.items[index]) {
formData.value.items[index].warehouseId = value?.[0]
const warehouse = warehouseList.value.find(w => w.id === value?.[0])
if (warehouse) {
formData.value.items[index].warehouseName = warehouse.name
}
}
}
/** 计算行项金额 */
function calcTotalPrice(item: PurchaseInItem) {
if (item.productPrice && item.count) {
const productTotal = Number(item.productPrice) * Number(item.count)
const taxPrice = item.taxPercent ? productTotal * Number(item.taxPercent) / 100 : 0
return `¥${(productTotal + taxPrice).toFixed(2)}`
}
return '-'
}
/** 监听表单数据变化,计算总价 */
watch(
() => formData.value,
(val) => {
if (!val || !val.items) return
// 计算每个明细的金额
val.items.forEach((item) => {
if (item.productPrice && item.count) {
item.totalProductPrice = Number(item.productPrice) * Number(item.count)
item.taxPrice = item.taxPercent ? item.totalProductPrice * Number(item.taxPercent) / 100 : 0
item.totalPrice = item.totalProductPrice + (item.taxPrice || 0)
}
})
// 计算总价
const totalPrice = val.items.reduce((prev, curr) => prev + (curr.totalPrice || 0), 0)
const discountPrice = val.discountPercent ? totalPrice * Number(val.discountPercent) / 100 : 0
formData.value.discountPrice = Math.round(discountPrice * 100) / 100
formData.value.totalPrice = Math.round((totalPrice - discountPrice + Number(val.otherPrice || 0)) * 100) / 100
},
{ deep: true },
)
/** 加载下拉列表数据 */
async function loadDropdownData() {
try {
const { http } = await import('@/http/http')
const [suppliers, accounts, warehouses] = await Promise.all([
http.get<SupplierSimple[]>('/erp/supplier/simple-list'),
http.get<AccountSimple[]>('/erp/account/simple-list'),
http.get<WarehouseSimple[]>('/erp/warehouse/simple-list'),
])
supplierList.value = suppliers || []
accountList.value = accounts || []
warehouseList.value = warehouses || []
// 设置默认账户
const defaultAccount = accountList.value.find(a => a.defaultStatus)
if (defaultAccount && !formData.value.accountId) {
formData.value.accountId = defaultAccount.id
}
// 设置默认仓库
defaultWarehouse.value = warehouseList.value.find(w => w.defaultStatus)
} catch {
// error handled by http
}
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/purchase-in/index')
}
/** 删除入库明细行 */
function handleRemoveItem(index: number) {
uni.showModal({
title: '提示',
content: `确定要删除第 ${index + 1} 项产品吗?`,
success: (res) => {
if (res.confirm) {
formData.value.items?.splice(index, 1)
}
},
})
}
/** 打开订单选择弹窗 */
function openOrderSelect() {
orderSelectVisible.value = true
orderQueryParams.value.pageNo = 1
orderList.value = []
selectedOrderId.value = formData.value.orderId
getOrderList()
}
/** 获取可入库订单列表 */
async function getOrderList() {
orderLoadMoreState.value = 'loading'
try {
const data = await getPurchaseOrderPage(orderQueryParams.value)
if (orderQueryParams.value.pageNo === 1) {
orderList.value = data.list
} else {
orderList.value = [...orderList.value, ...data.list]
}
orderTotal.value = data.total
orderLoadMoreState.value = orderList.value.length >= orderTotal.value ? 'finished' : 'loading'
} catch {
orderLoadMoreState.value = 'error'
}
}
/** 加载更多订单 */
function loadMoreOrders() {
if (orderLoadMoreState.value === 'finished') return
orderQueryParams.value.pageNo++
getOrderList()
}
/** 选择订单 */
function handleSelectOrder(item: PurchaseOrder) {
selectedOrderId.value = item.id
}
/** 确认选择订单 */
async function confirmSelectOrder() {
if (!selectedOrderId.value) return
try {
toast.loading('加载订单详情...')
const orderDetail = await getPurchaseOrder(selectedOrderId.value)
// 设置订单信息
formData.value.orderId = orderDetail.id
formData.value.orderNo = orderDetail.no
formData.value.supplierId = orderDetail.supplierId
formData.value.supplierName = orderDetail.supplierName
formData.value.accountId = orderDetail.accountId
formData.value.discountPercent = orderDetail.discountPercent
formData.value.remark = orderDetail.remark
// 设置入库明细
if (orderDetail.items) {
formData.value.items = orderDetail.items
.filter(item => (item.count || 0) - (item.inCount || 0) > 0)
.map(item => ({
productId: item.productId,
productName: item.productName,
productUnitId: item.productUnitId,
productUnitName: item.productUnitName,
productPrice: item.productPrice,
productSpec: item.productSpec,
productBarCode: item.productBarCode,
count: (item.count || 0) - (item.inCount || 0),
totalCount: item.count,
inCount: item.inCount,
taxPercent: item.taxPercent,
warehouseId: defaultWarehouse.value?.id,
warehouseName: defaultWarehouse.value?.name,
stockCount: item.stockCount,
orderItemId: item.id,
remark: item.remark,
}))
}
orderSelectVisible.value = false
} finally {
toast.close()
}
}
/** 加载详情 */
async function getDetail() {
if (!props.id) {
return
}
try {
toast.loading('加载中...')
formData.value = await getPurchaseIn(props.id)
} finally {
toast.close()
}
}
/** 提交表单 */
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.warehouseId) {
toast.warning(`${i + 1} 项产品请选择仓库`)
return
}
if (!item.count || Number(item.count) <= 0) {
toast.warning(`${i + 1} 项产品数量不能为空`)
return
}
}
formLoading.value = true
try {
if (props.id) {
await updatePurchaseIn(formData.value)
toast.success('修改成功')
} else {
await createPurchaseIn(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
await loadDropdownData()
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,447 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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, item.isQualified)"
>
{{ getStatusText(item.status, item.isQualified) }}
</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.inTime) }}</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-[#e6a23c] font-semibold">¥{{ item.totalPrice || 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.paymentPrice || 0 }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">已付</view>
</view>
<view class="text-center">
<view
class="text-30rpx font-semibold"
:class="(item.totalPrice || 0) - (item.paymentPrice || 0) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
>
¥{{ (item.totalPrice || 0) - (item.paymentPrice || 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-in:query'])"
size="small" plain @click="handleDetail(item)"
>
详情
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-in:update']) && item.status === 10"
size="small" type="primary" plain @click="handleEdit(item)"
>
修改
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-in:update-status']) && item.status === 10"
size="small" type="success" plain @click="handleAudit(item)"
>
审核
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-in:update-status']) && (item.status === 20 || item.status === 30)"
size="small" type="warning" plain @click="handleReverseAudit(item.id!)"
>
反审核
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-in:delete']) && item.status === 10"
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-in:create'])"
position="right-bottom"
type="primary"
:expandable="false"
@click="handleAdd"
/>
<!-- 审核弹窗 -->
<wd-popup v-model="auditVisible" position="bottom" closable @close="auditVisible = false">
<view class="p-32rpx">
<view class="text-32rpx text-[#333] font-semibold mb-32rpx text-center">
采购入库审核
</view>
<view class="mb-24rpx">
<view class="text-26rpx text-[#666] mb-12rpx">是否合格</view>
<wd-switch v-model="auditForm.isQualified" @change="handleQualifiedChange" />
</view>
<view v-if="!auditForm.isQualified" class="mb-24rpx">
<view class="text-26rpx text-[#666] mb-12rpx">返回方式</view>
<wd-radio-group v-model="auditForm.returnType" shape="button">
<wd-radio
v-for="opt in RETURN_TYPE_OPTIONS"
:key="opt.value"
:value="opt.value"
>
{{ opt.label }}
</wd-radio>
</wd-radio-group>
</view>
<view v-if="!auditForm.isQualified" class="mb-24rpx">
<view class="text-26rpx text-[#666] mb-12rpx">返回备注</view>
<wd-textarea
v-model="auditForm.returnRemark"
placeholder="请输入返回方式备注"
:maxlength="200"
/>
</view>
<view class="flex gap-24rpx mt-32rpx">
<wd-button class="flex-1" plain @click="auditVisible = false">
取消
</wd-button>
<wd-button class="flex-1" type="primary" :loading="auditLoading" @click="submitAudit">
确定
</wd-button>
</view>
</view>
</wd-popup>
</view>
</template>
<script lang="ts" setup>
import type { PurchaseIn } from '@/api/erp/purchase-in'
import type { LoadMoreState } from '@/http/types'
import { onReachBottom } from '@dcloudio/uni-app'
import { onMounted, reactive, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deletePurchaseIn, getPurchaseInPage, RETURN_TYPE_OPTIONS, updatePurchaseInStatus } from '@/api/erp/purchase-in'
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<PurchaseIn[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const activeStatus = ref<number | undefined>(undefined)
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
})
const statusTabs = [
{ label: '全部', value: undefined },
{ label: '未审核', value: 10 },
{ label: '已审核', value: 20 },
{ label: '不合格', value: 30 },
]
// 审核相关
const auditVisible = ref(false)
const auditLoading = ref(false)
const auditForm = reactive({
id: undefined as number | undefined,
isQualified: true,
returnType: undefined as string | undefined,
returnRemark: undefined as string | undefined,
})
/** 格式化日期 */
function formatDate(date?: string) {
if (!date) return '-'
return new Date(date).toLocaleDateString('zh-CN')
}
/** 获取状态文本 */
function getStatusText(status?: number, isQualified?: boolean) {
if (status === 10) return '未审核'
if (status === 20) return isQualified ? '已审核' : '不合格'
if (status === 30) return '不合格'
return '未知'
}
/** 获取状态样式 */
function getStatusClass(status?: number, isQualified?: boolean) {
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
if (status === 20) return isQualified ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff1f0] text-[#f5222d]'
if (status === 30) return 'bg-[#fff1f0] text-[#f5222d]'
return 'bg-[#f5f5f5] text-[#999]'
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 查询采购入库列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
const data = await getPurchaseInPage(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: PurchaseIn) {
if (item.status === 20 || item.status === 30) {
handleDetail(item)
} else if (item.status === 10) {
handleEdit(item)
}
}
/** 新增采购入库 */
function handleAdd() {
uni.navigateTo({
url: '/pages-erp/purchase-in/form/index',
})
}
/** 查看详情 */
function handleDetail(item: PurchaseIn) {
uni.navigateTo({
url: `/pages-erp/purchase-in/detail/index?id=${item.id}`,
})
}
/** 编辑 */
function handleEdit(item: PurchaseIn) {
uni.navigateTo({
url: `/pages-erp/purchase-in/form/index?id=${item.id}`,
})
}
/** 打开审核弹窗 */
function handleAudit(item: PurchaseIn) {
auditForm.id = item.id
auditForm.isQualified = true
auditForm.returnType = undefined
auditForm.returnRemark = undefined
auditVisible.value = true
}
/** 合格状态变化 */
function handleQualifiedChange(val: boolean) {
if (val) {
auditForm.returnType = undefined
auditForm.returnRemark = undefined
}
}
/** 提交审核 */
async function submitAudit() {
if (!auditForm.id) return
if (!auditForm.isQualified && !auditForm.returnType) {
toast.warning('请选择返回方式')
return
}
auditLoading.value = true
try {
await updatePurchaseInStatus({
id: auditForm.id,
isQualified: auditForm.isQualified,
returnType: auditForm.returnType,
returnRemark: auditForm.returnRemark,
status: auditForm.isQualified ? 20 : 30,
})
toast.success('审核成功')
auditVisible.value = false
list.value = []
queryParams.value.pageNo = 1
getList()
} finally {
auditLoading.value = false
}
}
/** 反审核 */
function handleReverseAudit(id: number) {
uni.showModal({
title: '提示',
content: '确定反审核该入库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updatePurchaseInStatus({
id,
isQualified: false,
status: 10,
})
toast.success('反审核成功')
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 deletePurchaseIn([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>

View File

@@ -0,0 +1,239 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar title="自动比价" left-arrow placeholder safe-area-inset-top fixed @click-left="handleBack" />
<view class="erp-page__body">
<view class="erp-section">
<view class="erp-section__title">比价单信息</view>
<view class="erp-field-row"><text>询比单号</text><text>{{ inquiry?.no || '-' }}</text></view>
<view class="erp-field-row"><text>产品名称</text><text>{{ inquiry?.productName || '-' }}</text></view>
<view class="erp-field-row"><text>需求数量</text><text>{{ formatCount(inquiry?.requireCount) }}</text></view>
</view>
<view class="erp-section">
<view class="erp-section__title">评分权重合计 {{ totalWeight }}%</view>
<view class="erp-form-item-list">
<view class="erp-form-input-row">
<text class="erp-form-input-label">价格权重</text>
<wd-input v-model="weightConfig.priceWeight" type="number" placeholder="0-100" />
</view>
<view class="erp-form-input-row">
<text class="erp-form-input-label">质量权重</text>
<wd-input v-model="weightConfig.qualityWeight" type="number" placeholder="0-100" />
</view>
<view class="erp-form-input-row">
<text class="erp-form-input-label">交付权重</text>
<wd-input v-model="weightConfig.deliveryWeight" type="number" placeholder="0-100" />
</view>
<view class="erp-form-input-row">
<text class="erp-form-input-label">服务权重</text>
<wd-input v-model="weightConfig.serviceWeight" type="number" placeholder="0-100" />
</view>
</view>
</view>
<view class="erp-section">
<view class="erp-section__title">供应商报价评分</view>
<view v-if="quoteList.length">
<view
v-for="(item, index) in quoteList"
:key="item.id || index"
class="erp-form-item-card erp-form-item-card--padded"
:class="{ 'border-[2rpx] border-[#52c41a]': bestQuote?.id === item.id }"
>
<view class="mb-12rpx flex items-center justify-between">
<text class="erp-card-title">{{ item.supplierName || '未命名供应商' }}</text>
<text class="text-24rpx text-[#1890ff]">{{ item.totalScore != null ? `${item.totalScore.toFixed(2)}` : '未计算' }}</text>
</view>
<view class="erp-field-row"><text>单价</text><text>¥{{ formatPrice(item.unitPrice) }}</text></view>
<view class="erp-field-row"><text>总价</text><text>¥{{ formatPrice(item.totalPrice) }}</text></view>
<view class="erp-field-row"><text>交货周期</text><text>{{ item.deliveryCycle ? `${item.deliveryCycle}` : '-' }}</text></view>
<view class="erp-form-input-row">
<text class="erp-form-input-label">质量评分</text>
<wd-input v-model="item.qualityScore" type="number" placeholder="0-100" />
</view>
<view class="erp-form-input-row">
<text class="erp-form-input-label">服务评分</text>
<wd-input v-model="item.serviceScore" type="number" placeholder="0-100" />
</view>
<view class="mt-12rpx text-24rpx text-[#999]">
价格得分{{ item.priceScore != null ? item.priceScore.toFixed(1) : '-' }}交付得分{{ item.deliveryScore != null ? item.deliveryScore.toFixed(1) : '-' }}
</view>
</view>
</view>
<view v-else class="erp-empty">暂无可比价报价</view>
</view>
<view v-if="bestQuote" class="erp-section">
<view class="erp-section__title">推荐结果</view>
<view class="text-28rpx text-[#52c41a] font-semibold">
推荐供应商{{ bestQuote.supplierName }}综合得分 {{ bestQuote.totalScore?.toFixed(2) }}
</view>
</view>
<view v-if="analysisSummary" class="erp-section">
<view class="erp-section__title">智能分析</view>
<view class="text-26rpx leading-[1.7] text-[#666] whitespace-pre-wrap">{{ analysisSummary }}</view>
<view v-if="compareRiskTips.length" class="mt-16rpx text-24rpx text-[#f5222d]">
<view v-for="item in compareRiskTips" :key="item">{{ item }}</view>
</view>
</view>
</view>
<view class="yd-detail-footer">
<view class="yd-detail-footer-actions">
<wd-button class="flex-1" type="primary" :loading="loading" @click="handleCompare">开始比价</wd-button>
<wd-button class="flex-1" type="success" :disabled="!bestQuote" :loading="saving" @click="handleSave">保存结果</wd-button>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import type { PurchaseInquiry, PurchaseInquiryCompareResp, PurchaseInquiryQuote } from '@/api/erp/purchase-inquiry'
import { computed, onMounted, reactive, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { comparePurchaseInquiry, getPurchaseInquiry, selectPurchaseInquiryQuote, updatePurchaseInquiry } from '@/api/erp/purchase-inquiry'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{ id?: number | any }>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const toast = useToast()
const inquiry = ref<PurchaseInquiry>()
const quoteList = ref<PurchaseInquiryQuote[]>([])
const loading = ref(false)
const saving = ref(false)
const analysisSummary = ref('')
const compareRiskTips = ref<string[]>([])
const bestQuote = ref<PurchaseInquiryQuote | null>(null)
const weightConfig = reactive({
priceWeight: 40,
qualityWeight: 25,
deliveryWeight: 20,
serviceWeight: 15,
})
const totalWeight = computed(() =>
Number(weightConfig.priceWeight || 0)
+ Number(weightConfig.qualityWeight || 0)
+ Number(weightConfig.deliveryWeight || 0)
+ Number(weightConfig.serviceWeight || 0),
)
function formatPrice(value?: number) {
return Number(value || 0).toFixed(2)
}
function formatCount(value?: number) {
return Number(value || 0).toFixed(2)
}
function handleBack() {
navigateBackPlus(`/pages-erp/purchase-inquiry/detail/index?id=${props.id}`)
}
async function loadData() {
if (!props.id) return
inquiry.value = await getPurchaseInquiry(Number(props.id))
quoteList.value = inquiry.value.quotes || []
bestQuote.value = quoteList.value.find(v => v.isSelected) || null
}
function applyCompareResult(result: PurchaseInquiryCompareResp) {
const currentMap = new Map((quoteList.value || []).map(quote => [quote.id, quote]))
quoteList.value = (result.quotes || []).map(quote => {
const current = currentMap.get(quote.quoteId)
return {
...current,
id: quote.quoteId,
supplierId: quote.supplierId,
supplierName: quote.supplierName,
unitPrice: quote.unitPrice,
totalPrice: quote.totalPrice,
deliveryCycle: quote.deliveryCycle,
expectedArrivalDate: quote.expectedArrivalDate,
qualificationFile: quote.qualificationFile,
priceScore: quote.priceScore,
qualityScore: quote.qualityScore,
deliveryScore: quote.deliveryScore,
serviceScore: quote.serviceScore,
totalScore: quote.totalScore,
isSelected: quote.recommended,
}
})
analysisSummary.value = result.analysisSummary || ''
compareRiskTips.value = result.riskTips || []
bestQuote.value = quoteList.value.find(v => v.id === result.recommendedQuoteId) || null
}
async function handleCompare() {
if (!props.id) return
if (totalWeight.value !== 100) {
toast.warning('权重合计必须等于 100%')
return
}
if (quoteList.value.length < 2) {
toast.warning('至少需要 2 条报价才能比价')
return
}
if (quoteList.value.some(v => !v.unitPrice || Number(v.unitPrice) <= 0)) {
toast.warning('请先补全所有报价单价')
return
}
loading.value = true
try {
const result = await comparePurchaseInquiry({
inquiryId: Number(props.id),
priceWeight: Number(weightConfig.priceWeight),
qualityWeight: Number(weightConfig.qualityWeight),
deliveryWeight: Number(weightConfig.deliveryWeight),
serviceWeight: Number(weightConfig.serviceWeight),
quotes: quoteList.value
.filter(v => !!v.id)
.map(v => ({
quoteId: Number(v.id),
qualityScore: v.qualityScore != null ? Number(v.qualityScore) : undefined,
serviceScore: v.serviceScore != null ? Number(v.serviceScore) : undefined,
})),
})
applyCompareResult(result)
if (bestQuote.value) {
toast.success(`比价完成,推荐供应商:${bestQuote.value.supplierName}`)
}
} finally {
loading.value = false
}
}
async function handleSave() {
if (!inquiry.value?.id || !bestQuote.value) return
saving.value = true
try {
await updatePurchaseInquiry({
...inquiry.value,
quotes: quoteList.value,
})
if (bestQuote.value.id) {
await selectPurchaseInquiryQuote(inquiry.value.id, Number(bestQuote.value.id))
}
toast.success('保存成功')
setTimeout(() => handleBack(), 500)
} finally {
saving.value = false
}
}
onMounted(() => {
loadData()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,241 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar title="采购询比详情" left-arrow placeholder safe-area-inset-top fixed @click-left="handleBack" />
<view v-if="detail">
<wd-cell-group title="基本信息" border>
<wd-cell title="询比单号" :value="detail.no || '-'" />
<wd-cell title="状态">
<view class="rounded-8rpx px-16rpx py-4rpx text-24rpx" :class="getStatusClass(detail.status)">
{{ getStatusText(detail.status) }}
</view>
</wd-cell>
<wd-cell title="产品" :value="detail.productName || '-'" />
<wd-cell title="需求数量" :value="formatCount(detail.requireCount)" />
<wd-cell title="预算金额" :value="`¥${formatPrice(detail.budgetPrice)}`" />
<wd-cell title="询价时间" :value="formatDate(detail.inquiryTime)" />
<wd-cell title="截止时间" :value="formatDate(detail.deadline)" />
<wd-cell title="创建人" :value="detail.creatorName || '-'" />
</wd-cell-group>
<wd-cell-group v-if="detail.remark" title="备注" border>
<wd-cell :value="detail.remark" />
</wd-cell-group>
<view class="mx-24rpx mt-24rpx">
<view class="mb-16rpx text-32rpx text-[#333] font-semibold">供应商报价{{ detail.quotes?.length || 0 }}</view>
<view v-if="detail.quotes?.length">
<view v-for="(item, index) in detail.quotes" :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">
<text class="text-28rpx text-[#333] font-semibold">{{ item.supplierName || '未命名供应商' }}</text>
<text v-if="item.isSelected" class="text-24rpx text-[#52c41a]">已中选</text>
</view>
<view class="p-24rpx">
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">联系人</text>
<text>{{ item.contactName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">联系电话</text>
<text>{{ item.contactPhone || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">单价</text>
<text>¥{{ formatPrice(item.unitPrice) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">总价</text>
<text>¥{{ formatPrice(item.totalPrice) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">交货周期</text>
<text>{{ item.deliveryCycle ? `${item.deliveryCycle}` : '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">预计到货</text>
<text>{{ formatDate(item.expectedArrivalDate) }}</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: 420rpx;">{{ item.paymentTerms || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">评分</text>
<text>{{ item.totalScore != null ? item.totalScore.toFixed(2) : '-' }}</text>
</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>
</view>
<view class="yd-detail-footer">
<view class="yd-detail-footer-actions">
<wd-button v-if="hasAccessByCodes(['erp:purchase-inquiry:update'])" class="flex-1" type="primary" @click="handlePublish">
邀请
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-inquiry:update']) && detail?.status !== 30"
class="flex-1"
type="warning"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-inquiry:update']) && detail?.status === 20 && (detail?.quoteCount || 0) >= 2"
class="flex-1"
type="success"
@click="handleCompare"
>
比价
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-inquiry:update-status']) && detail?.status === 10"
class="flex-1"
type="success"
@click="handleUpdateStatus(20)"
>
询价
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-inquiry:update-status']) && detail?.status === 20"
class="flex-1"
type="success"
@click="handleUpdateStatus(30)"
>
完成
</wd-button>
<wd-button v-if="hasAccessByCodes(['erp:purchase-inquiry:delete'])" class="flex-1" type="error" :loading="deleting" @click="handleDelete">
删除
</wd-button>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import type { PurchaseInquiry } from '@/api/erp/purchase-inquiry'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deletePurchaseInquiry, getPurchaseInquiry, updatePurchaseInquiryStatus } from '@/api/erp/purchase-inquiry'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{ id?: number | any }>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const detail = ref<PurchaseInquiry>()
const deleting = ref(false)
function formatPrice(value?: number) {
return Number(value || 0).toFixed(2)
}
function formatCount(value?: number) {
return Number(value || 0).toFixed(2)
}
function formatDate(value?: string | number | Date) {
if (!value) return '-'
const date = new Date(value)
if (Number.isNaN(date.getTime())) return String(value).slice(0, 10)
const month = `${date.getMonth() + 1}`.padStart(2, '0')
const day = `${date.getDate()}`.padStart(2, '0')
return `${date.getFullYear()}-${month}-${day}`
}
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-[#eef3ff] text-[#3f7cff]'
case 20: return 'bg-[#fff7e8] text-[#d48806]'
case 30: return 'bg-[#f0f9eb] text-[#52c41a]'
default: return 'bg-[#f5f5f5] text-[#999]'
}
}
function handleBack() {
navigateBackPlus('/pages-erp/purchase-inquiry/index')
}
async function getDetail() {
if (!props.id) return
detail.value = await getPurchaseInquiry(props.id)
}
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/purchase-inquiry/form/index?id=${props.id}` })
}
function handlePublish() {
uni.navigateTo({ url: `/pages-erp/purchase-inquiry/publish/index?id=${props.id}` })
}
function handleCompare() {
uni.navigateTo({ url: `/pages-erp/purchase-inquiry/compare/index?id=${props.id}` })
}
function handleUpdateStatus(status: number) {
if (!props.id) return
const actionText = status === 20 ? '开始询价' : '完成'
uni.showModal({
title: '提示',
content: `确定${actionText}该询比单吗?`,
success: async (res) => {
if (!res.confirm) return
try {
await updatePurchaseInquiryStatus(props.id, status)
toast.success(`${actionText}成功`)
getDetail()
} catch {
// http handled
}
},
})
}
function handleDelete() {
if (!props.id) return
uni.showModal({
title: '提示',
content: '确定要删除该采购询比吗?',
success: async (res) => {
if (!res.confirm) return
deleting.value = true
try {
await deletePurchaseInquiry([props.id])
toast.success('删除成功')
setTimeout(() => handleBack(), 500)
} finally {
deleting.value = false
}
},
})
}
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,266 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar :title="pageTitle" left-arrow placeholder safe-area-inset-top fixed @click-left="handleBack" />
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-cell title="询比单号" :value="formData.no || '保存后自动生成'" />
<wd-cell title="询价时间" title-width="180rpx" prop="inquiryTime" center>
<wd-datetime-picker v-model="formData.inquiryTime" type="date" label="" placeholder="请选择询价时间" />
</wd-cell>
<wd-cell title="截止时间" title-width="180rpx" center>
<wd-datetime-picker v-model="formData.deadline" type="date" label="" placeholder="请选择截止时间" />
</wd-cell>
<wd-cell title="产品" title-width="180rpx" prop="productId" center>
<wd-picker v-model="formData.productId" :columns="productColumns" placeholder="请选择产品" @confirm="onProductConfirm" />
</wd-cell>
<wd-input v-model="formData.requireCount" label="需求数量" label-width="180rpx" type="number" placeholder="请输入需求数量" clearable />
<wd-input v-model="formData.budgetPrice" 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 class="erp-form-section-heading">
<view class="text-32rpx text-[#333] font-semibold">供应商报价{{ formData.quotes.length }}</view>
<wd-button size="small" type="primary" @click="handleAddQuote">+ 添加报价</wd-button>
</view>
<view v-for="(item, index) in formData.quotes" :key="item.id || index" class="erp-form-item-card">
<view class="erp-form-item-card__header">
<text class="erp-card-title">报价 #{{ index + 1 }}</text>
<wd-button size="small" type="error" plain @click="handleRemoveQuote(index)">删除</wd-button>
</view>
<view class="erp-form-item-list">
<view class="mb-16rpx">
<text class="mb-8rpx block text-24rpx text-[#999]">供应商</text>
<wd-picker v-model="item.supplierId" :columns="supplierColumns" placeholder="请选择供应商" @confirm="(e: any) => onSupplierConfirm(e, index)" />
</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.contactName" placeholder="请输入联系人" clearable />
</view>
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">联系电话</text>
<wd-input v-model="item.contactPhone" 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.unitPrice" 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 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.deliveryCycle" type="number" placeholder="请输入交货周期" clearable />
</view>
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">预计到货</text>
<wd-datetime-picker v-model="item.expectedArrivalDate" type="date" label="" placeholder="请选择日期" />
</view>
</view>
<view class="mb-16rpx">
<text class="mb-8rpx block text-24rpx text-[#999]">付款条件</text>
<wd-input v-model="item.paymentTerms" placeholder="请输入付款条件" clearable />
</view>
<view class="mb-16rpx">
<text class="mb-8rpx block text-24rpx text-[#999]">资质附件 URL</text>
<wd-input v-model="item.qualificationFile" placeholder="请输入附件地址" clearable />
</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.quotes.length === 0" class="py-60rpx text-center text-28rpx text-[#999]">
暂无报价点击添加报价开始录入
</view>
</view>
<view class="yd-detail-footer">
<wd-button type="primary" block :loading="submitting" @click="handleSubmit">保存</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { ProductSimple } from '@/api/erp/product'
import type { PurchaseInquiry, PurchaseInquiryQuote } from '@/api/erp/purchase-inquiry'
import type { SupplierSimple } from '@/api/erp/supplier'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createPurchaseInquiry, getPurchaseInquiry, updatePurchaseInquiry } from '@/api/erp/purchase-inquiry'
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 formRef = ref<FormInstance>()
const submitting = ref(false)
const productList = ref<ProductSimple[]>([])
const supplierList = ref<SupplierSimple[]>([])
interface InquiryFormModel extends Omit<PurchaseInquiry, 'inquiryTime' | 'deadline' | 'quotes'> {
inquiryTime?: string | number
deadline?: string | number
quotes: (Omit<PurchaseInquiryQuote, 'quoteDate' | 'expectedArrivalDate'> & {
quoteDate?: string | number
expectedArrivalDate?: string | number
})[]
}
const formData = ref<InquiryFormModel>({
id: undefined,
no: undefined,
productId: undefined,
productName: undefined,
requireCount: 1,
budgetPrice: 0,
inquiryTime: Date.now(),
deadline: undefined,
remark: '',
quotes: [],
})
const formRules = {
productId: [{ required: true, message: '产品不能为空' }],
inquiryTime: [{ required: true, message: '询价时间不能为空' }],
requireCount: [{ required: true, message: '需求数量不能为空' }],
}
const pageTitle = computed(() => props.id ? '编辑采购询比' : '新增采购询比')
const productColumns = computed(() => [productList.value.map(v => ({ label: v.name, value: v.id }))])
const supplierColumns = computed(() => [supplierList.value.map(v => ({ label: v.name, value: v.id }))])
function onProductConfirm({ value }: any) {
const productId = value?.[0] ? Number(value[0]) : undefined
formData.value.productId = productId
const product = productList.value.find(v => v.id === productId)
formData.value.productName = product?.name
}
function onSupplierConfirm({ value }: any, index: number) {
const supplierId = value?.[0] ? Number(value[0]) : undefined
const current = formData.value.quotes?.[index]
if (!current) return
current.supplierId = supplierId
const supplier = supplierList.value.find(v => v.id === supplierId)
current.supplierName = supplier?.name
}
function calcTotalPrice(item: PurchaseInquiryQuote) {
const unitPrice = Number(item.unitPrice || 0)
const requireCount = Number(formData.value.requireCount || 0)
return (unitPrice * requireCount).toFixed(2)
}
function handleAddQuote() {
formData.value.quotes = formData.value.quotes || []
formData.value.quotes.push({
supplierId: undefined,
supplierName: undefined,
contactName: '',
contactPhone: '',
unitPrice: undefined,
totalPrice: undefined,
paymentTerms: '',
deliveryCycle: undefined,
expectedArrivalDate: undefined,
qualificationFile: '',
remark: '',
})
}
function handleRemoveQuote(index: number) {
uni.showModal({
title: '提示',
content: `确定删除第 ${index + 1} 条报价吗?`,
success: (res) => {
if (res.confirm) {
formData.value.quotes?.splice(index, 1)
}
},
})
}
function handleBack() {
navigateBackPlus('/pages-erp/purchase-inquiry/index')
}
async function getDetail() {
if (!props.id) return
const detail = await getPurchaseInquiry(props.id)
formData.value = {
...detail,
inquiryTime: detail.inquiryTime as string | number | undefined,
deadline: detail.deadline as string | number | undefined,
quotes: (detail.quotes || []).map(item => ({
...item,
quoteDate: item.quoteDate as string | number | undefined,
expectedArrivalDate: item.expectedArrivalDate as string | number | undefined,
})),
}
formData.value.quotes = formData.value.quotes || []
}
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
const quotes = formData.value.quotes || []
for (let i = 0; i < quotes.length; i++) {
const item = quotes[i]
if (!item.supplierId) {
toast.warning(`${i + 1} 条报价未选择供应商`)
return
}
if (!item.unitPrice || Number(item.unitPrice) <= 0) {
toast.warning(`${i + 1} 条报价单价不能为空`)
return
}
item.totalPrice = Number(calcTotalPrice(item))
}
submitting.value = true
try {
if (props.id) {
await updatePurchaseInquiry(formData.value as PurchaseInquiry)
toast.success('修改成功')
} else {
await createPurchaseInquiry(formData.value as PurchaseInquiry)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
submitting.value = false
}
}
onMounted(async () => {
const [products, suppliers] = await Promise.all([getProductSimpleList(), getSupplierSimpleList()])
productList.value = products || []
supplierList.value = suppliers || []
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,392 @@
<template>
<view class="yd-page-container erp-page">
<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="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 class="ml-16rpx line-clamp-1 text-right" style="max-width: 420rpx;">{{ item.productName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">询价时间</text>
<text>{{ formatDate(item.inquiryTime) }}</text>
</view>
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">截止时间</text>
<text>{{ formatDate(item.deadline) }}</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">{{ formatCount(item.requireCount) }}</view>
<view class="mt-4rpx text-22rpx text-[#999]">需求数量</view>
</view>
<view class="text-center">
<view class="text-30rpx text-[#e6a23c] font-semibold">¥{{ formatPrice(item.budgetPrice) }}</view>
<view class="mt-4rpx text-22rpx text-[#999]">预算金额</view>
</view>
<view class="text-center">
<view class="text-30rpx text-[#409eff] font-semibold">{{ item.quoteCount || 0 }}</view>
<view class="mt-4rpx text-22rpx text-[#999]">报价数</view>
</view>
<view class="text-center">
<view class="text-30rpx text-[#52c41a] font-semibold">¥{{ formatPrice(item.minQuotePrice) }}</view>
<view class="mt-4rpx text-22rpx text-[#999]">最低报价</view>
</view>
</view>
</view>
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
<wd-button v-if="hasAccessByCodes(['erp:purchase-inquiry:query'])" size="small" plain @click="handleDetail(item)">
详情
</wd-button>
<wd-button v-if="hasAccessByCodes(['erp:purchase-inquiry:update'])" size="small" type="primary" plain @click="handlePublish(item)">
邀请
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-inquiry:update']) && item.status !== 30"
size="small"
type="primary"
plain
@click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-inquiry:update-status']) && item.status === 10"
size="small"
type="success"
plain
@click="handleUpdateStatus(item.id!, 20)"
>
询价
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-inquiry:update']) && item.status === 20 && (item.quoteCount || 0) >= 2"
size="small"
type="warning"
plain
@click="handleCompare(item)"
>
比价
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-inquiry:update-status']) && item.status === 20"
size="small"
type="success"
plain
@click="handleUpdateStatus(item.id!, 30)"
>
完成
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-inquiry:delete'])"
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-inquiry: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" :style="{ paddingTop: `${getNavbarHeight()}px` }">
<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.productId" :columns="productColumns" placeholder="请选择产品" @confirm="onProductConfirm" />
</view>
<view class="yd-search-form-item">
<view class="yd-search-form-label">状态</view>
<wd-radio-group v-model="searchForm.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-item">
<view class="yd-search-form-label">创建人</view>
<wd-picker v-model="searchForm.creator" :columns="userColumns" placeholder="请选择创建人" @confirm="onUserConfirm" />
</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 { PurchaseInquiry } from '@/api/erp/purchase-inquiry'
import type { ProductSimple } from '@/api/erp/product'
import type { User } from '@/api/system/user'
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 { deletePurchaseInquiry, getPurchaseInquiryPage, updatePurchaseInquiryStatus } from '@/api/erp/purchase-inquiry'
import { getProductSimpleList } from '@/api/erp/product'
import { getSimpleUserList } from '@/api/system/user'
import { useAccess } from '@/hooks/useAccess'
import { getNavbarHeight, navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<PurchaseInquiry[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
})
const searchVisible = ref(false)
const productList = ref<ProductSimple[]>([])
const userList = ref<User[]>([])
const searchForm = reactive({
no: undefined as string | undefined,
productId: undefined as number | undefined,
status: -1,
creator: undefined as number | undefined,
})
const productColumns = computed(() => [[{ label: '全部', value: '' }, ...productList.value.map(v => ({ label: v.name, value: v.id }))]])
const userColumns = computed(() => [[{ label: '全部', value: '' }, ...userList.value.map(v => ({ label: v.nickname, value: v.id }))]])
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.no) conditions.push(`单号:${searchForm.no}`)
if (searchForm.productId) {
const product = productList.value.find(v => v.id === searchForm.productId)
conditions.push(`产品:${product?.name || searchForm.productId}`)
}
if (searchForm.status !== -1) conditions.push(`状态:${getStatusText(searchForm.status)}`)
if (searchForm.creator) {
const user = userList.value.find(v => v.id === searchForm.creator)
conditions.push(`创建人:${user?.nickname || searchForm.creator}`)
}
return conditions.length > 0 ? conditions.join(' | ') : '搜索采购询比'
})
function formatDate(value?: string | number | Date) {
if (!value) return '-'
const date = new Date(value)
if (Number.isNaN(date.getTime())) return String(value).slice(0, 10)
const month = `${date.getMonth() + 1}`.padStart(2, '0')
const day = `${date.getDate()}`.padStart(2, '0')
return `${date.getFullYear()}-${month}-${day}`
}
function formatPrice(value?: number) {
return Number(value || 0).toFixed(2)
}
function formatCount(value?: number) {
return Number(value || 0).toFixed(2)
}
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-[#eef3ff] text-[#3f7cff]'
case 20: return 'bg-[#fff7e8] text-[#d48806]'
case 30: return 'bg-[#f0f9eb] text-[#52c41a]'
default: return 'bg-[#f5f5f5] text-[#999]'
}
}
function onProductConfirm({ value }: any) {
searchForm.productId = value?.[0] ? Number(value[0]) : undefined
}
function onUserConfirm({ value }: any) {
searchForm.creator = value?.[0] ? Number(value[0]) : undefined
}
function handleBack() {
navigateBackPlus()
}
async function getList() {
loadMoreState.value = 'loading'
try {
const data = await getPurchaseInquiryPage({ ...queryParams.value })
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 handleSearch() {
searchVisible.value = false
queryParams.value = {
pageNo: 1,
pageSize: queryParams.value.pageSize,
no: searchForm.no,
productId: searchForm.productId,
status: searchForm.status === -1 ? undefined : searchForm.status,
creator: searchForm.creator,
}
list.value = []
getList()
}
function handleReset() {
searchForm.no = undefined
searchForm.productId = undefined
searchForm.status = -1
searchForm.creator = undefined
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10 }
list.value = []
getList()
}
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
function handleCardClick(item: PurchaseInquiry) {
if (item.status === 30) {
handleDetail(item)
} else {
handleEdit(item)
}
}
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/purchase-inquiry/form/index' })
}
function handleDetail(item: PurchaseInquiry) {
uni.navigateTo({ url: `/pages-erp/purchase-inquiry/detail/index?id=${item.id}` })
}
function handleEdit(item: PurchaseInquiry) {
uni.navigateTo({ url: `/pages-erp/purchase-inquiry/form/index?id=${item.id}` })
}
function handlePublish(item: PurchaseInquiry) {
uni.navigateTo({ url: `/pages-erp/purchase-inquiry/publish/index?id=${item.id}` })
}
function handleCompare(item: PurchaseInquiry) {
uni.navigateTo({ url: `/pages-erp/purchase-inquiry/compare/index?id=${item.id}` })
}
function handleUpdateStatus(id: number, status: number) {
const actionText = status === 20 ? '开始询价' : '完成'
uni.showModal({
title: '提示',
content: `确定${actionText}该询比单吗?`,
success: async (res) => {
if (!res.confirm) return
try {
await updatePurchaseInquiryStatus(id, status)
toast.success(`${actionText}成功`)
list.value = []
queryParams.value.pageNo = 1
getList()
} catch {
// http handled
}
},
})
}
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该采购询比吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deletePurchaseInquiry([id])
toast.success('删除成功')
list.value = []
queryParams.value.pageNo = 1
getList()
} catch {
// http handled
}
},
})
}
onReachBottom(() => {
loadMore()
})
onMounted(async () => {
const [products, users] = await Promise.all([getProductSimpleList(), getSimpleUserList()])
productList.value = products || []
userList.value = users || []
getList()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,218 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar title="询比邀请" left-arrow placeholder safe-area-inset-top fixed @click-left="handleBack" />
<view class="erp-page__body">
<view class="erp-section">
<view class="erp-section__title">询比信息</view>
<view class="erp-field-row"><text>询比单号</text><text>{{ inquiry?.no || '-' }}</text></view>
<view class="erp-field-row"><text>产品</text><text>{{ inquiry?.productName || '-' }}</text></view>
<view class="erp-field-row"><text>状态</text><text>{{ getStatusText(inquiry?.status) }}</text></view>
<view class="erp-field-row"><text>截止时间</text><text>{{ formatDateTime(inquiry?.deadline) }}</text></view>
</view>
<view class="erp-section">
<view class="erp-section__title">邀请设置</view>
<wd-cell-group border>
<wd-cell title="链接失效时间" title-width="180rpx" center>
<wd-datetime-picker v-model="formData.linkExpireTime" type="datetime" label="" placeholder="请选择链接失效时间" />
</wd-cell>
</wd-cell-group>
<view class="mt-24rpx text-26rpx text-[#666]">邀请供应商</view>
<view class="mt-16rpx">
<wd-checkbox-group v-model="formData.supplierIds" cell shape="button">
<wd-checkbox v-for="item in supplierList" :key="item.id" :model-value="item.id">
{{ item.name }}
</wd-checkbox>
</wd-checkbox-group>
</view>
<view class="mt-24rpx">
<wd-button type="primary" block :loading="submitting" @click="handleSubmit">发布 / 重新生成链接</wd-button>
</view>
</view>
<view class="erp-section">
<view class="erp-section__title">邀请概览</view>
<view class="grid grid-cols-2 gap-16rpx">
<view class="erp-metric-card">
<view class="erp-metric-card__label">已邀请</view>
<view class="erp-metric-card__value">{{ invitationList.length }}</view>
</view>
<view class="erp-metric-card">
<view class="erp-metric-card__label">已查看</view>
<view class="erp-metric-card__value">{{ summary.viewedCount }}</view>
</view>
<view class="erp-metric-card">
<view class="erp-metric-card__label">已报价</view>
<view class="erp-metric-card__value">{{ summary.quotedCount }}</view>
</view>
<view class="erp-metric-card">
<view class="erp-metric-card__label">待报价</view>
<view class="erp-metric-card__value">{{ summary.pendingCount }}</view>
</view>
</view>
</view>
<view class="erp-section">
<view class="erp-section__title">邀请记录</view>
<view v-if="invitationList.length">
<view v-for="item in invitationList" :key="item.id" class="erp-form-item-card erp-form-item-card--padded">
<view class="mb-12rpx flex items-center justify-between">
<text class="erp-card-title">{{ item.supplierName || '-' }}</text>
<text class="text-24rpx" :class="getInvitationStatusClass(item.status)">{{ getInvitationStatusText(item.status) }}</text>
</view>
<view class="erp-field-row"><text>报价单价</text><text>{{ item.unitPrice != null ? `¥${Number(item.unitPrice).toFixed(2)}` : '-' }}</text></view>
<view class="erp-field-row"><text>报价总额</text><text>{{ item.totalPrice != null ? `¥${Number(item.totalPrice).toFixed(2)}` : '-' }}</text></view>
<view class="erp-field-row"><text>预计到货</text><text>{{ formatDateTime(item.expectedArrivalDate) }}</text></view>
<view class="erp-field-row"><text>报价时间</text><text>{{ formatDateTime(item.quoteDate) }}</text></view>
<view class="erp-field-row"><text>首次查看</text><text>{{ formatDateTime(item.firstViewTime) }}</text></view>
<view class="erp-field-row"><text>提交来源</text><text>{{ item.submitSource || '-' }}</text></view>
<view class="mt-16rpx flex gap-12rpx">
<wd-button size="small" plain @click="copyLink(item.portalUrl)">复制链接</wd-button>
<wd-button v-if="item.qualificationFile" size="small" type="primary" plain @click="copyLink(item.qualificationFile)">复制附件地址</wd-button>
</view>
</view>
</view>
<view v-else class="erp-empty">暂无邀请记录</view>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import type { PurchaseInquiry, PurchaseInquiryInvitation, PurchaseInquiryPublishReq } from '@/api/erp/purchase-inquiry'
import type { SupplierSimple } from '@/api/erp/supplier'
import { computed, onMounted, reactive, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { getPurchaseInquiry, getPurchaseInquiryInvitationList, publishPurchaseInquiry } from '@/api/erp/purchase-inquiry'
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 inquiry = ref<PurchaseInquiry>()
const supplierList = ref<SupplierSimple[]>([])
const invitationList = ref<PurchaseInquiryInvitation[]>([])
const submitting = ref(false)
type PublishFormModel = Omit<PurchaseInquiryPublishReq, 'linkExpireTime'> & {
linkExpireTime?: string | number
}
const formData = reactive<PublishFormModel>({
inquiryId: 0,
supplierIds: [],
linkExpireTime: undefined,
})
const summary = computed(() => {
const viewedCount = invitationList.value.filter(v => [20, 30].includes(Number(v.status))).length
const quotedCount = invitationList.value.filter(v => !!v.quoteId || Number(v.status) === 30).length
const pendingCount = invitationList.value.filter(v => Number(v.status) === 10).length
return { viewedCount, quotedCount, pendingCount }
})
function getStatusText(status?: number) {
switch (status) {
case 10: return '待询价'
case 20: return '询价中'
case 30: return '已完成'
default: return '-'
}
}
function getInvitationStatusText(status?: number) {
switch (status) {
case 10: return '待报价'
case 20: return '已查看'
case 30: return '已报价'
case 40: return '已失效'
case 50: return '已作废'
default: return '-'
}
}
function getInvitationStatusClass(status?: number) {
switch (status) {
case 20: return 'text-[#d48806]'
case 30: return 'text-[#52c41a]'
case 40: return 'text-[#f5222d]'
default: return 'text-[#999]'
}
}
function formatDateTime(value?: string | number | Date) {
if (!value) return '-'
const date = new Date(value)
if (Number.isNaN(date.getTime())) return String(value)
const month = `${date.getMonth() + 1}`.padStart(2, '0')
const day = `${date.getDate()}`.padStart(2, '0')
const hour = `${date.getHours()}`.padStart(2, '0')
const minute = `${date.getMinutes()}`.padStart(2, '0')
return `${date.getFullYear()}-${month}-${day} ${hour}:${minute}`
}
function handleBack() {
navigateBackPlus(`/pages-erp/purchase-inquiry/detail/index?id=${props.id}`)
}
async function loadData() {
if (!props.id) return
formData.inquiryId = Number(props.id)
const [detail, suppliers, invitations] = await Promise.all([
getPurchaseInquiry(Number(props.id)),
getSupplierSimpleList(),
getPurchaseInquiryInvitationList(Number(props.id)),
])
inquiry.value = detail
supplierList.value = suppliers || []
invitationList.value = invitations || []
formData.supplierIds = invitationList.value.map(v => Number(v.supplierId)).filter(Boolean)
formData.linkExpireTime = (invitationList.value[0]?.linkExpireTime || detail?.deadline) as string | number | undefined
}
async function handleSubmit() {
if (!formData.supplierIds.length) {
toast.warning('请至少选择一个供应商')
return
}
submitting.value = true
try {
await publishPurchaseInquiry({
inquiryId: formData.inquiryId,
supplierIds: formData.supplierIds,
linkExpireTime: formData.linkExpireTime,
} as PurchaseInquiryPublishReq)
toast.success('询比邀请已发布')
await loadData()
} finally {
submitting.value = false
}
}
function copyLink(url?: string) {
if (!url) {
toast.warning('暂无可复制链接')
return
}
uni.setClipboardData({
data: url,
success: () => toast.success('链接已复制'),
})
}
onMounted(() => {
loadData()
})
</script>
<style lang="scss" scoped>
</style>

View 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>

View File

@@ -0,0 +1,297 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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>

View File

@@ -0,0 +1,529 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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" 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"
: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="erp-form-body">
<view class="erp-form-section-heading">
<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="erp-form-item-card"
>
<view class="erp-form-item-card__header">
<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="erp-form-item-list">
<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="erp-form-info-card">
<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>
<!-- 请购单选择弹窗 -->
<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>
<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 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<{
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,
purchaseRequisitionId: undefined,
purchaseRequisitionNo: 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 requisitionList = ref<PurchaseRequisition[]>([])
const requisitionPickerVisible = ref(false)
const requisitionLoading = ref(false)
/** 供应商下拉列 */
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 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]
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>

View File

@@ -0,0 +1,344 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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<{ pageNo: number; pageSize: number } & 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>

View File

@@ -0,0 +1,376 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="请购单详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 详情内容 -->
<view class="pb-180rpx">
<!-- 基本信息 -->
<wd-cell-group title="基本信息" border>
<wd-cell title="请购单号" :value="detail.no || '-'" />
<wd-cell title="请购类型">
<template #value>
<view
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
:class="getTypeClass(detail.type)"
>
{{ getTypeLabel(detail.type) }}
</view>
</template>
</wd-cell>
<wd-cell title="状态">
<template #value>
<view
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
:class="getStatusClass(detail.status)"
>
{{ getStatusLabel(detail.status) }}
</view>
</template>
</wd-cell>
<wd-cell title="优先级">
<template #value>
<view
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
:class="getPriorityClass(detail.priority)"
>
{{ getPriorityLabel(detail.priority) }}
</view>
</template>
</wd-cell>
<wd-cell title="紧急程度">
<template #value>
<view
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
:class="getEmergencyClass(detail.emergencyDegree)"
>
{{ getEmergencyLabel(detail.emergencyDegree) }}
</view>
</template>
</wd-cell>
<wd-cell title="请购人" :value="detail.requesterNickname || '-'" />
<wd-cell title="请购部门" :value="detail.requesterDeptName || '-'" />
<wd-cell title="请购时间" :value="formatDate(detail.requestTime)" />
<wd-cell title="期望到货" :value="formatDate(detail.expectedTime)" />
<wd-cell title="备注" :value="detail.remark || '-'" />
</wd-cell-group>
<!-- 金额信息 -->
<wd-cell-group title="金额信息" border>
<wd-cell title="合计数量" :value="formatCount(detail.totalCount)" />
<wd-cell title="合计产品金额" :value="formatPrice(detail.totalProductPrice)" />
<wd-cell title="合计税额" :value="formatPrice(detail.totalTaxPrice)" />
<wd-cell title="合计金额(含税)" :value="formatPrice(detail.totalPrice)" />
<wd-cell title="附加费" :value="formatPrice(detail.additionalFee)" />
</wd-cell-group>
<!-- 审核信息 -->
<wd-cell-group v-if="detail.status !== 1" title="审核信息" border>
<wd-cell title="审核人" :value="detail.approverName || '-'" />
<wd-cell title="审核时间" :value="formatDateTime(detail.approveTime)" />
<wd-cell title="审核意见" :value="detail.approveRemark || '-'" />
</wd-cell-group>
<!-- 请购产品清单 -->
<wd-cell-group title="请购产品清单" border>
<view v-if="!detail.items || detail.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品数据
</view>
<view v-else>
<view
v-for="(item, index) in detail.items"
:key="index"
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
>
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
{{ item.productName || '-' }}
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">规格</text>
<text class="text-[#666]">{{ item.productSpec || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">单位</text>
<text class="text-[#666]">{{ item.productUnitName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">需求数量</text>
<text class="text-[#333] font-semibold">{{ formatCount(item.count) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">参考单价</text>
<text class="text-[#666]">{{ formatPrice(item.productPrice) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">产品金额</text>
<text class="text-[#666]">{{ formatPrice(item.totalProductPrice) }}</text>
</view>
<view v-if="item.taxPercent" class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">税率</text>
<text class="text-[#666]">{{ item.taxPercent }}%</text>
</view>
<view v-if="item.taxPrice" class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">税额</text>
<text class="text-[#666]">{{ formatPrice(item.taxPrice) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">含税金额</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
<view v-if="item.supplierName" class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">建议供应商</text>
<text class="text-[#666]">{{ item.supplierName }}</text>
</view>
<view v-if="item.purpose" class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">用途</text>
<text class="text-[#666]">{{ item.purpose }}</text>
</view>
</view>
</view>
</wd-cell-group>
</view>
<!-- 底部操作按钮 -->
<view class="yd-detail-footer">
<wd-button
v-if="hasAccessByCodes(['erp:purchase-requisition:update']) && detail.status === 1"
type="primary"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-requisition:update-status']) && detail.status === 1"
type="success"
@click="handleApprove"
>
审核
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-requisition:approve']) && detail.status === 1"
type="warning"
@click="handleReject"
>
驳回
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-requisition:delete']) && detail.status === 1"
type="error"
@click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { PurchaseRequisition } from '@/api/erp/purchase-requisition'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import {
deletePurchaseRequisition,
EMERGENCY_OPTIONS,
getPurchaseRequisition,
PRIORITY_OPTIONS,
REQUISITION_TYPE_OPTIONS,
STATUS_OPTIONS,
updatePurchaseRequisitionStatus,
} from '@/api/erp/purchase-requisition'
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 detail = ref<PurchaseRequisition>({})
/** 获取类型标签 */
function getTypeLabel(type?: number) {
return REQUISITION_TYPE_OPTIONS.find(o => o.value === type)?.label || '-'
}
/** 获取类型样式 */
function getTypeClass(type?: number) {
const map: Record<number, string> = {
1: 'bg-[#e6f7ff] text-[#1890ff]',
2: 'bg-[#fff7e6] text-[#fa8c16]',
3: 'bg-[#f9f0ff] text-[#722ed1]',
}
return map[type || 1] || 'bg-[#f5f5f5] text-[#666]'
}
/** 获取状态标签 */
function getStatusLabel(status?: number) {
return STATUS_OPTIONS.find(o => o.value === status)?.label || '-'
}
/** 获取状态样式 */
function getStatusClass(status?: number) {
const map: Record<number, string> = {
1: 'bg-[#fff7e6] text-[#fa8c16]',
2: 'bg-[#f6ffed] text-[#52c41a]',
3: 'bg-[#fff1f0] text-[#f5222d]',
4: 'bg-[#f5f5f5] text-[#999]',
5: 'bg-[#e6f7ff] text-[#1890ff]',
}
return map[status || 1] || 'bg-[#f5f5f5] text-[#666]'
}
/** 获取优先级标签 */
function getPriorityLabel(priority?: number) {
return PRIORITY_OPTIONS.find(o => o.value === priority)?.label || '-'
}
/** 获取优先级样式 */
function getPriorityClass(priority?: number) {
const map: Record<number, string> = {
1: 'bg-[#f5f5f5] text-[#999]',
2: 'bg-[#e6f7ff] text-[#1890ff]',
3: 'bg-[#fff7e6] text-[#fa8c16]',
4: 'bg-[#fff1f0] text-[#f5222d]',
}
return map[priority || 1] || 'bg-[#f5f5f5] text-[#666]'
}
/** 获取紧急程度标签 */
function getEmergencyLabel(emergency?: number) {
return EMERGENCY_OPTIONS.find(o => o.value === emergency)?.label || '-'
}
/** 获取紧急程度样式 */
function getEmergencyClass(emergency?: number) {
const map: Record<number, string> = {
1: 'bg-[#f5f5f5] text-[#999]',
2: 'bg-[#e6f7ff] text-[#1890ff]',
3: 'bg-[#fff7e6] text-[#fa8c16]',
4: 'bg-[#fff1f0] text-[#f5222d]',
}
return map[emergency || 1] || 'bg-[#f5f5f5] text-[#666]'
}
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(date?: string) {
if (!date) return '-'
return new Date(date).toLocaleDateString('zh-CN')
}
/** 格式化日期时间 */
// function formatDateTime(dateStr?: string) {
// if (!dateStr) return '-'
// return dateStr.substring(0, 16).replace('T', ' ')
// }
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/purchase-requisition/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
detail.value = await getPurchaseRequisition(props.id)
} finally {
toast.close()
}
}
/** 编辑 */
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/purchase-requisition/form/index?id=${props.id}` })
}
/** 审核 */
function handleApprove() {
uni.showModal({
title: '提示',
content: '确定要审核通过该请购单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updatePurchaseRequisitionStatus(props.id, 2)
toast.success('审核成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 驳回 */
function handleReject() {
uni.showModal({
title: '提示',
content: '确定要驳回该请购单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updatePurchaseRequisitionStatus(props.id, 3)
toast.success('驳回成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete() {
uni.showModal({
title: '提示',
content: '确定要删除该请购单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deletePurchaseRequisition(props.id)
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} catch {
// error handled by http
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,564 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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="请购单号" :value="formData.no || '保存时自动生成'" />
<wd-cell
title="请购类型"
title-width="180rpx"
is-link
center
:value="getTypeLabel(formData.type)"
@click="typePickerVisible = true"
/>
<wd-cell
title="优先级"
title-width="180rpx"
is-link
center
:value="getPriorityLabel(formData.priority)"
@click="priorityPickerVisible = true"
/>
<wd-cell
title="紧急程度"
title-width="180rpx"
is-link
center
:value="getEmergencyLabel(formData.emergencyDegree)"
@click="emergencyPickerVisible = true"
/>
<wd-cell
title="请购时间"
title-width="180rpx"
is-link
center
:value="formData.requestTime ? formatDate(formData.requestTime) : '请选择'"
@click="requestDatePickerVisible = true"
/>
<wd-cell
title="期望到货"
title-width="180rpx"
is-link
center
:value="formData.expectedTime ? formatDate(formData.expectedTime) : '请选择'"
@click="expectedDatePickerVisible = true"
/>
<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="erp-form-body">
<view class="erp-form-section-heading">
<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="erp-form-item-card"
>
<view class="erp-form-item-card__header">
<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="erp-form-item-list">
<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="erp-form-info-card">
<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>
<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
@change="calcItemTotal(item)"
/>
</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
@change="calcItemTotal(item)"
/>
</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
@change="calcItemTotal(item)"
/>
</view>
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">含税金额</text>
<text class="block pt-16rpx text-28rpx text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
<view class="mb-16rpx flex gap-16rpx text-24rpx text-[#999]">
<view class="flex-1">
<text>产品金额: {{ formatPrice(item.totalProductPrice) }}</text>
</view>
<view class="flex-1">
<text>税额: {{ formatPrice(item.taxPrice) }}</text>
</view>
</view>
<view class="mb-16rpx">
<text class="mb-8rpx block text-24rpx text-[#999]">用途说明</text>
<wd-input
v-model="item.purpose"
placeholder="请输入用途"
clearable
/>
</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 v-if="formData.items?.length" class="mt-24rpx rounded-12rpx bg-white p-24rpx shadow-sm">
<view class="mb-12rpx flex justify-between text-28rpx">
<text class="text-[#999]">合计数量</text>
<text class="text-[#333]">{{ formatCount(totalCount) }}</text>
</view>
<view class="mb-12rpx flex justify-between text-28rpx">
<text class="text-[#999]">合计产品金额</text>
<text class="text-[#333]">{{ formatPrice(totalProductPrice) }}</text>
</view>
<view class="mb-12rpx flex justify-between text-28rpx">
<text class="text-[#999]">合计税额</text>
<text class="text-[#333]">{{ formatPrice(totalTaxPrice) }}</text>
</view>
<view class="flex justify-between text-28rpx">
<text class="text-[#999]">合计金额含税</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(totalPrice) }}</text>
</view>
</view>
</view>
<!-- 底部保存按钮 -->
<view class="yd-detail-footer">
<wd-button
type="primary"
block
:loading="formLoading"
@click="handleSubmit"
>
保存
</wd-button>
</view>
<!-- 请购类型选择器 -->
<wd-picker v-model:show="typePickerVisible"
:columns="typeColumns"
@confirm="onTypeConfirm"
/>
<!-- 优先级选择器 -->
<wd-picker v-model:show="priorityPickerVisible"
:columns="priorityColumns"
@confirm="onPriorityConfirm"
/>
<!-- 紧急程度选择器 -->
<wd-picker v-model:show="emergencyPickerVisible"
:columns="emergencyColumns"
@confirm="onEmergencyConfirm"
/>
<!-- 请购时间选择器 -->
<wd-datetime-picker
v-model="requestDatePickerVisible"
type="date"
:value="formData.requestTime"
@confirm="onRequestDateConfirm"
/>
<!-- 期望到货选择器 -->
<wd-datetime-picker
v-model="expectedDatePickerVisible"
type="date"
:value="formData.expectedTime"
@confirm="onExpectedDateConfirm"
/>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { PurchaseRequisition, PurchaseRequisitionItem } from '@/api/erp/purchase-requisition'
import type { ProductSimple } from '@/api/erp/product'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import {
createPurchaseRequisition,
EMERGENCY_OPTIONS,
getPurchaseRequisition,
PRIORITY_OPTIONS,
REQUISITION_TYPE_OPTIONS,
updatePurchaseRequisition,
} from '@/api/erp/purchase-requisition'
import { getProductSimpleList } from '@/api/erp/product'
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<PurchaseRequisition>({
id: undefined,
no: undefined,
type: 1,
priority: 2,
emergencyDegree: 1,
requestTime: undefined,
expectedTime: undefined,
remark: '',
items: [],
})
const formRules = {
requestTime: [{ required: true, message: '请购时间不能为空' }],
expectedTime: [{ required: true, message: '期望到货时间不能为空' }],
}
const formRef = ref<FormInstance>()
// 类型选择器
const typePickerVisible = ref(false)
const typeColumns = computed(() =>
REQUISITION_TYPE_OPTIONS.map(v => ({ label: v.label, value: v.value })),
)
// 优先级选择器
const priorityPickerVisible = ref(false)
const priorityColumns = computed(() =>
PRIORITY_OPTIONS.map(v => ({ label: v.label, value: v.value })),
)
// 紧急程度选择器
const emergencyPickerVisible = ref(false)
const emergencyColumns = computed(() =>
EMERGENCY_OPTIONS.map(v => ({ label: v.label, value: v.value })),
)
// 日期选择器
const requestDatePickerVisible = ref<any>(false)
const expectedDatePickerVisible = ref<any>(false)
// 产品列表
const productList = ref<ProductSimple[]>([])
const productColumns = computed(() =>
productList.value.map(v => ({ label: v.name, value: v.id })),
)
/** 合计数量 */
const totalCount = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.count) || 0), 0) || 0
})
/** 合计产品金额 */
const totalProductPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalProductPrice) || 0), 0) || 0
})
/** 合计税额 */
const totalTaxPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.taxPrice) || 0), 0) || 0
})
/** 合计金额(含税) */
const totalPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
})
/** 获取类型标签 */
function getTypeLabel(type?: number) {
return REQUISITION_TYPE_OPTIONS.find(o => o.value === type)?.label || '请选择'
}
/** 获取优先级标签 */
function getPriorityLabel(priority?: number) {
return PRIORITY_OPTIONS.find(o => o.value === priority)?.label || '请选择'
}
/** 获取紧急程度标签 */
function getEmergencyLabel(emergency?: number) {
return EMERGENCY_OPTIONS.find(o => o.value === emergency)?.label || '请选择'
}
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
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)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/purchase-requisition/index')
}
/** 加载下拉列表数据 */
async function loadDropdownData() {
try {
const products = await getProductSimpleList()
productList.value = products || []
} catch {
// error handled by http
}
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getPurchaseRequisition(props.id)
} finally {
toast.close()
}
}
/** 类型确认 */
function onTypeConfirm({ value }: any) {
formData.value.type = value?.[0] ?? formData.value.type
typePickerVisible.value = false
}
/** 优先级确认 */
function onPriorityConfirm({ value }: any) {
formData.value.priority = value?.[0] ?? formData.value.priority
priorityPickerVisible.value = false
}
/** 紧急程度确认 */
function onEmergencyConfirm({ value }: any) {
formData.value.emergencyDegree = value?.[0] ?? formData.value.emergencyDegree
emergencyPickerVisible.value = false
}
/** 请购时间确认 */
function onRequestDateConfirm({ value }: any) {
formData.value.requestTime = value
requestDatePickerVisible.value = false
}
/** 期望到货确认 */
function onExpectedDateConfirm({ value }: any) {
formData.value.expectedTime = value
expectedDatePickerVisible.value = false
}
/** 产品选择回调:自动填充规格/单位/条码 */
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
}
}
}
/** 添加产品项 */
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,
productSpec: undefined as any,
productBarCode: undefined as any,
productPrice: undefined,
count: 1 as any,
totalProductPrice: 0,
taxPercent: undefined,
taxPrice: 0,
totalPrice: 0,
purpose: '',
remark: '',
})
}
/** 移除产品项 */
function handleRemoveItem(index: number) {
uni.showModal({
title: '提示',
content: `确定要删除第 ${index + 1} 项产品吗?`,
success: (res) => {
if (res.confirm) {
formData.value.items?.splice(index, 1)
}
},
})
}
/** 计算产品项金额(含税) */
function calcItemTotal(item: PurchaseRequisitionItem) {
const count = Number(item.count) || 0
const price = Number(item.productPrice) || 0
const taxPercent = Number(item.taxPercent) || 0
// 产品金额 = 单价 × 数量
const totalProductPrice = count * price
// 税额 = 产品金额 × 税率 / 100
const taxPrice = totalProductPrice * taxPercent / 100
// 含税金额 = 产品金额 + 税额
item.totalProductPrice = Math.round(totalProductPrice * 100) / 100
item.taxPrice = Math.round(taxPrice * 100) / 100
item.totalPrice = Math.round((totalProductPrice + taxPrice) * 100) / 100
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
// 校验产品清单
if (!formData.value.items || formData.value.items.length === 0) {
toast.error('请添加请购产品')
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 {
// 设置合计
formData.value.totalCount = totalCount.value
formData.value.totalProductPrice = totalProductPrice.value
formData.value.totalTaxPrice = totalTaxPrice.value
formData.value.totalPrice = totalPrice.value
if (props.id) {
await updatePurchaseRequisition(formData.value)
toast.success('修改成功')
} else {
await createPurchaseRequisition(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
await loadDropdownData()
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,515 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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="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="queryParams.status === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
@click="onTabChange(tab.value)"
>
{{ tab.label }}
<view
v-if="queryParams.status === 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="handleDetail(item)"
>
<view class="p-24rpx">
<!-- 头部单号 + 状态 -->
<view class="mb-16rpx flex items-center justify-between">
<view class="text-28rpx text-[#333] font-semibold">
{{ item.no || '-' }}
</view>
<view class="flex items-center gap-8rpx">
<view
class="rounded-8rpx px-12rpx py-4rpx text-22rpx"
:class="getTypeClass(item.type)"
>
{{ getTypeLabel(item.type) }}
</view>
<view
class="rounded-8rpx px-12rpx py-4rpx text-22rpx"
:class="getStatusClass(item.status)"
>
{{ getStatusLabel(item.status) }}
</view>
</view>
</view>
<!-- 优先级 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">优先级</text>
<view
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
:class="getPriorityClass(item.priority)"
>
{{ getPriorityLabel(item.priority) }}
</view>
</view>
<!-- 请购人 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">请购人</text>
<text>{{ item.requesterNickname || '-' }}</text>
</view>
<!-- 请购部门 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">请购部门</text>
<text>{{ item.requesterDeptName || '-' }}</text>
</view>
<!-- 请购时间 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">请购时间</text>
<text>{{ formatDate(item.requestTime) }}</text>
</view>
<!-- 期望到货 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">期望到货</text>
<text>{{ formatDate(item.expectedTime) }}</text>
</view>
<!-- 紧急程度 -->
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">紧急程度</text>
<view
class="rounded-8rpx px-12rpx py-2rpx text-22rpx"
:class="getEmergencyClass(item.emergencyDegree)"
>
{{ getEmergencyLabel(item.emergencyDegree) }}
</view>
</view>
<!-- 数量金额区域 -->
<view class="flex items-center justify-around mt-12rpx pt-16rpx border-t border-[#f0f0f0]">
<view class="text-center">
<view class="text-32rpx text-[#333] font-semibold">{{ formatCount(item.totalCount) }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">总数量</view>
</view>
<view class="text-center">
<view class="text-32rpx text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</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-requisition:update']) && item.status === 1"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-requisition:update-status']) && item.status === 1"
size="small" type="success" plain @click="handleApprove(item.id!)"
>
审核
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-requisition:approve']) && item.status === 1"
size="small" type="warning" plain @click="handleReject(item.id!)"
>
驳回
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-requisition:delete']) && item.status === 1"
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-requisition: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" :style="{ paddingTop: `${getNavbarHeight()}px` }">
<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>
<view class="yd-search-form-radio-group">
<view
v-for="opt in typeOptions"
:key="opt.value"
class="yd-search-form-radio"
:class="{ 'yd-search-form-radio--active': searchForm.type === opt.value }"
@click="searchForm.type = opt.value"
>
{{ opt.label }}
</view>
</view>
</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="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 { PurchaseRequisition } from '@/api/erp/purchase-requisition'
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 {
deletePurchaseRequisition,
EMERGENCY_OPTIONS,
getPurchaseRequisitionPage,
PRIORITY_OPTIONS,
REQUISITION_TYPE_OPTIONS,
STATUS_OPTIONS,
updatePurchaseRequisitionStatus,
} from '@/api/erp/purchase-requisition'
import { useAccess } from '@/hooks/useAccess'
import { getNavbarHeight, navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<PurchaseRequisition[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
status: undefined,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
no: undefined as string | undefined,
type: undefined as number | undefined,
status: undefined as number | undefined,
})
/** 状态标签 */
const statusTabs = [
{ value: undefined, label: '全部' },
{ value: 1, label: '待审核' },
{ value: 2, label: '已审核' },
{ value: 5, label: '已采购' },
]
/** 类型选项 */
const typeOptions = [
{ value: undefined, label: '全部' },
...REQUISITION_TYPE_OPTIONS,
]
/** 状态选项 */
const statusOptions = [
{ value: undefined, label: '全部' },
...STATUS_OPTIONS,
]
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.no) conditions.push(`单号:${searchForm.no}`)
if (searchForm.type !== undefined) {
const typeLabel = REQUISITION_TYPE_OPTIONS.find(o => o.value === searchForm.type)?.label
if (typeLabel) conditions.push(`类型:${typeLabel}`)
}
if (searchForm.status !== undefined) {
const statusLabel = STATUS_OPTIONS.find(o => o.value === searchForm.status)?.label
if (statusLabel) conditions.push(`状态:${statusLabel}`)
}
return conditions.length > 0 ? conditions.join(' | ') : '搜索请购单'
})
/** 获取类型标签 */
function getTypeLabel(type?: number) {
return REQUISITION_TYPE_OPTIONS.find(o => o.value === type)?.label || '-'
}
/** 获取类型样式 */
function getTypeClass(type?: number) {
const map: Record<number, string> = {
1: 'bg-[#e6f7ff] text-[#1890ff]',
2: 'bg-[#fff7e6] text-[#fa8c16]',
3: 'bg-[#f9f0ff] text-[#722ed1]',
}
return map[type || 1] || 'bg-[#f5f5f5] text-[#666]'
}
/** 获取状态标签 */
function getStatusLabel(status?: number) {
return STATUS_OPTIONS.find(o => o.value === status)?.label || '-'
}
/** 获取状态样式 */
function getStatusClass(status?: number) {
const map: Record<number, string> = {
1: 'bg-[#fff7e6] text-[#fa8c16]',
2: 'bg-[#f6ffed] text-[#52c41a]',
3: 'bg-[#fff1f0] text-[#f5222d]',
4: 'bg-[#f5f5f5] text-[#999]',
5: 'bg-[#e6f7ff] text-[#1890ff]',
}
return map[status || 1] || 'bg-[#f5f5f5] text-[#666]'
}
/** 获取优先级标签 */
function getPriorityLabel(priority?: number) {
return PRIORITY_OPTIONS.find(o => o.value === priority)?.label || '-'
}
/** 获取优先级样式 */
function getPriorityClass(priority?: number) {
const map: Record<number, string> = {
1: 'bg-[#f5f5f5] text-[#999]',
2: 'bg-[#e6f7ff] text-[#1890ff]',
3: 'bg-[#fff7e6] text-[#fa8c16]',
4: 'bg-[#fff1f0] text-[#f5222d]',
}
return map[priority || 1] || 'bg-[#f5f5f5] text-[#666]'
}
/** 获取紧急程度标签 */
function getEmergencyLabel(emergency?: number) {
return EMERGENCY_OPTIONS.find(o => o.value === emergency)?.label || '-'
}
/** 获取紧急程度样式 */
function getEmergencyClass(emergency?: number) {
const map: Record<number, string> = {
1: 'bg-[#f5f5f5] text-[#999]',
2: 'bg-[#e6f7ff] text-[#1890ff]',
3: 'bg-[#fff7e6] text-[#fa8c16]',
4: 'bg-[#fff1f0] text-[#f5222d]',
}
return map[emergency || 1] || 'bg-[#f5f5f5] text-[#666]'
}
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(date?: string) {
if (!date) return '-'
return new Date(date).toLocaleDateString('zh-CN')
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 切换状态标签 */
function onTabChange(status: number | undefined) {
queryParams.value.status = status
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 查询请购单列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
if (searchForm.no) params.no = searchForm.no
if (searchForm.type !== undefined) params.type = searchForm.type
const data = await getPurchaseRequisitionPage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
pageNo: 1,
pageSize: queryParams.value.pageSize,
status: searchForm.status,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.no = undefined
searchForm.type = undefined
searchForm.status = undefined
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10, status: undefined }
list.value = []
getList()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
/** 新增请购单 */
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/purchase-requisition/form/index' })
}
/** 编辑 */
function handleEdit(item: PurchaseRequisition) {
uni.navigateTo({ url: `/pages-erp/purchase-requisition/form/index?id=${item.id}` })
}
/** 详情 */
function handleDetail(item: PurchaseRequisition) {
uni.navigateTo({ url: `/pages-erp/purchase-requisition/detail/index?id=${item.id}` })
}
/** 审核 */
function handleApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要审核通过该请购单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updatePurchaseRequisitionStatus(id, 2)
toast.success('审核成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 驳回 */
function handleReject(id: number) {
uni.showModal({
title: '提示',
content: '确定要驳回该请购单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updatePurchaseRequisitionStatus(id, 3)
toast.success('驳回成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该请购单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deletePurchaseRequisition(id)
toast.success('删除成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 刷新列表 */
function refreshList() {
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,100 @@
<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-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: '已审核',
}
/** 搜索条件 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>

View File

@@ -0,0 +1,309 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="采购退货详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 详情内容 -->
<view v-if="formData" class="pb-180rpx">
<!-- 基本信息 -->
<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.returnTime)" />
<wd-cell title="关联订单" :value="formData.orderNo || '-'" />
<wd-cell title="创建人" :value="formData.creatorName || '-'" />
<wd-cell title="创建时间" :value="formatDateTime(formData.createTime)" />
</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.otherPrice || 0}`" />
<wd-cell title="应退金额">
<text class="text-[#e6a23c] font-semibold">¥{{ formData.totalPrice || 0 }}</text>
</wd-cell>
<wd-cell title="已退金额">
<text class="text-[#52c41a] font-semibold">¥{{ formData.refundPrice || 0 }}</text>
</wd-cell>
<wd-cell title="未退金额">
<text
class="font-semibold"
:class="(formData.totalPrice || 0) - (formData.refundPrice || 0) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
>
¥{{ (formData.totalPrice || 0) - (formData.refundPrice || 0) }}
</text>
</wd-cell>
</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.warehouseName" class="text-24rpx text-[#1890ff]">{{ item.warehouseName }}</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 class="text-[#e6a23c]">¥{{ item.totalPrice || 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-return:update']) && formData?.status === 10"
class="flex-1" type="warning" @click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-return:update-status']) && formData?.status === 10"
class="flex-1" type="success" @click="handleAudit"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-return:update-status']) && formData?.status === 20"
class="flex-1" type="warning" @click="handleReverseAudit"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-return:delete'])"
class="flex-1" type="error" :loading="deleting" @click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import type { PurchaseReturn } from '@/api/erp/purchase-return'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deletePurchaseReturn, getPurchaseReturn, updatePurchaseReturnStatus } from '@/api/erp/purchase-return'
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<PurchaseReturn>()
const deleting = ref(false)
/** 获取状态文本 */
function getStatusText(status?: number) {
if (status === 10) return '待审核'
if (status === 20) return '已审核'
return '未知'
}
/** 获取状态样式 */
function getStatusClass(status?: number) {
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
return 'bg-[#f5f5f5] text-[#999]'
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/purchase-return/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) {
return
}
try {
toast.loading('加载中...')
formData.value = await getPurchaseReturn(props.id)
} finally {
toast.close()
}
}
/** 编辑操作 */
function handleEdit() {
uni.navigateTo({
url: `/pages-erp/purchase-return/form/index?id=${props.id}`,
})
}
/** 审批操作 */
function handleAudit() {
if (!props.id) {
return
}
uni.showModal({
title: '提示',
content: '确定要审批该退货单吗?',
success: async (res) => {
if (!res.confirm) {
return
}
try {
await updatePurchaseReturnStatus(props.id, 20)
toast.success('审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 反审批操作 */
function handleReverseAudit() {
if (!props.id) {
return
}
uni.showModal({
title: '提示',
content: '确定要反审批该退货单吗?',
success: async (res) => {
if (!res.confirm) {
return
}
try {
await updatePurchaseReturnStatus(props.id, 10)
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 deletePurchaseReturn([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} finally {
deleting.value = false
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,629 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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" center>
<wd-input
v-model="formData.no"
placeholder="保存时自动生成"
disabled
/>
</wd-cell>
<wd-cell title="退货时间" title-width="180rpx" prop="returnTime" center>
<wd-datetime-picker
v-model="formData.returnTime"
type="date"
label=""
placeholder="请选择退货时间"
/>
</wd-cell>
<wd-cell title="关联订单" title-width="180rpx" center is-link @click="openOrderSelect">
<text v-if="formData.orderNo" class="text-[#1890ff]">{{ formData.orderNo }}</text>
<text v-else class="text-[#999]">点击选择采购订单</text>
</wd-cell>
<wd-cell title="供应商" title-width="180rpx" center>
<text>{{ getSupplierName() || '-' }}</text>
</wd-cell>
<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>
<wd-input
v-model="formData.discountPercent"
label="优惠率(%)"
label-width="180rpx"
type="number"
placeholder="请输入优惠率"
clearable
/>
<wd-cell title="退款优惠" title-width="180rpx" center>
<text>¥{{ formData.discountPrice || 0 }}</text>
</wd-cell>
<wd-input
v-model="formData.otherPrice"
label="其他费用"
label-width="180rpx"
type="number"
placeholder="请输入其他费用"
clearable
/>
<wd-cell title="优惠后金额" title-width="180rpx" center>
<text>¥{{ formData.totalPrice || 0 }}</text>
</wd-cell>
<wd-cell title="结算账户" title-width="180rpx" prop="accountId" center>
<wd-picker
v-model="formData.accountId"
:columns="accountColumns"
label=""
placeholder="请选择结算账户"
@confirm="onAccountConfirm"
/>
</wd-cell>
</wd-cell-group>
</wd-form>
</view>
<!-- 退货明细 -->
<view class="erp-form-body">
<view class="erp-form-section-heading">
<view class="text-32rpx text-[#333] font-semibold">
退货明细{{ formData.items?.length || 0 }}
</view>
</view>
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card"
>
<view class="erp-form-item-card__header">
<text class="text-28rpx text-[#333] font-semibold">产品 #{{ index + 1 }} {{ item.productName || '' }}</text>
<wd-button
v-if="formData.items && formData.items.length > 1"
size="small" type="error" plain @click="handleRemoveItem(index)"
>
删除
</wd-button>
</view>
<view class="erp-form-item-list">
<!-- 仓库选择 -->
<view class="mb-16rpx">
<text class="mb-8rpx block text-24rpx text-[#999]">仓库</text>
<wd-picker
v-model="item.warehouseId"
:columns="warehouseColumns"
placeholder="请选择仓库"
@confirm="(e: any) => onWarehouseConfirm(e, index)"
/>
</view>
<!-- 自动填充的产品信息只读 -->
<view v-if="item.productId" class="erp-form-info-card">
<view class="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">产品名称</text>
<text class="text-[#333]">{{ item.productName || '-' }}</text>
</view>
<view v-if="item.productSpec" 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="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">库存</text>
<text class="text-[#333]">{{ item.stockCount || 0 }}</text>
</view>
<view v-if="item.inCount != null" class="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">已入库</text>
<text class="text-[#333]">{{ item.inCount }}</text>
</view>
<view v-if="item.returnCount != null" class="flex justify-between text-24rpx">
<text class="text-[#999]">已退货</text>
<text class="text-[#333]">{{ item.returnCount }}</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>
<!-- 采购订单选择弹窗可退货订单 -->
<wd-popup v-model="orderSelectVisible" position="right" custom-style="width: 100%; height: 100%;">
<view class="yd-page-container erp-page">
<wd-navbar
title="选择采购订单"
left-arrow placeholder safe-area-inset-top fixed
@click-left="orderSelectVisible = false"
/>
<wd-search
v-model="orderQueryParams.no"
placeholder="搜索订单单号"
@search="getOrderList"
@clear="getOrderList"
/>
<view class="px-24rpx">
<view
v-for="item in orderList"
:key="item.id"
class="erp-form-item-card"
:class="{ 'border-2 border-[#1890ff]': selectedOrderId === item.id }"
@click="handleSelectOrder(item)"
>
<view class="erp-form-item-list">
<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.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="flex items-center justify-around mt-12rpx pt-12rpx border-t border-[#f0f0f0]">
<view class="text-center">
<view class="text-28rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
<view class="text-22rpx text-[#999]">总数量</view>
</view>
<view class="text-center">
<view class="text-28rpx text-[#52c41a] font-semibold">{{ item.inCount || 0 }}</view>
<view class="text-22rpx text-[#999]">已入库</view>
</view>
<view class="text-center">
<view class="text-28rpx text-[#f5222d] font-semibold">{{ item.returnCount || 0 }}</view>
<view class="text-22rpx text-[#999]">已退货</view>
</view>
</view>
</view>
</view>
<view v-if="orderList.length === 0" 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 { PurchaseReturn, PurchaseReturnItem } from '@/api/erp/purchase-return'
import type { PurchaseOrder } from '@/api/erp/purchase-order'
import type { LoadMoreState } from '@/http/types'
import { computed, onMounted, ref, watch } from 'vue'
import { useToast } from 'wot-design-uni'
import { createPurchaseReturn, getPurchaseReturn, updatePurchaseReturn } from '@/api/erp/purchase-return'
import { getPurchaseOrder, getPurchaseOrderPage } from '@/api/erp/purchase-order'
import { navigateBackPlus } from '@/utils'
/** 账户简单信息 */
interface AccountSimple {
id: number
name: string
defaultStatus?: boolean
}
/** 仓库简单信息 */
interface WarehouseSimple {
id: number
name: string
defaultStatus?: boolean
}
/** 供应商简单信息 */
interface SupplierSimple {
id: number
name: string
}
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<PurchaseReturn>({
id: undefined,
no: undefined,
supplierId: undefined,
accountId: undefined,
returnTime: new Date().toISOString(),
orderId: undefined,
orderNo: undefined,
discountPercent: 0,
discountPrice: 0,
otherPrice: 0,
totalPrice: 0,
remark: '',
items: [],
})
const formRules = {
returnTime: [{ required: true, message: '退货时间不能为空' }],
}
const formRef = ref<FormInstance>()
const supplierList = ref<SupplierSimple[]>([])
const accountList = ref<AccountSimple[]>([])
const warehouseList = ref<WarehouseSimple[]>([])
const defaultWarehouse = ref<WarehouseSimple>()
// 采购订单选择相关(可退货订单)
const orderSelectVisible = ref(false)
const orderList = ref<PurchaseOrder[]>([])
const orderLoadMoreState = ref<LoadMoreState>('loading')
const orderQueryParams = ref({
pageNo: 1,
pageSize: 10,
no: undefined as string | undefined,
returnEnable: true, // 可退货订单
})
const orderTotal = ref(0)
const selectedOrderId = ref<number>()
/** 账户下拉列 */
const accountColumns = computed(() => {
if (!accountList.value.length) {
return []
}
return [accountList.value.map(a => ({ value: a.id, label: a.name }))]
})
/** 仓库下拉列 */
const warehouseColumns = computed(() => {
if (!warehouseList.value.length) {
return []
}
return [warehouseList.value.map(w => ({ value: w.id, label: w.name }))]
})
/** 获取供应商名称 */
function getSupplierName() {
if (!formData.value.supplierId) return ''
const supplier = supplierList.value.find(s => s.id === formData.value.supplierId)
return supplier?.name || formData.value.supplierName || ''
}
/** 账户选择回调 */
function getPickerSingleValue(payload: any) {
if (Array.isArray(payload?.value)) {
return payload.value[0]
}
if (payload?.value !== undefined) {
return payload.value
}
if (Array.isArray(payload?.selectedItems) && payload.selectedItems.length > 0) {
return payload.selectedItems[0]?.value
}
return undefined
}
function onAccountConfirm(payload: any) {
formData.value.accountId = getPickerSingleValue(payload)
}
/** 仓库选择回调 */
function onWarehouseConfirm(payload: any, index: number) {
if (formData.value.items && formData.value.items[index]) {
const warehouseId = getPickerSingleValue(payload)
formData.value.items[index].warehouseId = warehouseId
const warehouse = warehouseList.value.find(w => w.id === warehouseId)
if (warehouse) {
formData.value.items[index].warehouseName = warehouse.name
}
}
}
/** 计算行项金额 */
function calcTotalPrice(item: PurchaseReturnItem) {
if (item.productPrice && item.count) {
const productTotal = Number(item.productPrice) * Number(item.count)
const taxPrice = item.taxPercent ? productTotal * Number(item.taxPercent) / 100 : 0
return `¥${(productTotal + taxPrice).toFixed(2)}`
}
return '-'
}
/** 监听表单数据变化,计算总价 */
watch(
() => formData.value,
(val) => {
if (!val || !val.items) return
// 计算每个明细的金额
val.items.forEach((item) => {
if (item.productPrice && item.count) {
item.totalProductPrice = Number(item.productPrice) * Number(item.count)
item.taxPrice = item.taxPercent ? item.totalProductPrice * Number(item.taxPercent) / 100 : 0
item.totalPrice = item.totalProductPrice + (item.taxPrice || 0)
}
})
// 计算总价
const totalPrice = val.items.reduce((prev, curr) => prev + (curr.totalPrice || 0), 0)
const discountPrice = val.discountPercent ? totalPrice * Number(val.discountPercent) / 100 : 0
formData.value.discountPrice = Math.round(discountPrice * 100) / 100
formData.value.totalPrice = Math.round((totalPrice - discountPrice + Number(val.otherPrice || 0)) * 100) / 100
},
{ deep: true },
)
/** 加载下拉列表数据 */
async function loadDropdownData() {
try {
const { http } = await import('@/http/http')
const [suppliers, accounts, warehouses] = await Promise.all([
http.get<SupplierSimple[]>('/erp/supplier/simple-list'),
http.get<AccountSimple[]>('/erp/account/simple-list'),
http.get<WarehouseSimple[]>('/erp/warehouse/simple-list'),
])
supplierList.value = suppliers || []
accountList.value = accounts || []
warehouseList.value = warehouses || []
// 设置默认账户
const defaultAccount = accountList.value.find(a => a.defaultStatus)
if (defaultAccount && !formData.value.accountId) {
formData.value.accountId = defaultAccount.id
}
// 设置默认仓库
defaultWarehouse.value = warehouseList.value.find(w => w.defaultStatus)
} catch {
// error handled by http
}
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/purchase-return/index')
}
/** 删除退货明细行 */
function handleRemoveItem(index: number) {
uni.showModal({
title: '提示',
content: `确定要删除第 ${index + 1} 项产品吗?`,
success: (res) => {
if (res.confirm) {
formData.value.items?.splice(index, 1)
}
},
})
}
/** 打开订单选择弹窗 */
function openOrderSelect() {
orderSelectVisible.value = true
orderQueryParams.value.pageNo = 1
orderList.value = []
selectedOrderId.value = formData.value.orderId
getOrderList()
}
/** 获取可退货订单列表 */
async function getOrderList() {
orderLoadMoreState.value = 'loading'
try {
const data = await getPurchaseOrderPage(orderQueryParams.value)
if (orderQueryParams.value.pageNo === 1) {
orderList.value = data.list
} else {
orderList.value = [...orderList.value, ...data.list]
}
orderTotal.value = data.total
orderLoadMoreState.value = orderList.value.length >= orderTotal.value ? 'finished' : 'loading'
} catch {
orderLoadMoreState.value = 'error'
}
}
/** 加载更多订单 */
function loadMoreOrders() {
if (orderLoadMoreState.value === 'finished') return
orderQueryParams.value.pageNo++
getOrderList()
}
/** 选择订单 */
function handleSelectOrder(item: PurchaseOrder) {
selectedOrderId.value = item.id
}
/** 确认选择订单 */
async function confirmSelectOrder() {
if (!selectedOrderId.value) return
try {
toast.loading('加载订单详情...')
const orderDetail = await getPurchaseOrder(selectedOrderId.value)
// 设置订单信息
formData.value.orderId = orderDetail.id
formData.value.orderNo = orderDetail.no
formData.value.supplierId = orderDetail.supplierId
formData.value.supplierName = orderDetail.supplierName
formData.value.accountId = orderDetail.accountId
formData.value.discountPercent = orderDetail.discountPercent
formData.value.remark = orderDetail.remark
// 设置退货明细(可退货数量 = 已入库 - 已退货)
if (orderDetail.items) {
formData.value.items = orderDetail.items
.filter(item => ((item.inCount || 0) - (item.returnCount || 0)) > 0)
.map(item => ({
productId: item.productId,
productName: item.productName,
productUnitId: item.productUnitId,
productUnitName: item.productUnitName,
productPrice: item.productPrice,
productSpec: item.productSpec,
productBarCode: item.productBarCode,
count: (item.inCount || 0) - (item.returnCount || 0),
inCount: item.inCount,
returnCount: item.returnCount,
taxPercent: item.taxPercent,
warehouseId: defaultWarehouse.value?.id,
warehouseName: defaultWarehouse.value?.name,
stockCount: item.stockCount,
orderItemId: item.id,
remark: item.remark,
}))
}
orderSelectVisible.value = false
} finally {
toast.close()
}
}
/** 加载详情 */
async function getDetail() {
if (!props.id) {
return
}
try {
toast.loading('加载中...')
formData.value = await getPurchaseReturn(props.id)
} finally {
toast.close()
}
}
/** 提交表单 */
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.warehouseId) {
toast.warning(`${i + 1} 项产品请选择仓库`)
return
}
if (!item.count || Number(item.count) <= 0) {
toast.warning(`${i + 1} 项产品数量不能为空`)
return
}
}
formLoading.value = true
try {
if (props.id) {
await updatePurchaseReturn(formData.value)
toast.success('修改成功')
} else {
await createPurchaseReturn(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
await loadDropdownData()
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,366 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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.returnTime) }}</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-[#e6a23c] font-semibold">¥{{ item.totalPrice || 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.refundPrice || 0 }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">已退</view>
</view>
<view class="text-center">
<view
class="text-30rpx font-semibold"
:class="(item.totalPrice || 0) - (item.refundPrice || 0) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
>
¥{{ (item.totalPrice || 0) - (item.refundPrice || 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-return:query'])"
size="small" plain @click="handleDetail(item)"
>
详情
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-return:update']) && item.status === 10"
size="small" type="primary" plain @click="handleEdit(item)"
>
修改
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-return:update-status']) && item.status === 10"
size="small" type="success" plain @click="handleAudit(item.id!)"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-return:update-status']) && item.status === 20"
size="small" type="warning" plain @click="handleReverseAudit(item.id!)"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:purchase-return:delete'])"
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-return:create'])"
position="right-bottom"
type="primary"
:expandable="false"
@click="handleAdd"
/>
</view>
</template>
<script lang="ts" setup>
import type { PurchaseReturn } from '@/api/erp/purchase-return'
import type { LoadMoreState } from '@/http/types'
import { onReachBottom } from '@dcloudio/uni-app'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deletePurchaseReturn, getPurchaseReturnPage, updatePurchaseReturnStatus } from '@/api/erp/purchase-return'
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<PurchaseReturn[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const activeStatus = ref<number | undefined>(undefined)
const queryParams = ref<{ pageNo: number; pageSize: number } & 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) {
if (status === 10) return '待审核'
if (status === 20) return '已审核'
return '未知'
}
/** 获取状态样式 */
function getStatusClass(status?: number) {
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
return 'bg-[#f5f5f5] text-[#999]'
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 查询采购退货列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
const data = await getPurchaseReturnPage(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: PurchaseReturn) {
if (item.status === 20) {
handleDetail(item)
} else if (item.status === 10) {
handleEdit(item)
}
}
/** 新增采购退货 */
function handleAdd() {
uni.navigateTo({
url: '/pages-erp/purchase-return/form/index',
})
}
/** 查看详情 */
function handleDetail(item: PurchaseReturn) {
uni.navigateTo({
url: `/pages-erp/purchase-return/detail/index?id=${item.id}`,
})
}
/** 编辑 */
function handleEdit(item: PurchaseReturn) {
uni.navigateTo({
url: `/pages-erp/purchase-return/form/index?id=${item.id}`,
})
}
/** 审批 */
function handleAudit(id: number) {
uni.showModal({
title: '提示',
content: '确定审批该退货单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updatePurchaseReturnStatus(id, 20)
toast.success('审批成功')
list.value = []
queryParams.value.pageNo = 1
getList()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseAudit(id: number) {
uni.showModal({
title: '提示',
content: '确定反审批该退货单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updatePurchaseReturnStatus(id, 10)
toast.success('反审批成功')
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 deletePurchaseReturn([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>

View File

@@ -0,0 +1,271 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar title="采购统计" left-arrow placeholder safe-area-inset-top fixed @click-left="handleBack" />
<view class="erp-page__body">
<view class="grid grid-cols-2 gap-16rpx">
<view class="erp-metric-card">
<view class="erp-metric-card__label">今日采购</view>
<view class="erp-metric-card__value">¥{{ formatPrice(summary?.todayPrice) }}</view>
</view>
<view class="erp-metric-card">
<view class="erp-metric-card__label">昨日采购</view>
<view class="erp-metric-card__value">¥{{ formatPrice(summary?.yesterdayPrice) }}</view>
</view>
<view class="erp-metric-card">
<view class="erp-metric-card__label">本月采购</view>
<view class="erp-metric-card__value">¥{{ formatPrice(summary?.monthPrice) }}</view>
</view>
<view class="erp-metric-card">
<view class="erp-metric-card__label">今年采购</view>
<view class="erp-metric-card__value">¥{{ formatPrice(summary?.yearPrice) }}</view>
</view>
</view>
<view class="erp-section">
<view class="mb-16rpx flex items-center justify-between">
<view class="erp-section__title !mb-0 !p-0 !border-0">采购趋势</view>
<wd-radio-group v-model="trendType" shape="button" @change="handleTrendTypeChange">
<wd-radio value="week">按周</wd-radio>
<wd-radio value="month">按月</wd-radio>
</wd-radio-group>
</view>
<view class="grid grid-cols-2 gap-16rpx mb-16rpx">
<view class="erp-metric-card">
<view class="erp-metric-card__label">净采购金额</view>
<view class="erp-metric-card__value">¥{{ formatPrice(trendAnalysis.totalPrice) }}</view>
</view>
<view class="erp-metric-card">
<view class="erp-metric-card__label">净采购数量</view>
<view class="erp-metric-card__value">{{ formatCount(trendAnalysis.totalCount) }}</view>
</view>
</view>
<view v-if="trendList.length">
<view v-for="item in trendList" :key="item.time" class="erp-form-item-card erp-form-item-card--padded">
<view class="mb-8rpx flex items-center justify-between">
<text class="erp-card-title">{{ item.time }}</text>
<text class="text-24rpx text-[#999]">数量 {{ formatCount(item.count) }}</text>
</view>
<view class="text-32rpx font-semibold text-[#1890ff]">¥{{ formatPrice(item.price) }}</view>
</view>
</view>
<view v-else class="erp-empty">暂无趋势数据</view>
</view>
<view class="erp-section">
<view class="mb-16rpx flex items-center justify-between">
<view class="erp-section__title !mb-0 !p-0 !border-0">产品采购统计</view>
<wd-radio-group v-model="productSortBy" shape="button" @change="getProductRank">
<wd-radio value="price">按金额</wd-radio>
<wd-radio value="count">按数量</wd-radio>
</wd-radio-group>
</view>
<view class="mb-16rpx flex gap-16rpx">
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">开始日期</text>
<wd-datetime-picker v-model="productDateRange[0]" type="date" label="" placeholder="开始日期" />
</view>
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">结束日期</text>
<wd-datetime-picker v-model="productDateRange[1]" type="date" label="" placeholder="结束日期" />
</view>
</view>
<wd-button type="primary" plain block @click="getProductRank">刷新产品榜单</wd-button>
<view v-if="productRankList.length" class="mt-16rpx">
<view v-for="(item, index) in productRankList" :key="item.productId || index" class="erp-form-item-card erp-form-item-card--padded">
<view class="mb-8rpx flex items-center justify-between">
<text class="erp-card-title">#{{ index + 1 }} {{ item.productName }}</text>
<text class="text-24rpx text-[#999]">占比 {{ formatPercent(item.shareRate) }}</text>
</view>
<view class="erp-field-row"><text>净采购金额</text><text>¥{{ formatPrice(item.price) }}</text></view>
<view class="erp-field-row"><text>净采购数量</text><text>{{ formatCount(item.count) }}</text></view>
<view class="erp-field-row"><text>退货金额</text><text>¥{{ formatPrice(item.returnPrice) }}</text></view>
<view class="erp-field-row"><text>退货数量</text><text>{{ formatCount(item.returnCount) }}</text></view>
<view class="erp-field-row"><text>均价</text><text>¥{{ formatPrice(item.avgPrice) }}</text></view>
<view class="erp-field-row"><text>单据数</text><text>{{ item.orderCount || 0 }}</text></view>
</view>
</view>
<view v-else class="erp-empty">暂无产品统计数据</view>
</view>
<view class="erp-section">
<view class="mb-16rpx flex items-center justify-between">
<view class="erp-section__title !mb-0 !p-0 !border-0">供应商采购统计</view>
<wd-radio-group v-model="supplierSortBy" shape="button" @change="getSupplierRank">
<wd-radio value="price">按金额</wd-radio>
<wd-radio value="count">按数量</wd-radio>
</wd-radio-group>
</view>
<view class="mb-16rpx flex gap-16rpx">
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">开始日期</text>
<wd-datetime-picker v-model="supplierDateRange[0]" type="date" label="" placeholder="开始日期" />
</view>
<view class="flex-1">
<text class="mb-8rpx block text-24rpx text-[#999]">结束日期</text>
<wd-datetime-picker v-model="supplierDateRange[1]" type="date" label="" placeholder="结束日期" />
</view>
</view>
<wd-button type="primary" plain block @click="getSupplierRank">刷新供应商榜单</wd-button>
<view v-if="supplierRankList.length" class="mt-16rpx">
<view v-for="(item, index) in supplierRankList" :key="item.supplierId || index" class="erp-form-item-card erp-form-item-card--padded">
<view class="mb-8rpx flex items-center justify-between">
<text class="erp-card-title">#{{ index + 1 }} {{ item.supplierName }}</text>
<text class="text-24rpx text-[#999]">占比 {{ formatPercent(item.shareRate) }}</text>
</view>
<view class="erp-field-row"><text>净采购金额</text><text>¥{{ formatPrice(item.price) }}</text></view>
<view class="erp-field-row"><text>净采购数量</text><text>{{ formatCount(item.count) }}</text></view>
<view class="erp-field-row"><text>退货金额</text><text>¥{{ formatPrice(item.returnPrice) }}</text></view>
<view class="erp-field-row"><text>退货数量</text><text>{{ formatCount(item.returnCount) }}</text></view>
<view class="erp-field-row"><text>均价</text><text>¥{{ formatPrice(item.avgPrice) }}</text></view>
<view class="erp-field-row"><text>单据数</text><text>{{ item.orderCount || 0 }}</text></view>
</view>
</view>
<view v-else class="erp-empty">暂无供应商统计数据</view>
</view>
<view class="erp-section">
<view class="mb-16rpx flex items-center justify-between">
<view class="erp-section__title !mb-0 !p-0 !border-0">智能分析</view>
<wd-button type="primary" size="small" :loading="aiLoading" @click="analyzeWithAI">生成分析</wd-button>
</view>
<view v-if="aiResult" class="text-26rpx leading-[1.7] text-[#666] whitespace-pre-wrap">{{ aiResult }}</view>
<view v-else class="erp-empty">暂无分析内容</view>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import type { PurchaseProductRank, PurchaseSummary, PurchaseSupplierRank, PurchaseTrend } from '@/api/erp/purchase-statistics'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import {
analyzePurchaseStatistics,
getPurchaseProductRank,
getPurchaseSummary,
getPurchaseSupplierRank,
getPurchaseTrendByMonth,
getPurchaseTrendByWeek,
} from '@/api/erp/purchase-statistics'
import { navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const toast = useToast()
const summary = ref<PurchaseSummary>()
const trendList = ref<PurchaseTrend[]>([])
const productRankList = ref<PurchaseProductRank[]>([])
const supplierRankList = ref<PurchaseSupplierRank[]>([])
const trendType = ref<'week' | 'month'>('month')
const productSortBy = ref<'price' | 'count'>('price')
const supplierSortBy = ref<'price' | 'count'>('price')
const aiLoading = ref(false)
const aiResult = ref('')
const now = new Date()
const startOfYear = new Date(now.getFullYear(), 0, 1).getTime()
const productDateRange = ref<(number | string | undefined)[]>([startOfYear, Date.now()])
const supplierDateRange = ref<(number | string | undefined)[]>([startOfYear, Date.now()])
const trendAnalysis = computed(() => {
const prices = trendList.value.map(v => Number(v.price || 0))
const counts = trendList.value.map(v => Number(v.count || 0))
return {
totalPrice: prices.reduce((sum, item) => sum + item, 0),
totalCount: counts.reduce((sum, item) => sum + item, 0),
}
})
function formatPrice(value?: number) {
return Number(value || 0).toFixed(2)
}
function formatCount(value?: number) {
return Number(value || 0).toFixed(2)
}
function formatPercent(value?: number) {
return `${Number(value || 0).toFixed(2)}%`
}
function formatDateTime(value?: string | number | Date) {
if (!value) return ''
const date = new Date(value)
if (Number.isNaN(date.getTime())) return ''
const month = `${date.getMonth() + 1}`.padStart(2, '0')
const day = `${date.getDate()}`.padStart(2, '0')
return `${date.getFullYear()}-${month}-${day} 00:00:00`
}
function handleBack() {
navigateBackPlus()
}
async function getTrendData() {
trendList.value = trendType.value === 'week'
? await getPurchaseTrendByWeek(12)
: await getPurchaseTrendByMonth(12)
}
async function getProductRank() {
const [beginTime, endTime] = productDateRange.value
if (!beginTime || !endTime) {
toast.warning('请先选择完整的产品统计时间')
return
}
productRankList.value = await getPurchaseProductRank(formatDateTime(beginTime), formatDateTime(endTime).replace('00:00:00', '23:59:59'), 10, productSortBy.value)
}
async function getSupplierRank() {
const [beginTime, endTime] = supplierDateRange.value
if (!beginTime || !endTime) {
toast.warning('请先选择完整的供应商统计时间')
return
}
supplierRankList.value = await getPurchaseSupplierRank(formatDateTime(beginTime), formatDateTime(endTime).replace('00:00:00', '23:59:59'), 10, supplierSortBy.value)
}
async function handleTrendTypeChange() {
await getTrendData()
}
async function analyzeWithAI() {
aiLoading.value = true
try {
const result = await analyzePurchaseStatistics({
summary: summary.value,
trendData: trendList.value,
productRankList: productRankList.value,
supplierRankList: supplierRankList.value,
trendType: trendType.value,
productRankSortBy: productSortBy.value,
supplierRankSortBy: supplierSortBy.value,
})
aiResult.value = result?.data || result || ''
} catch {
aiResult.value = [
'采购数据分析',
`1. 当前累计净采购金额为 ¥${formatPrice(trendAnalysis.value.totalPrice)}`,
`2. 当前累计净采购数量为 ${formatCount(trendAnalysis.value.totalCount)}`,
`3. 产品榜首为 ${productRankList.value[0]?.productName || '暂无'}`,
`4. 供应商榜首为 ${supplierRankList.value[0]?.supplierName || '暂无'}`,
].join('\n')
} finally {
aiLoading.value = false
}
}
onMounted(async () => {
summary.value = await getPurchaseSummary()
await Promise.all([getTrendData(), getProductRank(), getSupplierRank()])
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,311 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="订单详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<view class="erp-page__body" :class="{ 'opacity-60': loading }">
<!-- 基本信息 -->
<view class="erp-section">
<view class="erp-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.orderTime) || '-' }}</text>
</view>
<view class="info-row">
<text class="info-label">状态</text>
<view :class="getStatusClass(detail.status)">
{{ getStatusText(detail.status) }}
</view>
</view>
</view>
<!-- 付款信息 -->
<view class="erp-section" v-if="detail.depositPrice || detail.paymentCondition">
<view class="erp-section__title">付款信息</view>
<view class="info-row" v-if="detail.paymentCondition">
<text class="info-label">付款条件</text>
<text class="info-value">{{ getPaymentConditionText(detail.paymentCondition) }}</text>
</view>
<view class="info-row" v-if="detail.paymentMethod">
<text class="info-label">付款方式</text>
<text class="info-value">{{ getPaymentMethodText(detail.paymentMethod) }}</text>
</view>
<view class="info-row" v-if="detail.depositPrice">
<text class="info-label">收取订金</text>
<text class="info-value text-[#409eff]">¥{{ formatPrice(detail.depositPrice) }}</text>
</view>
</view>
<!-- 产品清单 -->
<view class="erp-section">
<view class="erp-section__title">产品清单</view>
<view
v-for="(item, index) in detail.items"
:key="index"
class="product-item"
>
<view class="flex justify-between items-center mb-8rpx">
<text class="text-28rpx font-medium">{{ item.productName }}</text>
</view>
<view class="flex justify-between text-24rpx text-[#999]">
<text>单价: ¥{{ formatPrice(item.unitPrice) }}</text>
<text>数量: {{ item.count }}</text>
<text class="text-[#409eff]">小计: ¥{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
<view v-if="!detail.items || detail.items.length === 0" class="erp-empty">
暂无产品
</view>
</view>
<!-- 金额汇总 -->
<view class="erp-section">
<view class="erp-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">¥{{ formatPrice(detail.totalProductPrice) }}</text>
</view>
<view class="info-row" v-if="detail.discountPercent">
<text class="info-label">优惠率</text>
<text class="info-value">{{ detail.discountPercent }}%</text>
</view>
<view class="info-row" v-if="detail.discountPrice">
<text class="info-label">优惠金额</text>
<text class="info-value">-¥{{ formatPrice(detail.discountPrice) }}</text>
</view>
<view class="info-row total-row">
<text class="info-label">含税金额</text>
<text class="info-value text-[#409eff] text-36rpx">¥{{ formatPrice(detail.totalPrice) }}</text>
</view>
</view>
<!-- 其他信息 -->
<view class="erp-section" v-if="detail.remark">
<view class="erp-section__title">备注</view>
<view class="text-26rpx text-[#606266] leading-1.6">{{ detail.remark }}</view>
</view>
</view>
<!-- 底部操作按钮 -->
<view class="yd-detail-footer" v-if="detail.status === 10 && !detail.hasApprovalRecords">
<wd-button
v-if="hasAccessByCodes(['erp:sale-order:update'])"
type="primary" plain
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-order:update-status'])"
type="success"
@click="handleApprove"
>
审批
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { SaleOrder } from '@/api/erp/sale-order'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { getSaleOrder, updateSaleOrderStatus } from '@/api/erp/sale-order'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id?: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const loading = ref(false)
const detail = ref<Partial<SaleOrder>>({})
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/sale-order/index')
}
/** 格式化日期 */
function formatDate(date: any) {
if (!date) return ''
const d = new Date(date)
const year = d.getFullYear()
const month = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
}
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '0'
return String(Math.trunc(count))
}
/** 格式化价格 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '0.00'
return Number(price).toFixed(2)
}
/** 获取状态样式 */
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 getPaymentConditionText(condition?: number) {
const map: Record<number, string> = {
1: '款到发货',
2: '货到付款',
3: '月结',
}
return map[condition || 0] || '-'
}
/** 获取付款方式文本 */
function getPaymentMethodText(method?: number) {
const map: Record<number, string> = {
1: '现金',
2: '银行转账',
3: '微信支付',
4: '支付宝',
}
return map[method || 0] || '-'
}
/** 编辑 */
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/sale-order/form/index?id=${props.id}` })
}
/** 审批 */
function handleApprove() {
uni.showModal({
title: '提示',
content: '确定审批该订单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateSaleOrderStatus(props.id, 20)
toast.success('审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
loading.value = true
try {
detail.value = await getSaleOrder(props.id)
} catch (e) {
toast.error('加载失败')
} finally {
loading.value = false
}
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
.info-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16rpx 0;
border-bottom: 1rpx solid #f5f7fa;
&:last-child {
border-bottom: none;
}
.info-label {
color: #909399;
font-size: 28rpx;
flex-shrink: 0;
}
.info-value {
color: #333;
font-size: 28rpx;
text-align: right;
}
}
.total-row {
margin-top: 16rpx;
padding-top: 16rpx;
border-top: 2rpx solid #eee;
border-bottom: none;
}
.status-tag {
padding: 4rpx 16rpx;
border-radius: 8rpx;
font-size: 24rpx;
}
.product-item {
padding: 20rpx;
background: #f8fafc;
border-radius: 12rpx;
margin-bottom: 16rpx;
&:last-child {
margin-bottom: 0;
}
}
</style>

View File

@@ -0,0 +1,423 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar
:title="getTitle"
left-arrow
placeholder
safe-area-inset-top
fixed
@click-left="handleBack"
/>
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-picker
v-model="formData.customerId"
label="客户"
label-width="180rpx"
prop="customerId"
:columns="customerColumns"
placeholder="请选择"
/>
<wd-datetime-picker
v-model="formData.orderTime"
type="date"
label="订单时间"
label-width="180rpx"
placeholder="请选择"
/>
<wd-picker
v-model="formData.saleUserId"
label="销售人员"
label-width="180rpx"
:columns="userColumns"
placeholder="请选择"
/>
</wd-cell-group>
<wd-cell-group title="付款信息" border>
<wd-picker
v-model="formData.paymentCondition"
label="付款条件"
label-width="180rpx"
:columns="paymentConditionColumns"
placeholder="请选择"
/>
<wd-picker
v-model="formData.paymentMethod"
label="付款方式"
label-width="180rpx"
:columns="paymentMethodColumns"
placeholder="请选择"
/>
<wd-picker
v-model="formData.accountId"
label="结算账户"
label-width="180rpx"
:columns="accountColumns"
placeholder="请选择"
/>
<wd-input
v-model="formData.depositPrice"
label="收取订金"
label-width="180rpx"
placeholder="请输入订金"
type="number"
clearable
/>
</wd-cell-group>
<wd-cell-group title="订单产品" border>
<view class="erp-form-item-list">
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card erp-form-item-card--padded"
>
<view class="mb-12rpx flex items-center justify-between">
<text class="erp-card-title">{{ item.productName || `产品${index + 1}` }}</text>
<wd-button size="small" type="error" plain @click="removeItem(index)">删除</wd-button>
</view>
<view class="erp-form-input-row">
<text class="erp-form-input-label">数量</text>
<wd-input
v-model="item.count"
type="number"
placeholder="数量"
clearable
@change="calculateTotal"
/>
</view>
<view class="erp-form-input-row">
<text class="erp-form-input-label">单价</text>
<wd-input
v-model="item.unitPrice"
type="number"
placeholder="单价"
clearable
@change="calculateTotal"
/>
</view>
<view class="erp-form-total-row">
<text class="erp-form-input-label">小计</text>
<text class="text-28rpx text-[#409eff] font-semibold">{{ formatPrice(calculateItemTotal(item)) }}</text>
</view>
</view>
<wd-button type="primary" plain block @click="showProductPicker = true">添加产品</wd-button>
</view>
</wd-cell-group>
<wd-cell-group title="优惠信息" border>
<wd-input
v-model="formData.discountPercent"
label="优惠率(%)"
label-width="180rpx"
placeholder="请输入优惠率"
type="number"
clearable
@change="calculateTotal"
/>
<wd-input
:model-value="formatPrice(formData.discountPrice || 0)"
label="收款优惠"
label-width="180rpx"
placeholder="自动计算"
disabled
/>
<wd-input
:model-value="formatPrice(formData.totalPrice || 0)"
label="优惠后金额"
label-width="180rpx"
placeholder="自动计算"
disabled
/>
</wd-cell-group>
<wd-cell-group title="其他信息" border>
<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="yd-detail-footer">
<wd-button type="primary" block :loading="formLoading" @click="handleSubmit">
保存
</wd-button>
</view>
<wd-popup v-model="showProductPicker" position="bottom" custom-style="height: 60%">
<view class="erp-form-item-list">
<view class="mb-24rpx flex items-center justify-between">
<text class="text-32rpx font-semibold">选择产品</text>
<wd-button size="small" @click="showProductPicker = false">关闭</wd-button>
</view>
<scroll-view scroll-y class="product-picker-list">
<view
v-for="product in productList"
:key="product.id"
class="product-picker-item"
:class="{ 'is-active': selectedProductId === product.id }"
@click="selectedProductId = product.id"
>
<view class="product-picker-item__main">
<text class="product-picker-item__name">{{ product.name }}</text>
<text class="product-picker-item__price">¥{{ formatPrice(product.salePrice) }}</text>
</view>
</view>
</scroll-view>
<wd-button type="primary" block class="mt-24rpx" @click="addProduct">确定添加</wd-button>
</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 { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createSaleOrder, getSaleOrder, updateSaleOrder } from '@/api/erp/sale-order'
import { getProductSimpleList } from '@/api/erp/product'
import { getCustomerSimpleList } from '@/api/erp/customer'
import { getSimpleUserList } from '@/api/system/user'
import { getAccountSimpleList } from '@/api/erp/account'
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 formRef = ref<FormInstance>()
const customerList = ref<any[]>([])
const userList = ref<any[]>([])
const productList = ref<any[]>([])
const accountList = ref<any[]>([])
const showProductPicker = ref(false)
const selectedProductId = ref<number>()
const formData = ref<SaleOrder>({
id: undefined,
customerId: undefined,
orderTime: Date.now(),
saleUserId: undefined,
paymentCondition: undefined,
paymentMethod: undefined,
accountId: undefined,
depositPrice: undefined,
discountPercent: undefined,
discountPrice: 0,
totalPrice: 0,
remark: undefined,
items: [],
})
const formRules = {
customerId: [{ required: true, message: '请选择客户' }],
}
const customerColumns = computed(() => customerList.value.map(v => ({ label: v.name, value: v.id })))
const userColumns = computed(() => userList.value.map(v => ({ label: v.nickname, value: v.id })))
const accountColumns = computed(() => accountList.value.map(v => ({ label: v.name, value: v.id })))
const paymentConditionOptions = [
{ label: '款到发货', value: 1 },
{ label: '货到付款', value: 2 },
{ label: '月结', value: 3 },
]
const paymentConditionColumns = computed(() => paymentConditionOptions.map(v => ({ label: v.label, value: v.value })))
const paymentMethodOptions = [
{ label: '现金', value: 1 },
{ label: '银行转账', value: 2 },
{ label: '微信支付', value: 3 },
{ label: '支付宝', value: 4 },
]
const paymentMethodColumns = computed(() => paymentMethodOptions.map(v => ({ label: v.label, value: v.value })))
function formatPrice(price?: number) {
if (price === undefined || price === null) return '0.00'
return Number(price).toFixed(2)
}
function calculateItemTotal(item: SaleOrderItem) {
const count = Number(item.count) || 0
const unitPrice = Number(item.unitPrice) || 0
return count * unitPrice
}
function calculateTotal() {
if (!formData.value.items || formData.value.items.length === 0) {
formData.value.totalPrice = 0
formData.value.discountPrice = 0
return
}
const total = formData.value.items.reduce((sum, item) => sum + calculateItemTotal(item), 0)
const discountPercent = Number(formData.value.discountPercent) || 0
formData.value.discountPrice = total * (discountPercent / 100)
formData.value.totalPrice = total - formData.value.discountPrice
}
function addProduct() {
const product = productList.value.find(p => p.id === selectedProductId.value)
if (!product) {
toast.warning('请选择产品')
return
}
const newItem: SaleOrderItem = {
productId: product.id,
productName: product.name,
count: 1,
unitPrice: product.salePrice || 0,
totalPrice: product.salePrice || 0,
}
formData.value.items = [...(formData.value.items || []), newItem]
selectedProductId.value = undefined
showProductPicker.value = false
calculateTotal()
}
function removeItem(index: number) {
formData.value.items?.splice(index, 1)
calculateTotal()
}
function handleBack() {
navigateBackPlus('/pages-erp/sale-order/index')
}
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getSaleOrder(props.id)
calculateTotal()
} finally {
toast.close()
}
}
async function loadOptions() {
const [customersResult, usersResult, productsResult, accountsResult] = await Promise.allSettled([
getCustomerSimpleList(),
getSimpleUserList(),
getProductSimpleList(),
getAccountSimpleList(),
])
customerList.value = customersResult.status === 'fulfilled' ? (customersResult.value || []) : []
userList.value = usersResult.status === 'fulfilled' ? (usersResult.value || []) : []
productList.value = productsResult.status === 'fulfilled' ? (productsResult.value || []) : []
accountList.value = accountsResult.status === 'fulfilled' ? (accountsResult.value || []) : []
if ([customersResult, usersResult, productsResult, accountsResult].some(result => result.status === 'rejected')) {
console.error('加载选项失败', {
customersResult,
usersResult,
productsResult,
accountsResult,
})
}
}
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
if (!formData.value.items || formData.value.items.length === 0) {
toast.warning('请添加订单产品')
return
}
formLoading.value = true
try {
const submitData = { ...formData.value }
if (submitData.orderTime) {
submitData.orderTime = new Date(submitData.orderTime).getTime()
}
submitData.items = (submitData.items || []).map(item => ({
...item,
totalPrice: calculateItemTotal(item),
}))
if (props.id) {
await updateSaleOrder(submitData)
toast.success('修改成功')
} else {
await createSaleOrder(submitData)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
onMounted(async () => {
await loadOptions()
await getDetail()
})
</script>
<style lang="scss" scoped>
.product-picker-list {
max-height: 720rpx;
}
.product-picker-item {
padding: 24rpx;
border-bottom: 1rpx solid #f0f0f0;
}
.product-picker-item.is-active {
background: #f0f7ff;
}
.product-picker-item__main {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24rpx;
}
.product-picker-item__name {
flex: 1;
font-size: 28rpx;
color: #333;
}
.product-picker-item__price {
flex-shrink: 0;
font-size: 24rpx;
color: #999;
}
</style>

View File

@@ -0,0 +1,405 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="销售订单"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 搜索组件 -->
<view @click="openSearchForm">
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
</view>
<!-- 分类标签 -->
<view class="status-tabs">
<view
:class="['status-tabs__item', { 'is-active': queryParams.status === undefined }]"
@click="onStatusTabChange(undefined)"
>
全部
</view>
<view
:class="['status-tabs__item', { 'is-active': queryParams.status === 10 }]"
@click="onStatusTabChange(10)"
>
未审核
</view>
<view
:class="['status-tabs__item', { 'is-active': queryParams.status === 20 }]"
@click="onStatusTabChange(20)"
>
已审核
</view>
</view>
<!-- 订单列表 -->
<view class="erp-list">
<view
v-for="item in list"
:key="item.id"
class="erp-list-card"
>
<view class="erp-list-card__body" @click="handleDetail(item)">
<!-- 头部单号 + 状态 -->
<view class="mb-16rpx flex items-center justify-between">
<view class="erp-card-title">
{{ item.no || '-' }}
</view>
<view
class="erp-status-tag"
:class="getStatusClass(item.status)"
>
{{ getStatusText(item.status) }}
</view>
</view>
<!-- 客户 -->
<view class="erp-field-row">
<text class="erp-field-row__label">客户</text>
<text class="erp-field-row__value">{{ item.customerName || '-' }}</text>
</view>
<!-- 产品 -->
<view class="erp-field-row">
<text class="erp-field-row__label">产品</text>
<text class="erp-field-row__value line-clamp-1">{{ item.productNames || '-' }}</text>
</view>
<!-- 订单时间 -->
<view class="erp-field-row">
<text class="erp-field-row__label">订单时间</text>
<text class="erp-field-row__value">{{ formatDate(item.orderTime) || '-' }}</text>
</view>
<!-- 数量统计 -->
<view class="erp-metric-grid">
<view class="erp-metric">
<view class="erp-metric__value">{{ formatCount(item.totalCount) }}</view>
<view class="erp-metric__label">总数量</view>
</view>
<view class="erp-metric">
<view class="erp-metric__value">{{ formatCount(item.outCount) }}</view>
<view class="erp-metric__label">出库数</view>
</view>
<view class="erp-metric">
<view class="erp-metric__value text-[#409eff]">¥{{ formatPrice(item.totalPrice) }}</view>
<view class="erp-metric__label">含税金额</view>
</view>
</view>
</view>
<!-- 操作按钮 -->
<view class="erp-list-card__actions" @click.stop>
<wd-button
size="small" plain @click="handleDetail(item)"
>
详情
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-order:update']) && item.status === 10 && !item.hasApprovalRecords"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-order:update-status']) && item.status === 10"
size="small" type="success" plain @click="handleApprove(item.id)"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-order:delete']) && !item.hasApprovalRecords"
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-order: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-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 { SaleOrder } from '@/api/erp/sale-order'
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 { deleteSaleOrder, getSaleOrderPage, updateSaleOrderStatus } from '@/api/erp/sale-order'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
type SaleOrderQueryParams = Parameters<typeof getSaleOrderPage>[0]
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
/** 打开搜索表单 */
function openSearchForm() {
searchVisible.value = true
}
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<SaleOrder[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<SaleOrderQueryParams>({
pageNo: 1,
pageSize: 10,
status: undefined as number | undefined,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
no: undefined as string | undefined,
})
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.no) conditions.push(`单号:${searchForm.no}`)
return conditions.length > 0 ? conditions.join(' | ') : '搜索订单'
})
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 状态切换 */
function onStatusTabChange(status: number | undefined) {
queryParams.value.status = status
queryParams.value.pageNo = 1
list.value = []
getList()
}
/** 格式化日期 */
function formatDate(date?: string | number) {
if (!date) return '-'
return new Date(date).toLocaleDateString('zh-CN')
}
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '0'
return String(Math.trunc(count))
}
/** 格式化价格 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '0.00'
return Number(price).toFixed(2)
}
/** 获取状态样式 */
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 '-'
}
}
/** 查询订单列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
const data = await getSaleOrderPage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
...queryParams.value,
...searchForm,
pageNo: 1,
pageSize: queryParams.value.pageSize,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.no = undefined
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-order/form/index' })
}
/** 编辑订单 */
function handleEdit(item: SaleOrder) {
uni.navigateTo({ url: `/pages-erp/sale-order/form/index?id=${item.id}` })
}
/** 查看详情 */
function handleDetail(item: SaleOrder) {
uni.navigateTo({ url: `/pages-erp/sale-order/detail/index?id=${item.id}` })
}
/** 审批 */
function handleApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定审批该订单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateSaleOrderStatus(id, 20)
toast.success('审批成功')
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 deleteSaleOrder([id])
toast.success('删除成功')
list.value = []
queryParams.value.pageNo = 1
getList()
} catch {
// error handled by http
}
},
})
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
.status-tabs {
display: flex;
margin: 0 24rpx 16rpx;
background: #fff;
border: 1rpx solid #ebeef5;
border-radius: 16rpx;
overflow: hidden;
&__item {
flex: 1;
text-align: center;
padding: 20rpx 0;
font-size: 28rpx;
color: #606266;
cursor: pointer;
transition: all 0.2s;
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;
}
}
}
</style>

View File

@@ -0,0 +1,382 @@
<template>
<view class="yd-page-container erp-page">
<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>

View File

@@ -0,0 +1,643 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar
:title="pageTitle"
left-arrow
placeholder
safe-area-inset-top
fixed
@click-left="handleBack"
/>
<view class="erp-form-body">
<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="erp-form-item-card erp-form-item-card--padded"
>
<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 erp-page">
<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="erp-form-item-card"
:class="{ 'border-2 border-[#1890ff]': selectedOrderId === item.id }"
@click="handleSelectOrder(item)"
>
<view class="erp-form-item-list">
<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>

View File

@@ -0,0 +1,552 @@
<template>
<view class="yd-page-container erp-page">
<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>

View File

@@ -0,0 +1,293 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar
title="销售计划详情"
left-arrow
placeholder
safe-area-inset-top
fixed
@click-left="handleBack"
/>
<view v-if="detail" class="pb-180rpx">
<wd-cell-group title="基本信息" border>
<wd-cell title="计划编号" :value="detail.no || '-'" />
<wd-cell title="审核状态">
<view
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
:class="getStatusClass(detail.status)"
>
{{ getStatusText(detail.status) }}
</view>
</wd-cell>
<wd-cell title="计划名称" :value="detail.name || '-'" />
<wd-cell title="计划周期" :value="`${formatPlanDate(detail.startTime)} ~ ${formatPlanDate(detail.endTime)}`" />
<wd-cell title="审批人" :value="detail.approverName || '-'" />
<wd-cell title="创建人" :value="detail.creatorName || '-'" />
<wd-cell title="创建时间" :value="formatDateTime(detail.createTime) || '-'" />
</wd-cell-group>
<wd-cell-group title="金额信息" border>
<wd-cell title="目标金额" :value="`¥${formatPrice(detail.targetAmount)}`" />
<wd-cell title="已完成金额" :value="`¥${formatPrice(detail.completedAmount)}`" />
<wd-cell title="完成状态">
<text :class="getCompletionStatusClass(detail.completionStatus)">
{{ getCompletionStatusText(detail.completionStatus) }}
</text>
</wd-cell>
<view class="px-24rpx py-20rpx">
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
<text class="text-[#999]">整体进度</text>
<text>{{ normalizeProgress(detail.progress) }}%</text>
</view>
<view class="progress-track">
<view
class="progress-fill"
:class="normalizeProgress(detail.progress) >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
:style="{ width: `${normalizeProgress(detail.progress)}%` }"
/>
</view>
</view>
</wd-cell-group>
<view class="mx-24rpx mt-24rpx">
<view class="mb-16rpx text-32rpx font-semibold text-[#333]">
计划明细{{ detail.items?.length || 0 }}
</view>
<view v-if="detail.items && detail.items.length > 0">
<view
v-for="(item, index) in detail.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">
<text class="text-28rpx font-semibold text-[#333]">{{ item.productName || '-' }}</text>
<text class="text-24rpx text-[#1890ff]">{{ item.productUnitName || '-' }}</text>
</view>
<view class="p-24rpx">
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">计划数量</text>
<text>{{ formatNumber(item.planCount) }}</text>
</view>
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">销售单价</text>
<text>¥{{ formatPrice(item.productPrice) }}</text>
</view>
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">计划金额</text>
<text class="font-semibold text-[#1890ff]">¥{{ formatPrice(item.totalPrice) }}</text>
</view>
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">已完成金额</text>
<text>¥{{ formatPrice(item.completedAmount) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
<text class="text-[#999]">进度</text>
<text>{{ normalizeProgress(item.progress) }}%</text>
</view>
<view class="progress-track">
<view
class="progress-fill"
:class="normalizeProgress(item.progress) >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
:style="{ width: `${normalizeProgress(item.progress)}%` }"
/>
</view>
<view v-if="item.remark" class="mt-16rpx 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="detail.remark" title="备注" border>
<wd-cell :value="detail.remark" />
</wd-cell-group>
</view>
<view class="yd-detail-footer">
<view class="yd-detail-footer-actions">
<wd-button
v-if="hasAccessByCodes(['erp:sale-plan:update']) && detail?.status === 10"
class="flex-1"
type="warning"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-plan:update-status']) && detail?.status === 10"
class="flex-1"
type="success"
@click="handleAudit"
>
审核
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-plan:delete'])"
class="flex-1"
type="error"
:loading="deleting"
@click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import type { SalePlan } from '@/api/erp/sale-plan'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteSalePlan, getSalePlan, updateSalePlanStatus } from '@/api/erp/sale-plan'
import { useAccess } from '@/hooks/useAccess'
import { formatDate, formatDateTime } from '@/utils/date'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id?: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const detail = ref<SalePlan>()
const deleting = ref(false)
function formatPlanDate(value?: string | number) {
return value ? formatDate(value, 'YYYY-MM-DD') : '-'
}
function formatPrice(value?: number) {
if (value === undefined || value === null) return '0.00'
return Number(value).toFixed(2)
}
function formatNumber(value?: number) {
if (value === undefined || value === null) return '0'
return String(value)
}
function normalizeProgress(value?: number) {
const progress = Number(value || 0)
if (Number.isNaN(progress) || progress < 0) return 0
if (progress > 100) return 100
return Math.round(progress)
}
function getStatusText(status?: number) {
if (status === 10) return '待审核'
if (status === 20) return '已审核'
return '未知'
}
function getStatusClass(status?: number) {
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
return 'bg-[#f5f5f5] text-[#999]'
}
function getCompletionStatusText(status?: number) {
if (status === 0) return '未开始'
if (status === 1) return '进行中'
if (status === 2) return '已完成'
if (status === 3) return '已超期'
return '-'
}
function getCompletionStatusClass(status?: number) {
if (status === 0) return 'text-[#999]'
if (status === 1) return 'text-[#1890ff]'
if (status === 2) return 'text-[#52c41a]'
if (status === 3) return 'text-[#f5222d]'
return 'text-[#999]'
}
function handleBack() {
navigateBackPlus('/pages-erp/sale-plan/index')
}
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
detail.value = await getSalePlan(props.id)
} finally {
toast.close()
}
}
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/sale-plan/form/index?id=${props.id}` })
}
function handleAudit() {
if (!props.id) return
uni.showModal({
title: '提示',
content: '确定审核该销售计划吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateSalePlanStatus(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 deleteSalePlan([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} finally {
deleting.value = false
}
},
})
}
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
.progress-track {
width: 100%;
height: 12rpx;
border-radius: 999rpx;
background: #f0f0f0;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: inherit;
}
</style>

View File

@@ -0,0 +1,512 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar
:title="getTitle"
left-arrow
placeholder
safe-area-inset-top
fixed
@click-left="handleBack"
/>
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-cell title="计划编号" title-width="180rpx" center>
<wd-input
v-model="formData.no"
placeholder="保存后自动生成"
disabled
/>
</wd-cell>
<wd-input
v-model="formData.name"
label="计划名称"
label-width="180rpx"
prop="name"
placeholder="请输入计划名称"
clearable
/>
<wd-datetime-picker
v-model="formData.startTime"
type="date"
label="开始时间"
label-width="180rpx"
prop="startTime"
placeholder="请选择开始时间"
/>
<wd-datetime-picker
v-model="formData.endTime"
type="date"
label="结束时间"
label-width="180rpx"
prop="endTime"
placeholder="请选择结束时间"
/>
<wd-cell title="审批人" title-width="180rpx" center>
<wd-picker
v-model="formData.approverId"
:columns="userColumns"
label=""
placeholder="请选择审批人"
@confirm="onApproverConfirm"
/>
</wd-cell>
</wd-cell-group>
<wd-cell-group title="计划产品" border>
<view class="erp-form-item-list">
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card erp-form-item-card--padded"
>
<view class="erp-form-section-heading">
<text class="text-28rpx font-semibold text-[#333]">
{{ item.productName || `产品${index + 1}` }}
</text>
<wd-button size="small" type="error" plain @click="removeItem(index)">
删除
</wd-button>
</view>
<view class="mb-12rpx flex items-center justify-between text-24rpx text-[#666]">
<text class="text-[#999]">单位</text>
<text>{{ item.productUnitName || '-' }}</text>
</view>
<view class="mb-12rpx flex items-center">
<text class="w-140rpx text-24rpx text-[#999]">计划数量</text>
<wd-input
v-model="item.planCount"
type="number"
placeholder="请输入数量"
clearable
/>
</view>
<view class="mb-12rpx flex items-center">
<text class="w-140rpx text-24rpx text-[#999]">销售单价</text>
<wd-input
v-model="item.productPrice"
type="number"
placeholder="请输入单价"
clearable
/>
</view>
<view class="mb-12rpx flex items-center justify-between text-24rpx text-[#666]">
<text class="text-[#999]">计划金额</text>
<text class="text-28rpx font-semibold text-[#1890ff]">¥{{ formatPrice(item.totalPrice) }}</text>
</view>
<view
v-if="item.completedAmount !== undefined || item.progress !== undefined"
class="erp-form-info-card"
>
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
<text class="text-[#999]">已完成金额</text>
<text>¥{{ formatPrice(item.completedAmount) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
<text class="text-[#999]">进度</text>
<text>{{ normalizeProgress(item.progress) }}%</text>
</view>
<view class="progress-track">
<view
class="progress-fill"
:class="normalizeProgress(item.progress) >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
:style="{ width: `${normalizeProgress(item.progress)}%` }"
/>
</view>
</view>
<wd-input
v-model="item.remark"
label="备注"
label-width="140rpx"
placeholder="请输入备注"
clearable
/>
</view>
<wd-button type="primary" plain block @click="showProductPicker = true">
添加产品
</wd-button>
</view>
</wd-cell-group>
<wd-cell-group title="汇总信息" border>
<wd-cell title="目标金额" :value="`¥${formatPrice(formData.targetAmount)}`" />
<wd-cell title="已完成金额" :value="`¥${formatPrice(formData.completedAmount)}`" />
<view class="px-24rpx py-20rpx">
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
<text class="text-[#999]">整体进度</text>
<text>{{ totalProgress }}%</text>
</view>
<view class="progress-track">
<view
class="progress-fill"
:class="totalProgress >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
:style="{ width: `${totalProgress}%` }"
/>
</view>
</view>
<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="yd-detail-footer">
<wd-button type="primary" block :loading="formLoading" @click="handleSubmit">
保存
</wd-button>
</view>
<wd-popup v-model="showProductPicker" position="bottom" custom-style="height: 60%">
<view class="erp-form-item-list">
<view class="mb-24rpx flex items-center justify-between">
<text class="text-32rpx font-semibold">选择产品</text>
<wd-button size="small" @click="showProductPicker = false">关闭</wd-button>
</view>
<scroll-view scroll-y class="product-picker-list">
<view
v-for="product in productList"
:key="product.id"
class="product-picker-item"
:class="{ 'is-active': selectedProductId === product.id }"
@click="selectedProductId = product.id"
>
<view class="product-picker-item__main">
<view class="flex-1">
<view class="text-28rpx text-[#333]">{{ product.name }}</view>
<view class="mt-8rpx text-22rpx text-[#999]">
{{ product.unitName || '-' }} / ¥{{ formatPrice(product.salePrice) }}
</view>
</view>
<wd-icon
v-if="selectedProductId === product.id"
name="check"
color="#1890ff"
size="36rpx"
/>
</view>
</view>
</scroll-view>
<wd-button type="primary" block class="mt-24rpx" @click="addProduct">
确定添加
</wd-button>
</view>
</wd-popup>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { ProductSimple } from '@/api/erp/product'
import type { SalePlan, SalePlanItem } from '@/api/erp/sale-plan'
import type { User } from '@/api/system/user'
import { computed, onMounted, ref, watch } from 'vue'
import { useToast } from 'wot-design-uni'
import { getProductSimpleList } from '@/api/erp/product'
import { createSalePlan, getSalePlan, updateSalePlan } from '@/api/erp/sale-plan'
import { getSimpleUserList } from '@/api/system/user'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id?: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const toast = useToast()
const formLoading = ref(false)
const formRef = ref<FormInstance>()
const userList = ref<User[]>([])
const productList = ref<ProductSimple[]>([])
const showProductPicker = ref(false)
const selectedProductId = ref<number>()
const getTitle = computed(() => props.id ? '编辑销售计划' : '新增销售计划')
function createDefaultFormData(): SalePlan {
const startTime = Date.now()
const endTime = startTime + 7 * 24 * 60 * 60 * 1000
return {
id: undefined,
no: undefined,
name: undefined,
targetAmount: 0,
startTime,
endTime,
status: 10,
approverId: undefined,
approverName: undefined,
remark: '',
items: [],
completedAmount: 0,
progress: 0,
}
}
const formData = ref<SalePlan>(createDefaultFormData())
const formRules = {
name: [{ required: true, message: '请输入计划名称' }],
startTime: [{ required: true, message: '请选择开始时间' }],
endTime: [{ required: true, message: '请选择结束时间' }],
}
const userColumns = computed(() => {
if (!userList.value.length) {
return []
}
return [userList.value.map(item => ({ label: item.nickname, value: item.id }))]
})
const totalProgress = computed(() => {
const targetAmount = Number(formData.value.targetAmount || 0)
const completedAmount = Number(formData.value.completedAmount || 0)
if (!targetAmount || completedAmount <= 0) return 0
return normalizeProgress((completedAmount / targetAmount) * 100)
})
function getPickerSingleValue(payload: any) {
if (Array.isArray(payload?.value)) {
return payload.value[0]
}
if (payload?.value !== undefined) {
return payload.value
}
if (Array.isArray(payload?.selectedItems) && payload.selectedItems.length > 0) {
return payload.selectedItems[0]?.value
}
return undefined
}
function onApproverConfirm(payload: any) {
const approverId = getPickerSingleValue(payload)
formData.value.approverId = approverId
const approver = userList.value.find(item => item.id === approverId)
formData.value.approverName = approver?.nickname
}
function normalizeProgress(value?: number) {
const progress = Number(value || 0)
if (Number.isNaN(progress) || progress < 0) return 0
if (progress > 100) return 100
return Math.round(progress)
}
function formatPrice(value?: number) {
if (value === undefined || value === null) return '0.00'
return Number(value).toFixed(2)
}
function calcItemTotal(item: SalePlanItem) {
const count = Number(item.planCount) || 0
const price = Number(item.productPrice) || 0
return Math.round(count * price * 100) / 100
}
function removeItem(index: number) {
formData.value.items?.splice(index, 1)
}
function addProduct() {
const product = productList.value.find(item => item.id === selectedProductId.value)
if (!product) {
toast.warning('请选择产品')
return
}
if ((formData.value.items || []).some(item => item.productId === product.id)) {
toast.warning('该产品已添加')
return
}
const newItem: SalePlanItem = {
productId: product.id,
productName: product.name,
productUnitName: product.unitName,
planCount: 1,
productPrice: product.salePrice || 0,
totalPrice: product.salePrice || 0,
remark: undefined,
}
formData.value.items = [...(formData.value.items || []), newItem]
selectedProductId.value = undefined
showProductPicker.value = false
}
watch(
() => formData.value.items,
(items) => {
const list = items || []
let targetAmount = 0
let completedAmount = 0
list.forEach((item) => {
item.totalPrice = calcItemTotal(item)
targetAmount += Number(item.totalPrice || 0)
completedAmount += Number(item.completedAmount || 0)
if (item.completedAmount !== undefined && Number(item.totalPrice || 0) > 0) {
item.progress = normalizeProgress((Number(item.completedAmount || 0) / Number(item.totalPrice || 0)) * 100)
}
})
formData.value.targetAmount = Math.round(targetAmount * 100) / 100
formData.value.completedAmount = Math.round(completedAmount * 100) / 100
formData.value.progress = totalProgress.value
},
{ deep: true },
)
function handleBack() {
navigateBackPlus('/pages-erp/sale-plan/index')
}
async function loadOptions() {
const [usersResult, productsResult] = await Promise.allSettled([
getSimpleUserList(),
getProductSimpleList(),
])
userList.value = usersResult.status === 'fulfilled' ? (usersResult.value || []) : []
productList.value = productsResult.status === 'fulfilled' ? (productsResult.value || []) : []
}
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
const data = await getSalePlan(props.id)
formData.value = {
...createDefaultFormData(),
...data,
items: data.items || [],
}
} finally {
toast.close()
}
}
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
const startTime = Number(formData.value.startTime)
const endTime = Number(formData.value.endTime)
if (startTime && endTime && startTime > endTime) {
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.productId) {
toast.warning(`${i + 1}项产品未选择`)
return
}
if (!item.planCount || Number(item.planCount) <= 0) {
toast.warning(`${i + 1}项计划数量必须大于 0`)
return
}
if (item.productPrice === undefined || item.productPrice === null || Number(item.productPrice) < 0) {
toast.warning(`${i + 1}项销售单价不正确`)
return
}
}
formLoading.value = true
try {
const submitData: SalePlan = {
...formData.value,
startTime: formData.value.startTime ? Number(formData.value.startTime) : undefined,
endTime: formData.value.endTime ? Number(formData.value.endTime) : undefined,
targetAmount: Number(formData.value.targetAmount || 0),
completedAmount: Number(formData.value.completedAmount || 0),
progress: totalProgress.value,
items: (formData.value.items || []).map(item => ({
...item,
totalPrice: calcItemTotal(item),
})),
}
if (props.id) {
await updateSalePlan(submitData)
toast.success('修改成功')
} else {
await createSalePlan(submitData)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
onMounted(async () => {
await loadOptions()
await getDetail()
})
</script>
<style lang="scss" scoped>
.product-picker-list {
max-height: 720rpx;
}
.product-picker-item {
padding: 24rpx;
border-bottom: 1rpx solid #f0f0f0;
&.is-active {
background: #f0f7ff;
}
}
.product-picker-item__main {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24rpx;
}
.progress-track {
width: 100%;
height: 12rpx;
border-radius: 999rpx;
background: #f0f0f0;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: inherit;
}
</style>

View File

@@ -0,0 +1,446 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar
title="销售计划"
left-arrow
placeholder
safe-area-inset-top
fixed
@click-left="handleBack"
/>
<view @click="openSearchForm">
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
</view>
<view class="status-tabs">
<view
:class="['status-tabs__item', { 'is-active': activeStatus === undefined }]"
@click="handleQuickFilter(undefined)"
>
全部
</view>
<view
:class="['status-tabs__item', { 'is-active': activeStatus === 10 }]"
@click="handleQuickFilter(10)"
>
待审核
</view>
<view
:class="['status-tabs__item', { 'is-active': activeStatus === 20 }]"
@click="handleQuickFilter(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"
@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 class="ml-16rpx line-clamp-1 text-right" style="max-width: 420rpx;">{{ item.name || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">计划周期</text>
<text>{{ formatPlanDate(item.startTime) }} ~ {{ formatPlanDate(item.endTime) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">审批人</text>
<text>{{ item.approverName || '-' }}</text>
</view>
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">完成状态</text>
<text :class="getCompletionStatusClass(item.completionStatus)">
{{ getCompletionStatusText(item.completionStatus) }}
</text>
</view>
<view class="flex items-center justify-around border-t border-[#f0f0f0] pt-16rpx">
<view class="text-center">
<view class="text-30rpx text-[#333] font-semibold">¥{{ formatPrice(item.targetAmount) }}</view>
<view class="mt-4rpx text-22rpx text-[#999]">目标金额</view>
</view>
<view class="text-center">
<view class="text-30rpx text-[#52c41a] font-semibold">¥{{ formatPrice(item.completedAmount) }}</view>
<view class="mt-4rpx text-22rpx text-[#999]">已完成</view>
</view>
</view>
<view class="mt-16rpx">
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#999]">
<text>整体进度</text>
<text>{{ normalizeProgress(item.progress) }}%</text>
</view>
<view class="progress-track">
<view
class="progress-fill"
:class="normalizeProgress(item.progress) >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
:style="{ width: `${normalizeProgress(item.progress)}%` }"
/>
</view>
</view>
</view>
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
<wd-button
v-if="hasAccessByCodes(['erp:sale-plan:query'])"
size="small"
plain
@click="handleDetail(item)"
>
详情
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-plan:update']) && item.status === 10"
size="small"
type="primary"
plain
@click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-plan:update-status']) && item.status === 10"
size="small"
type="success"
plain
@click="handleAudit(item.id!)"
>
审核
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-plan:delete'])"
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-plan: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-input v-model="searchForm.name" placeholder="请输入计划名称" clearable />
</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 { SalePlan } from '@/api/erp/sale-plan'
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 { deleteSalePlan, getSalePlanPage, updateSalePlanStatus } from '@/api/erp/sale-plan'
import { useAccess } from '@/hooks/useAccess'
import { formatDate } from '@/utils/date'
import { navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<SalePlan[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const activeStatus = ref<number | undefined>(undefined)
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
status: undefined as number | undefined,
})
const searchVisible = ref(false)
const searchForm = reactive({
no: undefined as string | undefined,
name: undefined as string | undefined,
})
function openSearchForm() {
searchVisible.value = true
}
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.no) conditions.push(`编号:${searchForm.no}`)
if (searchForm.name) conditions.push(`名称:${searchForm.name}`)
return conditions.length > 0 ? conditions.join(' | ') : '搜索销售计划'
})
function handleBack() {
navigateBackPlus()
}
function formatPlanDate(value?: string | number) {
return value ? formatDate(value, 'YYYY-MM-DD') : '-'
}
function formatPrice(value?: number) {
if (value === undefined || value === null) return '0.00'
return Number(value).toFixed(2)
}
function normalizeProgress(value?: number) {
const progress = Number(value || 0)
if (Number.isNaN(progress) || progress < 0) return 0
if (progress > 100) return 100
return Math.round(progress)
}
function getStatusText(status?: number) {
if (status === 10) return '待审核'
if (status === 20) return '已审核'
return '未知'
}
function getStatusClass(status?: number) {
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
return 'bg-[#f5f5f5] text-[#999]'
}
function getCompletionStatusText(status?: number) {
if (status === 0) return '未开始'
if (status === 1) return '进行中'
if (status === 2) return '已完成'
if (status === 3) return '已超期'
return '-'
}
function getCompletionStatusClass(status?: number) {
if (status === 0) return 'text-[#999]'
if (status === 1) return 'text-[#1890ff]'
if (status === 2) return 'text-[#52c41a]'
if (status === 3) return 'text-[#f5222d]'
return 'text-[#999]'
}
async function getList() {
loadMoreState.value = 'loading'
try {
const data = await getSalePlanPage({ ...queryParams.value })
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 handleSearch() {
searchVisible.value = false
queryParams.value = {
...queryParams.value,
...searchForm,
status: activeStatus.value,
pageNo: 1,
pageSize: queryParams.value.pageSize,
}
list.value = []
getList()
}
function handleReset() {
searchForm.no = undefined
searchForm.name = undefined
searchVisible.value = false
queryParams.value = {
pageNo: 1,
pageSize: 10,
status: undefined,
}
activeStatus.value = undefined
list.value = []
getList()
}
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
function handleCardClick(item: SalePlan) {
if (item.status === 10) {
handleEdit(item)
return
}
handleDetail(item)
}
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/sale-plan/form/index' })
}
function handleEdit(item: SalePlan) {
uni.navigateTo({ url: `/pages-erp/sale-plan/form/index?id=${item.id}` })
}
function handleDetail(item: SalePlan) {
uni.navigateTo({ url: `/pages-erp/sale-plan/detail/index?id=${item.id}` })
}
function handleAudit(id: number) {
uni.showModal({
title: '提示',
content: '确定审核该销售计划吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateSalePlanStatus(id, 20)
toast.success('审核成功')
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 deleteSalePlan([id])
toast.success('删除成功')
list.value = []
queryParams.value.pageNo = 1
getList()
} catch {
// error handled by http
}
},
})
}
onReachBottom(() => {
loadMore()
})
onMounted(() => {
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;
transition: all 0.2s;
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;
}
}
}
.progress-track {
width: 100%;
height: 12rpx;
border-radius: 999rpx;
background: #f0f0f0;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: inherit;
}
</style>

View File

@@ -0,0 +1,95 @@
<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-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: '已审核',
}
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>

View File

@@ -0,0 +1,319 @@
<template>
<view class="yd-page-container erp-page">
<wd-navbar
title="销售退货详情"
left-arrow
placeholder
safe-area-inset-top
fixed
@click-left="handleBack"
/>
<view v-if="formData" class="pb-180rpx">
<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.customerName || '-'" />
<wd-cell title="退货时间" :value="formatDateTime(formData.returnTime)" />
<wd-cell title="关联订单" :value="formData.orderNo || '-'" />
<wd-cell title="销售人员" :value="formData.saleUserName || '-'" />
<wd-cell title="创建人" :value="formData.creatorName || '-'" />
<wd-cell title="创建时间" :value="formatDateTime(formData.createTime)" />
</wd-cell-group>
<wd-cell-group title="金额信息" border>
<wd-cell title="合计数量" :value="String(formData.totalCount || 0)" />
<wd-cell title="合计产品价格" :value="`¥${formatPrice(formData.totalProductPrice)}`" />
<wd-cell title="合计税额" :value="`¥${formatPrice(formData.totalTaxPrice)}`" />
<wd-cell title="优惠率" :value="`${formData.discountPercent || 0}%`" />
<wd-cell title="优惠金额" :value="`¥${formatPrice(formData.discountPrice)}`" />
<wd-cell title="其他费用" :value="`¥${formatPrice(formData.otherPrice)}`" />
<wd-cell title="应退金额">
<text class="text-[#e6a23c] font-semibold">¥{{ formatPrice(formData.totalPrice) }}</text>
</wd-cell>
<wd-cell title="已退金额">
<text class="text-[#52c41a] font-semibold">¥{{ formatPrice(formData.refundPrice) }}</text>
</wd-cell>
<wd-cell title="未退金额">
<text
class="font-semibold"
:class="getUnrefundPrice() > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
>
¥{{ formatPrice(getUnrefundPrice()) }}
</text>
</wd-cell>
</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.warehouseName" class="text-24rpx text-[#1890ff]">{{ item.warehouseName }}</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]">¥{{ formatPrice(item.productPrice) }}</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>¥{{ formatPrice(item.taxPrice) }}</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 class="text-[#e6a23c]">¥{{ formatPrice(item.totalPrice) }}</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.outCount != null || item.returnCount != null" class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
<view v-if="item.outCount != null" class="flex items-center">
<text class="mr-8rpx text-[#999]">已出库</text>
<text>{{ item.outCount }}</text>
</view>
<view v-if="item.returnCount != null" class="flex items-center">
<text class="mr-8rpx text-[#999]">已退货</text>
<text>{{ item.returnCount }}</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:sale-return:update']) && formData?.status === 10"
class="flex-1"
type="warning"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-return:update-status']) && formData?.status === 10"
class="flex-1"
type="success"
@click="handleAudit"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-return:update-status']) && formData?.status === 20"
class="flex-1"
type="warning"
@click="handleReverseAudit"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-return:delete'])"
class="flex-1"
type="error"
:loading="deleting"
@click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import type { SaleReturn } from '@/api/erp/sale-return'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteSaleReturn, getSaleReturn, updateSaleReturnStatus } from '@/api/erp/sale-return'
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<SaleReturn>()
const deleting = ref(false)
function formatPrice(value?: number) {
if (value === undefined || value === null) return '0.00'
return Number(value).toFixed(2)
}
function getUnrefundPrice() {
return Math.max(Number(formData.value?.totalPrice || 0) - Number(formData.value?.refundPrice || 0), 0)
}
function getStatusText(status?: number) {
if (status === 10) return '待审核'
if (status === 20) return '已审核'
return '未知'
}
function getStatusClass(status?: number) {
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
return 'bg-[#f5f5f5] text-[#999]'
}
function handleBack() {
navigateBackPlus('/pages-erp/sale-return/index')
}
async function getDetail() {
if (!props.id) {
return
}
try {
toast.loading('加载中...')
formData.value = await getSaleReturn(props.id)
} finally {
toast.close()
}
}
function handleEdit() {
uni.navigateTo({
url: `/pages-erp/sale-return/form/index?id=${props.id}`,
})
}
function handleAudit() {
if (!props.id) {
return
}
uni.showModal({
title: '提示',
content: '确定要审批该销售退货单吗?',
success: async (res) => {
if (!res.confirm) {
return
}
try {
await updateSaleReturnStatus(props.id, 20)
toast.success('审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
function handleReverseAudit() {
if (!props.id) {
return
}
uni.showModal({
title: '提示',
content: '确定要反审批该销售退货单吗?',
success: async (res) => {
if (!res.confirm) {
return
}
try {
await updateSaleReturnStatus(props.id, 10)
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 deleteSaleReturn([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} finally {
deleting.value = false
}
},
})
}
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,633 @@
<template>
<view class="yd-page-container erp-page">
<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" center>
<wd-input
v-model="formData.no"
placeholder="保存时自动生成"
disabled
/>
</wd-cell>
<wd-cell title="退货时间" title-width="180rpx" prop="returnTime" center>
<wd-datetime-picker
v-model="formData.returnTime"
type="date"
label=""
placeholder="请选择退货时间"
/>
</wd-cell>
<wd-cell title="关联订单" title-width="180rpx" center is-link @click="openOrderSelect">
<text v-if="formData.orderNo" class="text-[#1890ff]">{{ formData.orderNo }}</text>
<text v-else class="text-[#999]">点击选择销售订单</text>
</wd-cell>
<wd-cell title="客户" title-width="180rpx" center>
<text>{{ getCustomerName() || '-' }}</text>
</wd-cell>
<wd-cell title="销售人员" title-width="180rpx" center>
<text>{{ getSaleUserName() || '-' }}</text>
</wd-cell>
<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>
<wd-input
v-model="formData.discountPercent"
label="优惠率(%)"
label-width="180rpx"
type="number"
placeholder="请输入优惠率"
clearable
/>
<wd-cell title="退款优惠" title-width="180rpx" center>
<text>¥{{ formatPrice(formData.discountPrice) }}</text>
</wd-cell>
<wd-input
v-model="formData.otherPrice"
label="其他费用"
label-width="180rpx"
type="number"
placeholder="请输入其他费用"
clearable
/>
<wd-cell title="优惠后金额" title-width="180rpx" center>
<text>¥{{ formatPrice(formData.totalPrice) }}</text>
</wd-cell>
<wd-cell title="结算账户" title-width="180rpx" prop="accountId" center>
<wd-picker
v-model="formData.accountId"
:columns="accountColumns"
label=""
placeholder="请选择结算账户"
@confirm="onAccountConfirm"
/>
</wd-cell>
</wd-cell-group>
</wd-form>
</view>
<view class="erp-form-body">
<view class="erp-form-section-heading">
<view class="text-32rpx text-[#333] font-semibold">
退货明细{{ formData.items?.length || 0 }}
</view>
</view>
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card"
>
<view class="erp-form-item-card__header">
<text class="text-28rpx text-[#333] font-semibold">产品 #{{ index + 1 }} {{ item.productName || '' }}</text>
<wd-button
v-if="formData.items && formData.items.length > 1"
size="small"
type="error"
plain
@click="handleRemoveItem(index)"
>
删除
</wd-button>
</view>
<view class="erp-form-item-list">
<view class="mb-16rpx">
<text class="mb-8rpx block text-24rpx text-[#999]">仓库</text>
<wd-picker
v-model="item.warehouseId"
:columns="warehouseColumns"
placeholder="请选择仓库"
@confirm="(e: any) => onWarehouseConfirm(e, index)"
/>
</view>
<view v-if="item.productId" class="erp-form-info-card">
<view class="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">产品名称</text>
<text class="text-[#333]">{{ item.productName || '-' }}</text>
</view>
<view v-if="item.productSpec" 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="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">库存</text>
<text class="text-[#333]">{{ item.stockCount || 0 }}</text>
</view>
<view v-if="item.outCount != null" class="mb-8rpx flex justify-between text-24rpx">
<text class="text-[#999]">已出库</text>
<text class="text-[#333]">{{ item.outCount }}</text>
</view>
<view v-if="item.returnCount != null" class="flex justify-between text-24rpx">
<text class="text-[#999]">已退货</text>
<text class="text-[#333]">{{ item.returnCount }}</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>
<wd-popup v-model="orderSelectVisible" position="right" custom-style="width: 100%; height: 100%;">
<view class="yd-page-container erp-page">
<wd-navbar
title="选择销售订单"
left-arrow
placeholder
safe-area-inset-top
fixed
@click-left="orderSelectVisible = false"
/>
<wd-search
v-model="orderQueryParams.no"
placeholder="搜索订单单号"
@search="getOrderList"
@clear="getOrderList"
/>
<view class="px-24rpx">
<view
v-for="item in orderList"
:key="item.id"
class="erp-form-item-card"
:class="{ 'border-2 border-[#1890ff]': selectedOrderId === item.id }"
@click="handleSelectOrder(item)"
>
<view class="erp-form-item-list">
<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="ml-16rpx line-clamp-1 text-right" style="max-width: 400rpx;">{{ item.productNames || '-' }}</text>
</view>
<view class="flex items-center justify-around mt-12rpx pt-12rpx border-t border-[#f0f0f0]">
<view class="text-center">
<view class="text-28rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
<view class="text-22rpx text-[#999]">总数量</view>
</view>
<view class="text-center">
<view class="text-28rpx text-[#52c41a] font-semibold">{{ item.outCount || 0 }}</view>
<view class="text-22rpx text-[#999]">已出库</view>
</view>
<view class="text-center">
<view class="text-28rpx text-[#f5222d] font-semibold">{{ item.returnCount || 0 }}</view>
<view class="text-22rpx text-[#999]">已退货</view>
</view>
</view>
</view>
</view>
<view v-if="orderList.length === 0" 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 { Account } from '@/api/erp/account'
import type { CustomerSimple } from '@/api/erp/customer'
import type { SaleOrder, SaleOrderItem } from '@/api/erp/sale-order'
import type { SaleReturn, SaleReturnItem } from '@/api/erp/sale-return'
import type { Warehouse } from '@/api/erp/warehouse'
import type { LoadMoreState } from '@/http/types'
import type { User } from '@/api/system/user'
import { computed, onMounted, ref, watch } from 'vue'
import { useToast } from 'wot-design-uni'
import { getAccountSimpleList } from '@/api/erp/account'
import { getCustomerSimpleList } from '@/api/erp/customer'
import { getSaleOrder, getSaleOrderPage } from '@/api/erp/sale-order'
import { createSaleReturn, getSaleReturn, updateSaleReturn } from '@/api/erp/sale-return'
import { getWarehouseSimpleList } from '@/api/erp/warehouse'
import { getSimpleUserList } from '@/api/system/user'
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 formRef = ref<FormInstance>()
const customerList = ref<CustomerSimple[]>([])
const accountList = ref<Account[]>([])
const warehouseList = ref<Warehouse[]>([])
const userList = ref<User[]>([])
const defaultWarehouse = ref<Warehouse>()
const formData = ref<SaleReturn>({
id: undefined,
no: undefined,
customerId: undefined,
accountId: undefined,
saleUserId: undefined,
returnTime: Date.now(),
orderId: undefined,
orderNo: undefined,
discountPercent: 0,
discountPrice: 0,
otherPrice: 0,
totalPrice: 0,
remark: '',
items: [],
})
const formRules = {
returnTime: [{ required: true, message: '退货时间不能为空' }],
}
const orderSelectVisible = ref(false)
const orderList = ref<SaleOrder[]>([])
const orderLoadMoreState = ref<LoadMoreState>('loading')
const orderQueryParams = ref<{
pageNo: number
pageSize: number
no?: string
returnEnable: boolean
}>({
pageNo: 1,
pageSize: 10,
no: undefined as string | undefined,
returnEnable: true,
})
const orderTotal = ref(0)
const selectedOrderId = ref<number>()
const accountColumns = computed(() => {
if (!accountList.value.length) {
return []
}
return [accountList.value.map(a => ({ value: a.id, label: a.name }))]
})
const warehouseColumns = computed(() => {
if (!warehouseList.value.length) {
return []
}
return [warehouseList.value.map(w => ({ value: w.id, label: w.name }))]
})
function formatPrice(value?: number) {
if (value === undefined || value === null) return '0.00'
return Number(value).toFixed(2)
}
function getCustomerName() {
if (!formData.value.customerId) return ''
const customer = customerList.value.find(s => s.id === formData.value.customerId)
return customer?.name || formData.value.customerName || ''
}
function getSaleUserName() {
if (!formData.value.saleUserId) return ''
const user = userList.value.find(s => s.id === formData.value.saleUserId)
return user?.nickname || formData.value.saleUserName || ''
}
function getPickerSingleValue(payload: any) {
if (Array.isArray(payload?.value)) {
return payload.value[0]
}
if (payload?.value !== undefined) {
return payload.value
}
if (Array.isArray(payload?.selectedItems) && payload.selectedItems.length > 0) {
return payload.selectedItems[0]?.value
}
return undefined
}
function onAccountConfirm(payload: any) {
formData.value.accountId = getPickerSingleValue(payload)
}
function onWarehouseConfirm(payload: any, index: number) {
if (formData.value.items && formData.value.items[index]) {
const warehouseId = getPickerSingleValue(payload)
formData.value.items[index].warehouseId = warehouseId
const warehouse = warehouseList.value.find(w => w.id === warehouseId)
if (warehouse) {
formData.value.items[index].warehouseName = warehouse.name
}
}
}
function calcTotalPrice(item: SaleReturnItem) {
if (item.productPrice && item.count) {
const productTotal = Number(item.productPrice) * Number(item.count)
const taxPrice = item.taxPercent ? productTotal * Number(item.taxPercent) / 100 : 0
return `¥${(productTotal + taxPrice).toFixed(2)}`
}
return '-'
}
watch(
() => formData.value,
(val) => {
if (!val || !val.items) return
val.items.forEach((item) => {
if (item.productPrice && item.count) {
item.totalProductPrice = Number(item.productPrice) * Number(item.count)
item.taxPrice = item.taxPercent ? item.totalProductPrice * Number(item.taxPercent) / 100 : 0
item.totalPrice = item.totalProductPrice + (item.taxPrice || 0)
} else {
item.totalProductPrice = 0
item.taxPrice = 0
item.totalPrice = 0
}
})
const totalPrice = val.items.reduce((prev, curr) => prev + Number(curr.totalPrice || 0), 0)
const discountPrice = val.discountPercent ? totalPrice * Number(val.discountPercent) / 100 : 0
formData.value.discountPrice = Math.round(discountPrice * 100) / 100
formData.value.totalPrice = Math.round((totalPrice - discountPrice + Number(val.otherPrice || 0)) * 100) / 100
},
{ deep: true },
)
async function loadDropdownData() {
const [customers, accounts, warehouses, users] = await Promise.allSettled([
getCustomerSimpleList(),
getAccountSimpleList(),
getWarehouseSimpleList(),
getSimpleUserList(),
])
customerList.value = customers.status === 'fulfilled' ? (customers.value || []) : []
accountList.value = accounts.status === 'fulfilled' ? (accounts.value || []) : []
warehouseList.value = warehouses.status === 'fulfilled' ? (warehouses.value || []) : []
userList.value = users.status === 'fulfilled' ? (users.value || []) : []
const defaultAccount = accountList.value.find(a => (a as any).defaultStatus)
if (defaultAccount && !formData.value.accountId) {
formData.value.accountId = defaultAccount.id
}
defaultWarehouse.value = warehouseList.value.find(w => w.defaultStatus)
}
function handleBack() {
navigateBackPlus('/pages-erp/sale-return/index')
}
function handleRemoveItem(index: number) {
uni.showModal({
title: '提示',
content: `确定要删除第 ${index + 1} 项产品吗?`,
success: (res) => {
if (res.confirm) {
formData.value.items?.splice(index, 1)
}
},
})
}
function openOrderSelect() {
orderSelectVisible.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)
if (orderQueryParams.value.pageNo === 1) {
orderList.value = data.list
} else {
orderList.value = [...orderList.value, ...data.list]
}
orderTotal.value = data.total
orderLoadMoreState.value = orderList.value.length >= orderTotal.value ? 'finished' : 'loading'
} catch {
orderLoadMoreState.value = 'error'
}
}
function loadMoreOrders() {
if (orderLoadMoreState.value === 'finished') return
orderQueryParams.value.pageNo++
getOrderList()
}
function handleSelectOrder(item: SaleOrder) {
selectedOrderId.value = item.id
}
function mapSaleOrderItem(item: SaleOrderItem) {
const availableCount = Math.max(Number(item.outCount || 0) - Number(item.returnCount || 0), 0)
return {
productId: item.productId,
productName: item.productName,
productUnitId: item.productUnitId,
productUnitName: item.productUnitName,
productPrice: item.productPrice ?? item.unitPrice,
productSpec: item.productSpec,
productBarCode: item.productBarCode,
count: availableCount,
outCount: item.outCount,
returnCount: item.returnCount,
taxPercent: item.taxPercent,
warehouseId: defaultWarehouse.value?.id,
warehouseName: defaultWarehouse.value?.name,
stockCount: item.stockCount,
orderItemId: item.id,
remark: item.remark,
} as SaleReturnItem
}
async function confirmSelectOrder() {
if (!selectedOrderId.value) return
try {
toast.loading('加载订单详情...')
const orderDetail = await getSaleOrder(selectedOrderId.value)
formData.value.orderId = orderDetail.id
formData.value.orderNo = orderDetail.no
formData.value.customerId = orderDetail.customerId
formData.value.customerName = orderDetail.customerName
formData.value.accountId = orderDetail.accountId
formData.value.saleUserId = orderDetail.saleUserId
formData.value.saleUserName = orderDetail.saleUserName
formData.value.discountPercent = orderDetail.discountPercent
formData.value.remark = orderDetail.remark
if (orderDetail.items) {
formData.value.items = orderDetail.items
.filter(item => (Number(item.outCount || 0) - Number(item.returnCount || 0)) > 0)
.map(mapSaleOrderItem)
}
orderSelectVisible.value = false
} finally {
toast.close()
}
}
async function getDetail() {
if (!props.id) {
return
}
try {
toast.loading('加载中...')
formData.value = await getSaleReturn(props.id)
} finally {
toast.close()
}
}
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.warehouseId) {
toast.warning(`${i + 1}项产品请选择仓库`)
return
}
if (!item.count || Number(item.count) <= 0) {
toast.warning(`${i + 1}项产品数量不能为空`)
return
}
if (Number(item.count) > Math.max(Number(item.outCount || 0) - Number(item.returnCount || 0), 0)) {
toast.warning(`${i + 1}项产品数量不能超过可退数量`)
return
}
}
formLoading.value = true
try {
if (props.id) {
await updateSaleReturn(formData.value)
toast.success('修改成功')
} else {
await createSaleReturn(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
onMounted(async () => {
await loadDropdownData()
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,371 @@
<template>
<view class="yd-page-container erp-page">
<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="String(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.customerName || '-' }}</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.returnTime) }}</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-[#e6a23c] font-semibold">¥{{ formatPrice(item.totalPrice) }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">应退</view>
</view>
<view class="text-center">
<view class="text-30rpx text-[#52c41a] font-semibold">¥{{ formatPrice(item.refundPrice) }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">已退</view>
</view>
<view class="text-center">
<view
class="text-30rpx font-semibold"
:class="getUnrefundPrice(item) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
>
¥{{ formatPrice(getUnrefundPrice(item)) }}
</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:sale-return:query'])"
size="small"
plain
@click="handleDetail(item)"
>
详情
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-return:update']) && item.status === 10"
size="small"
type="primary"
plain
@click="handleEdit(item)"
>
修改
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-return:update-status']) && item.status === 10"
size="small"
type="success"
plain
@click="handleAudit(item.id!)"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-return:update-status']) && item.status === 20"
size="small"
type="warning"
plain
@click="handleReverseAudit(item.id!)"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:sale-return:delete'])"
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-return:create'])"
position="right-bottom"
type="primary"
:expandable="false"
@click="handleAdd"
/>
</view>
</template>
<script lang="ts" setup>
import type { SaleReturn } from '@/api/erp/sale-return'
import type { LoadMoreState } from '@/http/types'
import { onReachBottom } from '@dcloudio/uni-app'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteSaleReturn, getSaleReturnPage, updateSaleReturnStatus } from '@/api/erp/sale-return'
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<SaleReturn[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const activeStatus = ref<number | undefined>(undefined)
const queryParams = ref<{
pageNo: number
pageSize: number
no?: string
customerId?: number
status?: number
}>({
pageNo: 1,
pageSize: 10,
})
const statusTabs = [
{ label: '全部', value: undefined },
{ label: '待审核', value: 10 },
{ label: '已审核', value: 20 },
]
function formatDate(date?: string | number) {
if (!date) return '-'
const value = new Date(date)
if (Number.isNaN(value.getTime())) return String(date).slice(0, 10)
return `${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}`
}
function formatPrice(price?: number) {
if (price === undefined || price === null) return '0.00'
return Number(price).toFixed(2)
}
function getUnrefundPrice(item: SaleReturn) {
return Math.max(Number(item.totalPrice || 0) - Number(item.refundPrice || 0), 0)
}
function getStatusText(status?: number) {
if (status === 10) return '待审核'
if (status === 20) return '已审核'
return '未知'
}
function getStatusClass(status?: number) {
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
return 'bg-[#f5f5f5] text-[#999]'
}
function handleBack() {
navigateBackPlus()
}
async function getList() {
loadMoreState.value = 'loading'
try {
const data = await getSaleReturnPage({ ...queryParams.value })
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: SaleReturn) {
if (item.status === 20) {
handleDetail(item)
} else if (item.status === 10) {
handleEdit(item)
}
}
function handleAdd() {
uni.navigateTo({
url: '/pages-erp/sale-return/form/index',
})
}
function handleDetail(item: SaleReturn) {
uni.navigateTo({
url: `/pages-erp/sale-return/detail/index?id=${item.id}`,
})
}
function handleEdit(item: SaleReturn) {
uni.navigateTo({
url: `/pages-erp/sale-return/form/index?id=${item.id}`,
})
}
function handleAudit(id: number) {
uni.showModal({
title: '提示',
content: '确定审批该销售退货单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateSaleReturnStatus(id, 20)
toast.success('审批成功')
list.value = []
queryParams.value.pageNo = 1
getList()
} catch {
// error handled by http
}
},
})
}
function handleReverseAudit(id: number) {
uni.showModal({
title: '提示',
content: '确定反审批该销售退货单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateSaleReturnStatus(id, 10)
toast.success('反审批成功')
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 deleteSaleReturn([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>

View File

@@ -0,0 +1,238 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="盘点单详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 详情内容 -->
<view class="pb-180rpx">
<!-- 基本信息 -->
<wd-cell-group title="基本信息" border>
<wd-cell title="盘点单号" :value="detail.no || '-'" />
<wd-cell title="盘点时间" :value="formatDate(detail.checkTime)" />
<wd-cell title="审核状态">
<template #value>
<view
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
:class="detail.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ detail.status === 20 ? '已审核' : '未审核' }}
</view>
</template>
</wd-cell>
<wd-cell title="备注" :value="detail.remark || '-'" />
</wd-cell-group>
<!-- 金额信息 -->
<wd-cell-group title="金额信息" border>
<wd-cell title="盘点数量" :value="formatCount(detail.totalCount)" />
<wd-cell title="盘点金额" :value="formatPrice(detail.totalPrice)" />
</wd-cell-group>
<!-- 盘点产品清单 -->
<wd-cell-group title="盘点产品清单" border>
<view v-if="!detail.items || detail.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品数据
</view>
<view v-else>
<view
v-for="(item, index) in detail.items"
:key="index"
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
>
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
{{ item.productName || '-' }}
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">仓库</text>
<text class="text-[#666]">{{ item.warehouseName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">账面数量</text>
<text class="text-[#666]">{{ formatCount(item.stockCount) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">实际数量</text>
<text class="text-[#666]">{{ formatCount(item.actualCount) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">盈亏数量</text>
<text
class="font-semibold"
:class="(item.count || 0) >= 0 ? 'text-[#52c41a]' : 'text-[#f5222d]'"
>
{{ (item.count || 0) >= 0 ? '+' : '' }}{{ formatCount(item.count) }}
</text>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
</view>
</wd-cell-group>
</view>
<!-- 底部操作按钮 -->
<view class="yd-detail-footer">
<wd-button
v-if="hasAccessByCodes(['erp:stock-check:update']) && detail.status === 10"
type="primary"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-check:update-status']) && detail.status === 10"
type="success"
@click="handleApprove"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-check:update-status']) && detail.status === 20"
type="warning"
@click="handleReverseApprove"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-check:delete']) && detail.status === 10"
type="error"
@click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { StockCheck } from '@/api/erp/stock-check'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteStockCheck, getStockCheck, updateStockCheckStatus } from '@/api/erp/stock-check'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const detail = ref<StockCheck>({})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-check/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
detail.value = await getStockCheck(props.id)
} finally {
toast.close()
}
}
/** 编辑 */
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/stock-check/form/index?id=${props.id}` })
}
/** 审批 */
function handleApprove() {
uni.showModal({
title: '提示',
content: '确定要审批该盘点单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockCheckStatus(props.id, 20)
toast.success('审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove() {
uni.showModal({
title: '提示',
content: '确定要反审批该盘点单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockCheckStatus(props.id, 10)
toast.success('反审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete() {
uni.showModal({
title: '提示',
content: '确定要删除该盘点单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockCheck([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} catch {
// error handled by http
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,400 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-cell title="盘点单号" :value="formData.no || '保存时自动生成'" />
<wd-cell
title="盘点时间"
title-width="180rpx"
is-link
:value="formData.checkTime ? formatDate(formData.checkTime) : '请选择'"
@click="datePickerVisible = true"
/>
<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-if="formData.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品请点击下方按钮添加
</view>
<view v-else>
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card erp-form-item-card--padded"
>
<view class="mb-12rpx flex items-center justify-between">
<view class="text-28rpx text-[#333] font-semibold">
{{ item.productName || '请选择产品' }}
</view>
<wd-icon name="delete" size="40rpx" color="#f56c6c" @click="removeItem(index)" />
</view>
<view class="mb-12rpx">
<wd-cell
title="仓库"
title-width="140rpx"
is-link
:value="item.warehouseName || '请选择'"
@click="openWarehousePicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-cell
title="产品"
title-width="140rpx"
is-link
:value="item.productName || '请选择'"
@click="openProductPicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.stockCount"
label="账面数量"
label-width="140rpx"
type="number"
placeholder="请输入账面数量"
@change="calcItemDiff(item)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.actualCount"
label="实际数量"
label-width="140rpx"
type="number"
placeholder="请输入实际数量"
@change="calcItemDiff(item)"
/>
</view>
<view class="mb-12rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">盈亏数量</text>
<text
class="font-semibold"
:class="(item.count || 0) >= 0 ? 'text-[#52c41a]' : 'text-[#f5222d]'"
>
{{ (item.count || 0) >= 0 ? '+' : '' }}{{ formatCount(item.count) }}
</text>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.productPrice"
label="单价"
label-width="140rpx"
type="digit"
placeholder="请输入单价"
@change="calcItemTotal(item)"
/>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
</view>
<view class="px-24rpx pb-24rpx">
<wd-button type="primary" plain block @click="addItem">
<wd-icon name="add" class="mr-8rpx" />
添加产品
</wd-button>
</view>
</wd-cell-group>
<!-- 合计信息 -->
<wd-cell-group title="合计信息" border>
<wd-cell title="盘点数量" :value="formatCount(totalCount)" />
<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-datetime-picker
v-model="datePickerVisible"
type="date"
:value="formData.checkTime"
@confirm="onDateConfirm"
/>
<!-- 仓库选择器 -->
<wd-picker v-model:show="warehousePickerVisible"
:columns="warehouseColumns"
@confirm="onWarehouseConfirm"
/>
<!-- 产品选择器 -->
<wd-picker v-model:show="productPickerVisible"
:columns="productColumns"
@confirm="onProductConfirm"
/>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { StockCheck, StockCheckItem } from '@/api/erp/stock-check'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createStockCheck, getStockCheck, updateStockCheck } from '@/api/erp/stock-check'
import { getWarehouseSimpleList } from '@/api/erp/warehouse'
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<StockCheck>({
id: undefined,
no: undefined,
checkTime: undefined,
remark: undefined,
items: [],
})
const formRules = {
checkTime: [{ required: true, message: '盘点时间不能为空' }],
}
const formRef = ref<FormInstance>()
// 仓库列表
const warehouseList = ref<{ id?: number, name?: string }[]>([])
const warehousePickerVisible = ref(false)
const warehouseColumns = computed(() => [
warehouseList.value.map(v => ({ value: v.id, label: v.name })),
])
// 产品列表
const productList = ref<{ id: number, name: string, unitName?: string }[]>([])
const productPickerVisible = ref(false)
const productColumns = computed(() => [
productList.value.map(v => ({ value: v.id, label: v.name })),
])
// 日期选择器
const datePickerVisible = ref<any>(false)
// 当前编辑的产品项索引
const currentItemIndex = ref(-1)
/** 合计数量 */
const totalCount = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + Math.abs(Number(item.count) || 0), 0) || 0
})
/** 合计金额 */
const totalPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + Math.abs(Number(item.totalPrice) || 0), 0) || 0
})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
if (typeof dateStr === 'number') {
const d = new Date(dateStr)
const pad = (n: number) => n.toString().padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
}
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-check/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getStockCheck(props.id)
} finally {
toast.close()
}
}
/** 日期确认 */
function onDateConfirm({ value }: any) {
formData.value.checkTime = value
datePickerVisible.value = false
}
/** 打开仓库选择器 */
function openWarehousePicker(index: number) {
currentItemIndex.value = index
warehousePickerVisible.value = true
}
/** 仓库确认 */
function onWarehouseConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.warehouseId = value?.[0]
const warehouse = warehouseList.value.find(w => w.id === item.warehouseId)
item.warehouseName = warehouse?.name
}
warehousePickerVisible.value = false
}
/** 打开产品选择器 */
function openProductPicker(index: number) {
currentItemIndex.value = index
productPickerVisible.value = true
}
/** 产品确认 */
function onProductConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.productId = value?.[0]
const product = productList.value.find(p => p.id === item.productId)
item.productName = product?.name
item.productUnitName = product?.unitName
}
productPickerVisible.value = false
}
/** 添加产品项 */
function addItem() {
if (!formData.value.items) {
formData.value.items = []
}
formData.value.items.push({
warehouseId: undefined,
warehouseName: undefined,
productId: undefined,
productName: undefined,
productUnitName: undefined,
stockCount: undefined,
actualCount: undefined,
count: 0,
productPrice: undefined,
totalPrice: 0,
})
}
/** 移除产品项 */
function removeItem(index: number) {
formData.value.items?.splice(index, 1)
}
/** 计算盈亏数量 */
function calcItemDiff(item: StockCheckItem) {
const stockCount = Number(item.stockCount) || 0
const actualCount = Number(item.actualCount) || 0
item.count = actualCount - stockCount
calcItemTotal(item)
}
/** 计算产品项金额 */
function calcItemTotal(item: StockCheckItem) {
const count = Math.abs(Number(item.count) || 0)
const price = Number(item.productPrice) || 0
item.totalPrice = count * price
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
// 校验产品清单
if (!formData.value.items || formData.value.items.length === 0) {
toast.error('请添加盘点产品')
return
}
for (const item of formData.value.items) {
if (!item.warehouseId) {
toast.error('请选择仓库')
return
}
if (!item.productId) {
toast.error('请选择产品')
return
}
}
formLoading.value = true
try {
// 设置合计
formData.value.totalCount = totalCount.value
formData.value.totalPrice = totalPrice.value
if (props.id) {
await updateStockCheck(formData.value)
toast.success('修改成功')
} else {
await createStockCheck(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
// 加载仓库列表
warehouseList.value = await getWarehouseSimpleList()
// 加载详情
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,383 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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="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="queryParams.status === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
@click="onTabChange(tab.value)"
>
{{ tab.label }}
<view
v-if="queryParams.status === 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="handleDetail(item)"
>
<view class="p-24rpx">
<!-- 头部单号 + 状态 -->
<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="item.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ item.status === 20 ? '已审核' : '未审核' }}
</view>
</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.checkTime) }}</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-32rpx text-[#333] font-semibold">{{ formatCount(item.totalCount) }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">盘点数量</view>
</view>
<view class="text-center">
<view class="text-32rpx text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</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:stock-check:update']) && item.status === 10"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-check:update-status']) && item.status === 10"
size="small" type="success" plain @click="handleApprove(item.id!)"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-check:update-status']) && item.status === 20"
size="small" type="warning" plain @click="handleReverseApprove(item.id!)"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-check:delete']) && item.status === 10"
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:stock-check: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" :style="{ paddingTop: `${getNavbarHeight()}px` }">
<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>
<view class="yd-search-form-radio-group">
<view
v-for="opt in statusOptions"
:key="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 { StockCheck } from '@/api/erp/stock-check'
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 { deleteStockCheck, getStockCheckPage, updateStockCheckStatus } from '@/api/erp/stock-check'
import { useAccess } from '@/hooks/useAccess'
import { getNavbarHeight, navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<StockCheck[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
status: undefined,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
no: undefined as string | undefined,
status: undefined as number | undefined,
})
/** 状态标签 */
const statusTabs = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 状态选项 */
const statusOptions = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.no) conditions.push(`单号:${searchForm.no}`)
if (searchForm.status !== undefined) {
const statusLabel = statusOptions.find(o => o.value === searchForm.status)?.label
if (statusLabel && statusLabel !== '全部') conditions.push(`状态:${statusLabel}`)
}
return conditions.length > 0 ? conditions.join(' | ') : '搜索盘点单'
})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 切换状态标签 */
function onTabChange(status: number | undefined) {
queryParams.value.status = status
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 查询盘点单列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
if (searchForm.no) params.no = searchForm.no
const data = await getStockCheckPage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
pageNo: 1,
pageSize: queryParams.value.pageSize,
status: searchForm.status,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.no = undefined
searchForm.status = undefined
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10, status: undefined }
list.value = []
getList()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
/** 新增盘点单 */
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/stock-check/form/index' })
}
/** 编辑 */
function handleEdit(item: StockCheck) {
uni.navigateTo({ url: `/pages-erp/stock-check/form/index?id=${item.id}` })
}
/** 详情 */
function handleDetail(item: StockCheck) {
uni.navigateTo({ url: `/pages-erp/stock-check/detail/index?id=${item.id}` })
}
/** 审批 */
function handleApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要审批该盘点单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockCheckStatus(id, 20)
toast.success('审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要反审批该盘点单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockCheckStatus(id, 10)
toast.success('反审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该盘点单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockCheck([id])
toast.success('删除成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 刷新列表 */
function refreshList() {
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,226 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="报溢单详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 详情内容 -->
<view class="pb-180rpx">
<!-- 基本信息 -->
<wd-cell-group title="基本信息" border>
<wd-cell title="报溢单号" :value="detail.no || '-'" />
<wd-cell title="报溢时间" :value="formatDate(detail.gainTime)" />
<wd-cell title="报溢原因" :value="detail.reason || '-'" />
<wd-cell title="审核状态">
<template #value>
<view
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
:class="detail.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ detail.status === 20 ? '已审核' : '未审核' }}
</view>
</template>
</wd-cell>
<wd-cell title="备注" :value="detail.remark || '-'" />
</wd-cell-group>
<!-- 金额信息 -->
<wd-cell-group title="金额信息" border>
<wd-cell title="合计数量" :value="formatCount(detail.totalCount)" />
<wd-cell title="合计金额" :value="formatPrice(detail.totalPrice)" />
</wd-cell-group>
<!-- 报溢产品清单 -->
<wd-cell-group title="报溢产品清单" border>
<view v-if="!detail.items || detail.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品数据
</view>
<view v-else>
<view
v-for="(item, index) in detail.items"
:key="index"
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
>
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
{{ item.productName || '-' }}
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">仓库</text>
<text class="text-[#666]">{{ item.warehouseName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">数量</text>
<text class="text-[#52c41a] font-semibold">+{{ formatCount(item.count) }}</text>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
</view>
</wd-cell-group>
</view>
<!-- 底部操作按钮 -->
<view class="yd-detail-footer">
<wd-button
v-if="hasAccessByCodes(['erp:stock-gain:update']) && detail.status === 10"
type="primary"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-gain:update-status']) && detail.status === 10"
type="success"
@click="handleApprove"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-gain:update-status']) && detail.status === 20"
type="warning"
@click="handleReverseApprove"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-gain:delete']) && detail.status === 10"
type="error"
@click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { StockGain } from '@/api/erp/stock-gain'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteStockGain, getStockGain, updateStockGainStatus } from '@/api/erp/stock-gain'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const detail = ref<StockGain>({})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-gain/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
detail.value = await getStockGain(props.id)
} finally {
toast.close()
}
}
/** 编辑 */
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/stock-gain/form/index?id=${props.id}` })
}
/** 审批 */
function handleApprove() {
uni.showModal({
title: '提示',
content: '确定要审批该报溢单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockGainStatus(props.id, 20)
toast.success('审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove() {
uni.showModal({
title: '提示',
content: '确定要反审批该报溢单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockGainStatus(props.id, 10)
toast.success('反审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete() {
uni.showModal({
title: '提示',
content: '确定要删除该报溢单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockGain([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} catch {
// error handled by http
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,383 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-cell title="报溢单号" :value="formData.no || '保存时自动生成'" />
<wd-cell
title="报溢时间"
title-width="180rpx"
is-link
:value="formData.gainTime ? formatDate(formData.gainTime) : '请选择'"
@click="datePickerVisible = true"
/>
<wd-input
v-model="formData.reason"
label="报溢原因"
label-width="180rpx"
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-if="formData.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品请点击下方按钮添加
</view>
<view v-else>
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card erp-form-item-card--padded"
>
<view class="mb-12rpx flex items-center justify-between">
<view class="text-28rpx text-[#333] font-semibold">
{{ item.productName || '请选择产品' }}
</view>
<wd-icon name="delete" size="40rpx" color="#f56c6c" @click="removeItem(index)" />
</view>
<view class="mb-12rpx">
<wd-cell
title="仓库"
title-width="120rpx"
is-link
:value="item.warehouseName || '请选择'"
@click="openWarehousePicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-cell
title="产品"
title-width="120rpx"
is-link
:value="item.productName || '请选择'"
@click="openProductPicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.count"
label="数量"
label-width="120rpx"
type="number"
placeholder="请输入数量"
@change="calcItemTotal(item)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.productPrice"
label="单价"
label-width="120rpx"
type="digit"
placeholder="请输入单价"
@change="calcItemTotal(item)"
/>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
</view>
<view class="px-24rpx pb-24rpx">
<wd-button type="primary" plain block @click="addItem">
<wd-icon name="add" class="mr-8rpx" />
添加产品
</wd-button>
</view>
</wd-cell-group>
<!-- 合计信息 -->
<wd-cell-group title="合计信息" border>
<wd-cell title="合计数量" :value="formatCount(totalCount)" />
<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-datetime-picker
v-model="datePickerVisible"
type="date"
:value="formData.gainTime"
@confirm="onDateConfirm"
/>
<!-- 仓库选择器 -->
<wd-picker v-model:show="warehousePickerVisible"
:columns="warehouseColumns"
@confirm="onWarehouseConfirm"
/>
<!-- 产品选择器 -->
<wd-picker v-model:show="productPickerVisible"
:columns="productColumns"
@confirm="onProductConfirm"
/>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { StockGain, StockGainItem } from '@/api/erp/stock-gain'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createStockGain, getStockGain, updateStockGain } from '@/api/erp/stock-gain'
import { getWarehouseSimpleList } from '@/api/erp/warehouse'
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<StockGain>({
id: undefined,
no: undefined,
gainTime: undefined,
reason: undefined,
remark: undefined,
items: [],
})
const formRules = {
gainTime: [{ required: true, message: '报溢时间不能为空' }],
}
const formRef = ref<FormInstance>()
// 仓库列表
const warehouseList = ref<{ id?: number, name?: string }[]>([])
const warehousePickerVisible = ref(false)
const warehouseColumns = computed(() => [
warehouseList.value.map(v => ({ value: v.id, label: v.name })),
])
// 产品列表
const productList = ref<{ id: number, name: string, unitName?: string }[]>([])
const productPickerVisible = ref(false)
const productColumns = computed(() => [
productList.value.map(v => ({ value: v.id, label: v.name })),
])
// 日期选择器
const datePickerVisible = ref<any>(false)
// 当前编辑的产品项索引
const currentItemIndex = ref(-1)
/** 合计数量 */
const totalCount = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.count) || 0), 0) || 0
})
/** 合计金额 */
const totalPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
if (typeof dateStr === 'number') {
const d = new Date(dateStr)
const pad = (n: number) => n.toString().padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
}
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-gain/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getStockGain(props.id)
} finally {
toast.close()
}
}
/** 日期确认 */
function onDateConfirm({ value }: any) {
formData.value.gainTime = value
datePickerVisible.value = false
}
/** 打开仓库选择器 */
function openWarehousePicker(index: number) {
currentItemIndex.value = index
warehousePickerVisible.value = true
}
/** 仓库确认 */
function onWarehouseConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.warehouseId = value?.[0]
const warehouse = warehouseList.value.find(w => w.id === item.warehouseId)
item.warehouseName = warehouse?.name
}
warehousePickerVisible.value = false
}
/** 打开产品选择器 */
function openProductPicker(index: number) {
currentItemIndex.value = index
productPickerVisible.value = true
}
/** 产品确认 */
function onProductConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.productId = value?.[0]
const product = productList.value.find(p => p.id === item.productId)
item.productName = product?.name
item.productUnitName = product?.unitName
}
productPickerVisible.value = false
}
/** 添加产品项 */
function addItem() {
if (!formData.value.items) {
formData.value.items = []
}
formData.value.items.push({
warehouseId: undefined,
warehouseName: undefined,
productId: undefined,
productName: undefined,
productUnitName: undefined,
count: undefined,
productPrice: undefined,
totalPrice: 0,
})
}
/** 移除产品项 */
function removeItem(index: number) {
formData.value.items?.splice(index, 1)
}
/** 计算产品项金额 */
function calcItemTotal(item: StockGainItem) {
const count = Number(item.count) || 0
const price = Number(item.productPrice) || 0
item.totalPrice = count * price
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
// 校验产品清单
if (!formData.value.items || formData.value.items.length === 0) {
toast.error('请添加报溢产品')
return
}
for (const item of formData.value.items) {
if (!item.warehouseId) {
toast.error('请选择仓库')
return
}
if (!item.productId) {
toast.error('请选择产品')
return
}
if (!item.count || Number(item.count) <= 0) {
toast.error('请输入有效的数量')
return
}
}
formLoading.value = true
try {
// 设置合计
formData.value.totalCount = totalCount.value
formData.value.totalPrice = totalPrice.value
if (props.id) {
await updateStockGain(formData.value)
toast.success('修改成功')
} else {
await createStockGain(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
// 加载仓库列表
warehouseList.value = await getWarehouseSimpleList()
// 加载详情
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,388 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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="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="queryParams.status === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
@click="onTabChange(tab.value)"
>
{{ tab.label }}
<view
v-if="queryParams.status === 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="handleDetail(item)"
>
<view class="p-24rpx">
<!-- 头部单号 + 状态 -->
<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="item.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ item.status === 20 ? '已审核' : '未审核' }}
</view>
</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.gainTime) }}</text>
</view>
<!-- 报溢原因 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">报溢原因</text>
<text>{{ item.reason || '-' }}</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-32rpx text-[#52c41a] font-semibold">{{ formatCount(item.totalCount) }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">数量</view>
</view>
<view class="text-center">
<view class="text-32rpx text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</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:stock-gain:update']) && item.status === 10"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-gain:update-status']) && item.status === 10"
size="small" type="success" plain @click="handleApprove(item.id!)"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-gain:update-status']) && item.status === 20"
size="small" type="warning" plain @click="handleReverseApprove(item.id!)"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-gain:delete']) && item.status === 10"
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:stock-gain: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" :style="{ paddingTop: `${getNavbarHeight()}px` }">
<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>
<view class="yd-search-form-radio-group">
<view
v-for="opt in statusOptions"
:key="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 { StockGain } from '@/api/erp/stock-gain'
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 { deleteStockGain, getStockGainPage, updateStockGainStatus } from '@/api/erp/stock-gain'
import { useAccess } from '@/hooks/useAccess'
import { getNavbarHeight, navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<StockGain[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
status: undefined,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
no: undefined as string | undefined,
status: undefined as number | undefined,
})
/** 状态标签 */
const statusTabs = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 状态选项 */
const statusOptions = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.no) conditions.push(`单号:${searchForm.no}`)
if (searchForm.status !== undefined) {
const statusLabel = statusOptions.find(o => o.value === searchForm.status)?.label
if (statusLabel && statusLabel !== '全部') conditions.push(`状态:${statusLabel}`)
}
return conditions.length > 0 ? conditions.join(' | ') : '搜索报溢单'
})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 切换状态标签 */
function onTabChange(status: number | undefined) {
queryParams.value.status = status
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 查询报溢单列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
if (searchForm.no) params.no = searchForm.no
const data = await getStockGainPage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
pageNo: 1,
pageSize: queryParams.value.pageSize,
status: searchForm.status,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.no = undefined
searchForm.status = undefined
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10, status: undefined }
list.value = []
getList()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
/** 新增报溢单 */
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/stock-gain/form/index' })
}
/** 编辑 */
function handleEdit(item: StockGain) {
uni.navigateTo({ url: `/pages-erp/stock-gain/form/index?id=${item.id}` })
}
/** 详情 */
function handleDetail(item: StockGain) {
uni.navigateTo({ url: `/pages-erp/stock-gain/detail/index?id=${item.id}` })
}
/** 审批 */
function handleApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要审批该报溢单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockGainStatus(id, 20)
toast.success('审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要反审批该报溢单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockGainStatus(id, 10)
toast.success('反审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该报溢单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockGain([id])
toast.success('删除成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 刷新列表 */
function refreshList() {
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,239 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="入库单详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 详情内容 -->
<view class="pb-180rpx">
<!-- 基本信息 -->
<wd-cell-group title="基本信息" border>
<wd-cell title="入库单号" :value="detail.no || '-'" />
<wd-cell title="入库时间" :value="formatDate(detail.inTime)" />
<wd-cell title="供应商" :value="detail.supplierName || '-'" />
<wd-cell title="审核状态">
<template #value>
<view
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
:class="detail.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ detail.status === 20 ? '已审核' : '未审核' }}
</view>
</template>
</wd-cell>
<wd-cell title="备注" :value="detail.remark || '-'" />
</wd-cell-group>
<!-- 金额信息 -->
<wd-cell-group title="金额信息" border>
<wd-cell title="合计数量" :value="formatCount(detail.totalCount)" />
<wd-cell title="合计金额" :value="formatPrice(detail.totalPrice)" />
</wd-cell-group>
<!-- 入库产品清单 -->
<wd-cell-group title="入库产品清单" border>
<view v-if="!detail.items || detail.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品数据
</view>
<view v-else>
<view
v-for="(item, index) in detail.items"
:key="index"
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
>
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
{{ item.productName || '-' }}
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">仓库</text>
<text class="text-[#666]">{{ item.warehouseName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">单位</text>
<text class="text-[#666]">{{ item.productUnitName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">数量</text>
<text class="text-[#666]">{{ formatCount(item.count) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">单价</text>
<text class="text-[#666]">{{ formatPrice(item.productPrice) }}</text>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
<view v-if="item.remark" class="mt-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">备注</text>
<text class="text-[#666]">{{ item.remark }}</text>
</view>
</view>
</view>
</wd-cell-group>
</view>
<!-- 底部操作按钮 -->
<view class="yd-detail-footer">
<wd-button
v-if="hasAccessByCodes(['erp:stock-in:update']) && detail.status !== 20"
type="primary"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-in:update-status']) && detail.status === 10"
type="success"
@click="handleApprove"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-in:update-status']) && detail.status === 20"
type="warning"
@click="handleReverseApprove"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-in:delete']) && detail.status !== 20"
type="error"
@click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { StockIn } from '@/api/erp/stock-in'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteStockIn, getStockIn, updateStockInStatus } from '@/api/erp/stock-in'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const detail = ref<StockIn>({})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(date?: string) {
if (!date) return '-'
return new Date(date).toLocaleDateString('zh-CN')
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-in/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
detail.value = await getStockIn(props.id)
} finally {
toast.close()
}
}
/** 编辑 */
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/stock-in/form/index?id=${props.id}` })
}
/** 审批 */
function handleApprove() {
uni.showModal({
title: '提示',
content: '确定要审批该入库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockInStatus(props.id, 20)
toast.success('审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove() {
uni.showModal({
title: '提示',
content: '确定要反审批该入库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockInStatus(props.id, 10)
toast.success('反审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete() {
uni.showModal({
title: '提示',
content: '确定要删除该入库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockIn([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} catch {
// error handled by http
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,421 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-cell title="入库单号" :value="formData.no || '保存时自动生成'" />
<wd-cell
title="入库时间"
title-width="180rpx"
is-link
:value="formData.inTime ? formatDate(formData.inTime) : '请选择'"
@click="datePickerVisible = true"
/>
<wd-cell
title="供应商"
title-width="180rpx"
is-link
:value="getSupplierName()"
@click="supplierPickerVisible = true"
/>
<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-if="formData.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品请点击下方按钮添加
</view>
<view v-else>
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card erp-form-item-card--padded"
>
<view class="mb-12rpx flex items-center justify-between">
<view class="text-28rpx text-[#333] font-semibold">
{{ item.productName || '请选择产品' }}
</view>
<wd-icon name="delete" size="40rpx" color="#f56c6c" @click="removeItem(index)" />
</view>
<view class="mb-12rpx">
<wd-cell
title="仓库"
title-width="120rpx"
is-link
:value="item.warehouseName || '请选择'"
@click="openWarehousePicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-cell
title="产品"
title-width="120rpx"
is-link
:value="item.productName || '请选择'"
@click="openProductPicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.count"
label="数量"
label-width="120rpx"
type="number"
placeholder="请输入数量"
@change="calcItemTotal(item)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.productPrice"
label="单价"
label-width="120rpx"
type="digit"
placeholder="请输入单价"
@change="calcItemTotal(item)"
/>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
<view class="mt-12rpx">
<wd-input
v-model="item.remark"
label="备注"
label-width="120rpx"
placeholder="请输入备注"
/>
</view>
</view>
</view>
<view class="px-24rpx pb-24rpx">
<wd-button type="primary" plain block @click="addItem">
<wd-icon name="add" class="mr-8rpx" />
添加产品
</wd-button>
</view>
</wd-cell-group>
<!-- 合计信息 -->
<wd-cell-group title="合计信息" border>
<wd-cell title="合计数量" :value="formatCount(totalCount)" />
<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-datetime-picker
v-model="datePickerVisible"
type="date"
:value="formData.inTime"
@confirm="onDateConfirm"
/>
<!-- 供应商选择器 -->
<wd-picker v-model:show="supplierPickerVisible"
:columns="supplierColumns"
@confirm="onSupplierConfirm"
/>
<!-- 仓库选择器 -->
<wd-picker v-model:show="warehousePickerVisible"
:columns="warehouseColumns"
@confirm="onWarehouseConfirm"
/>
<!-- 产品选择器 -->
<wd-picker v-model:show="productPickerVisible"
:columns="productColumns"
@confirm="onProductConfirm"
/>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { StockIn, StockInItem } from '@/api/erp/stock-in'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createStockIn, getStockIn, updateStockIn } from '@/api/erp/stock-in'
import { getSupplierSimpleList } from '@/api/erp/supplier'
import { getWarehouseSimpleList } from '@/api/erp/warehouse'
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<StockIn>({
id: undefined,
no: undefined,
supplierId: undefined,
inTime: undefined,
remark: undefined,
items: [],
})
const formRules = {
inTime: [{ required: true, message: '入库时间不能为空' }],
}
const formRef = ref<FormInstance>()
// 供应商列表
const supplierList = ref<{ id: number, name: string }[]>([])
const supplierPickerVisible = ref(false)
const supplierColumns = computed(() => [
supplierList.value.map(v => ({ value: v.id, label: v.name })),
])
// 仓库列表
const warehouseList = ref<{ id?: number, name?: string }[]>([])
const warehousePickerVisible = ref(false)
const warehouseColumns = computed(() => [
warehouseList.value.map(v => ({ value: v.id, label: v.name })),
])
// 产品列表简化实际可能需要从产品API获取
const productList = ref<{ id: number, name: string, unitName?: string }[]>([])
const productPickerVisible = ref(false)
const productColumns = computed(() => [
productList.value.map(v => ({ value: v.id, label: v.name })),
])
// 日期选择器
const datePickerVisible = ref<any>(false)
// 当前编辑的产品项索引
const currentItemIndex = ref(-1)
/** 合计数量 */
const totalCount = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.count) || 0), 0) || 0
})
/** 合计金额 */
const totalPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
})
/** 获取供应商名称 */
function getSupplierName() {
if (!formData.value.supplierId) return '请选择'
const supplier = supplierList.value.find(s => s.id === formData.value.supplierId)
return supplier?.name || '请选择'
}
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
if (typeof dateStr === 'number') {
const d = new Date(dateStr)
const pad = (n: number) => n.toString().padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
}
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-in/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getStockIn(props.id)
} finally {
toast.close()
}
}
/** 日期确认 */
function onDateConfirm({ value }: any) {
formData.value.inTime = value
datePickerVisible.value = false
}
/** 供应商确认 */
function onSupplierConfirm({ value }: any) {
formData.value.supplierId = value?.[0]
supplierPickerVisible.value = false
}
/** 打开仓库选择器 */
function openWarehousePicker(index: number) {
currentItemIndex.value = index
warehousePickerVisible.value = true
}
/** 仓库确认 */
function onWarehouseConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.warehouseId = value?.[0]
const warehouse = warehouseList.value.find(w => w.id === item.warehouseId)
item.warehouseName = warehouse?.name
}
warehousePickerVisible.value = false
}
/** 打开产品选择器 */
function openProductPicker(index: number) {
currentItemIndex.value = index
productPickerVisible.value = true
}
/** 产品确认 */
function onProductConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.productId = value?.[0]
const product = productList.value.find(p => p.id === item.productId)
item.productName = product?.name
item.productUnitName = product?.unitName
}
productPickerVisible.value = false
}
/** 添加产品项 */
function addItem() {
if (!formData.value.items) {
formData.value.items = []
}
formData.value.items.push({
warehouseId: undefined,
warehouseName: undefined,
productId: undefined,
productName: undefined,
productUnitName: undefined,
count: undefined,
productPrice: undefined,
totalPrice: 0,
remark: undefined,
})
}
/** 移除产品项 */
function removeItem(index: number) {
formData.value.items?.splice(index, 1)
}
/** 计算产品项金额 */
function calcItemTotal(item: StockInItem) {
const count = Number(item.count) || 0
const price = Number(item.productPrice) || 0
item.totalPrice = count * price
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
// 校验产品清单
if (!formData.value.items || formData.value.items.length === 0) {
toast.error('请添加入库产品')
return
}
for (const item of formData.value.items) {
if (!item.warehouseId) {
toast.error('请选择仓库')
return
}
if (!item.productId) {
toast.error('请选择产品')
return
}
if (!item.count || Number(item.count) <= 0) {
toast.error('请输入有效的数量')
return
}
}
formLoading.value = true
try {
// 设置合计
formData.value.totalCount = totalCount.value
formData.value.totalPrice = totalPrice.value
if (props.id) {
await updateStockIn(formData.value)
toast.success('修改成功')
} else {
await createStockIn(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
// 加载供应商列表
supplierList.value = await getSupplierSimpleList()
// 加载仓库列表
warehouseList.value = await getWarehouseSimpleList()
// 加载详情
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,389 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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="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="queryParams.status === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
@click="onTabChange(tab.value)"
>
{{ tab.label }}
<view
v-if="queryParams.status === 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="handleDetail(item)"
>
<view class="p-24rpx">
<!-- 头部单号 + 状态 -->
<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="item.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ item.status === 20 ? '已审核' : '未审核' }}
</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.inTime) }}</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-32rpx text-[#333] font-semibold">{{ formatCount(item.totalCount) }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">数量</view>
</view>
<view class="text-center">
<view class="text-32rpx text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</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:stock-in:update']) && item.status !== 20"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-in:update-status']) && item.status === 10"
size="small" type="success" plain @click="handleApprove(item.id!)"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-in:update-status']) && item.status === 20"
size="small" type="warning" plain @click="handleReverseApprove(item.id!)"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-in: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:stock-in: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" :style="{ paddingTop: `${getNavbarHeight()}px` }">
<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>
<view class="yd-search-form-radio-group">
<view
v-for="opt in statusOptions"
:key="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 { StockIn } from '@/api/erp/stock-in'
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 { deleteStockIn, getStockInPage, updateStockInStatus } from '@/api/erp/stock-in'
import { useAccess } from '@/hooks/useAccess'
import { getNavbarHeight, navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<StockIn[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
status: undefined,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
no: undefined as string | undefined,
status: undefined as number | undefined,
})
/** 状态标签 */
const statusTabs = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 状态选项 */
const statusOptions = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.no) conditions.push(`单号:${searchForm.no}`)
if (searchForm.status !== undefined) {
const statusLabel = statusOptions.find(o => o.value === searchForm.status)?.label
if (statusLabel && statusLabel !== '全部') conditions.push(`状态:${statusLabel}`)
}
return conditions.length > 0 ? conditions.join(' | ') : '搜索入库单'
})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(date?: string) {
if (!date) return '-'
return new Date(date).toLocaleDateString('zh-CN')
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 切换状态标签 */
function onTabChange(status: number | undefined) {
queryParams.value.status = status
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 查询入库单列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
if (searchForm.no) params.no = searchForm.no
const data = await getStockInPage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
pageNo: 1,
pageSize: queryParams.value.pageSize,
status: searchForm.status,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.no = undefined
searchForm.status = undefined
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10, status: undefined }
list.value = []
getList()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
/** 新增入库单 */
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/stock-in/form/index' })
}
/** 编辑 */
function handleEdit(item: StockIn) {
uni.navigateTo({ url: `/pages-erp/stock-in/form/index?id=${item.id}` })
}
/** 详情 */
function handleDetail(item: StockIn) {
uni.navigateTo({ url: `/pages-erp/stock-in/detail/index?id=${item.id}` })
}
/** 审批 */
function handleApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要审批该入库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockInStatus(id, 20)
toast.success('审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要反审批该入库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockInStatus(id, 10)
toast.success('反审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该入库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockIn([id])
toast.success('删除成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 刷新列表 */
function refreshList() {
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,145 @@
<template>
<view class="recent-scan-list">
<view
v-for="(record, index) in records"
:key="record.id"
class="recent-scan-list__item"
:class="{ 'recent-scan-list__item--new': index === latestIndex }"
>
<view class="recent-scan-list__info">
<view class="recent-scan-list__name">{{ record.productName }}</view>
<view class="recent-scan-list__meta">
<text>{{ record.warehouseName }}</text>
<text v-if="record.locationCode"> · {{ record.locationCode }}</text>
</view>
</view>
<view class="recent-scan-list__actions">
<view class="recent-scan-list__count">
<text class="count-btn" @tap="$emit('decrease', index)">-</text>
<text class="count-num">{{ record.scanCount }}</text>
<text class="count-btn" @tap="$emit('increase', index)">+</text>
</view>
<view class="recent-scan-list__delete" @tap="$emit('delete', index)">
<wd-icon name="delete" size="32rpx" color="#ff4d4f" />
</view>
</view>
</view>
<view v-if="records.length === 0" class="recent-scan-list__empty">
<text>暂无扫码记录</text>
</view>
</view>
</template>
<script setup lang="ts">
defineProps<{
records: {
id?: number
productName?: string
warehouseName?: string
locationCode?: string
scanCount: number
}[]
latestIndex?: number
}>()
defineEmits<{
delete: [index: number]
increase: [index: number]
decrease: [index: number]
}>()
</script>
<style lang="scss" scoped>
.recent-scan-list {
max-height: 400rpx;
overflow-y: auto;
&__item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16rpx 0;
border-bottom: 1rpx solid #f0f0f0;
&:last-child {
border-bottom: none;
}
&--new {
background: #e6f4ff;
border-radius: 8rpx;
padding: 16rpx;
margin: 8rpx 0;
border-bottom: none;
}
}
&__info {
flex: 1;
min-width: 0;
}
&__name {
font-size: 28rpx;
font-weight: 600;
color: #1f2329;
margin-bottom: 4rpx;
}
&__meta {
font-size: 22rpx;
color: #86909c;
}
&__actions {
display: flex;
align-items: center;
gap: 16rpx;
}
&__count {
display: flex;
align-items: center;
gap: 8rpx;
.count-btn {
width: 48rpx;
height: 48rpx;
line-height: 48rpx;
text-align: center;
background: #f7f8fa;
border-radius: 8rpx;
font-size: 28rpx;
font-weight: 600;
color: #1677ff;
&:active {
background: #e6f4ff;
}
}
.count-num {
min-width: 60rpx;
text-align: center;
font-size: 28rpx;
font-weight: 600;
color: #1f2329;
}
}
&__delete {
padding: 8rpx;
&:active {
opacity: 0.7;
}
}
&__empty {
padding: 40rpx;
text-align: center;
color: #86909c;
font-size: 26rpx;
}
}
</style>

View File

@@ -0,0 +1,66 @@
<template>
<view class="scan-context-bar">
<view class="scan-context-bar__item">
<text class="scan-context-bar__label">仓库</text>
<text class="scan-context-bar__value">{{ warehouseName || '未选择' }}</text>
</view>
<view class="scan-context-bar__divider" />
<view class="scan-context-bar__item">
<text class="scan-context-bar__label">已扫</text>
<text class="scan-context-bar__value scan-context-bar__value--highlight">{{ scannedCount }}</text>
</view>
<view class="scan-context-bar__divider" />
<view class="scan-context-bar__item">
<text class="scan-context-bar__label">记录</text>
<text class="scan-context-bar__value scan-context-bar__value--highlight">{{ recordCount }}</text>
</view>
</view>
</template>
<script setup lang="ts">
defineProps<{
warehouseName?: string
scannedCount: number
recordCount: number
}>()
</script>
<style lang="scss" scoped>
.scan-context-bar {
display: flex;
align-items: center;
justify-content: space-around;
padding: 20rpx 24rpx;
background: linear-gradient(135deg, #1677ff 0%, #4096ff 100%);
border-radius: 16rpx;
margin-bottom: 16rpx;
&__item {
display: flex;
flex-direction: column;
align-items: center;
gap: 4rpx;
}
&__label {
font-size: 22rpx;
color: rgba(255, 255, 255, 0.8);
}
&__value {
font-size: 28rpx;
font-weight: 600;
color: #fff;
&--highlight {
font-size: 36rpx;
}
}
&__divider {
width: 2rpx;
height: 40rpx;
background: rgba(255, 255, 255, 0.3);
}
}
</style>

View File

@@ -0,0 +1,41 @@
<template>
<view v-if="tone !== 'idle'" class="scan-feedback-bar" :class="`scan-feedback-bar--${tone}`">
<text class="scan-feedback-bar__text">{{ message }}</text>
</view>
</template>
<script setup lang="ts">
defineProps<{
tone: 'success' | 'error' | 'idle'
message: string
}>()
</script>
<style lang="scss" scoped>
.scan-feedback-bar {
padding: 16rpx 20rpx;
border-radius: 12rpx;
margin-top: 16rpx;
&--success {
background: #f6ffed;
border: 2rpx solid #b7eb8f;
.scan-feedback-bar__text {
color: #52c41a;
}
}
&--error {
background: #fff2f0;
border: 2rpx solid #ffccc7;
.scan-feedback-bar__text {
color: #ff4d4f;
}
}
&__text {
font-size: 26rpx;
font-weight: 600;
}
}
</style>

View File

@@ -0,0 +1,840 @@
<template>
<view class="yd-page-container erp-page scan-page">
<wd-navbar
title="扫码入库"
left-arrow
placeholder
safe-area-inset-top
fixed
@click-left="handleBack"
/>
<view class="scan-page__content">
<!-- 顶部上下文条 -->
<ScanContextBar
:warehouse-name="currentWarehouse?.name"
:scanned-count="scannedTotalCount"
:record-count="records.length"
/>
<!-- 扫码工作台 -->
<view class="scan-workbench">
<!-- 扫码面板 -->
<view class="scan-panel">
<!-- 步骤指示器 -->
<view class="scan-step-indicator">
<view class="scan-step-indicator__item" :class="{ 'active': step === 'idle', 'done': step !== 'idle' }">
<view class="scan-step-indicator__dot">1</view>
<text>扫仓库</text>
</view>
<view class="scan-step-indicator__line" :class="{ 'done': step !== 'idle' }" />
<view class="scan-step-indicator__item" :class="{ 'active': step === 'warehouse-scanned' }">
<view class="scan-step-indicator__dot">2</view>
<text>扫产品</text>
</view>
</view>
<!-- 当前作业提示 -->
<view class="scan-current-hint">
<text v-if="step === 'idle'">请扫描仓库条码</text>
<text v-else>产品已入库请继续扫码</text>
</view>
<!-- 仓库扫码区 -->
<view class="scan-row" :class="{ 'scan-row--dim': step !== 'idle' }">
<input
v-model="warehouseBarCode"
class="scan-field"
:class="{ 'scan-field--active': step === 'idle' }"
placeholder="扫描仓库条码"
confirm-type="next"
:focus="warehouseInputFocus"
:cursor-spacing="20"
:adjust-position="true"
:hold-keyboard="true"
@blur="handleWarehouseBlur"
@confirm="(e) => handleWarehouseScan(e.detail.value)"
>
<button class="scan-camera-btn" :disabled="scanLoading" @tap="handleCameraScan('warehouse')">
</button>
</view>
<!-- 仓库预览 -->
<view class="scan-location-preview" v-if="currentWarehouse">
<view class="scan-location-preview__row">
<text class="scan-location-preview__label">仓库</text>
<text class="scan-location-preview__value scan-location-preview__value--code">
{{ currentWarehouse.name }}
</text>
</view>
</view>
<!-- 产品扫码区 -->
<view class="scan-row" :class="{ 'scan-row--dim': step === 'idle' }">
<input
v-model="productBarCode"
class="scan-field"
:class="{ 'scan-field--active': step !== 'idle' }"
placeholder="扫描产品条码"
confirm-type="done"
:focus="productInputFocus"
:cursor-spacing="20"
:adjust-position="true"
:hold-keyboard="true"
@blur="handleProductBlur"
@confirm="(e) => handleProductScan(e.detail.value)"
>
<button class="scan-camera-btn" :disabled="scanLoading || step === 'idle'" @tap="handleCameraScan('product')">
</button>
</view>
<!-- 产品预览 -->
<view class="scan-product-preview" v-if="productPreview">
<view class="scan-product-preview__row">
<text class="scan-product-preview__label">产品</text>
<text class="scan-product-preview__value scan-product-preview__value--name">
{{ productPreview.name }}
</text>
</view>
<view class="scan-product-preview__row">
<text class="scan-product-preview__label">规格</text>
<text class="scan-product-preview__value">{{ productPreview.standard || '-' }}</text>
</view>
<view class="scan-product-preview__row">
<text class="scan-product-preview__label">条码</text>
<text class="scan-product-preview__value">{{ productPreview.barCode || '-' }}</text>
</view>
</view>
<ScanFeedbackBar :tone="feedbackTone" :message="feedbackMessage" />
</view>
<!-- 扫码记录列表 -->
<view class="scan-panel scan-panel--list">
<view class="scan-panel__header">
<view class="scan-panel__title">扫码记录</view>
<view class="scan-panel__meta"> {{ records.length }} </view>
</view>
<RecentScanList
:records="records"
:latest-index="latestRecordIndex"
@delete="handleDeleteRecord"
@increase="handleIncreaseCount"
@decrease="handleDecreaseCount"
/>
</view>
<!-- 提交栏 -->
<view class="scan-footer">
<button class="scan-footer__clear" @tap="handleClearAll">清空记录</button>
<button class="scan-footer__submit" :loading="submitting" @tap="handleSubmit">提交入库</button>
</view>
</view>
</view>
</view>
</template>
<script setup lang="ts">
import { computed, nextTick, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { getWarehouseByBarCode } from '@/api/erp/warehouse'
import { getProductByBarCode, type ProductByBarCode } from '@/api/erp/product'
import { createStockIn } from '@/api/erp/stock-in'
import ScanFeedbackBar from '@/pages-erp/stock-in/scan/components/scan-feedback-bar.vue'
import RecentScanList from '@/pages-erp/stock-in/scan/components/recent-scan-list.vue'
import ScanContextBar from '@/pages-erp/stock-in/scan/components/scan-context-bar.vue'
import { navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
/** 扫码入库记录 */
export interface ScanRecord {
id?: number
productId?: number
productName?: string
productSpec?: string
productBarCode?: string
productUnit?: string
productPrice?: number
warehouseId?: number
warehouseName?: string
scanCount: number
scanTime?: string
}
type Step = 'idle' | 'warehouse-scanned'
const toast = useToast()
// 扫码步骤
const step = ref<Step>('idle')
// 扫码数据
const warehouseBarCode = ref('')
const currentWarehouse = ref<{ id: number; name: string } | null>(null)
const productBarCode = ref('')
const productPreview = ref<ProductByBarCode | null>(null)
// 状态
const scanLoading = ref(false)
const submitting = ref(false)
const records = ref<ScanRecord[]>([])
const feedbackTone = ref<'success' | 'error' | 'idle'>('idle')
const feedbackMessage = ref('')
// 输入框焦点控制
const warehouseInputFocus = ref(false)
const productInputFocus = ref(false)
// 计算属性
const scannedTotalCount = computed(() =>
records.value.reduce((sum, r) => sum + Number(r.scanCount || 0), 0),
)
const latestRecordIndex = computed(() => {
if (records.value.length === 0) return undefined
return records.value.length - 1
})
/** 返回上一页 */
function handleBack() {
if (records.value.length > 0) {
uni.showModal({
title: '提示',
content: '确定要退出吗?未保存的数据将丢失',
success: (res) => {
if (res.confirm) {
navigateBackPlus('/pages-erp/stock-in/index')
}
},
})
} else {
navigateBackPlus('/pages-erp/stock-in/index')
}
}
/** 初始化页面 */
onMounted(async () => {
await nextTick()
setTimeout(() => {
focusWarehouseInput()
}, 300)
})
const ERROR_DISPLAY_MS = 2000
/** 聚焦仓库码输入框 */
function focusWarehouseInput() {
productInputFocus.value = false
warehouseInputFocus.value = false
nextTick(() => {
warehouseInputFocus.value = true
})
}
/** 仓库输入框失焦处理 */
function handleWarehouseBlur() {
if (step.value === 'idle' && !scanLoading.value) {
setTimeout(() => {
if (step.value === 'idle') {
focusWarehouseInput()
}
}, 100)
}
}
/** 产品输入框失焦处理 */
function handleProductBlur() {
if (step.value === 'warehouse-scanned' && !scanLoading.value) {
setTimeout(() => {
if (step.value === 'warehouse-scanned') {
focusProductInput()
}
}, 100)
}
}
/** 扫仓库码(相机扫码调用) */
async function handleWarehouseScan(rawValue?: string) {
const code = normalizeScanCode(rawValue || warehouseBarCode.value)
if (!code) {
setErrorFeedback('请先扫描仓库条码')
return
}
scanLoading.value = true
try {
try {
const warehouse = await getWarehouseByBarCode(code)
currentWarehouse.value = warehouse?.id
? {
id: warehouse.id,
name: warehouse.name || '-',
}
: null
} catch {
setErrorFeedback(`仓库码 ${code} 不存在`)
resetToIdle()
return
}
if (!currentWarehouse.value?.id) {
setErrorFeedback(`仓库码 ${code} 未找到对应仓库`)
resetToIdle()
return
}
warehouseBarCode.value = code
step.value = 'warehouse-scanned'
productBarCode.value = ''
productPreview.value = null
clearFeedback()
focusProductInput()
} finally {
scanLoading.value = false
}
}
/** 聚焦产品码输入框 */
function focusProductInput() {
warehouseInputFocus.value = false
productInputFocus.value = false
nextTick(() => {
productInputFocus.value = true
})
}
/** 扫产品码(相机扫码调用) */
async function handleProductScan(rawValue?: string) {
const code = normalizeScanCode(rawValue || productBarCode.value)
if (!code) {
setErrorFeedback('请先扫描产品条码')
return
}
if (!currentWarehouse.value) {
setErrorFeedback('请先扫描仓库条码')
step.value = 'idle'
return
}
scanLoading.value = true
try {
try {
productPreview.value = await getProductByBarCode(code)
} catch {
setErrorFeedback(`条码 ${code} 未匹配到产品`)
resetToProductScan()
return
}
if (!productPreview.value?.id) {
setErrorFeedback(`条码 ${code} 未匹配到产品`)
resetToProductScan()
return
}
productBarCode.value = code
clearFeedback()
// 自动确认入库
nextTick(() => handleConfirm())
} finally {
scanLoading.value = false
}
}
/** 确认入库 */
async function handleConfirm() {
if (!currentWarehouse.value || !productPreview.value) return
// 检查是否已存在相同记录
const existingIndex = records.value.findIndex(r =>
r.warehouseId === currentWarehouse.value!.id &&
r.productId === productPreview.value!.id
)
if (existingIndex >= 0) {
records.value[existingIndex].scanCount += 1
} else {
const record: ScanRecord = {
id: Date.now(),
productId: productPreview.value!.id,
productName: productPreview.value!.name,
productSpec: productPreview.value!.standard,
productBarCode: productPreview.value!.barCode,
productUnit: productPreview.value!.unitName,
productPrice: Number(productPreview.value!.minPrice || 0),
warehouseId: currentWarehouse.value!.id,
warehouseName: currentWarehouse.value!.name,
scanCount: 1,
scanTime: new Date().toISOString(),
}
records.value.push(record)
}
const productName = productPreview.value!.name
clearScanInputs()
setSuccessFeedback(`${productName}${currentWarehouse.value!.name} 入库成功`)
await nextTick()
focusProductInput()
}
/** 重置到初始状态 */
function resetToIdle() {
clearScanInputs()
currentWarehouse.value = null
productPreview.value = null
step.value = 'idle'
setTimeout(() => {
clearFeedback()
focusWarehouseInput()
}, ERROR_DISPLAY_MS)
}
/** 重置到产品扫码阶段 */
function resetToProductScan() {
productBarCode.value = ''
productPreview.value = null
setTimeout(() => {
clearFeedback()
focusProductInput()
}, ERROR_DISPLAY_MS)
}
/** 相机扫码 */
function handleCameraScan(target: 'warehouse' | 'product') {
if (scanLoading.value) return
// #ifdef APP-PLUS
plus.android.requestPermissions(
['android.permission.CAMERA'],
function(result) {
const granted = result.granted
if (granted && granted.length > 0) {
doScan(target)
} else {
toast.error('请在设置中开启相机权限')
uni.openSetting()
}
},
function() {
toast.error('相机权限获取失败')
},
)
// #endif
// #ifndef APP-PLUS
doScan(target)
// #endif
}
function doScan(target: 'warehouse' | 'product') {
uni.scanCode({
onlyFromCamera: true,
success: async (result) => {
const code = normalizeScanResult(result)
if (!code) return
if (target === 'warehouse') {
warehouseBarCode.value = code
await handleWarehouseScan()
} else {
productBarCode.value = code
await handleProductScan()
}
},
fail: (error) => {
if (String(error?.errMsg || '').includes('cancel')) return
toast.error('相机扫码失败,请重试')
},
})
}
/** 删除单条记录 */
function handleDeleteRecord(index: number) {
records.value.splice(index, 1)
}
/** 增加数量 */
function handleIncreaseCount(index: number) {
if (records.value[index]) {
records.value[index].scanCount += 1
}
}
/** 减少数量 */
function handleDecreaseCount(index: number) {
if (records.value[index] && records.value[index].scanCount > 1) {
records.value[index].scanCount -= 1
}
}
/** 清空所有记录 */
function handleClearAll() {
if (records.value.length === 0) return
uni.showModal({
title: '确认清空',
content: '确定要清空所有扫码记录吗?',
success: (res) => {
if (!res.confirm) return
records.value = []
clearFeedback()
},
})
}
/** 提交入库单 */
async function handleSubmit() {
if (records.value.length === 0) {
toast.warning('暂无扫码记录')
return
}
submitting.value = true
try {
const items = records.value.map(r => ({
warehouseId: r.warehouseId,
productId: r.productId,
productPrice: r.productPrice,
count: r.scanCount,
supplierId: 1,
}))
await createStockIn({
inTime: new Date().toISOString(),
items,
})
toast.success(`已提交 ${records.value.length} 条入库记录`)
records.value = []
clearFeedback()
resetToIdle()
} finally {
submitting.value = false
}
}
/** 清空本次扫码输入 */
function clearScanInputs() {
warehouseBarCode.value = ''
productBarCode.value = ''
productPreview.value = null
}
function setSuccessFeedback(message: string) {
feedbackTone.value = 'success'
feedbackMessage.value = message
}
function setErrorFeedback(message: string) {
feedbackTone.value = 'error'
feedbackMessage.value = message
}
function clearFeedback() {
feedbackTone.value = 'idle'
feedbackMessage.value = ''
}
/** 规范化扫码结果 */
function normalizeScanCode(value: string): string {
if (!value) return ''
let result = value.trim()
const prefixes = ['CODE128:', 'CODE39:', 'EAN13:', 'QR:', 'DATA:', 'MECARD:', 'VCARD:']
for (const prefix of prefixes) {
if (result.startsWith(prefix)) {
result = result.substring(prefix.length)
break
}
}
return result
}
/** 规范化相机扫码结果 */
function normalizeScanResult(result: UniApp.ScanCodeSuccessRes): string {
if (!result) return ''
const value = result.result || (result as UniApp.ScanCodeSuccessRes & { code?: string }).code || ''
return normalizeScanCode(value)
}
</script>
<style lang="scss" scoped>
.scan-page {
background: #f4f6f8;
min-height: 100vh;
&__content {
padding: 24rpx;
padding-top: calc(24rpx + env(safe-area-inset-top) + 88rpx);
box-sizing: border-box;
}
}
.scan-workbench {
display: flex;
flex-direction: column;
gap: 16rpx;
}
.scan-panel {
padding: 24rpx;
border-radius: 18rpx;
background: #fff;
&--list {
padding-bottom: 8rpx;
}
&__header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
margin-bottom: 16rpx;
}
&__title {
color: #1f2329;
font-size: 28rpx;
font-weight: 600;
}
&__meta {
color: #86909c;
font-size: 22rpx;
}
}
// 步骤指示器
.scan-step-indicator {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 24rpx;
&__item {
display: flex;
flex-direction: column;
align-items: center;
gap: 8rpx;
text {
font-size: 22rpx;
color: #86909c;
}
&.active text {
color: #1677ff;
font-weight: 600;
}
&.done text {
color: #52c41a;
}
}
&__dot {
width: 48rpx;
height: 48rpx;
line-height: 48rpx;
border-radius: 50%;
background: #f2f3f5;
color: #86909c;
font-size: 24rpx;
font-weight: 600;
text-align: center;
}
&__item.active &__dot {
background: #1677ff;
color: #fff;
}
&__item.done &__dot {
background: #52c41a;
color: #fff;
}
&__line {
flex: 1;
height: 2rpx;
background: #e5e6eb;
margin: 0 12rpx;
margin-bottom: 28rpx;
max-width: 80rpx;
&.done {
background: #52c41a;
}
}
}
// 当前作业提示
.scan-current-hint {
text-align: center;
font-size: 30rpx;
font-weight: 600;
color: #1f2329;
margin-bottom: 20rpx;
}
// 输入行
.scan-row {
display: flex;
align-items: center;
gap: 12rpx;
margin-bottom: 16rpx;
transition: opacity 0.2s;
&--dim {
opacity: 0.4;
pointer-events: none;
}
}
.scan-field {
flex: 1;
height: 88rpx;
padding: 0 24rpx;
line-height: 88rpx;
border: 2rpx solid #e5e6eb;
border-radius: 14rpx;
background: #f7f8fa;
color: #1f2329;
box-sizing: border-box;
font-size: 28rpx;
&--active {
border-color: #1677ff;
background: #fff;
box-shadow: 0 0 0 4rpx rgba(22, 119, 255, 0.1);
}
}
.scan-camera-btn {
width: 88rpx;
height: 88rpx;
line-height: 88rpx;
border-radius: 14rpx;
background: #1677ff;
color: #fff;
font-size: 26rpx;
font-weight: 600;
padding: 0;
border: none;
flex-shrink: 0;
&:active { opacity: 0.85; }
&[disabled] { background: #d9d9d9; }
}
// 仓库预览
.scan-location-preview {
margin-bottom: 16rpx;
padding: 20rpx;
border-radius: 14rpx;
background: #f6fff0;
border: 2rpx solid #b7eb8f;
&__row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6rpx 0;
}
&__label {
color: #4e5969;
font-size: 24rpx;
flex-shrink: 0;
}
&__value {
color: #1f2329;
font-size: 24rpx;
font-weight: 600;
margin-right: 12rpx;
&--code {
color: #52c41a;
font-size: 28rpx;
font-weight: 700;
}
}
}
// 产品预览
.scan-product-preview {
margin-bottom: 16rpx;
padding: 20rpx;
border-radius: 14rpx;
background: #f0f5ff;
border: 2rpx solid #adc6ff;
&__row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6rpx 0;
}
&__label {
color: #4e5969;
font-size: 24rpx;
flex-shrink: 0;
}
&__value {
color: #1f2329;
font-size: 24rpx;
text-align: right;
&--name {
font-size: 28rpx;
font-weight: 600;
}
}
}
// 底部栏
.scan-footer {
position: sticky;
bottom: 0;
display: flex;
gap: 16rpx;
padding: 20rpx 0 calc(20rpx + env(safe-area-inset-bottom));
background: #f4f6f8;
&__clear {
flex: 1;
height: 88rpx;
line-height: 88rpx;
border-radius: 16rpx;
background: #fff;
color: #4e5969;
font-size: 28rpx;
border: 2rpx solid #e5e6eb;
}
&__submit {
flex: 2;
height: 88rpx;
line-height: 88rpx;
border-radius: 16rpx;
background: #1677ff;
color: #fff;
font-size: 28rpx;
font-weight: 600;
}
}
</style>

View File

@@ -0,0 +1,226 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="报损单详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 详情内容 -->
<view class="pb-180rpx">
<!-- 基本信息 -->
<wd-cell-group title="基本信息" border>
<wd-cell title="报损单号" :value="detail.no || '-'" />
<wd-cell title="报损时间" :value="formatDate(detail.lossTime)" />
<wd-cell title="报损原因" :value="detail.reason || '-'" />
<wd-cell title="审核状态">
<template #value>
<view
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
:class="detail.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ detail.status === 20 ? '已审核' : '未审核' }}
</view>
</template>
</wd-cell>
<wd-cell title="备注" :value="detail.remark || '-'" />
</wd-cell-group>
<!-- 金额信息 -->
<wd-cell-group title="金额信息" border>
<wd-cell title="合计数量" :value="formatCount(detail.totalCount)" />
<wd-cell title="合计金额" :value="formatPrice(detail.totalPrice)" />
</wd-cell-group>
<!-- 报损产品清单 -->
<wd-cell-group title="报损产品清单" border>
<view v-if="!detail.items || detail.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品数据
</view>
<view v-else>
<view
v-for="(item, index) in detail.items"
:key="index"
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
>
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
{{ item.productName || '-' }}
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">仓库</text>
<text class="text-[#666]">{{ item.warehouseName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">数量</text>
<text class="text-[#f5222d] font-semibold">-{{ formatCount(item.count) }}</text>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#f5222d] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
</view>
</wd-cell-group>
</view>
<!-- 底部操作按钮 -->
<view class="yd-detail-footer">
<wd-button
v-if="hasAccessByCodes(['erp:stock-loss:update']) && detail.status === 10"
type="primary"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-loss:update-status']) && detail.status === 10"
type="success"
@click="handleApprove"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-loss:update-status']) && detail.status === 20"
type="warning"
@click="handleReverseApprove"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-loss:delete']) && detail.status === 10"
type="error"
@click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { StockLoss } from '@/api/erp/stock-loss'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteStockLoss, getStockLoss, updateStockLossStatus } from '@/api/erp/stock-loss'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const detail = ref<StockLoss>({})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-loss/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
detail.value = await getStockLoss(props.id)
} finally {
toast.close()
}
}
/** 编辑 */
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/stock-loss/form/index?id=${props.id}` })
}
/** 审批 */
function handleApprove() {
uni.showModal({
title: '提示',
content: '确定要审批该报损单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockLossStatus(props.id, 20)
toast.success('审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove() {
uni.showModal({
title: '提示',
content: '确定要反审批该报损单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockLossStatus(props.id, 10)
toast.success('反审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete() {
uni.showModal({
title: '提示',
content: '确定要删除该报损单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockLoss([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} catch {
// error handled by http
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,383 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-cell title="报损单号" :value="formData.no || '保存时自动生成'" />
<wd-cell
title="报损时间"
title-width="180rpx"
is-link
:value="formData.lossTime ? formatDate(formData.lossTime) : '请选择'"
@click="datePickerVisible = true"
/>
<wd-input
v-model="formData.reason"
label="报损原因"
label-width="180rpx"
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-if="formData.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品请点击下方按钮添加
</view>
<view v-else>
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card erp-form-item-card--padded"
>
<view class="mb-12rpx flex items-center justify-between">
<view class="text-28rpx text-[#333] font-semibold">
{{ item.productName || '请选择产品' }}
</view>
<wd-icon name="delete" size="40rpx" color="#f56c6c" @click="removeItem(index)" />
</view>
<view class="mb-12rpx">
<wd-cell
title="仓库"
title-width="120rpx"
is-link
:value="item.warehouseName || '请选择'"
@click="openWarehousePicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-cell
title="产品"
title-width="120rpx"
is-link
:value="item.productName || '请选择'"
@click="openProductPicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.count"
label="数量"
label-width="120rpx"
type="number"
placeholder="请输入数量"
@change="calcItemTotal(item)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.productPrice"
label="单价"
label-width="120rpx"
type="digit"
placeholder="请输入单价"
@change="calcItemTotal(item)"
/>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#f5222d] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
</view>
<view class="px-24rpx pb-24rpx">
<wd-button type="primary" plain block @click="addItem">
<wd-icon name="add" class="mr-8rpx" />
添加产品
</wd-button>
</view>
</wd-cell-group>
<!-- 合计信息 -->
<wd-cell-group title="合计信息" border>
<wd-cell title="合计数量" :value="formatCount(totalCount)" />
<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-datetime-picker
v-model="datePickerVisible"
type="date"
:value="formData.lossTime"
@confirm="onDateConfirm"
/>
<!-- 仓库选择器 -->
<wd-picker v-model:show="warehousePickerVisible"
:columns="warehouseColumns"
@confirm="onWarehouseConfirm"
/>
<!-- 产品选择器 -->
<wd-picker v-model:show="productPickerVisible"
:columns="productColumns"
@confirm="onProductConfirm"
/>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { StockLoss, StockLossItem } from '@/api/erp/stock-loss'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createStockLoss, getStockLoss, updateStockLoss } from '@/api/erp/stock-loss'
import { getWarehouseSimpleList } from '@/api/erp/warehouse'
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<StockLoss>({
id: undefined,
no: undefined,
lossTime: undefined,
reason: undefined,
remark: undefined,
items: [],
})
const formRules = {
lossTime: [{ required: true, message: '报损时间不能为空' }],
}
const formRef = ref<FormInstance>()
// 仓库列表
const warehouseList = ref<{ id?: number, name?: string }[]>([])
const warehousePickerVisible = ref(false)
const warehouseColumns = computed(() => [
warehouseList.value.map(v => ({ value: v.id, label: v.name })),
])
// 产品列表
const productList = ref<{ id: number, name: string, unitName?: string }[]>([])
const productPickerVisible = ref(false)
const productColumns = computed(() => [
productList.value.map(v => ({ value: v.id, label: v.name })),
])
// 日期选择器
const datePickerVisible = ref<any>(false)
// 当前编辑的产品项索引
const currentItemIndex = ref(-1)
/** 合计数量 */
const totalCount = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.count) || 0), 0) || 0
})
/** 合计金额 */
const totalPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
if (typeof dateStr === 'number') {
const d = new Date(dateStr)
const pad = (n: number) => n.toString().padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
}
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-loss/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getStockLoss(props.id)
} finally {
toast.close()
}
}
/** 日期确认 */
function onDateConfirm({ value }: any) {
formData.value.lossTime = value
datePickerVisible.value = false
}
/** 打开仓库选择器 */
function openWarehousePicker(index: number) {
currentItemIndex.value = index
warehousePickerVisible.value = true
}
/** 仓库确认 */
function onWarehouseConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.warehouseId = value?.[0]
const warehouse = warehouseList.value.find(w => w.id === item.warehouseId)
item.warehouseName = warehouse?.name
}
warehousePickerVisible.value = false
}
/** 打开产品选择器 */
function openProductPicker(index: number) {
currentItemIndex.value = index
productPickerVisible.value = true
}
/** 产品确认 */
function onProductConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.productId = value?.[0]
const product = productList.value.find(p => p.id === item.productId)
item.productName = product?.name
item.productUnitName = product?.unitName
}
productPickerVisible.value = false
}
/** 添加产品项 */
function addItem() {
if (!formData.value.items) {
formData.value.items = []
}
formData.value.items.push({
warehouseId: undefined,
warehouseName: undefined,
productId: undefined,
productName: undefined,
productUnitName: undefined,
count: undefined,
productPrice: undefined,
totalPrice: 0,
})
}
/** 移除产品项 */
function removeItem(index: number) {
formData.value.items?.splice(index, 1)
}
/** 计算产品项金额 */
function calcItemTotal(item: StockLossItem) {
const count = Number(item.count) || 0
const price = Number(item.productPrice) || 0
item.totalPrice = count * price
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
// 校验产品清单
if (!formData.value.items || formData.value.items.length === 0) {
toast.error('请添加报损产品')
return
}
for (const item of formData.value.items) {
if (!item.warehouseId) {
toast.error('请选择仓库')
return
}
if (!item.productId) {
toast.error('请选择产品')
return
}
if (!item.count || Number(item.count) <= 0) {
toast.error('请输入有效的数量')
return
}
}
formLoading.value = true
try {
// 设置合计
formData.value.totalCount = totalCount.value
formData.value.totalPrice = totalPrice.value
if (props.id) {
await updateStockLoss(formData.value)
toast.success('修改成功')
} else {
await createStockLoss(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
// 加载仓库列表
warehouseList.value = await getWarehouseSimpleList()
// 加载详情
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,388 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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="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="queryParams.status === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
@click="onTabChange(tab.value)"
>
{{ tab.label }}
<view
v-if="queryParams.status === 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="handleDetail(item)"
>
<view class="p-24rpx">
<!-- 头部单号 + 状态 -->
<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="item.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ item.status === 20 ? '已审核' : '未审核' }}
</view>
</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.lossTime) }}</text>
</view>
<!-- 报损原因 -->
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
<text class="text-[#999]">报损原因</text>
<text>{{ item.reason || '-' }}</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-32rpx text-[#f5222d] font-semibold">{{ formatCount(item.totalCount) }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">数量</view>
</view>
<view class="text-center">
<view class="text-32rpx text-[#f5222d] font-semibold">{{ formatPrice(item.totalPrice) }}</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:stock-loss:update']) && item.status === 10"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-loss:update-status']) && item.status === 10"
size="small" type="success" plain @click="handleApprove(item.id!)"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-loss:update-status']) && item.status === 20"
size="small" type="warning" plain @click="handleReverseApprove(item.id!)"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-loss:delete']) && item.status === 10"
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:stock-loss: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" :style="{ paddingTop: `${getNavbarHeight()}px` }">
<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>
<view class="yd-search-form-radio-group">
<view
v-for="opt in statusOptions"
:key="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 { StockLoss } from '@/api/erp/stock-loss'
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 { deleteStockLoss, getStockLossPage, updateStockLossStatus } from '@/api/erp/stock-loss'
import { useAccess } from '@/hooks/useAccess'
import { getNavbarHeight, navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<StockLoss[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
status: undefined,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
no: undefined as string | undefined,
status: undefined as number | undefined,
})
/** 状态标签 */
const statusTabs = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 状态选项 */
const statusOptions = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.no) conditions.push(`单号:${searchForm.no}`)
if (searchForm.status !== undefined) {
const statusLabel = statusOptions.find(o => o.value === searchForm.status)?.label
if (statusLabel && statusLabel !== '全部') conditions.push(`状态:${statusLabel}`)
}
return conditions.length > 0 ? conditions.join(' | ') : '搜索报损单'
})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 切换状态标签 */
function onTabChange(status: number | undefined) {
queryParams.value.status = status
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 查询报损单列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
if (searchForm.no) params.no = searchForm.no
const data = await getStockLossPage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
pageNo: 1,
pageSize: queryParams.value.pageSize,
status: searchForm.status,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.no = undefined
searchForm.status = undefined
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10, status: undefined }
list.value = []
getList()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
/** 新增报损单 */
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/stock-loss/form/index' })
}
/** 编辑 */
function handleEdit(item: StockLoss) {
uni.navigateTo({ url: `/pages-erp/stock-loss/form/index?id=${item.id}` })
}
/** 详情 */
function handleDetail(item: StockLoss) {
uni.navigateTo({ url: `/pages-erp/stock-loss/detail/index?id=${item.id}` })
}
/** 审批 */
function handleApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要审批该报损单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockLossStatus(id, 20)
toast.success('审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要反审批该报损单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockLossStatus(id, 10)
toast.success('反审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该报损单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockLoss([id])
toast.success('删除成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 刷新列表 */
function refreshList() {
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,229 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="调拨单详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 详情内容 -->
<view class="pb-180rpx">
<!-- 基本信息 -->
<wd-cell-group title="基本信息" border>
<wd-cell title="调拨单号" :value="detail.no || '-'" />
<wd-cell title="调拨时间" :value="formatDate(detail.moveTime)" />
<wd-cell title="审核状态">
<template #value>
<view
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
:class="detail.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ detail.status === 20 ? '已审核' : '未审核' }}
</view>
</template>
</wd-cell>
<wd-cell title="备注" :value="detail.remark || '-'" />
</wd-cell-group>
<!-- 金额信息 -->
<wd-cell-group title="金额信息" border>
<wd-cell title="调拨数量" :value="formatCount(detail.totalCount)" />
<wd-cell title="调拨金额" :value="formatPrice(detail.totalPrice)" />
</wd-cell-group>
<!-- 调拨产品清单 -->
<wd-cell-group title="调拨产品清单" border>
<view v-if="!detail.items || detail.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品数据
</view>
<view v-else>
<view
v-for="(item, index) in detail.items"
:key="index"
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
>
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
{{ item.productName || '-' }}
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">调出仓库</text>
<text class="text-[#f5222d]">{{ item.fromWarehouseName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">调入仓库</text>
<text class="text-[#52c41a]">{{ item.toWarehouseName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">数量</text>
<text class="text-[#666]">{{ formatCount(item.count) }}</text>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
</view>
</wd-cell-group>
</view>
<!-- 底部操作按钮 -->
<view class="yd-detail-footer">
<wd-button
v-if="hasAccessByCodes(['erp:stock-move:update']) && detail.status === 10"
type="primary"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-move:update-status']) && detail.status === 10"
type="success"
@click="handleApprove"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-move:update-status']) && detail.status === 20"
type="warning"
@click="handleReverseApprove"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-move:delete']) && detail.status === 10"
type="error"
@click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { StockMove } from '@/api/erp/stock-move'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteStockMove, getStockMove, updateStockMoveStatus } from '@/api/erp/stock-move'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const detail = ref<StockMove>({})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-move/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
detail.value = await getStockMove(props.id)
} finally {
toast.close()
}
}
/** 编辑 */
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/stock-move/form/index?id=${props.id}` })
}
/** 审批 */
function handleApprove() {
uni.showModal({
title: '提示',
content: '确定要审批该调拨单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockMoveStatus(props.id, 20)
toast.success('审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove() {
uni.showModal({
title: '提示',
content: '确定要反审批该调拨单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockMoveStatus(props.id, 10)
toast.success('反审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete() {
uni.showModal({
title: '提示',
content: '确定要删除该调拨单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockMove([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} catch {
// error handled by http
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,418 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-cell title="调拨单号" :value="formData.no || '保存时自动生成'" />
<wd-cell
title="调拨时间"
title-width="180rpx"
is-link
:value="formData.moveTime ? formatDate(formData.moveTime) : '请选择'"
@click="datePickerVisible = true"
/>
<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-if="formData.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品请点击下方按钮添加
</view>
<view v-else>
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card erp-form-item-card--padded"
>
<view class="mb-12rpx flex items-center justify-between">
<view class="text-28rpx text-[#333] font-semibold">
{{ item.productName || '请选择产品' }}
</view>
<wd-icon name="delete" size="40rpx" color="#f56c6c" @click="removeItem(index)" />
</view>
<view class="mb-12rpx">
<wd-cell
title="调出仓库"
title-width="140rpx"
is-link
:value="item.fromWarehouseName || '请选择'"
@click="openFromWarehousePicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-cell
title="调入仓库"
title-width="140rpx"
is-link
:value="item.toWarehouseName || '请选择'"
@click="openToWarehousePicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-cell
title="产品"
title-width="140rpx"
is-link
:value="item.productName || '请选择'"
@click="openProductPicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.count"
label="数量"
label-width="140rpx"
type="number"
placeholder="请输入数量"
@change="calcItemTotal(item)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.productPrice"
label="单价"
label-width="140rpx"
type="digit"
placeholder="请输入单价"
@change="calcItemTotal(item)"
/>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
</view>
</view>
<view class="px-24rpx pb-24rpx">
<wd-button type="primary" plain block @click="addItem">
<wd-icon name="add" class="mr-8rpx" />
添加产品
</wd-button>
</view>
</wd-cell-group>
<!-- 合计信息 -->
<wd-cell-group title="合计信息" border>
<wd-cell title="调拨数量" :value="formatCount(totalCount)" />
<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-datetime-picker
v-model="datePickerVisible"
type="date"
:value="formData.moveTime"
@confirm="onDateConfirm"
/>
<!-- 调出仓库选择器 -->
<wd-picker v-model:show="fromWarehousePickerVisible"
:columns="warehouseColumns"
@confirm="onFromWarehouseConfirm"
/>
<!-- 调入仓库选择器 -->
<wd-picker v-model:show="toWarehousePickerVisible"
:columns="warehouseColumns"
@confirm="onToWarehouseConfirm"
/>
<!-- 产品选择器 -->
<wd-picker v-model:show="productPickerVisible"
:columns="productColumns"
@confirm="onProductConfirm"
/>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { StockMove, StockMoveItem } from '@/api/erp/stock-move'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createStockMove, getStockMove, updateStockMove } from '@/api/erp/stock-move'
import { getWarehouseSimpleList } from '@/api/erp/warehouse'
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<StockMove>({
id: undefined,
no: undefined,
moveTime: undefined,
remark: undefined,
items: [],
})
const formRules = {
moveTime: [{ required: true, message: '调拨时间不能为空' }],
}
const formRef = ref<FormInstance>()
// 仓库列表
const warehouseList = ref<{ id?: number, name?: string }[]>([])
const fromWarehousePickerVisible = ref(false)
const toWarehousePickerVisible = ref(false)
const warehouseColumns = computed(() => [
warehouseList.value.map(v => ({ value: v.id, label: v.name })),
])
// 产品列表
const productList = ref<{ id: number, name: string, unitName?: string }[]>([])
const productPickerVisible = ref(false)
const productColumns = computed(() => [
productList.value.map(v => ({ value: v.id, label: v.name })),
])
// 日期选择器
const datePickerVisible = ref<any>(false)
// 当前编辑的产品项索引
const currentItemIndex = ref(-1)
/** 合计数量 */
const totalCount = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.count) || 0), 0) || 0
})
/** 合计金额 */
const totalPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
if (typeof dateStr === 'number') {
const d = new Date(dateStr)
const pad = (n: number) => n.toString().padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
}
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-move/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getStockMove(props.id)
} finally {
toast.close()
}
}
/** 日期确认 */
function onDateConfirm({ value }: any) {
formData.value.moveTime = value
datePickerVisible.value = false
}
/** 打开调出仓库选择器 */
function openFromWarehousePicker(index: number) {
currentItemIndex.value = index
fromWarehousePickerVisible.value = true
}
/** 调出仓库确认 */
function onFromWarehouseConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.fromWarehouseId = value?.[0]
const warehouse = warehouseList.value.find(w => w.id === item.fromWarehouseId)
item.fromWarehouseName = warehouse?.name
}
fromWarehousePickerVisible.value = false
}
/** 打开调入仓库选择器 */
function openToWarehousePicker(index: number) {
currentItemIndex.value = index
toWarehousePickerVisible.value = true
}
/** 调入仓库确认 */
function onToWarehouseConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.toWarehouseId = value?.[0]
const warehouse = warehouseList.value.find(w => w.id === item.toWarehouseId)
item.toWarehouseName = warehouse?.name
}
toWarehousePickerVisible.value = false
}
/** 打开产品选择器 */
function openProductPicker(index: number) {
currentItemIndex.value = index
productPickerVisible.value = true
}
/** 产品确认 */
function onProductConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.productId = value?.[0]
const product = productList.value.find(p => p.id === item.productId)
item.productName = product?.name
item.productUnitName = product?.unitName
}
productPickerVisible.value = false
}
/** 添加产品项 */
function addItem() {
if (!formData.value.items) {
formData.value.items = []
}
formData.value.items.push({
fromWarehouseId: undefined,
fromWarehouseName: undefined,
toWarehouseId: undefined,
toWarehouseName: undefined,
productId: undefined,
productName: undefined,
productUnitName: undefined,
count: undefined,
productPrice: undefined,
totalPrice: 0,
})
}
/** 移除产品项 */
function removeItem(index: number) {
formData.value.items?.splice(index, 1)
}
/** 计算产品项金额 */
function calcItemTotal(item: StockMoveItem) {
const count = Number(item.count) || 0
const price = Number(item.productPrice) || 0
item.totalPrice = count * price
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
// 校验产品清单
if (!formData.value.items || formData.value.items.length === 0) {
toast.error('请添加调拨产品')
return
}
for (const item of formData.value.items) {
if (!item.fromWarehouseId) {
toast.error('请选择调出仓库')
return
}
if (!item.toWarehouseId) {
toast.error('请选择调入仓库')
return
}
if (item.fromWarehouseId === item.toWarehouseId) {
toast.error('调出仓库和调入仓库不能相同')
return
}
if (!item.productId) {
toast.error('请选择产品')
return
}
if (!item.count || Number(item.count) <= 0) {
toast.error('请输入有效的数量')
return
}
}
formLoading.value = true
try {
// 设置合计
formData.value.totalCount = totalCount.value
formData.value.totalPrice = totalPrice.value
if (props.id) {
await updateStockMove(formData.value)
toast.success('修改成功')
} else {
await createStockMove(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
// 加载仓库列表
warehouseList.value = await getWarehouseSimpleList()
// 加载详情
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,383 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<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="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="queryParams.status === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
@click="onTabChange(tab.value)"
>
{{ tab.label }}
<view
v-if="queryParams.status === 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="handleDetail(item)"
>
<view class="p-24rpx">
<!-- 头部单号 + 状态 -->
<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="item.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ item.status === 20 ? '已审核' : '未审核' }}
</view>
</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.moveTime) }}</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-32rpx text-[#333] font-semibold">{{ formatCount(item.totalCount) }}</view>
<view class="text-22rpx text-[#999] mt-4rpx">调拨数量</view>
</view>
<view class="text-center">
<view class="text-32rpx text-[#1890ff] font-semibold">{{ formatPrice(item.totalPrice) }}</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:stock-move:update']) && item.status === 10"
size="small" type="primary" plain @click="handleEdit(item)"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-move:update-status']) && item.status === 10"
size="small" type="success" plain @click="handleApprove(item.id!)"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-move:update-status']) && item.status === 20"
size="small" type="warning" plain @click="handleReverseApprove(item.id!)"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-move:delete']) && item.status === 10"
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:stock-move: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" :style="{ paddingTop: `${getNavbarHeight()}px` }">
<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>
<view class="yd-search-form-radio-group">
<view
v-for="opt in statusOptions"
:key="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 { StockMove } from '@/api/erp/stock-move'
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 { deleteStockMove, getStockMovePage, updateStockMoveStatus } from '@/api/erp/stock-move'
import { useAccess } from '@/hooks/useAccess'
import { getNavbarHeight, navigateBackPlus } from '@/utils'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const total = ref(0)
const list = ref<StockMove[]>([])
const loadMoreState = ref<LoadMoreState>('loading')
const queryParams = ref<{ pageNo: number; pageSize: number } & Record<string, any>>({
pageNo: 1,
pageSize: 10,
status: undefined,
})
// 搜索相关
const searchVisible = ref(false)
const searchForm = reactive({
no: undefined as string | undefined,
status: undefined as number | undefined,
})
/** 状态标签 */
const statusTabs = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 状态选项 */
const statusOptions = [
{ value: undefined, label: '全部' },
{ value: 10, label: '未审核' },
{ value: 20, label: '已审核' },
]
/** 搜索条件 placeholder */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (searchForm.no) conditions.push(`单号:${searchForm.no}`)
if (searchForm.status !== undefined) {
const statusLabel = statusOptions.find(o => o.value === searchForm.status)?.label
if (statusLabel && statusLabel !== '全部') conditions.push(`状态:${statusLabel}`)
}
return conditions.length > 0 ? conditions.join(' | ') : '搜索调拨单'
})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 切换状态标签 */
function onTabChange(status: number | undefined) {
queryParams.value.status = status
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 查询调拨单列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const params = { ...queryParams.value }
if (searchForm.no) params.no = searchForm.no
const data = await getStockMovePage(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 handleSearch() {
searchVisible.value = false
queryParams.value = {
pageNo: 1,
pageSize: queryParams.value.pageSize,
status: searchForm.status,
}
list.value = []
getList()
}
/** 重置 */
function handleReset() {
searchForm.no = undefined
searchForm.status = undefined
searchVisible.value = false
queryParams.value = { pageNo: 1, pageSize: 10, status: undefined }
list.value = []
getList()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') return
queryParams.value.pageNo++
getList()
}
/** 新增调拨单 */
function handleAdd() {
uni.navigateTo({ url: '/pages-erp/stock-move/form/index' })
}
/** 编辑 */
function handleEdit(item: StockMove) {
uni.navigateTo({ url: `/pages-erp/stock-move/form/index?id=${item.id}` })
}
/** 详情 */
function handleDetail(item: StockMove) {
uni.navigateTo({ url: `/pages-erp/stock-move/detail/index?id=${item.id}` })
}
/** 审批 */
function handleApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要审批该调拨单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockMoveStatus(id, 20)
toast.success('审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove(id: number) {
uni.showModal({
title: '提示',
content: '确定要反审批该调拨单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockMoveStatus(id, 10)
toast.success('反审批成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete(id: number) {
uni.showModal({
title: '提示',
content: '确定要删除该调拨单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockMove([id])
toast.success('删除成功')
refreshList()
} catch {
// error handled by http
}
},
})
}
/** 刷新列表 */
function refreshList() {
list.value = []
queryParams.value.pageNo = 1
getList()
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,239 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
title="出库单详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 详情内容 -->
<view class="pb-180rpx">
<!-- 基本信息 -->
<wd-cell-group title="基本信息" border>
<wd-cell title="出库单号" :value="detail.no || '-'" />
<wd-cell title="出库时间" :value="formatDate(detail.outTime)" />
<wd-cell title="客户" :value="detail.customerName || '-'" />
<wd-cell title="审核状态">
<template #value>
<view
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
:class="detail.status === 20 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff7e6] text-[#fa8c16]'"
>
{{ detail.status === 20 ? '已审核' : '未审核' }}
</view>
</template>
</wd-cell>
<wd-cell title="备注" :value="detail.remark || '-'" />
</wd-cell-group>
<!-- 金额信息 -->
<wd-cell-group title="金额信息" border>
<wd-cell title="合计数量" :value="formatCount(detail.totalCount)" />
<wd-cell title="合计金额" :value="formatPrice(detail.totalPrice)" />
</wd-cell-group>
<!-- 出库产品清单 -->
<wd-cell-group title="出库产品清单" border>
<view v-if="!detail.items || detail.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品数据
</view>
<view v-else>
<view
v-for="(item, index) in detail.items"
:key="index"
class="mx-24rpx mb-20rpx rounded-12rpx bg-[#f9f9f9] p-24rpx"
>
<view class="mb-12rpx text-28rpx text-[#333] font-semibold">
{{ item.productName || '-' }}
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">仓库</text>
<text class="text-[#666]">{{ item.warehouseName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">单位</text>
<text class="text-[#666]">{{ item.productUnitName || '-' }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">数量</text>
<text class="text-[#666]">{{ formatCount(item.count) }}</text>
</view>
<view class="mb-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">单价</text>
<text class="text-[#666]">{{ formatPrice(item.productPrice) }}</text>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#f5222d] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
<view v-if="item.remark" class="mt-8rpx flex items-center justify-between text-26rpx">
<text class="text-[#999]">备注</text>
<text class="text-[#666]">{{ item.remark }}</text>
</view>
</view>
</view>
</wd-cell-group>
</view>
<!-- 底部操作按钮 -->
<view class="yd-detail-footer">
<wd-button
v-if="hasAccessByCodes(['erp:stock-out:update']) && detail.status !== 20"
type="primary"
@click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-out:update-status']) && detail.status === 10"
type="success"
@click="handleApprove"
>
审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-out:update-status']) && detail.status === 20"
type="warning"
@click="handleReverseApprove"
>
反审批
</wd-button>
<wd-button
v-if="hasAccessByCodes(['erp:stock-out:delete']) && detail.status !== 20"
type="error"
@click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { StockOut } from '@/api/erp/stock-out'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteStockOut, getStockOut, updateStockOutStatus } from '@/api/erp/stock-out'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
const props = defineProps<{
id: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const detail = ref<StockOut>({})
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(date?: string) {
if (!date) return '-'
return new Date(date).toLocaleDateString('zh-CN')
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-out/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
detail.value = await getStockOut(props.id)
} finally {
toast.close()
}
}
/** 编辑 */
function handleEdit() {
uni.navigateTo({ url: `/pages-erp/stock-out/form/index?id=${props.id}` })
}
/** 审批 */
function handleApprove() {
uni.showModal({
title: '提示',
content: '确定要审批该出库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockOutStatus(props.id, 20)
toast.success('审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 反审批 */
function handleReverseApprove() {
uni.showModal({
title: '提示',
content: '确定要反审批该出库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await updateStockOutStatus(props.id, 10)
toast.success('反审批成功')
getDetail()
} catch {
// error handled by http
}
},
})
}
/** 删除 */
function handleDelete() {
uni.showModal({
title: '提示',
content: '确定要删除该出库单吗?',
success: async (res) => {
if (!res.confirm) return
try {
await deleteStockOut([props.id])
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} catch {
// error handled by http
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,418 @@
<template>
<view class="yd-page-container erp-page">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view class="erp-form-body">
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group title="基本信息" border>
<wd-cell title="出库单号" :value="formData.no || '保存时自动生成'" />
<wd-cell
title="出库时间"
title-width="180rpx"
is-link
:value="formData.outTime ? formatDate(formData.outTime) : '请选择'"
@click="datePickerVisible = true"
/>
<wd-cell
title="客户"
title-width="180rpx"
is-link
:value="getCustomerName()"
@click="customerPickerVisible = true"
/>
<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-if="formData.items.length === 0" class="py-40rpx text-center text-[#999]">
暂无产品请点击下方按钮添加
</view>
<view v-else>
<view
v-for="(item, index) in formData.items"
:key="index"
class="erp-form-item-card erp-form-item-card--padded"
>
<view class="mb-12rpx flex items-center justify-between">
<view class="text-28rpx text-[#333] font-semibold">
{{ item.productName || '请选择产品' }}
</view>
<wd-icon name="delete" size="40rpx" color="#f56c6c" @click="removeItem(index)" />
</view>
<view class="mb-12rpx">
<wd-cell
title="仓库"
title-width="120rpx"
is-link
:value="item.warehouseName || '请选择'"
@click="openWarehousePicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-cell
title="产品"
title-width="120rpx"
is-link
:value="item.productName || '请选择'"
@click="openProductPicker(index)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.count"
label="数量"
label-width="120rpx"
type="number"
placeholder="请输入数量"
@change="calcItemTotal(item)"
/>
</view>
<view class="mb-12rpx">
<wd-input
v-model="item.productPrice"
label="单价"
label-width="120rpx"
type="digit"
placeholder="请输入单价"
@change="calcItemTotal(item)"
/>
</view>
<view class="flex items-center justify-between text-26rpx">
<text class="text-[#999]">金额</text>
<text class="text-[#f5222d] font-semibold">{{ formatPrice(item.totalPrice) }}</text>
</view>
<view class="mt-12rpx">
<wd-input
v-model="item.remark"
label="备注"
label-width="120rpx"
placeholder="请输入备注"
/>
</view>
</view>
</view>
<view class="px-24rpx pb-24rpx">
<wd-button type="primary" plain block @click="addItem">
<wd-icon name="add" class="mr-8rpx" />
添加产品
</wd-button>
</view>
</wd-cell-group>
<!-- 合计信息 -->
<wd-cell-group title="合计信息" border>
<wd-cell title="合计数量" :value="formatCount(totalCount)" />
<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-datetime-picker
v-model="datePickerVisible"
type="date"
:value="formData.outTime"
@confirm="onDateConfirm"
/>
<!-- 客户选择器 -->
<wd-picker v-model:show="customerPickerVisible"
:columns="customerColumns"
@confirm="onCustomerConfirm"
/>
<!-- 仓库选择器 -->
<wd-picker v-model:show="warehousePickerVisible"
:columns="warehouseColumns"
@confirm="onWarehouseConfirm"
/>
<!-- 产品选择器 -->
<wd-picker v-model:show="productPickerVisible"
:columns="productColumns"
@confirm="onProductConfirm"
/>
</view>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
import type { StockOut, StockOutItem } from '@/api/erp/stock-out'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createStockOut, getStockOut, updateStockOut } from '@/api/erp/stock-out'
import { getWarehouseSimpleList } from '@/api/erp/warehouse'
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<StockOut>({
id: undefined,
no: undefined,
customerId: undefined,
outTime: undefined,
remark: undefined,
items: [],
})
const formRules = {
outTime: [{ required: true, message: '出库时间不能为空' }],
}
const formRef = ref<FormInstance>()
// 客户列表
const customerList = ref<{ id: number, name: string }[]>([])
const customerPickerVisible = ref(false)
const customerColumns = computed(() => [
customerList.value.map(v => ({ value: v.id, label: v.name })),
])
// 仓库列表
const warehouseList = ref<{ id?: number, name?: string }[]>([])
const warehousePickerVisible = ref(false)
const warehouseColumns = computed(() => [
warehouseList.value.map(v => ({ value: v.id, label: v.name })),
])
// 产品列表
const productList = ref<{ id: number, name: string, unitName?: string }[]>([])
const productPickerVisible = ref(false)
const productColumns = computed(() => [
productList.value.map(v => ({ value: v.id, label: v.name })),
])
// 日期选择器
const datePickerVisible = ref<any>(false)
// 当前编辑的产品项索引
const currentItemIndex = ref(-1)
/** 合计数量 */
const totalCount = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.count) || 0), 0) || 0
})
/** 合计金额 */
const totalPrice = computed(() => {
return formData.value.items?.reduce((sum, item) => sum + (Number(item.totalPrice) || 0), 0) || 0
})
/** 获取客户名称 */
function getCustomerName() {
if (!formData.value.customerId) return '请选择'
const customer = customerList.value.find(c => c.id === formData.value.customerId)
return customer?.name || '请选择'
}
/** 格式化数量 */
function formatCount(count?: number) {
if (count === undefined || count === null) return '-'
return count.toFixed(2)
}
/** 格式化金额 */
function formatPrice(price?: number) {
if (price === undefined || price === null) return '-'
return `¥${price.toFixed(2)}`
}
/** 格式化日期 */
function formatDate(dateStr?: string) {
if (!dateStr) return '-'
if (typeof dateStr === 'number') {
const d = new Date(dateStr)
const pad = (n: number) => n.toString().padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
}
return dateStr.substring(0, 10)
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-erp/stock-out/index')
}
/** 加载详情 */
async function getDetail() {
if (!props.id) return
try {
toast.loading('加载中...')
formData.value = await getStockOut(props.id)
} finally {
toast.close()
}
}
/** 日期确认 */
function onDateConfirm({ value }: any) {
formData.value.outTime = value
datePickerVisible.value = false
}
/** 客户确认 */
function onCustomerConfirm({ value }: any) {
formData.value.customerId = value?.[0]
customerPickerVisible.value = false
}
/** 打开仓库选择器 */
function openWarehousePicker(index: number) {
currentItemIndex.value = index
warehousePickerVisible.value = true
}
/** 仓库确认 */
function onWarehouseConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.warehouseId = value?.[0]
const warehouse = warehouseList.value.find(w => w.id === item.warehouseId)
item.warehouseName = warehouse?.name
}
warehousePickerVisible.value = false
}
/** 打开产品选择器 */
function openProductPicker(index: number) {
currentItemIndex.value = index
productPickerVisible.value = true
}
/** 产品确认 */
function onProductConfirm({ value }: any) {
if (currentItemIndex.value >= 0 && formData.value.items) {
const item = formData.value.items[currentItemIndex.value]
item.productId = value?.[0]
const product = productList.value.find(p => p.id === item.productId)
item.productName = product?.name
item.productUnitName = product?.unitName
}
productPickerVisible.value = false
}
/** 添加产品项 */
function addItem() {
if (!formData.value.items) {
formData.value.items = []
}
formData.value.items.push({
warehouseId: undefined,
warehouseName: undefined,
productId: undefined,
productName: undefined,
productUnitName: undefined,
count: undefined,
productPrice: undefined,
totalPrice: 0,
remark: undefined,
})
}
/** 移除产品项 */
function removeItem(index: number) {
formData.value.items?.splice(index, 1)
}
/** 计算产品项金额 */
function calcItemTotal(item: StockOutItem) {
const count = Number(item.count) || 0
const price = Number(item.productPrice) || 0
item.totalPrice = count * price
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value!.validate()
if (!valid) return
// 校验产品清单
if (!formData.value.items || formData.value.items.length === 0) {
toast.error('请添加出库产品')
return
}
for (const item of formData.value.items) {
if (!item.warehouseId) {
toast.error('请选择仓库')
return
}
if (!item.productId) {
toast.error('请选择产品')
return
}
if (!item.count || Number(item.count) <= 0) {
toast.error('请输入有效的数量')
return
}
}
formLoading.value = true
try {
// 设置合计
formData.value.totalCount = totalCount.value
formData.value.totalPrice = totalPrice.value
if (props.id) {
await updateStockOut(formData.value)
toast.success('修改成功')
} else {
await createStockOut(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(async () => {
// 加载仓库列表
warehouseList.value = await getWarehouseSimpleList()
// 加载详情
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

Some files were not shown because too many files have changed in this diff Show More