|
@@ -2,13 +2,14 @@
|
|
|
|
|
|
|
|
import { useState, useEffect } from 'react';
|
|
import { useState, useEffect } from 'react';
|
|
|
import { useRouter } from 'next/navigation';
|
|
import { useRouter } from 'next/navigation';
|
|
|
-import { ArrowLeft, Users, Building2, Globe, DollarSign } from 'lucide-react';
|
|
|
|
|
|
|
+import { ArrowLeft, Users, Building2, Globe, DollarSign, Clock, CheckCircle2, ShieldCheck, Smartphone, Banknote } from 'lucide-react';
|
|
|
import { productService, orderService, settlementService } from '@/lib/services';
|
|
import { productService, orderService, settlementService } from '@/lib/services';
|
|
|
import { getCurrentUser } from '@/lib/auth';
|
|
import { getCurrentUser } from '@/lib/auth';
|
|
|
import ProductSearchSelector from '@/components/admin/orders/ProductSearchSelector';
|
|
import ProductSearchSelector from '@/components/admin/orders/ProductSearchSelector';
|
|
|
import AiDataParserPanel from '@/components/admin/orders/AiDataParserPanel';
|
|
import AiDataParserPanel from '@/components/admin/orders/AiDataParserPanel';
|
|
|
import DynamicOrderSchemaForm from '@/components/admin/orders/DynamicOrderSchemaForm';
|
|
import DynamicOrderSchemaForm from '@/components/admin/orders/DynamicOrderSchemaForm';
|
|
|
import AdminUserSelect from '@/components/common/AdminUserSelect';
|
|
import AdminUserSelect from '@/components/common/AdminUserSelect';
|
|
|
|
|
+import { ImageUploadField } from '@/components/common/ImageUploadField';
|
|
|
import { SchemaProperty, VasAgency } from '@/types';
|
|
import { SchemaProperty, VasAgency } from '@/types';
|
|
|
import { toast } from 'react-hot-toast';
|
|
import { toast } from 'react-hot-toast';
|
|
|
|
|
|
|
@@ -26,6 +27,13 @@ export default function AdminCreateOrderPage() {
|
|
|
const [handlerId, setHandlerId] = useState<string>('');
|
|
const [handlerId, setHandlerId] = useState<string>('');
|
|
|
const [customPrice, setCustomPrice] = useState<string>(''); // 单位: 元
|
|
const [customPrice, setCustomPrice] = useState<string>(''); // 单位: 元
|
|
|
|
|
|
|
|
|
|
+ // 2.5 收款时机与收款登记状态
|
|
|
|
|
+ const [paymentTiming, setPaymentTiming] = useState<'pay_later' | 'paid_now'>('pay_later');
|
|
|
|
|
+ const [paymentMethod, setPaymentMethod] = useState<string>('wechat');
|
|
|
|
|
+ const [externalTradeNo, setExternalTradeNo] = useState<string>('');
|
|
|
|
|
+ const [voucherUrl, setVoucherUrl] = useState<string>('');
|
|
|
|
|
+ const [paymentNote, setPaymentNote] = useState<string>('');
|
|
|
|
|
+
|
|
|
// 3. 表单与 Schema 状态
|
|
// 3. 表单与 Schema 状态
|
|
|
const [formSchema, setFormSchema] = useState<any>(null);
|
|
const [formSchema, setFormSchema] = useState<any>(null);
|
|
|
const [formValues, setFormValues] = useState<Record<string, any>>({});
|
|
const [formValues, setFormValues] = useState<Record<string, any>>({});
|
|
@@ -61,22 +69,32 @@ export default function AdminCreateOrderPage() {
|
|
|
|
|
|
|
|
const selectedAgency = agencies.find((a) => a.id === selectedAgencyId);
|
|
const selectedAgency = agencies.find((a) => a.id === selectedAgencyId);
|
|
|
|
|
|
|
|
- // 加载 Schema
|
|
|
|
|
|
|
+ // 加载商品默认价与 Schema
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
|
|
+ if (!selectedProduct) {
|
|
|
|
|
+ setFormSchema(null);
|
|
|
|
|
+ setSortedFields([]);
|
|
|
|
|
+ setFormValues({});
|
|
|
|
|
+ setCustomPrice('');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 默认价格填充 (分转元): 优先取 price_amount,兼顾 base_price
|
|
|
|
|
+ if (selectedProduct.price_amount !== undefined) {
|
|
|
|
|
+ setCustomPrice((selectedProduct.price_amount / 100).toFixed(2));
|
|
|
|
|
+ } else if (selectedProduct.base_price !== undefined) {
|
|
|
|
|
+ setCustomPrice((selectedProduct.base_price / 100).toFixed(2));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!selectedProduct.schema_id) {
|
|
|
|
|
+ setFormSchema(null);
|
|
|
|
|
+ setSortedFields([]);
|
|
|
|
|
+ setFormValues({});
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
async function loadSchema() {
|
|
async function loadSchema() {
|
|
|
- if (!selectedProduct?.schema_id) {
|
|
|
|
|
- setFormSchema(null);
|
|
|
|
|
- setSortedFields([]);
|
|
|
|
|
- setFormValues({});
|
|
|
|
|
- setCustomPrice('');
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
try {
|
|
try {
|
|
|
- // 默认价格填充 (分转元)
|
|
|
|
|
- if (selectedProduct.base_price !== undefined) {
|
|
|
|
|
- setCustomPrice((selectedProduct.base_price / 100).toFixed(2));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
const res = await productService.getSchemaDetail(selectedProduct.schema_id);
|
|
const res = await productService.getSchemaDetail(selectedProduct.schema_id);
|
|
|
const data = res?.data || res;
|
|
const data = res?.data || res;
|
|
|
const schemaJson =
|
|
const schemaJson =
|
|
@@ -127,12 +145,16 @@ export default function AdminCreateOrderPage() {
|
|
|
e.preventDefault();
|
|
e.preventDefault();
|
|
|
if (!selectedProduct) return toast.error('请先搜索并选择商品');
|
|
if (!selectedProduct) return toast.error('请先搜索并选择商品');
|
|
|
|
|
|
|
|
- // 中介底价校验
|
|
|
|
|
|
|
+ // 价格校验
|
|
|
let finalAmountCents: number | undefined = undefined;
|
|
let finalAmountCents: number | undefined = undefined;
|
|
|
if (customPrice && !isNaN(Number(customPrice))) {
|
|
if (customPrice && !isNaN(Number(customPrice))) {
|
|
|
finalAmountCents = Math.round(Number(customPrice) * 100);
|
|
finalAmountCents = Math.round(Number(customPrice) * 100);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (finalAmountCents === undefined || finalAmountCents <= 0) {
|
|
|
|
|
+ return toast.error('请输入有效的金额 (必须大于 0)');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (channelType === 'agency') {
|
|
if (channelType === 'agency') {
|
|
|
if (!selectedAgencyId) {
|
|
if (!selectedAgencyId) {
|
|
|
return toast.error('请选择合作中介机构');
|
|
return toast.error('请选择合作中介机构');
|
|
@@ -157,12 +179,21 @@ export default function AdminCreateOrderPage() {
|
|
|
agency_id: channelType === 'agency' ? selectedAgencyId : undefined,
|
|
agency_id: channelType === 'agency' ? selectedAgencyId : undefined,
|
|
|
handler_id: channelType === 'website' ? undefined : handlerId.trim(),
|
|
handler_id: channelType === 'website' ? undefined : handlerId.trim(),
|
|
|
final_amount: finalAmountCents,
|
|
final_amount: finalAmountCents,
|
|
|
|
|
+ payment_timing: paymentTiming,
|
|
|
|
|
+ payment_method: paymentTiming === 'paid_now' ? paymentMethod : undefined,
|
|
|
|
|
+ external_trade_no: paymentTiming === 'paid_now' ? (externalTradeNo.trim() || undefined) : undefined,
|
|
|
|
|
+ voucher_url: paymentTiming === 'paid_now' ? (voucherUrl.trim() || undefined) : undefined,
|
|
|
|
|
+ payment_note: paymentTiming === 'paid_now' ? (paymentNote.trim() || undefined) : undefined,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const res = await orderService.createByAdmin(payload);
|
|
const res = await orderService.createByAdmin(payload);
|
|
|
const orderId = res?.data?.id || res?.id || res?.data?.order_id || res?.order_id;
|
|
const orderId = res?.data?.id || res?.id || res?.data?.order_id || res?.order_id;
|
|
|
|
|
|
|
|
- toast.success(`代下单成功!订单号: ${orderId}`);
|
|
|
|
|
|
|
+ if (paymentTiming === 'pay_later') {
|
|
|
|
|
+ toast.success(`代客下单成功!任务已入队调度 [待出签/收款] 订单号: ${orderId}`);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ toast.success(`代下单并收款核销成功!订单号: ${orderId}`);
|
|
|
|
|
+ }
|
|
|
router.push('/admin/orders');
|
|
router.push('/admin/orders');
|
|
|
} catch (error: any) {
|
|
} catch (error: any) {
|
|
|
console.error(error);
|
|
console.error(error);
|
|
@@ -351,29 +382,196 @@ export default function AdminCreateOrderPage() {
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
|
|
|
|
|
- {/* 自定义结算价格 */}
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+
|
|
|
|
|
+ {/* Step 1.6: 收款时机与金额登记 */}
|
|
|
|
|
+ {selectedProduct && (
|
|
|
|
|
+ <div className="bg-white border-2 border-black shadow-[4px_4px_0px_#000] overflow-hidden">
|
|
|
|
|
+ <div className="px-5 py-3 border-b-2 border-black bg-neutral-200 text-black flex items-center justify-between">
|
|
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
|
|
+ <span className="w-5 h-5 bg-amber-300 border border-black flex items-center justify-center text-black text-[10px] font-black">
|
|
|
|
|
+ 1.6
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <label className="text-xs font-black uppercase tracking-wider text-black">
|
|
|
|
|
+ [ PAYMENT & PRICING // 收款模式、结算金额与入账登记 ]
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <span className="text-[10px] text-neutral-500 font-bold uppercase">
|
|
|
|
|
+ 先办后付 vs 现结核销
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="p-5 space-y-4">
|
|
|
|
|
+ {/* 收款时机选择 */}
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label className="text-xs font-black text-black uppercase block mb-2">
|
|
|
|
|
+ [ 1. 选择收款与业务节奏模式 ]
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
|
|
|
|
|
+ {/* Pay later */}
|
|
|
|
|
+ <div
|
|
|
|
|
+ onClick={() => setPaymentTiming('pay_later')}
|
|
|
|
|
+ className={`p-3.5 border-2 cursor-pointer transition ${
|
|
|
|
|
+ paymentTiming === 'pay_later'
|
|
|
|
|
+ ? 'border-black bg-amber-100 shadow-[3px_3px_0px_#000]'
|
|
|
|
|
+ : 'border-neutral-300 bg-neutral-50 hover:border-black'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ <div className="flex items-center justify-between mb-1">
|
|
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
|
|
+ <Clock size={16} className="text-amber-800" />
|
|
|
|
|
+ <span className="text-xs font-black text-black uppercase">[ 先办后付 // 稍后收款 ]</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <span className="px-1.5 py-0.5 bg-amber-300 border border-black text-[9px] font-black">
|
|
|
|
|
+ 业务推荐
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <p className="text-[11px] text-neutral-600 font-sans leading-relaxed">
|
|
|
|
|
+ 先替客户下单,<strong>任务立即下发队列调度</strong>。待出签办妥或客户打款后,在后台随时一键<strong>[ 登记收款 ]</strong>生成流水。
|
|
|
|
|
+ </p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ {/* Paid now */}
|
|
|
|
|
+ <div
|
|
|
|
|
+ onClick={() => setPaymentTiming('paid_now')}
|
|
|
|
|
+ className={`p-3.5 border-2 cursor-pointer transition ${
|
|
|
|
|
+ paymentTiming === 'paid_now'
|
|
|
|
|
+ ? 'border-black bg-emerald-100 shadow-[3px_3px_0px_#000]'
|
|
|
|
|
+ : 'border-neutral-300 bg-neutral-50 hover:border-black'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ <div className="flex items-center gap-2 mb-1">
|
|
|
|
|
+ <CheckCircle2 size={16} className="text-emerald-800" />
|
|
|
|
|
+ <span className="text-xs font-black text-black uppercase">[ 当场全款已收 // 现结录入 ]</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <p className="text-[11px] text-neutral-600 font-sans leading-relaxed">
|
|
|
|
|
+ 客户已通过微信/支付宝/公户全款转账,现场直接核销入账,立即在数据库生成<strong>已支付流水凭据</strong>。
|
|
|
|
|
+ </p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 金额输入及差额提示 */}
|
|
|
|
|
+ <div className="pt-3 border-t-2 border-dashed border-neutral-300 grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
|
<div>
|
|
<div>
|
|
|
<label className="text-xs font-black text-black uppercase block mb-1">
|
|
<label className="text-xs font-black text-black uppercase block mb-1">
|
|
|
- [ 实收结算价格 (元) ]
|
|
|
|
|
|
|
+ [ {paymentTiming === 'pay_later' ? '约定应收金额 (元)' : '实际到账金额 (元)'} ] <span className="text-rose-600">*</span>
|
|
|
</label>
|
|
</label>
|
|
|
<div className="relative">
|
|
<div className="relative">
|
|
|
- <span className="absolute left-3 top-2 text-xs font-bold text-black pointer-events-none">
|
|
|
|
|
|
|
+ <span className="absolute left-3 top-2.5 text-xs font-bold text-black pointer-events-none">
|
|
|
¥
|
|
¥
|
|
|
</span>
|
|
</span>
|
|
|
<input
|
|
<input
|
|
|
type="number"
|
|
type="number"
|
|
|
step="0.01"
|
|
step="0.01"
|
|
|
|
|
+ required
|
|
|
value={customPrice}
|
|
value={customPrice}
|
|
|
onChange={(e) => setCustomPrice(e.target.value)}
|
|
onChange={(e) => setCustomPrice(e.target.value)}
|
|
|
- placeholder="默认商品指导价"
|
|
|
|
|
- className="w-full pl-7 pr-3 py-2 border-2 border-black bg-neutral-50 text-xs font-mono font-bold focus:bg-white outline-none shadow-[2px_2px_0px_#000] text-black"
|
|
|
|
|
|
|
+ placeholder="商品指导价"
|
|
|
|
|
+ className="w-full pl-7 pr-3 py-2 border-2 border-black bg-neutral-50 text-xs font-mono font-black focus:bg-white outline-none shadow-[2px_2px_0px_#000] text-black"
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</div>
|
|
|
- <span className="text-[10px] text-neutral-500 font-mono mt-1 block">
|
|
|
|
|
- 留空则使用商品默认标价。若填写将覆盖商品基础价。
|
|
|
|
|
- </span>
|
|
|
|
|
|
|
+ <div className="text-[10px] text-neutral-500 font-mono mt-1 flex items-center justify-between">
|
|
|
|
|
+ <span>
|
|
|
|
|
+ 商品指导标价: ¥{((selectedProduct.price_amount || selectedProduct.base_price || 0) / 100).toFixed(2)}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ {customPrice && !isNaN(Number(customPrice)) && (
|
|
|
|
|
+ <span className={`font-bold ${
|
|
|
|
|
+ Number(customPrice) * 100 < (selectedProduct.price_amount || 0)
|
|
|
|
|
+ ? 'text-rose-600'
|
|
|
|
|
+ : Number(customPrice) * 100 > (selectedProduct.price_amount || 0)
|
|
|
|
|
+ ? 'text-emerald-700'
|
|
|
|
|
+ : 'text-neutral-500'
|
|
|
|
|
+ }`}>
|
|
|
|
|
+ 差额: ¥{((Number(customPrice) * 100 - (selectedProduct.price_amount || 0)) / 100).toFixed(2)}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+
|
|
|
|
|
+ {paymentTiming === 'pay_later' ? (
|
|
|
|
|
+ <div className="p-3 bg-amber-50 border border-black text-xs font-mono flex items-start gap-2">
|
|
|
|
|
+ <Clock size={16} className="text-amber-800 shrink-0 mt-0.5" />
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <span className="text-black font-black block mb-0.5">先办后付调度保障:</span>
|
|
|
|
|
+ <p className="text-[11px] text-neutral-700 font-sans leading-relaxed">
|
|
|
|
|
+ 订单创建后将自动标记为 <strong>[ 待收款 (先办后付) ]</strong>,抢单机器人将以最高优先级即刻开始抓取办理。后续款项到手后,在订单列表点击 <strong>[ 💰 登记收款 ]</strong> 即可补录流水。
|
|
|
|
|
+ </p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label className="text-xs font-black text-black uppercase block mb-1">
|
|
|
|
|
+ [ 收款渠道方式 ] <span className="text-rose-600">*</span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <div className="grid grid-cols-2 gap-2">
|
|
|
|
|
+ {[
|
|
|
|
|
+ { id: 'wechat', label: '微信私域转账' },
|
|
|
|
|
+ { id: 'alipay', label: '支付宝转账' },
|
|
|
|
|
+ { id: 'bank_transfer', label: '银行公户/私户' },
|
|
|
|
|
+ { id: 'cash', label: '现金收款' },
|
|
|
|
|
+ ].map((m) => (
|
|
|
|
|
+ <button
|
|
|
|
|
+ type="button"
|
|
|
|
|
+ key={m.id}
|
|
|
|
|
+ onClick={() => setPaymentMethod(m.id)}
|
|
|
|
|
+ className={`px-2.5 py-1.5 border-2 text-xs font-bold text-left transition ${
|
|
|
|
|
+ paymentMethod === m.id
|
|
|
|
|
+ ? 'border-black bg-amber-300 text-black shadow-[2px_2px_0px_#000]'
|
|
|
|
|
+ : 'border-neutral-300 bg-neutral-50 hover:border-black text-neutral-700'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ {m.label}
|
|
|
|
|
+ </button>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 当场结清时的补充凭据 */}
|
|
|
|
|
+ {paymentTiming === 'paid_now' && (
|
|
|
|
|
+ <div className="grid grid-cols-1 md:grid-cols-3 gap-3 pt-3 border-t border-dashed border-neutral-300">
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label className="text-[11px] font-bold text-black uppercase block mb-1">
|
|
|
|
|
+ 外部转账单号 (选填)
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ value={externalTradeNo}
|
|
|
|
|
+ onChange={(e) => setExternalTradeNo(e.target.value)}
|
|
|
|
|
+ placeholder="微信单号 / 银行流水号"
|
|
|
|
|
+ className="w-full px-2.5 py-1.5 border-2 border-black bg-neutral-50 text-xs font-mono font-bold focus:bg-white outline-none shadow-[2px_2px_0px_#000] text-black"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <ImageUploadField
|
|
|
|
|
+ label="转账水单/截图 (上传至 R2)"
|
|
|
|
|
+ value={voucherUrl}
|
|
|
|
|
+ onChange={setVoucherUrl}
|
|
|
|
|
+ prefix="vouchers"
|
|
|
|
|
+ maxSizeMB={5}
|
|
|
|
|
+ helperText="点击选择水单截图,自动上传至 R2 对象存储"
|
|
|
|
|
+ compact={true}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label className="text-[11px] font-bold text-black uppercase block mb-1">
|
|
|
|
|
+ 入账备注说明 (选填)
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ value={paymentNote}
|
|
|
|
|
+ onChange={(e) => setPaymentNote(e.target.value)}
|
|
|
|
|
+ placeholder="例如: 客户微信当面付清"
|
|
|
|
|
+ className="w-full px-2.5 py-1.5 border-2 border-black bg-neutral-50 text-xs font-mono font-bold focus:bg-white outline-none shadow-[2px_2px_0px_#000] text-black"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|