商户管理优化, 商户只能上架下架, 管理员可以编辑
This commit is contained in:
@@ -45,9 +45,13 @@ export default function PlatformMerchants() {
|
||||
const [adjustLoading, setAdjustLoading] = useState(false)
|
||||
const [adjustSubmitting, setAdjustSubmitting] = useState(false)
|
||||
const [adjustWallet, setAdjustWallet] = useState<WalletAccount | null>(null)
|
||||
const [editProduct, setEditProduct] = useState<ProductCatalogItem | null>(null)
|
||||
const [editProductOpen, setEditProductOpen] = useState(false)
|
||||
const [editProductSubmitting, setEditProductSubmitting] = useState(false)
|
||||
const [createForm] = Form.useForm()
|
||||
const [settingsForm] = Form.useForm()
|
||||
const [adjustForm] = Form.useForm()
|
||||
const [editProductForm] = Form.useForm()
|
||||
|
||||
const load = useCallback(async (page = data.page, size = data.size) => {
|
||||
setLoading(true)
|
||||
@@ -184,6 +188,42 @@ export default function PlatformMerchants() {
|
||||
}
|
||||
}
|
||||
|
||||
const openProductEdit = (record: ProductCatalogItem) => {
|
||||
setEditProduct(record)
|
||||
editProductForm.resetFields()
|
||||
editProductForm.setFieldsValue({
|
||||
display_name: record.display_name,
|
||||
price_amount: record.price_amount,
|
||||
cost_amount: record.cost_amount,
|
||||
stock: record.stock,
|
||||
status: record.status,
|
||||
})
|
||||
setEditProductOpen(true)
|
||||
}
|
||||
|
||||
const submitProductEdit = async () => {
|
||||
if (!selectedMerchant || !editProduct) return
|
||||
const values = await editProductForm.validateFields()
|
||||
setEditProductSubmitting(true)
|
||||
try {
|
||||
await platformApi.updateMerchantProduct(selectedMerchant.id, editProduct.id, {
|
||||
display_name: values.display_name,
|
||||
price_amount: Number(values.price_amount || 0),
|
||||
cost_amount: Number(values.cost_amount || 0),
|
||||
stock: Number(values.stock ?? -1),
|
||||
status: values.status,
|
||||
})
|
||||
message.success('商品已更新')
|
||||
setEditProductOpen(false)
|
||||
const productsData = await platformApi.merchantProducts(selectedMerchant.id)
|
||||
setMerchantProducts(productsData || [])
|
||||
} catch (e) {
|
||||
message.error(e instanceof Error ? e.message : '保存失败')
|
||||
} finally {
|
||||
setEditProductSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const columns: ColumnsType<Merchant> = [
|
||||
{ title: 'ID', dataIndex: 'id', width: 70, align: 'center' },
|
||||
{ title: '编码', dataIndex: 'code', width: 160, render: (v) => <Typography.Text code copyable={{ text: v }}>{v}</Typography.Text> },
|
||||
@@ -515,6 +555,14 @@ export default function PlatformMerchants() {
|
||||
width: 80,
|
||||
render: (v) => (v === 'active' ? <Tag color="green">上架</Tag> : <Tag>下架</Tag>),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 60,
|
||||
render: (_, record: ProductCatalogItem) => (
|
||||
<Button type="link" size="small" onClick={() => openProductEdit(record)}>编辑</Button>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Checkbox.Group>
|
||||
@@ -524,6 +572,40 @@ export default function PlatformMerchants() {
|
||||
</Space>
|
||||
</Spin>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
title={editProduct ? `编辑商品:${editProduct.sku}` : '编辑商品'}
|
||||
open={editProductOpen}
|
||||
onOk={submitProductEdit}
|
||||
onCancel={() => setEditProductOpen(false)}
|
||||
destroyOnClose
|
||||
width={560}
|
||||
confirmLoading={editProductSubmitting}
|
||||
okText="保存"
|
||||
>
|
||||
<Form form={editProductForm} layout="vertical" style={{ marginTop: 16 }}>
|
||||
<Form.Item name="display_name" label="展示名">
|
||||
<Input maxLength={160} />
|
||||
</Form.Item>
|
||||
<Space size="middle" style={{ width: '100%' }}>
|
||||
<Form.Item name="price_amount" label="售价(积分)" rules={[{ required: true }]} style={{ width: 160 }}>
|
||||
<InputNumber min={0} precision={0} style={{ width: '100%' }} />
|
||||
</Form.Item>
|
||||
<Form.Item name="cost_amount" label="成本(积分)" rules={[{ required: true }]} style={{ width: 160 }}>
|
||||
<InputNumber min={0} precision={0} style={{ width: '100%' }} />
|
||||
</Form.Item>
|
||||
<Form.Item name="stock" label="库存(-1 无限)" style={{ width: 160 }}>
|
||||
<InputNumber min={-1} precision={0} style={{ width: '100%' }} />
|
||||
</Form.Item>
|
||||
</Space>
|
||||
<Form.Item name="status" label="状态" rules={[{ required: true }]}>
|
||||
<Select options={[{ value: 'active', label: '上架' }, { value: 'inactive', label: '下架' }]} />
|
||||
</Form.Item>
|
||||
<Typography.Text type="secondary">
|
||||
下架后商户将无法再创建该商品订单;价格/成本调整立即对后续订单生效。
|
||||
</Typography.Text>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user