page.tsx 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. 'use client';
  2. import { useState, useEffect } from 'react';
  3. import { useRouter } from 'next/navigation';
  4. import { ArrowLeft, Users, Building2, Globe, DollarSign, Clock, CheckCircle2, ShieldCheck, Smartphone, Banknote } from 'lucide-react';
  5. import { productService, orderService, settlementService } from '@/lib/services';
  6. import { getCurrentUser } from '@/lib/auth';
  7. import ProductSearchSelector from '@/components/admin/orders/ProductSearchSelector';
  8. import AiDataParserPanel from '@/components/admin/orders/AiDataParserPanel';
  9. import DynamicOrderSchemaForm from '@/components/admin/orders/DynamicOrderSchemaForm';
  10. import AdminUserSelect from '@/components/common/AdminUserSelect';
  11. import { ImageUploadField } from '@/components/common/ImageUploadField';
  12. import { SchemaProperty, VasAgency } from '@/types';
  13. import { toast } from 'react-hot-toast';
  14. import { SUPPORTED_CURRENCIES, getCurrencySymbol } from '@/lib/currency';
  15. export default function AdminCreateOrderPage() {
  16. const router = useRouter();
  17. const [loading, setLoading] = useState(false);
  18. // 1. 商品状态
  19. const [selectedProduct, setSelectedProduct] = useState<any>(null);
  20. // 2. 渠道与分润归属状态
  21. const [channelType, setChannelType] = useState<'direct' | 'agency' | 'website'>('direct');
  22. const [handlerId, setHandlerId] = useState<string>('');
  23. const [agencies, setAgencies] = useState<VasAgency[]>([]);
  24. const [selectedAgencyId, setSelectedAgencyId] = useState<string>('');
  25. const [customPrice, setCustomPrice] = useState<string>(''); // 单位: 元/欧/刀
  26. const [currency, setCurrency] = useState<string>('CNY'); // 结算币种代码
  27. // 2.5 收款时机与收款登记状态
  28. const [paymentTiming, setPaymentTiming] = useState<'pay_later' | 'paid_now'>('pay_later');
  29. const [paymentMethod, setPaymentMethod] = useState<string>('wechat');
  30. const [externalTradeNo, setExternalTradeNo] = useState<string>('');
  31. const [voucherUrl, setVoucherUrl] = useState<string>('');
  32. const [paymentNote, setPaymentNote] = useState<string>('');
  33. // 3. 表单与 Schema 状态
  34. const [formSchema, setFormSchema] = useState<any>(null);
  35. const [formValues, setFormValues] = useState<Record<string, any>>({});
  36. const [sortedFields, setSortedFields] = useState<string[]>([]);
  37. // 加载中介列表与当前用户信息
  38. useEffect(() => {
  39. const user = getCurrentUser();
  40. if (user?.nickname || user?.id) {
  41. setHandlerId(user.nickname || user.id);
  42. }
  43. async function loadAgencies() {
  44. try {
  45. const res = await settlementService.listAgencies({ active_only: true });
  46. const list = res?.data?.items || res?.data || [];
  47. setAgencies(Array.isArray(list) ? list : []);
  48. } catch {
  49. setAgencies([]);
  50. }
  51. }
  52. loadAgencies();
  53. }, []);
  54. // 选中中介时自动锁定 handler_id
  55. const handleAgencySelect = (agencyId: string) => {
  56. setSelectedAgencyId(agencyId);
  57. const agency = agencies.find((a) => a.id === agencyId);
  58. if (agency) {
  59. setHandlerId(agency.owner_id);
  60. }
  61. };
  62. const selectedAgency = agencies.find((a) => a.id === selectedAgencyId);
  63. // 加载商品默认价与 Schema
  64. useEffect(() => {
  65. if (!selectedProduct) {
  66. setFormSchema(null);
  67. setSortedFields([]);
  68. setFormValues({});
  69. setCustomPrice('');
  70. return;
  71. }
  72. // 默认价格与币种填充: 优先取 price_amount,兼顾 base_price
  73. const prodCurrency = (selectedProduct.price_currency || selectedProduct.currency || 'CNY').toUpperCase();
  74. setCurrency(prodCurrency);
  75. if (selectedProduct.price_amount !== undefined) {
  76. setCustomPrice((selectedProduct.price_amount / 100).toFixed(2));
  77. } else if (selectedProduct.base_price !== undefined) {
  78. setCustomPrice((selectedProduct.base_price / 100).toFixed(2));
  79. }
  80. if (!selectedProduct.schema_id) {
  81. setFormSchema(null);
  82. setSortedFields([]);
  83. setFormValues({});
  84. return;
  85. }
  86. async function loadSchema() {
  87. try {
  88. const res = await productService.getSchemaDetail(selectedProduct.schema_id);
  89. const data = res?.data || res;
  90. const schemaJson =
  91. typeof data?.schema_json === 'string'
  92. ? JSON.parse(data.schema_json)
  93. : data?.schema_json;
  94. setFormSchema(schemaJson);
  95. setFormValues({});
  96. if (schemaJson?.properties) {
  97. const keys = Object.keys(schemaJson.properties);
  98. if (Array.isArray(schemaJson['ui:order'])) {
  99. setSortedFields(schemaJson['ui:order']);
  100. } else {
  101. const sorted = keys.sort((a, b) => {
  102. const propA = schemaJson.properties[a] as SchemaProperty;
  103. const propB = schemaJson.properties[b] as SchemaProperty;
  104. const orderA = propA['x-order'] ?? propA.order ?? 999;
  105. const orderB = propB['x-order'] ?? propB.order ?? 999;
  106. return orderA - orderB;
  107. });
  108. setSortedFields(sorted);
  109. }
  110. }
  111. } catch {
  112. toast.error('表单定义加载失败');
  113. }
  114. }
  115. loadSchema();
  116. }, [selectedProduct]);
  117. // AI 解析结果回填
  118. const handleAiFieldsParsed = (fields: Record<string, any>) => {
  119. setFormValues((prev) => ({
  120. ...prev,
  121. ...fields,
  122. }));
  123. };
  124. // 单个字段修改
  125. const handleInputChange = (key: string, value: any) => {
  126. setFormValues((prev) => ({ ...prev, [key]: value }));
  127. };
  128. // 提交订单
  129. const handleSubmit = async (e: React.FormEvent) => {
  130. e.preventDefault();
  131. if (!selectedProduct) return toast.error('请先搜索并选择商品');
  132. // 价格校验
  133. let finalAmountCents: number | undefined = undefined;
  134. if (customPrice && !isNaN(Number(customPrice))) {
  135. finalAmountCents = Math.round(Number(customPrice) * 100);
  136. }
  137. if (finalAmountCents === undefined || finalAmountCents <= 0) {
  138. return toast.error('请输入有效的金额 (必须大于 0)');
  139. }
  140. if (channelType === 'agency') {
  141. if (!selectedAgencyId) {
  142. return toast.error('请选择合作中介机构');
  143. }
  144. if (selectedAgency && finalAmountCents !== undefined && finalAmountCents < selectedAgency.min_floor_price) {
  145. const sym = getCurrencySymbol(currency);
  146. return toast.error(
  147. `录入价格 ${sym}${(finalAmountCents / 100).toFixed(2)} 低于该中介协议最低结算底价 ${sym}${(selectedAgency.min_floor_price / 100).toFixed(2)}!`
  148. );
  149. }
  150. }
  151. if (channelType === 'direct' && !handlerId.trim()) {
  152. return toast.error('社交自收直客单必须填写40%提成归属人ID/姓名');
  153. }
  154. setLoading(true);
  155. try {
  156. const payload = {
  157. product_id: selectedProduct.id,
  158. user_inputs: formValues,
  159. channel_type: channelType,
  160. agency_id: channelType === 'agency' ? selectedAgencyId : undefined,
  161. handler_id: channelType === 'website' ? undefined : handlerId.trim(),
  162. final_amount: finalAmountCents,
  163. currency: currency,
  164. payment_timing: paymentTiming,
  165. payment_method: paymentTiming === 'paid_now' ? paymentMethod : undefined,
  166. external_trade_no: paymentTiming === 'paid_now' ? (externalTradeNo.trim() || undefined) : undefined,
  167. voucher_url: paymentTiming === 'paid_now' ? (voucherUrl.trim() || undefined) : undefined,
  168. payment_note: paymentTiming === 'paid_now' ? (paymentNote.trim() || undefined) : undefined,
  169. };
  170. const res = await orderService.createByAdmin(payload);
  171. const orderId = res?.data?.id || res?.id || res?.data?.order_id || res?.order_id;
  172. if (paymentTiming === 'pay_later') {
  173. toast.success(`代客下单成功!任务已入队调度 [待出签/收款] 订单号: ${orderId}`);
  174. } else {
  175. toast.success(`代下单并收款核销成功!订单号: ${orderId}`);
  176. }
  177. router.push('/admin/orders');
  178. } catch (error: any) {
  179. console.error(error);
  180. toast.error('下单失败: ' + (error.response?.data?.message || error.message));
  181. } finally {
  182. setLoading(false);
  183. }
  184. };
  185. return (
  186. <div className="space-y-6 font-mono">
  187. {/* 头部导航 */}
  188. <div className="flex items-center justify-between border-b-2 border-black pb-4">
  189. <div className="flex items-center gap-3">
  190. <button
  191. onClick={() => router.back()}
  192. className="px-3 py-1.5 bg-white hover:bg-neutral-100 border-2 border-black text-xs font-bold uppercase shadow-[2px_2px_0px_#000] flex items-center gap-1"
  193. >
  194. <ArrowLeft size={14} /> [ 返回列表 ]
  195. </button>
  196. <div>
  197. <h1 className="text-base md:text-lg font-black uppercase text-black">
  198. [ DISPATCH // 管理员代客下单 ]
  199. </h1>
  200. <p className="text-[10px] text-neutral-500 font-mono">
  201. 手工为客户创建订单并即时下发抢单机器人调度队列
  202. </p>
  203. </div>
  204. </div>
  205. </div>
  206. <div className="space-y-6">
  207. {/* Step 1: 搜索选择商品 */}
  208. <ProductSearchSelector
  209. selectedProduct={selectedProduct}
  210. onSelectProduct={setSelectedProduct}
  211. />
  212. {/* Step 1.5: 渠道来源与合伙分润设置 */}
  213. {selectedProduct && (
  214. <div className="bg-white border-2 border-black shadow-[4px_4px_0px_#000] overflow-hidden">
  215. <div className="px-5 py-3 border-b-2 border-black bg-neutral-200 text-black flex items-center justify-between">
  216. <div className="flex items-center gap-2">
  217. <span className="w-5 h-5 bg-amber-300 border border-black flex items-center justify-center text-black text-[10px] font-black">
  218. 1.5
  219. </span>
  220. <label className="text-xs font-black uppercase tracking-wider text-black">
  221. [ CHANNEL & ASSIGNMENT // 渠道来源、销售归属与协议定价 ]
  222. </label>
  223. </div>
  224. <span className="text-[10px] text-neutral-500 font-bold uppercase">
  225. 40% 销售包干提成归属判定
  226. </span>
  227. </div>
  228. <div className="p-5 space-y-4">
  229. {/* 渠道类型选择 */}
  230. <div>
  231. <label className="text-xs font-black text-black uppercase block mb-2">
  232. [ 1. 选择业务合作渠道模式 ]
  233. </label>
  234. <div className="grid grid-cols-1 md:grid-cols-3 gap-3">
  235. {/* Direct */}
  236. <div
  237. onClick={() => {
  238. setChannelType('direct');
  239. const u = getCurrentUser();
  240. if (u?.nickname || u?.id) setHandlerId(u.nickname || u.id);
  241. }}
  242. className={`p-3.5 border-2 cursor-pointer transition ${
  243. channelType === 'direct'
  244. ? 'border-black bg-amber-100 shadow-[3px_3px_0px_#000]'
  245. : 'border-neutral-300 bg-neutral-50 hover:border-black'
  246. }`}
  247. >
  248. <div className="flex items-center gap-2 mb-1">
  249. <Users size={16} className="text-black" />
  250. <span className="text-xs font-black text-black uppercase">[ 社交自收直客 ]</span>
  251. </div>
  252. <p className="text-[11px] text-neutral-600 font-sans leading-relaxed">
  253. 小红书/微信自引流直客,拿该单 <strong>40% 销售包干提成</strong>,对录错承担全额赔偿。
  254. </p>
  255. </div>
  256. {/* Agency */}
  257. <div
  258. onClick={() => setChannelType('agency')}
  259. className={`p-3.5 border-2 cursor-pointer transition ${
  260. channelType === 'agency'
  261. ? 'border-black bg-purple-100 shadow-[3px_3px_0px_#000]'
  262. : 'border-neutral-300 bg-neutral-50 hover:border-black'
  263. }`}
  264. >
  265. <div className="flex items-center gap-2 mb-1">
  266. <Building2 size={16} className="text-purple-900" />
  267. <span className="text-xs font-black text-black uppercase">[ 中介同行渠道 ]</span>
  268. </div>
  269. <p className="text-[11px] text-neutral-600 font-sans leading-relaxed">
  270. 旅行社或同行转介绍,受<strong>专属底价</strong>保护,40%提成自动锁定归属该中介拓展人。
  271. </p>
  272. </div>
  273. {/* Website */}
  274. <div
  275. onClick={() => {
  276. setChannelType('website');
  277. setHandlerId('');
  278. }}
  279. className={`p-3.5 border-2 cursor-pointer transition ${
  280. channelType === 'website'
  281. ? 'border-black bg-neutral-200 shadow-[3px_3px_0px_#000]'
  282. : 'border-neutral-300 bg-neutral-50 hover:border-black'
  283. }`}
  284. >
  285. <div className="flex items-center gap-2 mb-1">
  286. <Globe size={16} className="text-black" />
  287. <span className="text-xs font-black text-black uppercase">[ 官网自主下单 ]</span>
  288. </div>
  289. <p className="text-[11px] text-neutral-600 font-sans leading-relaxed">
  290. 公海自然流量,无专属对接人,40%销售提成由合伙双方(各20%)平分。
  291. </p>
  292. </div>
  293. </div>
  294. </div>
  295. {/* 细化字段配置 */}
  296. <div className="grid grid-cols-1 md:grid-cols-2 gap-4 pt-3 border-t-2 border-dashed border-neutral-300">
  297. {/* Direct: 接单客服 */}
  298. {channelType === 'direct' && (
  299. <div>
  300. <AdminUserSelect
  301. value={handlerId}
  302. onChange={setHandlerId}
  303. label="40% 销售包干提成归属人 (系统管理员)"
  304. badgeText="客服/销售"
  305. placeholder="选择系统管理员作为提成人"
  306. helperText="若录错护照/姓名导致废单,损失从该人当期提成中全额扣减。"
  307. required
  308. />
  309. </div>
  310. )}
  311. {/* Agency: 选择中介 */}
  312. {channelType === 'agency' && (
  313. <div className="space-y-2">
  314. <label className="text-xs font-black text-black uppercase block mb-1">
  315. [ 合作中介机构档案 ] <span className="text-rose-600">*</span>
  316. </label>
  317. <select
  318. value={selectedAgencyId}
  319. onChange={(e) => handleAgencySelect(e.target.value)}
  320. className="w-full px-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 cursor-pointer"
  321. >
  322. <option value="">-- 请选择合作中介机构 --</option>
  323. {agencies.map((agency) => (
  324. <option key={agency.id} value={agency.id}>
  325. {agency.name} (最低底价: ¥{(agency.min_floor_price / 100).toFixed(2)})
  326. </option>
  327. ))}
  328. </select>
  329. {selectedAgency && (
  330. <div className="p-2.5 bg-neutral-100 border border-black text-[11px] font-mono space-y-1">
  331. <div>
  332. <span className="text-neutral-500 font-bold">专属拓展维系人: </span>
  333. <span className="text-black font-black">{selectedAgency.owner_id}</span>
  334. <span className="text-[10px] text-purple-700 ml-1">(自动绑定拿40%提成)</span>
  335. </div>
  336. <div>
  337. <span className="text-neutral-500 font-bold">协议最低底价: </span>
  338. <span className="text-rose-600 font-black">¥{(selectedAgency.min_floor_price / 100).toFixed(2)}</span>
  339. <span className="text-[10px] text-neutral-400 ml-1">低于此底价系统将阻断提交</span>
  340. </div>
  341. </div>
  342. )}
  343. </div>
  344. )}
  345. {/* Website */}
  346. {channelType === 'website' && (
  347. <div className="p-3 bg-neutral-100 border border-black text-xs font-mono">
  348. <span className="text-neutral-500 font-bold block mb-1">公海单利润流转:</span>
  349. <p className="text-[11px] text-neutral-700 font-sans">
  350. 该单无专属对接人。40% 销售提成与 40% 合伙分红合并,由合伙人甲乙双方各按 50%(每人到手40%净利)平分;技术版权费 20% 归脚本开发者。
  351. </p>
  352. </div>
  353. )}
  354. </div>
  355. </div>
  356. </div>
  357. )}
  358. {/* Step 1.6: 收款时机与金额登记 */}
  359. {selectedProduct && (
  360. <div className="bg-white border-2 border-black shadow-[4px_4px_0px_#000] overflow-hidden">
  361. <div className="px-5 py-3 border-b-2 border-black bg-neutral-200 text-black flex items-center justify-between">
  362. <div className="flex items-center gap-2">
  363. <span className="w-5 h-5 bg-amber-300 border border-black flex items-center justify-center text-black text-[10px] font-black">
  364. 1.6
  365. </span>
  366. <label className="text-xs font-black uppercase tracking-wider text-black">
  367. [ PAYMENT & PRICING // 收款模式、结算金额与入账登记 ]
  368. </label>
  369. </div>
  370. <span className="text-[10px] text-neutral-500 font-bold uppercase">
  371. 先办后付 vs 现结核销
  372. </span>
  373. </div>
  374. <div className="p-5 space-y-4">
  375. {/* 收款时机选择 */}
  376. <div>
  377. <label className="text-xs font-black text-black uppercase block mb-2">
  378. [ 1. 选择收款与业务节奏模式 ]
  379. </label>
  380. <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
  381. {/* Pay later */}
  382. <div
  383. onClick={() => setPaymentTiming('pay_later')}
  384. className={`p-3.5 border-2 cursor-pointer transition ${
  385. paymentTiming === 'pay_later'
  386. ? 'border-black bg-amber-100 shadow-[3px_3px_0px_#000]'
  387. : 'border-neutral-300 bg-neutral-50 hover:border-black'
  388. }`}
  389. >
  390. <div className="flex items-center justify-between mb-1">
  391. <div className="flex items-center gap-2">
  392. <Clock size={16} className="text-amber-800" />
  393. <span className="text-xs font-black text-black uppercase">[ 先办后付 // 稍后收款 ]</span>
  394. </div>
  395. <span className="px-1.5 py-0.5 bg-amber-300 border border-black text-[9px] font-black">
  396. 业务推荐
  397. </span>
  398. </div>
  399. <p className="text-[11px] text-neutral-600 font-sans leading-relaxed">
  400. 先替客户下单,<strong>任务立即下发队列调度</strong>。待出签办妥或客户打款后,在后台随时一键<strong>[ 登记收款 ]</strong>生成流水。
  401. </p>
  402. </div>
  403. {/* Paid now */}
  404. <div
  405. onClick={() => setPaymentTiming('paid_now')}
  406. className={`p-3.5 border-2 cursor-pointer transition ${
  407. paymentTiming === 'paid_now'
  408. ? 'border-black bg-emerald-100 shadow-[3px_3px_0px_#000]'
  409. : 'border-neutral-300 bg-neutral-50 hover:border-black'
  410. }`}
  411. >
  412. <div className="flex items-center gap-2 mb-1">
  413. <CheckCircle2 size={16} className="text-emerald-800" />
  414. <span className="text-xs font-black text-black uppercase">[ 当场全款已收 // 现结录入 ]</span>
  415. </div>
  416. <p className="text-[11px] text-neutral-600 font-sans leading-relaxed">
  417. 客户已通过微信/支付宝/公户全款转账,现场直接核销入账,立即在数据库生成<strong>已支付流水凭据</strong>。
  418. </p>
  419. </div>
  420. </div>
  421. </div>
  422. {/* 金额输入及差额提示 */}
  423. <div className="pt-3 border-t-2 border-dashed border-neutral-300 grid grid-cols-1 md:grid-cols-2 gap-4">
  424. <div>
  425. <div className="flex items-center justify-between mb-1">
  426. <label className="text-xs font-black text-black uppercase">
  427. [ {paymentTiming === 'pay_later' ? '约定应收金额' : '实际到账金额'} ] <span className="text-rose-600">*</span>
  428. </label>
  429. <div className="flex items-center gap-1.5">
  430. <span className="text-[10px] text-neutral-500 font-bold uppercase">币种:</span>
  431. <select
  432. value={currency}
  433. onChange={(e) => setCurrency(e.target.value)}
  434. className="px-2 py-0.5 border-2 border-black bg-amber-100 text-xs font-black cursor-pointer shadow-[1px_1px_0px_#000] focus:outline-hidden"
  435. >
  436. {SUPPORTED_CURRENCIES.map((c) => (
  437. <option key={c.code} value={c.code}>
  438. {c.name}
  439. </option>
  440. ))}
  441. </select>
  442. </div>
  443. </div>
  444. <div className="relative">
  445. <span className="absolute left-3 top-2.5 text-xs font-bold text-black pointer-events-none">
  446. {getCurrencySymbol(currency)}
  447. </span>
  448. <input
  449. type="number"
  450. step="0.01"
  451. required
  452. value={customPrice}
  453. onChange={(e) => setCustomPrice(e.target.value)}
  454. placeholder="商品指导价"
  455. className="w-full pl-8 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"
  456. />
  457. </div>
  458. <div className="text-[10px] text-neutral-500 font-mono mt-1 flex items-center justify-between">
  459. <span>
  460. 商品指导标价: {getCurrencySymbol(selectedProduct.price_currency || 'CNY')}{((selectedProduct.price_amount || selectedProduct.base_price || 0) / 100).toFixed(2)} ({selectedProduct.price_currency || 'CNY'})
  461. </span>
  462. {customPrice && !isNaN(Number(customPrice)) && (
  463. <span className={`font-bold ${
  464. Number(customPrice) * 100 < (selectedProduct.price_amount || 0)
  465. ? 'text-rose-600'
  466. : Number(customPrice) * 100 > (selectedProduct.price_amount || 0)
  467. ? 'text-emerald-700'
  468. : 'text-neutral-500'
  469. }`}>
  470. 差额: {Number(customPrice) * 100 >= (selectedProduct.price_amount || 0) ? '+' : ''}{getCurrencySymbol(currency)}{((Number(customPrice) * 100 - (selectedProduct.price_amount || 0)) / 100).toFixed(2)}
  471. </span>
  472. )}
  473. </div>
  474. </div>
  475. {paymentTiming === 'pay_later' ? (
  476. <div className="p-3 bg-amber-50 border border-black text-xs font-mono flex items-start gap-2">
  477. <Clock size={16} className="text-amber-800 shrink-0 mt-0.5" />
  478. <div>
  479. <span className="text-black font-black block mb-0.5">先办后付调度保障:</span>
  480. <p className="text-[11px] text-neutral-700 font-sans leading-relaxed">
  481. 订单创建后将自动标记为 <strong>[ 待收款 (先办后付) ]</strong>,抢单机器人将以最高优先级即刻开始抓取办理。后续款项到手后,在订单列表点击 <strong>[ 💰 登记收款 ]</strong> 即可补录流水。
  482. </p>
  483. </div>
  484. </div>
  485. ) : (
  486. <div>
  487. <label className="text-xs font-black text-black uppercase block mb-1">
  488. [ 收款渠道方式 ] <span className="text-rose-600">*</span>
  489. </label>
  490. <div className="grid grid-cols-2 gap-2">
  491. {[
  492. { id: 'wechat', label: '微信私域转账' },
  493. { id: 'alipay', label: '支付宝转账' },
  494. { id: 'bank_transfer', label: '银行公户/私户' },
  495. { id: 'cash', label: '现金收款' },
  496. ].map((m) => (
  497. <button
  498. type="button"
  499. key={m.id}
  500. onClick={() => setPaymentMethod(m.id)}
  501. className={`px-2.5 py-1.5 border-2 text-xs font-bold text-left transition ${
  502. paymentMethod === m.id
  503. ? 'border-black bg-amber-300 text-black shadow-[2px_2px_0px_#000]'
  504. : 'border-neutral-300 bg-neutral-50 hover:border-black text-neutral-700'
  505. }`}
  506. >
  507. {m.label}
  508. </button>
  509. ))}
  510. </div>
  511. </div>
  512. )}
  513. </div>
  514. {/* 当场结清时的补充凭据 */}
  515. {paymentTiming === 'paid_now' && (
  516. <div className="grid grid-cols-1 md:grid-cols-3 gap-3 pt-3 border-t border-dashed border-neutral-300">
  517. <div>
  518. <label className="text-[11px] font-bold text-black uppercase block mb-1">
  519. 外部转账单号 (选填)
  520. </label>
  521. <input
  522. type="text"
  523. value={externalTradeNo}
  524. onChange={(e) => setExternalTradeNo(e.target.value)}
  525. placeholder="微信单号 / 银行流水号"
  526. 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"
  527. />
  528. </div>
  529. <div>
  530. <ImageUploadField
  531. label="转账水单/截图 (上传至 R2)"
  532. value={voucherUrl}
  533. onChange={setVoucherUrl}
  534. prefix="vouchers"
  535. maxSizeMB={5}
  536. helperText="点击选择水单截图,自动上传至 R2 对象存储"
  537. compact={true}
  538. />
  539. </div>
  540. <div>
  541. <label className="text-[11px] font-bold text-black uppercase block mb-1">
  542. 入账备注说明 (选填)
  543. </label>
  544. <input
  545. type="text"
  546. value={paymentNote}
  547. onChange={(e) => setPaymentNote(e.target.value)}
  548. placeholder="例如: 客户微信当面付清"
  549. 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"
  550. />
  551. </div>
  552. </div>
  553. )}
  554. </div>
  555. </div>
  556. )}
  557. {/* Step 2: 填写表单 (含 AI) */}
  558. {selectedProduct && (
  559. <form onSubmit={handleSubmit}>
  560. <div className="bg-white border-2 border-black shadow-[4px_4px_0px_#000] overflow-hidden">
  561. <div className="px-5 py-3 border-b-2 border-black bg-neutral-200 text-black flex items-center gap-2">
  562. <span className="w-5 h-5 bg-amber-300 border border-black flex items-center justify-center text-black text-[10px] font-black">
  563. 02
  564. </span>
  565. <label className="text-xs font-black uppercase tracking-wider text-black">
  566. [ APPLICANT DOSSIER // 填写申请资料与 Schema 字段 ]
  567. </label>
  568. </div>
  569. {/* AI 智能填充面板 */}
  570. {formSchema && (
  571. <AiDataParserPanel
  572. schemaId={selectedProduct.schema_id}
  573. onFieldsParsed={handleAiFieldsParsed}
  574. />
  575. )}
  576. {/* 动态表单项及底部提交按钮 */}
  577. <DynamicOrderSchemaForm
  578. formSchema={formSchema}
  579. sortedFields={sortedFields}
  580. formValues={formValues}
  581. onInputChange={handleInputChange}
  582. onSubmit={handleSubmit}
  583. loading={loading}
  584. selectedProduct={selectedProduct}
  585. />
  586. </div>
  587. </form>
  588. )}
  589. </div>
  590. </div>
  591. );
  592. }