优化本地Mock接单

This commit is contained in:
yml2213
2026-08-21 12:39:24 +08:00
parent e6ab139071
commit c3bd6daee2
7 changed files with 278 additions and 47 deletions
@@ -68,6 +68,7 @@ import {
updateAdminWorkOrder,
updateAdminWorkOrderSharing,
} from '@/services/admin'
import { fetchAdminKuaishouIndustryShops } from '@/services/admin/kuaishou-industry'
import type {
CollectField,
UploadedFile,
@@ -78,6 +79,7 @@ import type {
import { ADMIN_DEFAULT_PAGE_SIZE, buildAdminTablePagination } from '@/utils/admin-pagination'
import { hasAdminRole } from '@/utils/admin-auth'
import { formatAdminDateTime } from '@/utils/admin-time'
import { buildMockWorkOrderShopOptions } from '@/utils/mock-work-order'
import {
DeadlineCountdown,
formatTimeoutPolicyLabel,
@@ -2293,12 +2295,18 @@ function formatRequirementFieldsText(fields: CollectField[]): string {
function MockWorkOrderForm({ onCreated }: { onCreated: () => Promise<void> }) {
const { message } = App.useApp()
const [loading, setLoading] = useState(false)
const shopsQuery = useQuery({
queryKey: ['admin-kuaishou-industry-shops', 'mock-work-order'],
queryFn: fetchAdminKuaishouIndustryShops,
})
const shopOptions = buildMockWorkOrderShopOptions(shopsQuery.data?.data.shops || [])
async function submit(values: {
platformOrderId?: string
productName?: string
rewardAmount?: number
paymentAmount?: number
platformOrderId: string
sellerId: string
productName: string
rewardAmount: number
paymentAmount: number
materialComplete?: boolean
}) {
setLoading(true)
@@ -2314,32 +2322,58 @@ function MockWorkOrderForm({ onCreated }: { onCreated: () => Promise<void> }) {
}
return (
<Form
className="worker-order-mock-form"
layout="inline"
initialValues={{
productName: '指挥官秘钥1个',
rewardAmount: 25,
materialComplete: false,
}}
onFinish={submit}
>
<Form.Item className="worker-order-mock-field-order" label="订单号" name="platformOrderId">
<Input placeholder="留空自动生成" />
<Form className="worker-order-mock-form" layout="inline" onFinish={submit}>
<Form.Item
className="worker-order-mock-field-order"
label="订单号"
name="platformOrderId"
rules={[{ required: true, whitespace: true, message: '请填写订单号' }]}
>
<Input placeholder="请输入订单号" />
</Form.Item>
<Form.Item className="worker-order-mock-field-product" label="商品" name="productName">
<Input />
<Form.Item
className="worker-order-mock-field-shop"
label="店铺"
name="sellerId"
rules={[{ required: true, message: '请选择店铺' }]}
>
<Select
showSearch
optionFilterProp="label"
loading={shopsQuery.isLoading}
options={shopOptions}
placeholder={shopOptions.length > 0 ? '请选择店铺' : '暂无可用店铺'}
/>
</Form.Item>
<Form.Item className="worker-order-mock-field-amount" label="接单金额" name="rewardAmount">
<Form.Item
className="worker-order-mock-field-product"
label="商品"
name="productName"
rules={[{ required: true, whitespace: true, message: '请填写商品名称' }]}
>
<Input placeholder="请输入商品名称" />
</Form.Item>
<Form.Item
className="worker-order-mock-field-amount"
label="接单金额"
name="rewardAmount"
rules={[
{ required: true, message: '请填写接单金额' },
{ type: 'number', min: 0.01, message: '接单金额必须大于 0' },
]}
>
<InputNumber min={0.01} step={1} addonAfter="元" />
</Form.Item>
<Form.Item
className="worker-order-mock-field-amount"
label="用户付款金额"
name="paymentAmount"
tooltip="留空默认等于接单金额;填得比接单金额低,可测试超价提示"
rules={[
{ required: true, message: '请填写用户付款金额' },
{ type: 'number', min: 0.01, message: '用户付款金额必须大于 0' },
]}
>
<InputNumber min={0} step={1} addonAfter="元" placeholder="默认同接单金额" />
<InputNumber min={0.01} step={1} addonAfter="元" />
</Form.Item>
<Form.Item
className="worker-order-mock-field-complete"
@@ -428,10 +428,11 @@ export function fetchAdminWorkOrderEvents(workOrderId: number) {
}
export function createAdminMockWorkOrder(payload: {
platformOrderId?: string
productName?: string
rewardAmount?: number
paymentAmount?: number
platformOrderId: string
sellerId: string
productName: string
rewardAmount: number
paymentAmount: number
materialComplete?: boolean
}) {
return apiPost<{ order: WorkOrder }>('/api/v1/admin/worker-platform/orders/mock', payload)
+11 -6
View File
@@ -115,23 +115,24 @@
.worker-orders-toolbar {
display: flex;
align-items: center;
gap: 24px;
flex-direction: column;
align-items: stretch;
gap: 16px;
min-width: 0;
}
.worker-orders-search-controls {
flex: 0 0 auto;
width: 100%;
}
.worker-orders-mock {
flex: 1;
width: 100%;
min-width: 0;
display: flex;
align-items: center;
gap: 12px;
padding-left: 24px;
border-left: 1px solid #edf0f5;
padding-top: 16px;
border-top: 1px solid #edf0f5;
}
.worker-orders-mock > .ant-typography {
@@ -157,6 +158,10 @@
width: 150px;
}
.worker-order-mock-field-shop .ant-select {
width: 190px;
}
.worker-order-mock-field-product .ant-input {
width: 190px;
}
@@ -0,0 +1,20 @@
export type MockWorkOrderShop = {
sellerId: string
shopId: string
shopName: string
enabled: boolean
}
export function buildMockWorkOrderShopOptions(shops: MockWorkOrderShop[]) {
return shops
.filter((shop) => shop.enabled)
.map((shop) => {
const value = String(shop.sellerId || shop.shopId || '').trim()
const name = String(shop.shopName || shop.shopId || value).trim()
return {
value,
label: `${name}${value}`,
}
})
.filter((shop) => Boolean(shop.value))
}
@@ -0,0 +1,14 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { buildMockWorkOrderShopOptions } from '../src/utils/mock-work-order.ts'
test('本地 Mock 店铺选择仅展示启用店铺', () => {
assert.deepEqual(
buildMockWorkOrderShopOptions([
{ sellerId: 'seller-1', shopId: 'shop-1', shopName: '测试店铺', enabled: true },
{ sellerId: 'seller-2', shopId: 'shop-2', shopName: '已停用店铺', enabled: false },
]),
[{ value: 'seller-1', label: '测试店铺(seller-1' }],
)
})