feat(admin): 重构接单模板与商品绑定内联编辑 UI 布局
- 优化接单模板与模板列表 6:4 比例自适应布局 - 适用商品绑定支持左侧直接内联展开编辑,免弹窗模式 - 支持绑定规则多标签快速切换、实时新增与删除 - 基础表单与商品绑定统一采用 3 列网格布局,严格几何对齐 - 「启用拼单」开关及参数行内紧凑展开,移除多余背景框与纵向滚动条
This commit is contained in:
@@ -14,6 +14,7 @@ export async function listWorkProductRuleMappings(
|
||||
input: {
|
||||
enabled?: boolean | null
|
||||
sellerId?: string
|
||||
ruleId?: number | string | null
|
||||
} = {},
|
||||
): Promise<WorkProductRuleMappingRow[]> {
|
||||
const conditions: string[] = []
|
||||
@@ -29,6 +30,11 @@ export async function listWorkProductRuleMappings(
|
||||
params.push(sellerId)
|
||||
conditions.push(`wprm.seller_ids_json ? $${params.length}`)
|
||||
}
|
||||
const ruleId = Number(input.ruleId)
|
||||
if (Number.isInteger(ruleId) && ruleId > 0) {
|
||||
params.push(ruleId)
|
||||
conditions.push(`wprm.rule_id = $${params.length}`)
|
||||
}
|
||||
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''
|
||||
const result = await query<WorkProductRuleMappingRow>(
|
||||
`${MAPPING_SELECT}
|
||||
@@ -41,6 +47,61 @@ export async function listWorkProductRuleMappings(
|
||||
return result.rows
|
||||
}
|
||||
|
||||
export async function listWorkProductRuleMappingsPage(
|
||||
input: {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
enabled?: boolean | null
|
||||
keyword?: string
|
||||
ruleId?: number | string | null
|
||||
} = {},
|
||||
): Promise<{ items: WorkProductRuleMappingRow[]; total: number }> {
|
||||
const page = Math.max(1, Math.floor(Number(input.page) || 1))
|
||||
const pageSize = Math.min(100, Math.max(1, Math.floor(Number(input.pageSize) || 20)))
|
||||
const conditions: string[] = []
|
||||
const params: unknown[] = []
|
||||
if (input.enabled !== undefined && input.enabled !== null) {
|
||||
params.push(input.enabled)
|
||||
conditions.push(`wprm.enabled = $${params.length}`)
|
||||
}
|
||||
const ruleId = Number(input.ruleId)
|
||||
if (Number.isInteger(ruleId) && ruleId > 0) {
|
||||
params.push(ruleId)
|
||||
conditions.push(`wprm.rule_id = $${params.length}`)
|
||||
}
|
||||
const keyword = String(input.keyword || '').trim()
|
||||
if (keyword) {
|
||||
params.push(`%${keyword}%`)
|
||||
const parameter = `$${params.length}`
|
||||
conditions.push(`(
|
||||
wpr.rule_key ILIKE ${parameter}
|
||||
OR wpr.product_name ILIKE ${parameter}
|
||||
OR wprm.item_title ILIKE ${parameter}
|
||||
OR wprm.rel_item_id ILIKE ${parameter}
|
||||
OR wprm.rel_sku_id ILIKE ${parameter}
|
||||
OR wprm.sku_nick ILIKE ${parameter}
|
||||
)`)
|
||||
}
|
||||
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''
|
||||
const totalResult = await query<{ total: number }>(
|
||||
`SELECT COUNT(*)::int AS total FROM work_product_rule_mappings wprm
|
||||
INNER JOIN work_product_rules wpr ON wpr.id = wprm.rule_id ${where}`,
|
||||
params,
|
||||
)
|
||||
const offset = (page - 1) * pageSize
|
||||
const listParams = [...params, pageSize, offset]
|
||||
const result = await query<WorkProductRuleMappingRow>(
|
||||
`${MAPPING_SELECT}
|
||||
${where}
|
||||
ORDER BY wprm.seller_ids_json::text ASC, wprm.rel_item_id ASC, wprm.item_title ASC,
|
||||
CASE WHEN wprm.mapping_type = 'product_default' THEN 0 ELSE 1 END ASC,
|
||||
wprm.id ASC
|
||||
LIMIT $${listParams.length - 1} OFFSET $${listParams.length}`,
|
||||
listParams,
|
||||
)
|
||||
return { items: result.rows, total: Number(totalResult.rows[0]?.total || 0) }
|
||||
}
|
||||
|
||||
export async function upsertWorkProductRuleMapping(input: {
|
||||
mappingId?: number | null
|
||||
ruleId: number
|
||||
|
||||
Reference in New Issue
Block a user