pay is ok
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useParams, useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { Button, Row, Col, Tag, Statistic, Modal, Form, Input, InputNumber, message, Spin, Descriptions } from 'antd';
|
||||
import { Button, Row, Col, Tag, Statistic, Modal, Form, Input, InputNumber, message, Spin, Descriptions, Radio } from 'antd';
|
||||
import { ShoppingCartOutlined, SafetyCertificateOutlined, ThunderboltOutlined, EyeOutlined, StarOutlined } from '@ant-design/icons';
|
||||
import { getConfigs, createOrder } from '../api';
|
||||
import { getConfigs, createOrder, nativePay } from '../api';
|
||||
import ModelViewer from '../components/ModelViewer';
|
||||
import './ProductDetail.css';
|
||||
|
||||
@@ -16,7 +16,7 @@ const ProductDetail = () => {
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
|
||||
const refCode = searchParams.get('ref');
|
||||
const refCode = searchParams.get('ref') || 'flw666';
|
||||
|
||||
useEffect(() => {
|
||||
fetchProduct();
|
||||
@@ -43,17 +43,29 @@ const ProductDetail = () => {
|
||||
const handleBuy = async (values) => {
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const isPickup = values.delivery_method === 'pickup';
|
||||
const orderData = {
|
||||
config: product.id,
|
||||
goodid: product.id,
|
||||
quantity: values.quantity,
|
||||
customer_name: values.customer_name,
|
||||
phone_number: values.phone_number,
|
||||
shipping_address: values.shipping_address,
|
||||
shipping_address: isPickup ? '线下自提' : values.shipping_address,
|
||||
ref_code: refCode
|
||||
};
|
||||
const response = await createOrder(orderData);
|
||||
message.success('订单创建成功');
|
||||
navigate(`/payment/${response.data.id}`);
|
||||
const response = await nativePay(orderData);
|
||||
message.success('订单已创建,请完成支付');
|
||||
navigate(`/payment/${response.data.order_id}`, {
|
||||
state: {
|
||||
codeUrl: response.data.code_url,
|
||||
order_id: response.data.order_id,
|
||||
orderInfo: {
|
||||
...orderData,
|
||||
id: response.data.order_id,
|
||||
config_name: product.name,
|
||||
total_price: product.price * values.quantity
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.error('创建订单失败,请检查填写信息');
|
||||
@@ -217,8 +229,14 @@ const ProductDetail = () => {
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={handleBuy}
|
||||
initialValues={{ quantity: 1 }}
|
||||
initialValues={{ quantity: 1, delivery_method: 'shipping' }}
|
||||
>
|
||||
<Form.Item label="配送方式" name="delivery_method">
|
||||
<Radio.Group buttonStyle="solid">
|
||||
<Radio.Button value="shipping">快递配送</Radio.Button>
|
||||
<Radio.Button value="pickup">线下自提</Radio.Button>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label="购买数量" name="quantity" rules={[{ required: true }]}>
|
||||
<InputNumber min={1} max={100} style={{ width: '100%' }} />
|
||||
</Form.Item>
|
||||
@@ -228,8 +246,22 @@ const ProductDetail = () => {
|
||||
<Form.Item label="联系电话" name="phone_number" rules={[{ required: true, message: '请输入电话' }]}>
|
||||
<Input placeholder="13800000000" />
|
||||
</Form.Item>
|
||||
<Form.Item label="收货地址" name="shipping_address" rules={[{ required: true, message: '请输入地址' }]}>
|
||||
<Input.TextArea rows={3} placeholder="北京市..." />
|
||||
<Form.Item
|
||||
noStyle
|
||||
shouldUpdate={(prevValues, currentValues) => prevValues.delivery_method !== currentValues.delivery_method}
|
||||
>
|
||||
{({ getFieldValue }) =>
|
||||
getFieldValue('delivery_method') === 'shipping' ? (
|
||||
<Form.Item label="收货地址" name="shipping_address" rules={[{ required: true, message: '请输入地址' }]}>
|
||||
<Input.TextArea rows={3} placeholder="北京市..." />
|
||||
</Form.Item>
|
||||
) : (
|
||||
<div style={{ marginBottom: 24, padding: '12px', background: '#f5f5f5', borderRadius: '4px', border: '1px solid #d9d9d9' }}>
|
||||
<p style={{ margin: 0, color: '#666' }}>自提地址:昆明市云纺国际商厦B座1406</p>
|
||||
<p style={{ margin: 0, fontSize: '12px', color: '#999' }}>请在工作日 9:00 - 18:00 期间前往提货</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</Form.Item>
|
||||
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 10, marginTop: 20 }}>
|
||||
|
||||
Reference in New Issue
Block a user