feat(admin): 增加履约渠道批量删除并统一分页配置
This commit is contained in:
@@ -6,7 +6,12 @@
|
||||
* · 没有命中规则的新单落在「待分类」,收入进未分类桶,不产生成本噪音;
|
||||
* · 第三方卡券是「只统计」渠道:不建任务、不发领取页。
|
||||
*/
|
||||
import { PlusOutlined, ReloadOutlined, ThunderboltOutlined } from '@ant-design/icons'
|
||||
import {
|
||||
DeleteOutlined,
|
||||
PlusOutlined,
|
||||
ReloadOutlined,
|
||||
ThunderboltOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
@@ -30,7 +35,7 @@ import PercentTable from '@/components/common/PercentTable'
|
||||
import FinanceSubNav from '@/components/admin/FinanceSubNav'
|
||||
import {
|
||||
assignChannelBySku,
|
||||
deleteChannelRule,
|
||||
deleteChannelRules,
|
||||
fetchChannelExceptions,
|
||||
fetchChannelRules,
|
||||
fetchPendingChannelGroups,
|
||||
@@ -43,6 +48,11 @@ import {
|
||||
} from '@/services/admin'
|
||||
import { formatRedeemAmount } from '@/utils/redeem'
|
||||
import { formatDateTime } from '@/utils/date-time'
|
||||
import {
|
||||
ADMIN_DEFAULT_PAGE_SIZE,
|
||||
buildAdminLocalTablePagination,
|
||||
buildAdminTablePagination,
|
||||
} from '@/utils/admin-pagination'
|
||||
|
||||
const CHANNEL_OPTIONS = [
|
||||
{ value: 'work_order', label: '接单平台' },
|
||||
@@ -80,11 +90,13 @@ export default function AdminFulfillmentChannelPage() {
|
||||
function PendingPanel() {
|
||||
const queryClient = useQueryClient()
|
||||
const [keyword, setKeyword] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(ADMIN_DEFAULT_PAGE_SIZE)
|
||||
const [selections, setSelections] = useState<Record<string, string>>({})
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: ['fulfillment-pending', keyword],
|
||||
queryFn: () => fetchPendingChannelGroups({ page: 1, pageSize: 100, keyword }),
|
||||
queryKey: ['fulfillment-pending', keyword, page, pageSize],
|
||||
queryFn: () => fetchPendingChannelGroups({ page, pageSize, keyword }),
|
||||
})
|
||||
|
||||
const assignMutation = useMutation({
|
||||
@@ -191,7 +203,10 @@ function PendingPanel() {
|
||||
allowClear
|
||||
placeholder="SKU / 商品名"
|
||||
style={{ width: 220 }}
|
||||
onSearch={(value) => setKeyword(value)}
|
||||
onSearch={(value) => {
|
||||
setKeyword(value)
|
||||
setPage(1)
|
||||
}}
|
||||
/>
|
||||
<Button icon={<ReloadOutlined />} onClick={() => void query.refetch()}>
|
||||
刷新
|
||||
@@ -218,7 +233,15 @@ function PendingPanel() {
|
||||
loading={query.isFetching}
|
||||
dataSource={query.data?.data?.items || []}
|
||||
columns={columns}
|
||||
pagination={{ pageSize: 20, showSizeChanger: false }}
|
||||
pagination={buildAdminTablePagination({
|
||||
current: query.data?.data?.page || page,
|
||||
pageSize: query.data?.data?.pageSize || pageSize,
|
||||
total: query.data?.data?.total || 0,
|
||||
onChange: (nextPage, nextPageSize) => {
|
||||
setPage(nextPageSize !== pageSize ? 1 : nextPage)
|
||||
setPageSize(nextPageSize)
|
||||
},
|
||||
})}
|
||||
/>
|
||||
</Card>
|
||||
)
|
||||
@@ -227,6 +250,7 @@ function PendingPanel() {
|
||||
function RulesPanel() {
|
||||
const queryClient = useQueryClient()
|
||||
const [open, setOpen] = useState(false)
|
||||
const [selectedRuleIds, setSelectedRuleIds] = useState<number[]>([])
|
||||
const [form] = Form.useForm()
|
||||
|
||||
const query = useQuery({
|
||||
@@ -246,14 +270,31 @@ function RulesPanel() {
|
||||
})
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: (id: number) => deleteChannelRule(id),
|
||||
onSuccess: () => {
|
||||
message.success('规则已删除')
|
||||
mutationFn: (ids: number[]) => deleteChannelRules(ids),
|
||||
onSuccess: (result) => {
|
||||
const missingHint = result.data.missingIds.length
|
||||
? `,${result.data.missingIds.length} 条已不存在`
|
||||
: ''
|
||||
message.success(`已删除 ${result.data.deletedCount} 条渠道规则${missingHint}`)
|
||||
setSelectedRuleIds([])
|
||||
void queryClient.invalidateQueries({ queryKey: ['fulfillment-rules'] })
|
||||
void queryClient.invalidateQueries({ queryKey: ['fulfillment-pending'] })
|
||||
},
|
||||
onError: () => message.error('删除规则失败'),
|
||||
})
|
||||
|
||||
function confirmDeleteRules(ids: number[]) {
|
||||
if (ids.length === 0) return
|
||||
Modal.confirm({
|
||||
title: ids.length === 1 ? '删除渠道规则' : `批量删除 ${ids.length} 条渠道规则`,
|
||||
content: '删除后会立即影响新订单的渠道判定;历史订单和成本数据不会被删除。',
|
||||
okText: '确认删除',
|
||||
okButtonProps: { danger: true },
|
||||
cancelText: '取消',
|
||||
onOk: () => deleteMutation.mutateAsync(ids),
|
||||
})
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '作用范围', width: 110, render: () => <Tag color="blue">全局</Tag> },
|
||||
{
|
||||
@@ -288,7 +329,7 @@ function RulesPanel() {
|
||||
danger
|
||||
size="small"
|
||||
loading={deleteMutation.isPending}
|
||||
onClick={() => deleteMutation.mutate(row.id)}
|
||||
onClick={() => confirmDeleteRules([row.id])}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
@@ -301,6 +342,15 @@ function RulesPanel() {
|
||||
title={`统一渠道配置(${query.data?.data?.length ?? 0})`}
|
||||
extra={
|
||||
<Space>
|
||||
<Button
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
disabled={selectedRuleIds.length === 0}
|
||||
loading={deleteMutation.isPending}
|
||||
onClick={() => confirmDeleteRules(selectedRuleIds)}
|
||||
>
|
||||
批量删除{selectedRuleIds.length ? ` (${selectedRuleIds.length})` : ''}
|
||||
</Button>
|
||||
<Button icon={<ReloadOutlined />} onClick={() => void query.refetch()}>
|
||||
刷新
|
||||
</Button>
|
||||
@@ -320,7 +370,11 @@ function RulesPanel() {
|
||||
loading={query.isFetching}
|
||||
dataSource={query.data?.data || []}
|
||||
columns={columns}
|
||||
pagination={{ pageSize: 20, showSizeChanger: false }}
|
||||
rowSelection={{
|
||||
selectedRowKeys: selectedRuleIds,
|
||||
onChange: (keys) => setSelectedRuleIds(keys.map(Number)),
|
||||
}}
|
||||
pagination={buildAdminLocalTablePagination()}
|
||||
/>
|
||||
|
||||
<Modal
|
||||
@@ -366,9 +420,11 @@ function RulesPanel() {
|
||||
|
||||
function ExceptionsPanel() {
|
||||
const [reason, setReason] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(ADMIN_DEFAULT_PAGE_SIZE)
|
||||
const query = useQuery({
|
||||
queryKey: ['fulfillment-exceptions', reason],
|
||||
queryFn: () => fetchChannelExceptions({ reason, status: 'open', page: 1, pageSize: 100 }),
|
||||
queryKey: ['fulfillment-exceptions', reason, page, pageSize],
|
||||
queryFn: () => fetchChannelExceptions({ reason, status: 'open', page, pageSize }),
|
||||
})
|
||||
|
||||
const REASON_OPTIONS = [
|
||||
@@ -408,7 +464,10 @@ function ExceptionsPanel() {
|
||||
style={{ width: 180 }}
|
||||
value={reason}
|
||||
options={REASON_OPTIONS}
|
||||
onChange={setReason}
|
||||
onChange={(value) => {
|
||||
setReason(value)
|
||||
setPage(1)
|
||||
}}
|
||||
/>
|
||||
<Button icon={<ReloadOutlined />} onClick={() => void query.refetch()}>
|
||||
刷新
|
||||
@@ -422,7 +481,15 @@ function ExceptionsPanel() {
|
||||
loading={query.isFetching}
|
||||
dataSource={query.data?.data?.items || []}
|
||||
columns={columns}
|
||||
pagination={{ pageSize: 20, showSizeChanger: false }}
|
||||
pagination={buildAdminTablePagination({
|
||||
current: query.data?.data?.page || page,
|
||||
pageSize: query.data?.data?.pageSize || pageSize,
|
||||
total: query.data?.data?.total || 0,
|
||||
onChange: (nextPage, nextPageSize) => {
|
||||
setPage(nextPageSize !== pageSize ? 1 : nextPage)
|
||||
setPageSize(nextPageSize)
|
||||
},
|
||||
})}
|
||||
/>
|
||||
</Card>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user