Compare commits
60 Commits
b392c28787
...
v3.4
| Author | SHA1 | Date | |
|---|---|---|---|
| 309b180087 | |||
| 118d57d710 | |||
| 0cb2b2cebb | |||
| daeb24bbeb | |||
| f4766d32ff | |||
| b920c894b9 | |||
| 37038a7591 | |||
| 944306e45c | |||
| 9ed0c24d11 | |||
| 50349dd8e9 | |||
| e2fd28a35b | |||
| 15c35c49de | |||
| a49d8d99b6 | |||
| aa9d689c76 | |||
| b59d4484ec | |||
| cd23119470 | |||
| 18ab639669 | |||
| fc03905777 | |||
| ea8152ebf3 | |||
| 78973e3fbf | |||
| 317f910f3c | |||
| d36fe13bcd | |||
| 15b878f2a4 | |||
| 09eda9a11e | |||
| 23c0cc7a5f | |||
| 1725b9e4b4 | |||
| cc9933d1ce | |||
| b810cabc6d | |||
| 25aee745cc | |||
| 097c7dec4b | |||
| 92cf51ba3d | |||
| 94d2a88581 | |||
| da21cd3daa | |||
| 19cb312465 | |||
| 2b7ef65cce | |||
| 745c192693 | |||
| 34532dc9bf | |||
| f053908acb | |||
| 959e0b66cb | |||
| ac1e0a9f13 | |||
| 2a208d5dea | |||
| 82c447b193 | |||
| 75765bf9d4 | |||
| 6479365d6a | |||
| d11757c854 | |||
| 479de04f7c | |||
| cebeefdb22 | |||
| e93e4a7721 | |||
| cd6b82abd8 | |||
| 047ffd7b16 | |||
| bca1d8afea | |||
| 0418370c31 | |||
| cd206d6baa | |||
| aeb72154a7 | |||
| e0d3c840a2 | |||
| f2303f7fb8 | |||
| fb530e2ff5 | |||
| 8c4419e04e | |||
| 85f2c156b0 | |||
| addfcfb0b1 |
@@ -51,7 +51,7 @@
|
|||||||
|-----|------|----------|
|
|-----|------|----------|
|
||||||
| ACC-010 | 工单 | 四类型;总部决策;补发/退款流转 |
|
| ACC-010 | 工单 | 四类型;总部决策;补发/退款流转 |
|
||||||
| ACC-011 | 发票 | 四组合申请;2 工作日回传;可下载 |
|
| ACC-011 | 发票 | 四组合申请;2 工作日回传;可下载 |
|
||||||
| ACC-012 | 代下单 | W3:手机号建用户;权益自动发 |
|
| ACC-012 | 代下单 | W3:客户+合伙人双短信;手机号建用户(来源 PARTNER_PROXY);线下确认后已付款已完成并发权益;C 端展示代下单人 |
|
||||||
| ACC-013 | 问卷评价 | 成交问卷无激励;核销评价;总部可看 |
|
| ACC-013 | 问卷评价 | 成交问卷无激励;核销评价;总部可看 |
|
||||||
| ACC-014 | 推广分享 | 推广码归因;商品分享带渠道 |
|
| ACC-014 | 推广分享 | 推广码归因;商品分享带渠道 |
|
||||||
| ACC-018 | 话术 | OPT-012 3 日内对齐 |
|
| ACC-018 | 话术 | OPT-012 3 日内对齐 |
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ import ResourcesPage from './pages/ResourcesPage';
|
|||||||
import StoreBillsPage from './pages/StoreBillsPage';
|
import StoreBillsPage from './pages/StoreBillsPage';
|
||||||
import PartnerBillsPage from './pages/PartnerBillsPage';
|
import PartnerBillsPage from './pages/PartnerBillsPage';
|
||||||
import WineryBillsPage from './pages/WineryBillsPage';
|
import WineryBillsPage from './pages/WineryBillsPage';
|
||||||
|
import LogisticsBillsPage from './pages/LogisticsBillsPage';
|
||||||
import TicketsPage from './pages/TicketsPage';
|
import TicketsPage from './pages/TicketsPage';
|
||||||
|
import SupportTicketsPage from './pages/SupportTicketsPage';
|
||||||
import InvoicesPage from './pages/InvoicesPage';
|
import InvoicesPage from './pages/InvoicesPage';
|
||||||
import UserLogsPage from './pages/UserLogsPage';
|
import UserLogsPage from './pages/UserLogsPage';
|
||||||
import HqLogsPage from './pages/HqLogsPage';
|
import HqLogsPage from './pages/HqLogsPage';
|
||||||
@@ -41,6 +43,9 @@ import PartnerLogsPage from './pages/PartnerLogsPage';
|
|||||||
import WechatBindingsPage from './pages/WechatBindingsPage';
|
import WechatBindingsPage from './pages/WechatBindingsPage';
|
||||||
import HqPermissionsPage from './pages/HqPermissionsPage';
|
import HqPermissionsPage from './pages/HqPermissionsPage';
|
||||||
import SystemSettingsPage from './pages/SystemSettingsPage';
|
import SystemSettingsPage from './pages/SystemSettingsPage';
|
||||||
|
import WecomBotsPage from './pages/WecomBotsPage';
|
||||||
|
import LlmConfigsPage from './pages/LlmConfigsPage';
|
||||||
|
import KnowledgeBasesPage from './pages/KnowledgeBasesPage';
|
||||||
|
|
||||||
function RequireAuth({ children }: { children: React.ReactNode }) {
|
function RequireAuth({ children }: { children: React.ReactNode }) {
|
||||||
if (!getToken()) return <Navigate to="/login" replace />;
|
if (!getToken()) return <Navigate to="/login" replace />;
|
||||||
@@ -67,6 +72,9 @@ export default function App() {
|
|||||||
<Route index element={<PromoCodeDetailPage />} />
|
<Route index element={<PromoCodeDetailPage />} />
|
||||||
<Route path="users" element={<PromoCodeUsersPage />} />
|
<Route path="users" element={<PromoCodeUsersPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
<Route path="/wecom-bots" element={<WecomBotsPage />} />
|
||||||
|
<Route path="/llm-configs" element={<LlmConfigsPage />} />
|
||||||
|
<Route path="/knowledge-bases" element={<KnowledgeBasesPage />} />
|
||||||
<Route path="/products" element={<ProductsPage />} />
|
<Route path="/products" element={<ProductsPage />} />
|
||||||
<Route path="/product-detail-templates" element={<ProductDetailTemplatesPage />} />
|
<Route path="/product-detail-templates" element={<ProductDetailTemplatesPage />} />
|
||||||
<Route path="/stores" element={<StoresPage />} />
|
<Route path="/stores" element={<StoresPage />} />
|
||||||
@@ -88,10 +96,12 @@ export default function App() {
|
|||||||
<Route path="/finance/store-bills" element={<StoreBillsPage />} />
|
<Route path="/finance/store-bills" element={<StoreBillsPage />} />
|
||||||
<Route path="/finance/partner-bills" element={<PartnerBillsPage />} />
|
<Route path="/finance/partner-bills" element={<PartnerBillsPage />} />
|
||||||
<Route path="/finance/winery-bills" element={<WineryBillsPage />} />
|
<Route path="/finance/winery-bills" element={<WineryBillsPage />} />
|
||||||
|
<Route path="/finance/logistics-bills" element={<LogisticsBillsPage />} />
|
||||||
<Route path="/store-bills" element={<Navigate to="/finance/store-bills" replace />} />
|
<Route path="/store-bills" element={<Navigate to="/finance/store-bills" replace />} />
|
||||||
<Route path="/store-payouts" element={<Navigate to="/finance/store-bills" replace />} />
|
<Route path="/store-payouts" element={<Navigate to="/finance/store-bills" replace />} />
|
||||||
<Route path="/partner-bills" element={<Navigate to="/finance/partner-bills" replace />} />
|
<Route path="/partner-bills" element={<Navigate to="/finance/partner-bills" replace />} />
|
||||||
<Route path="/tickets" element={<TicketsPage />} />
|
<Route path="/tickets" element={<TicketsPage />} />
|
||||||
|
<Route path="/tickets/support" element={<SupportTicketsPage />} />
|
||||||
<Route path="/invoices" element={<InvoicesPage />} />
|
<Route path="/invoices" element={<InvoicesPage />} />
|
||||||
<Route path="/logs/users" element={<UserLogsPage />} />
|
<Route path="/logs/users" element={<UserLogsPage />} />
|
||||||
<Route path="/logs/stores" element={<StoreLogsPage />} />
|
<Route path="/logs/stores" element={<StoreLogsPage />} />
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { useMemo } from 'react';
|
||||||
|
import { Select } from 'antd';
|
||||||
|
import { getDistrictOptionsByCityCode } from '../lib/china-region';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
cityCode?: string | null;
|
||||||
|
value?: string[];
|
||||||
|
onChange?: (value: string[]) => void;
|
||||||
|
placeholder?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 已选开城城市后,仅多选该市下区县(不再选省/市) */
|
||||||
|
export default function CityDistrictMultiSelect({
|
||||||
|
cityCode,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
placeholder,
|
||||||
|
disabled,
|
||||||
|
}: Props) {
|
||||||
|
const options = useMemo(() => getDistrictOptionsByCityCode(cityCode), [cityCode]);
|
||||||
|
const ready = Boolean(cityCode) && options.length > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
mode="multiple"
|
||||||
|
allowClear
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
disabled={disabled || !ready}
|
||||||
|
placeholder={
|
||||||
|
placeholder ??
|
||||||
|
(cityCode ? (ready ? '请选择区县(可多选)' : '该城市暂无区县数据') : '请先选择开城城市')
|
||||||
|
}
|
||||||
|
options={options}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
maxTagCount="responsive"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Cascader,
|
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Drawer,
|
Drawer,
|
||||||
Form,
|
Form,
|
||||||
@@ -27,8 +26,9 @@ import {
|
|||||||
type PartnerPermissionKey,
|
type PartnerPermissionKey,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
import { CHINA_REGION_OPTIONS } from '../lib/china-region';
|
import { districtCodeLabel, formatDistrictLabels } from '../lib/china-region';
|
||||||
import { fmtTime } from '../lib/constants';
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import CityDistrictMultiSelect from './CityDistrictMultiSelect';
|
||||||
import PartnerSubAccountList from './PartnerSubAccountList';
|
import PartnerSubAccountList from './PartnerSubAccountList';
|
||||||
|
|
||||||
type PartnerRow = {
|
type PartnerRow = {
|
||||||
@@ -37,6 +37,7 @@ type PartnerRow = {
|
|||||||
phone: string;
|
phone: string;
|
||||||
name: string;
|
name: string;
|
||||||
scopeType?: string;
|
scopeType?: string;
|
||||||
|
districtCodes?: string[] | null;
|
||||||
orderCommissionRate?: number;
|
orderCommissionRate?: number;
|
||||||
redeemCommissionRate?: number;
|
redeemCommissionRate?: number;
|
||||||
accountCount: number;
|
accountCount: number;
|
||||||
@@ -65,6 +66,7 @@ type PartnerDetail = PartnerRow & {
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
cityId: string;
|
cityId: string;
|
||||||
|
cityCode?: string;
|
||||||
maxPartnerCommissionRate?: number;
|
maxPartnerCommissionRate?: number;
|
||||||
onChanged?: () => void;
|
onChanged?: () => void;
|
||||||
};
|
};
|
||||||
@@ -92,14 +94,31 @@ function commissionSumError(
|
|||||||
redeemPercent: number,
|
redeemPercent: number,
|
||||||
maxRate: number,
|
maxRate: number,
|
||||||
): string | null {
|
): string | null {
|
||||||
const sum = orderPercent / 100 + redeemPercent / 100;
|
// API 可能把 Prisma Decimal 序列化为字符串;`"0.05" + 1e-9` 会变成字符串拼接导致误判超限
|
||||||
if (sum > maxRate + 1e-9) {
|
const max = Number(maxRate);
|
||||||
return `订单佣金与核销佣金合计不得超过 ${(maxRate * 100).toFixed(2)}%(当前 ${(sum * 100).toFixed(2)}%)`;
|
const sum = Number(orderPercent) / 100 + Number(redeemPercent) / 100;
|
||||||
|
if (!Number.isFinite(max) || !Number.isFinite(sum)) return '佣金比例无效';
|
||||||
|
if (sum > max + 1e-9) {
|
||||||
|
return `订单佣金与核销佣金合计不得超过 ${(max * 100).toFixed(2)}%(当前 ${(sum * 100).toFixed(2)}%)`;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0.05, onChanged }: Props) {
|
function formatApiError(err: unknown): string | null {
|
||||||
|
if (err && typeof err === 'object' && 'errorFields' in err) return null;
|
||||||
|
if (!(err instanceof Error)) return '操作失败';
|
||||||
|
return err.message.replace(/\b(\d{6})\b/g, (code) => {
|
||||||
|
const label = districtCodeLabel(code);
|
||||||
|
return label !== code ? `${label}(${code})` : code;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CityPartnersPanel({
|
||||||
|
cityId,
|
||||||
|
cityCode,
|
||||||
|
maxPartnerCommissionRate = 0.05,
|
||||||
|
onChanged,
|
||||||
|
}: Props) {
|
||||||
const [editForm] = Form.useForm();
|
const [editForm] = Form.useForm();
|
||||||
const [createForm] = Form.useForm();
|
const [createForm] = Form.useForm();
|
||||||
const [subForm] = Form.useForm();
|
const [subForm] = Form.useForm();
|
||||||
@@ -153,29 +172,34 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
|
|
||||||
async function savePartner() {
|
async function savePartner() {
|
||||||
if (!detail) return;
|
if (!detail) return;
|
||||||
const v = await editForm.validateFields();
|
try {
|
||||||
const err = commissionSumError(
|
const v = await editForm.validateFields();
|
||||||
Number(v.orderCommissionRate ?? 0),
|
const err = commissionSumError(
|
||||||
Number(v.redeemCommissionRate ?? 0),
|
Number(v.orderCommissionRate ?? 0),
|
||||||
maxPartnerCommissionRate,
|
Number(v.redeemCommissionRate ?? 0),
|
||||||
);
|
maxPartnerCommissionRate,
|
||||||
if (err) {
|
);
|
||||||
message.error(err);
|
if (err) {
|
||||||
return;
|
message.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request(`/admin/partners/${detail.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...v,
|
||||||
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
|
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已保存');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
void loadPartners();
|
||||||
|
onChanged?.();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
}
|
}
|
||||||
await request(`/admin/partners/${detail.id}`, {
|
|
||||||
method: 'PUT',
|
|
||||||
body: JSON.stringify({
|
|
||||||
...v,
|
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
|
||||||
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
message.success('已保存');
|
|
||||||
setDrawerOpen(false);
|
|
||||||
void loadPartners();
|
|
||||||
onChanged?.();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteSubAccount(subId: string) {
|
async function deleteSubAccount(subId: string) {
|
||||||
@@ -187,6 +211,14 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<PartnerRow> = [
|
const columns: ColumnsType<PartnerRow> = [
|
||||||
|
{
|
||||||
|
title: '区县',
|
||||||
|
dataIndex: 'districtCodes',
|
||||||
|
width: 160,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (codes: string[] | null | undefined, row) =>
|
||||||
|
row.scopeType === CityPartnerScopeType.CITY_WIDE ? '全城' : formatDistrictLabels(codes),
|
||||||
|
},
|
||||||
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
||||||
{ title: '主账号', dataIndex: 'phone', width: 120 },
|
{ title: '主账号', dataIndex: 'phone', width: 120 },
|
||||||
{
|
{
|
||||||
@@ -249,11 +281,11 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
label: '主账号',
|
label: '主账号',
|
||||||
children: (
|
children: (
|
||||||
<Form form={editForm} layout="vertical">
|
<Form form={editForm} layout="vertical">
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="companyName" label="公司名"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="contactPhone" label="业务联系电话"><Input /></Form.Item>
|
<Form.Item name="contactPhone" label="业务联系电话"><Input /></Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="address" label="地址"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="bindingStatus" label="绑定状态" rules={[{ required: true }]}>
|
<Form.Item name="bindingStatus" label="绑定状态" rules={[{ required: true }]}>
|
||||||
<Select options={BINDING_OPTIONS} />
|
<Select options={BINDING_OPTIONS} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -261,8 +293,12 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县">
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={cityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
@@ -316,42 +352,51 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
<Modal title="新建城市合伙人" open={createOpen} width={560} onCancel={() => setCreateOpen(false)} onOk={async () => {
|
<Modal title="新建城市合伙人" open={createOpen} width={560} onCancel={() => setCreateOpen(false)} onOk={async () => {
|
||||||
const v = await createForm.validateFields();
|
try {
|
||||||
const err = commissionSumError(
|
const v = await createForm.validateFields();
|
||||||
Number(v.orderCommissionRate ?? 0),
|
const err = commissionSumError(
|
||||||
Number(v.redeemCommissionRate ?? 3),
|
Number(v.orderCommissionRate ?? 0),
|
||||||
maxPartnerCommissionRate,
|
Number(v.redeemCommissionRate ?? 3),
|
||||||
);
|
maxPartnerCommissionRate,
|
||||||
if (err) {
|
);
|
||||||
message.error(err);
|
if (err) {
|
||||||
return;
|
message.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request('/admin/partners', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...v,
|
||||||
|
cityId,
|
||||||
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
|
districtCodes: createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
|
void loadPartners();
|
||||||
|
onChanged?.();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
}
|
}
|
||||||
await request('/admin/partners', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({
|
|
||||||
...v,
|
|
||||||
cityId,
|
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
|
||||||
districtCodes: createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
message.success('已创建');
|
|
||||||
setCreateOpen(false);
|
|
||||||
void loadPartners();
|
|
||||||
onChanged?.();
|
|
||||||
}}>
|
}}>
|
||||||
<Form form={createForm} layout="vertical">
|
<Form form={createForm} layout="vertical">
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="companyName" label="公司名"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="address" label="地址"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县" rules={[{ required: true }]}>
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="选填;仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={cityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Button, Space } from 'antd';
|
||||||
|
import { ArrowDownOutlined, ArrowUpOutlined, DeleteOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
|
import {
|
||||||
|
parseMiniHomeBanners,
|
||||||
|
serializeMiniHomeBanners,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import OssUpload from './OssUpload';
|
||||||
|
|
||||||
|
const MAX_BANNERS = 8;
|
||||||
|
|
||||||
|
/** 编辑态保留空位;下发/入库仍用 parseMiniHomeBanners 过滤空串 */
|
||||||
|
function parseBannersForEdit(raw?: string | null): string[] {
|
||||||
|
if (!raw?.trim()) return [];
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(raw.trim()) as unknown;
|
||||||
|
if (!Array.isArray(parsed)) return parseMiniHomeBanners(raw);
|
||||||
|
return parsed
|
||||||
|
.filter((u): u is string => typeof u === 'string')
|
||||||
|
.map((u) => u.trim())
|
||||||
|
.slice(0, MAX_BANNERS);
|
||||||
|
} catch {
|
||||||
|
return parseMiniHomeBanners(raw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ant Form 控件:单图 URL 字符串(默认 OSS 路径 footer) */
|
||||||
|
export function ConfigImageField({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
bizType = 'footer',
|
||||||
|
}: {
|
||||||
|
value?: string;
|
||||||
|
onChange?: (url: string) => void;
|
||||||
|
bizType?: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<OssUpload
|
||||||
|
bizType={bizType}
|
||||||
|
mediaType="IMAGE"
|
||||||
|
value={value ?? ''}
|
||||||
|
onChange={(url) => onChange?.(url ?? '')}
|
||||||
|
placeholder="上传或粘贴图片 URL"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ant Form 控件:多图 JSON 字符串(默认 OSS 路径 swiper) */
|
||||||
|
export function ConfigImageListField({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
bizType = 'swiper',
|
||||||
|
}: {
|
||||||
|
value?: string;
|
||||||
|
onChange?: (json: string) => void;
|
||||||
|
bizType?: string;
|
||||||
|
}) {
|
||||||
|
const [urls, setUrls] = useState<string[]>(() => parseBannersForEdit(value));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setUrls(parseBannersForEdit(value));
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
|
/** 本地可含空位;写入 Form 时去掉空串 */
|
||||||
|
function commit(next: string[]) {
|
||||||
|
const clipped = next.slice(0, MAX_BANNERS);
|
||||||
|
setUrls(clipped);
|
||||||
|
onChange?.(serializeMiniHomeBanners(clipped));
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAt(index: number, url: string) {
|
||||||
|
const next = [...urls];
|
||||||
|
next[index] = url;
|
||||||
|
commit(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeAt(index: number) {
|
||||||
|
commit(urls.filter((_, i) => i !== index));
|
||||||
|
}
|
||||||
|
|
||||||
|
function move(index: number, delta: number) {
|
||||||
|
const target = index + delta;
|
||||||
|
if (target < 0 || target >= urls.length) return;
|
||||||
|
const next = [...urls];
|
||||||
|
const tmp = next[index];
|
||||||
|
next[index] = next[target];
|
||||||
|
next[target] = tmp;
|
||||||
|
commit(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
function add() {
|
||||||
|
if (urls.length >= MAX_BANNERS) return;
|
||||||
|
// 只加本地空位,避免 serialize 过滤空串导致「点击无反应」
|
||||||
|
setUrls((prev) => [...prev, '']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Space direction="vertical" style={{ width: '100%' }} size="middle">
|
||||||
|
{urls.map((url, index) => (
|
||||||
|
<Space key={`banner-${index}`} align="start" style={{ width: '100%' }} wrap>
|
||||||
|
<div style={{ flex: 1, minWidth: 240 }}>
|
||||||
|
<OssUpload
|
||||||
|
bizType={bizType}
|
||||||
|
mediaType="IMAGE"
|
||||||
|
value={url}
|
||||||
|
onChange={(u) => updateAt(index, u)}
|
||||||
|
placeholder="上传或粘贴图片 URL"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
icon={<ArrowUpOutlined />}
|
||||||
|
disabled={index === 0}
|
||||||
|
onClick={() => move(index, -1)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
icon={<ArrowDownOutlined />}
|
||||||
|
disabled={index === urls.length - 1}
|
||||||
|
onClick={() => move(index, 1)}
|
||||||
|
/>
|
||||||
|
<Button type="text" danger icon={<DeleteOutlined />} onClick={() => removeAt(index)} />
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
))}
|
||||||
|
<Button
|
||||||
|
type="dashed"
|
||||||
|
block
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
disabled={urls.length >= MAX_BANNERS}
|
||||||
|
onClick={add}
|
||||||
|
>
|
||||||
|
添加轮播图({urls.length}/{MAX_BANNERS})
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { Button, Empty, Input, List, Modal, Space, Spin, Typography, message } from 'antd';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import {
|
||||||
|
placeToPicked,
|
||||||
|
type LbsPlaceItem,
|
||||||
|
type TencentPickedLocation,
|
||||||
|
} from '../lib/tencentLocPicker';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onPick: (loc: TencentPickedLocation) => void;
|
||||||
|
latitude?: number | null;
|
||||||
|
longitude?: number | null;
|
||||||
|
/** 城市名,提升搜索相关性 */
|
||||||
|
region?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
function hasCoords(lat: unknown, lng: unknown): lat is number {
|
||||||
|
const a = typeof lat === 'number' ? lat : Number(lat);
|
||||||
|
const b = typeof lng === 'number' ? lng : Number(lng);
|
||||||
|
return Number.isFinite(a) && Number.isFinite(b) && !(a === 0 && b === 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TencentLocPickerModal({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
onPick,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
region,
|
||||||
|
}: Props) {
|
||||||
|
const [keyword, setKeyword] = useState('');
|
||||||
|
const [items, setItems] = useState<LbsPlaceItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [pending, setPending] = useState<TencentPickedLocation | null>(null);
|
||||||
|
const [hint, setHint] = useState('输入地点名称搜索,或加载附近地点');
|
||||||
|
const seqRef = useRef(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) {
|
||||||
|
setKeyword('');
|
||||||
|
setItems([]);
|
||||||
|
setPending(null);
|
||||||
|
setHint('输入地点名称搜索,或加载附近地点');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const lat = latitude != null ? Number(latitude) : NaN;
|
||||||
|
const lng = longitude != null ? Number(longitude) : NaN;
|
||||||
|
if (hasCoords(lat, lng)) {
|
||||||
|
void loadNearby(lat, lng);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
async function loadNearby(lat: number, lng: number) {
|
||||||
|
const seq = ++seqRef.current;
|
||||||
|
setLoading(true);
|
||||||
|
setHint('正在加载附近地点…');
|
||||||
|
try {
|
||||||
|
const res = await request<{ items: LbsPlaceItem[] }>(
|
||||||
|
`/common/lbs/nearby?lat=${encodeURIComponent(String(lat))}&lng=${encodeURIComponent(String(lng))}`,
|
||||||
|
);
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
setItems(res.items ?? []);
|
||||||
|
setHint(res.items?.length ? `附近 ${res.items.length} 个地点,点击选择` : '附近暂无地点,请搜索');
|
||||||
|
} catch (e) {
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
const msg = e instanceof Error ? e.message : '加载附近地点失败';
|
||||||
|
setItems([]);
|
||||||
|
setHint(msg);
|
||||||
|
message.error(msg);
|
||||||
|
} finally {
|
||||||
|
if (seq === seqRef.current) setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runSearch(q: string) {
|
||||||
|
const trimmed = q.trim();
|
||||||
|
if (!trimmed) {
|
||||||
|
message.warning('请输入搜索关键词');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const seq = ++seqRef.current;
|
||||||
|
setLoading(true);
|
||||||
|
setHint('搜索中…');
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams({ keyword: trimmed });
|
||||||
|
if (region?.trim()) params.set('region', region.trim());
|
||||||
|
const lat = latitude != null ? Number(latitude) : NaN;
|
||||||
|
const lng = longitude != null ? Number(longitude) : NaN;
|
||||||
|
if (Number.isFinite(lat) && Number.isFinite(lng)) {
|
||||||
|
params.set('lat', String(lat));
|
||||||
|
params.set('lng', String(lng));
|
||||||
|
}
|
||||||
|
const res = await request<{ items: LbsPlaceItem[] }>(`/common/lbs/suggest?${params.toString()}`);
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
setItems(res.items ?? []);
|
||||||
|
setHint(res.items?.length ? `找到 ${res.items.length} 个结果,点击选择` : '无匹配结果,换个关键词试试');
|
||||||
|
} catch (e) {
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
const msg = e instanceof Error ? e.message : '搜索失败';
|
||||||
|
setItems([]);
|
||||||
|
setHint(msg);
|
||||||
|
message.error(msg);
|
||||||
|
} finally {
|
||||||
|
if (seq === seqRef.current) setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function useBrowserLocation() {
|
||||||
|
if (!navigator.geolocation) {
|
||||||
|
message.error('当前浏览器不支持定位');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLoading(true);
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
(pos) => {
|
||||||
|
const lat = pos.coords.latitude;
|
||||||
|
const lng = pos.coords.longitude;
|
||||||
|
setPending({ latitude: lat, longitude: lng, name: '当前位置' });
|
||||||
|
void loadNearby(lat, lng);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
setLoading(false);
|
||||||
|
message.error('定位失败,请检查浏览器定位权限');
|
||||||
|
},
|
||||||
|
{ enableHighAccuracy: true, timeout: 12000 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmPick() {
|
||||||
|
if (!pending) {
|
||||||
|
message.warning('请先从列表中选择一个地点');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onPick(pending);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title="地图选点(腾讯位置服务)"
|
||||||
|
open={open}
|
||||||
|
onCancel={onClose}
|
||||||
|
width={720}
|
||||||
|
destroyOnClose
|
||||||
|
footer={
|
||||||
|
<Space style={{ width: '100%', justifyContent: 'space-between' }}>
|
||||||
|
<Typography.Text type="secondary" style={{ maxWidth: 420 }} ellipsis>
|
||||||
|
{pending
|
||||||
|
? `${pending.latitude.toFixed(6)}, ${pending.longitude.toFixed(6)}${
|
||||||
|
pending.name ? ` · ${pending.name}` : ''
|
||||||
|
}`
|
||||||
|
: '搜索或选择附近地点后确认'}
|
||||||
|
</Typography.Text>
|
||||||
|
<Space>
|
||||||
|
<Button onClick={onClose}>取消</Button>
|
||||||
|
<Button type="primary" disabled={!pending} onClick={confirmPick}>
|
||||||
|
确认选点
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Space direction="vertical" style={{ width: '100%' }} size="middle">
|
||||||
|
<Space.Compact style={{ width: '100%' }}>
|
||||||
|
<Input
|
||||||
|
allowClear
|
||||||
|
placeholder="输入小区 / 写字楼 / 门店名称"
|
||||||
|
value={keyword}
|
||||||
|
onChange={(e) => setKeyword(e.target.value)}
|
||||||
|
onPressEnter={() => void runSearch(keyword)}
|
||||||
|
/>
|
||||||
|
<Button type="primary" loading={loading} onClick={() => void runSearch(keyword)}>
|
||||||
|
搜索
|
||||||
|
</Button>
|
||||||
|
</Space.Compact>
|
||||||
|
<Space wrap>
|
||||||
|
<Button onClick={useBrowserLocation} disabled={loading}>
|
||||||
|
定位当前位置
|
||||||
|
</Button>
|
||||||
|
<Typography.Text type="secondary">{hint}</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
<div style={{ height: 420, overflow: 'auto', border: '1px solid #f0f0f0', borderRadius: 8 }}>
|
||||||
|
{loading && !items.length ? (
|
||||||
|
<div style={{ height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<Spin tip="加载中…" />
|
||||||
|
</div>
|
||||||
|
) : items.length ? (
|
||||||
|
<List
|
||||||
|
size="small"
|
||||||
|
dataSource={items}
|
||||||
|
renderItem={(item) => {
|
||||||
|
const active =
|
||||||
|
pending?.latitude === item.latitude && pending?.longitude === item.longitude;
|
||||||
|
return (
|
||||||
|
<List.Item
|
||||||
|
style={{
|
||||||
|
cursor: 'pointer',
|
||||||
|
background: active ? 'rgba(22, 119, 255, 0.08)' : undefined,
|
||||||
|
paddingInline: 12,
|
||||||
|
}}
|
||||||
|
onClick={() => setPending(placeToPicked(item))}
|
||||||
|
>
|
||||||
|
<List.Item.Meta
|
||||||
|
title={item.title}
|
||||||
|
description={
|
||||||
|
<span>
|
||||||
|
{item.address}
|
||||||
|
<br />
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
{item.latitude.toFixed(6)}, {item.longitude.toFixed(6)}
|
||||||
|
</Typography.Text>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</List.Item>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Empty style={{ marginTop: 80 }} description={hint} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Space>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
|
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
|
||||||
import { Layout, Menu, Typography, Button, Space } from 'antd';
|
import { Layout, Menu, Typography, Button, Space } from 'antd';
|
||||||
import type { MenuProps } from 'antd';
|
import type { MenuProps } from 'antd';
|
||||||
import {
|
import {
|
||||||
|
RobotOutlined,
|
||||||
DashboardOutlined,
|
DashboardOutlined,
|
||||||
UserOutlined,
|
UserOutlined,
|
||||||
ShoppingOutlined,
|
ShoppingOutlined,
|
||||||
@@ -18,11 +19,14 @@ import {
|
|||||||
SettingOutlined,
|
SettingOutlined,
|
||||||
AccountBookOutlined,
|
AccountBookOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
|
import { hasAnySystemSettingsPermission } from '@dukang/shared-types';
|
||||||
import { clearAuth, request, type HqProfile } from '../lib/api';
|
import { clearAuth, request, type HqProfile } from '../lib/api';
|
||||||
import { bindAdminEllipsisTitle } from '../lib/ellipsis-title';
|
import { bindAdminEllipsisTitle } from '../lib/ellipsis-title';
|
||||||
|
|
||||||
const { Header, Sider, Content } = Layout;
|
const { Header, Sider, Content } = Layout;
|
||||||
|
|
||||||
|
type MenuItem = NonNullable<MenuProps['items']>[number];
|
||||||
|
|
||||||
const MENU_ITEMS: MenuProps['items'] = [
|
const MENU_ITEMS: MenuProps['items'] = [
|
||||||
{ key: '/', icon: <DashboardOutlined />, label: '概览' },
|
{ key: '/', icon: <DashboardOutlined />, label: '概览' },
|
||||||
{ key: '/users', icon: <UserOutlined />, label: '用户' },
|
{ key: '/users', icon: <UserOutlined />, label: '用户' },
|
||||||
@@ -38,6 +42,9 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
},
|
},
|
||||||
{ key: '/orders', icon: <ShoppingOutlined />, label: '订单' },
|
{ key: '/orders', icon: <ShoppingOutlined />, label: '订单' },
|
||||||
{ key: '/promo-codes', icon: <GiftOutlined />, label: '推广码' },
|
{ key: '/promo-codes', icon: <GiftOutlined />, label: '推广码' },
|
||||||
|
{ key: '/wecom-bots', icon: <TeamOutlined />, label: '企微机器人' },
|
||||||
|
{ key: '/llm-configs', icon: <RobotOutlined />, label: '语言模型' },
|
||||||
|
{ key: '/knowledge-bases', icon: <FileTextOutlined />, label: '知识库' },
|
||||||
{
|
{
|
||||||
key: 'stores-group',
|
key: 'stores-group',
|
||||||
icon: <ShopOutlined />,
|
icon: <ShopOutlined />,
|
||||||
@@ -68,6 +75,7 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
{ key: '/finance/store-bills', label: '门店账单' },
|
{ key: '/finance/store-bills', label: '门店账单' },
|
||||||
{ key: '/finance/partner-bills', label: '合伙人账单' },
|
{ key: '/finance/partner-bills', label: '合伙人账单' },
|
||||||
{ key: '/finance/winery-bills', label: '酒厂账单' },
|
{ key: '/finance/winery-bills', label: '酒厂账单' },
|
||||||
|
{ key: '/finance/logistics-bills', label: '物流对账' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -91,7 +99,15 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
{ key: '/deliveries/xiaofeixia', label: '小飞侠联调' },
|
{ key: '/deliveries/xiaofeixia', label: '小飞侠联调' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ key: '/tickets', icon: <CarOutlined />, label: '工单中心' },
|
{
|
||||||
|
key: 'tickets-group',
|
||||||
|
icon: <CarOutlined />,
|
||||||
|
label: '工单',
|
||||||
|
children: [
|
||||||
|
{ key: '/tickets', label: '工单中心' },
|
||||||
|
{ key: '/tickets/support', label: '技术支持' },
|
||||||
|
],
|
||||||
|
},
|
||||||
{ key: '/invoices', icon: <FileTextOutlined />, label: '发票管理' },
|
{ key: '/invoices', icon: <FileTextOutlined />, label: '发票管理' },
|
||||||
{ key: '/resources', icon: <CloudUploadOutlined />, label: 'OSS 资源库' },
|
{ key: '/resources', icon: <CloudUploadOutlined />, label: 'OSS 资源库' },
|
||||||
{
|
{
|
||||||
@@ -111,6 +127,83 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
{ key: '/hq-accounts', icon: <SafetyOutlined />, label: 'HQ账户' },
|
{ key: '/hq-accounts', icon: <SafetyOutlined />, label: 'HQ账户' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function menuAllowed(key: string, permissionKeys: string[]): boolean {
|
||||||
|
if (key === 'tickets-group') {
|
||||||
|
return permissionKeys.includes('tickets') || permissionKeys.includes('tech_support');
|
||||||
|
}
|
||||||
|
const map: Record<string, string | 'system_settings_any'> = {
|
||||||
|
'/': 'dashboard',
|
||||||
|
'/users': 'users',
|
||||||
|
'/wechat-bindings': 'wechat_bindings',
|
||||||
|
'products-group': 'products',
|
||||||
|
'/products': 'products',
|
||||||
|
'/product-detail-templates': 'products',
|
||||||
|
'/orders': 'orders',
|
||||||
|
'/promo-codes': 'promo_codes',
|
||||||
|
'/wecom-bots': 'wecom_bots',
|
||||||
|
'/llm-configs': 'llm_configs',
|
||||||
|
'/knowledge-bases': 'knowledge_bases',
|
||||||
|
'stores-group': 'stores',
|
||||||
|
'/stores': 'stores',
|
||||||
|
'/store-categories': 'stores',
|
||||||
|
'/store-accounts': 'stores',
|
||||||
|
'/store-media': 'stores',
|
||||||
|
'partners-group': 'partners',
|
||||||
|
'/cities': 'partners',
|
||||||
|
'/city-partners': 'partners',
|
||||||
|
'/city-warehouses': 'partners',
|
||||||
|
'/fulfillment-providers': 'partners',
|
||||||
|
'finance-group': 'finance',
|
||||||
|
'/finance/store-bills': 'finance',
|
||||||
|
'/finance/partner-bills': 'finance',
|
||||||
|
'/finance/winery-bills': 'finance',
|
||||||
|
'/finance/logistics-bills': 'finance',
|
||||||
|
'benefit-group': 'benefit',
|
||||||
|
'/benefit/coupons': 'benefit',
|
||||||
|
'/benefit/ledgers': 'benefit',
|
||||||
|
'/redeem-records': 'benefit',
|
||||||
|
'/redeem-pending': 'benefit',
|
||||||
|
'/redeem/debug': 'benefit',
|
||||||
|
'deliveries-group': 'deliveries',
|
||||||
|
'/deliveries': 'deliveries',
|
||||||
|
'/deliveries/xiaofeixia': 'deliveries',
|
||||||
|
'/tickets': 'tickets',
|
||||||
|
'/tickets/support': 'tech_support',
|
||||||
|
'/invoices': 'invoices',
|
||||||
|
'/resources': 'resources',
|
||||||
|
'logs-group': 'logs',
|
||||||
|
'/logs/users': 'logs',
|
||||||
|
'/logs/stores': 'logs',
|
||||||
|
'/logs/partners': 'logs',
|
||||||
|
'/logs/hq': 'logs',
|
||||||
|
'/logs/third-party': 'logs',
|
||||||
|
'/hq-permissions': 'hq_permissions',
|
||||||
|
'/system-settings': 'system_settings_any',
|
||||||
|
'/hq-accounts': 'hq_accounts',
|
||||||
|
};
|
||||||
|
const need = map[key];
|
||||||
|
if (!need) return true;
|
||||||
|
if (need === 'system_settings_any') return hasAnySystemSettingsPermission(permissionKeys);
|
||||||
|
return permissionKeys.includes(need);
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterMenuItems(items: MenuProps['items'], permissionKeys: string[]): MenuProps['items'] {
|
||||||
|
if (!items) return items;
|
||||||
|
return items
|
||||||
|
.map((item) => {
|
||||||
|
if (!item || typeof item !== 'object' || !('key' in item)) return item;
|
||||||
|
const key = String(item.key);
|
||||||
|
if ('children' in item && Array.isArray(item.children)) {
|
||||||
|
if (!menuAllowed(key, permissionKeys)) return null;
|
||||||
|
const children = filterMenuItems(item.children as MenuProps['items'], permissionKeys);
|
||||||
|
if (!children?.length) return null;
|
||||||
|
return { ...item, children } as MenuItem;
|
||||||
|
}
|
||||||
|
return menuAllowed(key, permissionKeys) ? item : null;
|
||||||
|
})
|
||||||
|
.filter(Boolean) as MenuProps['items'];
|
||||||
|
}
|
||||||
|
|
||||||
export default function AdminLayout() {
|
export default function AdminLayout() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@@ -138,6 +231,12 @@ export default function AdminLayout() {
|
|||||||
? '/promo-codes'
|
? '/promo-codes'
|
||||||
: location.pathname;
|
: location.pathname;
|
||||||
|
|
||||||
|
const menuItems = useMemo(() => {
|
||||||
|
if (!profile) return MENU_ITEMS;
|
||||||
|
if (profile.adminRole === 'SUPER_ADMIN') return MENU_ITEMS;
|
||||||
|
return filterMenuItems(MENU_ITEMS, profile.permissionKeys ?? []);
|
||||||
|
}, [profile]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout style={{ height: '100vh', overflow: 'hidden' }}>
|
<Layout style={{ height: '100vh', overflow: 'hidden' }}>
|
||||||
<Sider
|
<Sider
|
||||||
@@ -156,8 +255,8 @@ export default function AdminLayout() {
|
|||||||
theme="dark"
|
theme="dark"
|
||||||
mode="inline"
|
mode="inline"
|
||||||
selectedKeys={[selectedKey]}
|
selectedKeys={[selectedKey]}
|
||||||
defaultOpenKeys={['products-group', 'stores-group', 'partners-group', 'finance-group', 'benefit-group', 'logs-group', 'deliveries-group']}
|
defaultOpenKeys={[]}
|
||||||
items={MENU_ITEMS}
|
items={menuItems}
|
||||||
onClick={({ key }) => {
|
onClick={({ key }) => {
|
||||||
if (key.startsWith('/')) navigate(key);
|
if (key.startsWith('/')) navigate(key);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export type HqProfile = {
|
|||||||
name: string;
|
name: string;
|
||||||
adminRole: string;
|
adminRole: string;
|
||||||
status: string;
|
status: string;
|
||||||
|
permissionKeys?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getToken() {
|
export function getToken() {
|
||||||
@@ -145,6 +146,8 @@ export type AdminOrderRow = {
|
|||||||
city?: { id: string; name: string; code: string };
|
city?: { id: string; name: string; code: string };
|
||||||
fulfillmentWarehouseId?: string | null;
|
fulfillmentWarehouseId?: string | null;
|
||||||
fulfillmentWarehouse?: { id: string; name: string } | null;
|
fulfillmentWarehouse?: { id: string; name: string } | null;
|
||||||
|
fulfillmentHold?: boolean;
|
||||||
|
fulfillmentHoldReason?: string | null;
|
||||||
user?: { id: string; userNo: string; phone: string | null; nickname: string | null };
|
user?: { id: string; userNo: string; phone: string | null; nickname: string | null };
|
||||||
delivery?: {
|
delivery?: {
|
||||||
provider: string;
|
provider: string;
|
||||||
|
|||||||
@@ -79,6 +79,39 @@ export function districtCodeToCityCode(districtCode: string): string {
|
|||||||
return `${districtCode.slice(0, 4)}00`;
|
return `${districtCode.slice(0, 4)}00`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DistrictOption = { value: string; label: string };
|
||||||
|
|
||||||
|
/** 按开城城市 code(4 位或 6 位)取该市下区县列表 */
|
||||||
|
export function getDistrictOptionsByCityCode(cityCode?: string | null): DistrictOption[] {
|
||||||
|
if (!cityCode?.trim()) return [];
|
||||||
|
const normalized = normalizeCityAdcode(cityCode.trim());
|
||||||
|
const prefix4 = normalized.slice(0, 4);
|
||||||
|
|
||||||
|
for (const province of regionData) {
|
||||||
|
for (const city of province.children ?? []) {
|
||||||
|
const cityValue = String(city.value);
|
||||||
|
const cityNorm = normalizeCityAdcode(cityValue);
|
||||||
|
if (cityNorm === normalized || cityValue === prefix4 || cityValue === cityCode.trim()) {
|
||||||
|
return (city.children ?? []).map((d) => ({
|
||||||
|
value: String(d.value),
|
||||||
|
label: String(d.label),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function districtCodeLabel(code: string): string {
|
||||||
|
return codeToText[code] || code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表展示:区县码 → 中文名,顿号拼接 */
|
||||||
|
export function formatDistrictLabels(codes?: string[] | null): string {
|
||||||
|
if (!codes?.length) return '—';
|
||||||
|
return codes.map((c) => districtCodeLabel(String(c))).join('、');
|
||||||
|
}
|
||||||
|
|
||||||
export function parseRegionCodes(codes?: string[]): ParsedChinaRegion | null {
|
export function parseRegionCodes(codes?: string[]): ParsedChinaRegion | null {
|
||||||
if (!codes || codes.length < 3) return null;
|
if (!codes || codes.length < 3) return null;
|
||||||
const [provinceCode, cityCode, districtCode] = codes;
|
const [provinceCode, cityCode, districtCode] = codes;
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ export const ORDER_STATUS_COLORS: Record<string, string> = {
|
|||||||
|
|
||||||
export const STORE_STATUS_LABELS: Record<string, string> = {
|
export const STORE_STATUS_LABELS: Record<string, string> = {
|
||||||
OPEN: '营业中',
|
OPEN: '营业中',
|
||||||
PAUSED: '暂停',
|
PAUSED: '临时闭店',
|
||||||
CLOSED: '已关闭',
|
CLOSED: '永久关闭',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const STORE_AUDIT_STATUS_LABELS: Record<string, string> = {
|
export const STORE_AUDIT_STATUS_LABELS: Record<string, string> = {
|
||||||
@@ -128,3 +128,18 @@ export const LEDGER_TYPE_LABELS: Record<string, string> = {
|
|||||||
export function fmtTime(v?: string | null) {
|
export function fmtTime(v?: string | null) {
|
||||||
return v ? new Date(v).toLocaleString('zh-CN') : '—';
|
return v ? new Date(v).toLocaleString('zh-CN') : '—';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 手机号脱敏展示:138****5678;空值返回 — */
|
||||||
|
export function maskPhone(phone?: string | null): string {
|
||||||
|
const raw = String(phone ?? '').trim();
|
||||||
|
if (!raw) return '—';
|
||||||
|
const digits = raw.replace(/\D/g, '');
|
||||||
|
if (digits.length >= 11) {
|
||||||
|
return `${digits.slice(0, 3)}****${digits.slice(-4)}`;
|
||||||
|
}
|
||||||
|
if (digits.length >= 7) {
|
||||||
|
return `${digits.slice(0, 3)}****${digits.slice(-2)}`;
|
||||||
|
}
|
||||||
|
if (digits.length > 0) return `${digits.slice(0, 1)}****`;
|
||||||
|
return '****';
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export const HQ_OPERATION_ACTION_OPTIONS = [
|
|||||||
{ value: 'STORE_AUDIT', label: '门店审核' },
|
{ value: 'STORE_AUDIT', label: '门店审核' },
|
||||||
{ value: 'STORE_ACCOUNT_CREATE', label: '新增门店账户' },
|
{ value: 'STORE_ACCOUNT_CREATE', label: '新增门店账户' },
|
||||||
{ value: 'STORE_ACCOUNT_UPDATE', label: '编辑门店账户' },
|
{ value: 'STORE_ACCOUNT_UPDATE', label: '编辑门店账户' },
|
||||||
|
{ value: 'STORE_ACCOUNT_STAFF_DELETE', label: '删除门店子账号' },
|
||||||
{ value: 'STORE_CATEGORY_CREATE', label: '新增门店分类' },
|
{ value: 'STORE_CATEGORY_CREATE', label: '新增门店分类' },
|
||||||
{ value: 'STORE_CATEGORY_UPDATE', label: '编辑门店分类' },
|
{ value: 'STORE_CATEGORY_UPDATE', label: '编辑门店分类' },
|
||||||
{ value: 'STORE_CATEGORY_DELETE', label: '删除门店分类' },
|
{ value: 'STORE_CATEGORY_DELETE', label: '删除门店分类' },
|
||||||
@@ -38,6 +39,15 @@ export const HQ_OPERATION_ACTION_OPTIONS = [
|
|||||||
{ value: 'DELIVERY_UPDATE', label: '编辑配送单' },
|
{ value: 'DELIVERY_UPDATE', label: '编辑配送单' },
|
||||||
{ value: 'TICKET_APPROVE', label: '工单通过' },
|
{ value: 'TICKET_APPROVE', label: '工单通过' },
|
||||||
{ value: 'TICKET_REJECT', label: '工单驳回' },
|
{ value: 'TICKET_REJECT', label: '工单驳回' },
|
||||||
|
{ value: 'TICKET_CREATE', label: '创建工单' },
|
||||||
|
{ value: 'SUPPORT_TICKET_CREATE', label: '创建技术支持工单' },
|
||||||
|
{ value: 'SUPPORT_TICKET_APPROVE', label: '技术支持评审通过' },
|
||||||
|
{ value: 'SUPPORT_TICKET_REJECT', label: '技术支持评审驳回' },
|
||||||
|
{ value: 'SUPPORT_TICKET_START_TESTING', label: '技术支持转入测试' },
|
||||||
|
{ value: 'SUPPORT_TICKET_PASS', label: '技术支持测试通过' },
|
||||||
|
{ value: 'INVOICE_CREATE', label: '创建发票申请' },
|
||||||
|
{ value: 'INVOICE_ISSUE', label: '开具发票' },
|
||||||
|
{ value: 'INVOICE_REJECT', label: '驳回发票' },
|
||||||
{ value: 'STORE_PAYOUT_CONFIRM', label: '门店打款确认' },
|
{ value: 'STORE_PAYOUT_CONFIRM', label: '门店打款确认' },
|
||||||
{ value: 'STORE_PAYOUT_BATCH_CONFIRM', label: '批量门店打款' },
|
{ value: 'STORE_PAYOUT_BATCH_CONFIRM', label: '批量门店打款' },
|
||||||
{ value: 'STORE_BILL_CONFIRM', label: '门店对账单确认打款' },
|
{ value: 'STORE_BILL_CONFIRM', label: '门店对账单确认打款' },
|
||||||
|
|||||||
@@ -6,10 +6,20 @@ export type StoreCreateForm = {
|
|||||||
city?: string;
|
city?: string;
|
||||||
district: string;
|
district: string;
|
||||||
districtCode?: string;
|
districtCode?: string;
|
||||||
|
categoryParentId?: string;
|
||||||
|
categoryId: string;
|
||||||
name: string;
|
name: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
address: string;
|
address: string;
|
||||||
|
latitude?: number | null;
|
||||||
|
longitude?: number | null;
|
||||||
intro?: string;
|
intro?: string;
|
||||||
|
benefitUsageRule?: string;
|
||||||
|
openTime?: string;
|
||||||
|
closeTime?: string;
|
||||||
|
openTime2?: string;
|
||||||
|
closeTime2?: string;
|
||||||
|
avgPrice?: number | null;
|
||||||
coverUrl?: string;
|
coverUrl?: string;
|
||||||
envPhotoUrls?: string[];
|
envPhotoUrls?: string[];
|
||||||
contractUrl?: string;
|
contractUrl?: string;
|
||||||
@@ -21,20 +31,67 @@ export type StoreCreateForm = {
|
|||||||
|
|
||||||
const PHONE_RE = /^1\d{10}$/;
|
const PHONE_RE = /^1\d{10}$/;
|
||||||
const BANK_RE = /^\d{16,19}$/;
|
const BANK_RE = /^\d{16,19}$/;
|
||||||
|
const TIME_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
||||||
|
|
||||||
|
function timeToMinutes(hhmm: string): number {
|
||||||
|
const [h, m] = hhmm.split(':').map(Number);
|
||||||
|
return h * 60 + m;
|
||||||
|
}
|
||||||
|
|
||||||
export function validateStoreCreateStep1(
|
export function validateStoreCreateStep1(
|
||||||
form: Pick<StoreCreateForm, 'partnerAccountId' | 'cityId' | 'regionCodes' | 'name' | 'phone' | 'address' | 'intro'>,
|
form: Pick<
|
||||||
|
StoreCreateForm,
|
||||||
|
| 'partnerAccountId'
|
||||||
|
| 'cityId'
|
||||||
|
| 'regionCodes'
|
||||||
|
| 'categoryId'
|
||||||
|
| 'name'
|
||||||
|
| 'phone'
|
||||||
|
| 'address'
|
||||||
|
| 'intro'
|
||||||
|
| 'benefitUsageRule'
|
||||||
|
| 'openTime'
|
||||||
|
| 'closeTime'
|
||||||
|
| 'openTime2'
|
||||||
|
| 'closeTime2'
|
||||||
|
| 'avgPrice'
|
||||||
|
>,
|
||||||
): string | null {
|
): string | null {
|
||||||
if (!form.partnerAccountId) return '请选择开城合伙人';
|
if (!form.partnerAccountId) return '请选择开城合伙人';
|
||||||
if (!form.regionCodes || form.regionCodes.length < 3) return '请选择省 / 市 / 区县';
|
if (!form.regionCodes || form.regionCodes.length < 3) return '请选择省 / 市 / 区县';
|
||||||
if (!form.cityId) return '所选地区未匹配到开城城市,请先在「开城 → 城市」配置对应区划';
|
if (!form.cityId) return '所选地区未匹配到开城城市,请先在「开城 → 城市」配置对应区划';
|
||||||
|
if (!form.categoryId?.trim()) return '请选择门店分类(细类)';
|
||||||
if (!form.name?.trim()) return '请填写门店名称';
|
if (!form.name?.trim()) return '请填写门店名称';
|
||||||
if (!form.phone?.trim()) return '请填写门店手机号';
|
if (!form.phone?.trim()) return '请填写门店手机号';
|
||||||
if (!PHONE_RE.test(form.phone.trim())) return '门店手机号须为11位手机号';
|
if (!PHONE_RE.test(form.phone.trim())) return '门店手机号须为11位手机号';
|
||||||
if (!form.address?.trim()) return '请填写详细地址';
|
if (!form.address?.trim()) return '请填写详细地址';
|
||||||
|
|
||||||
|
const openTime = String(form.openTime || '').trim();
|
||||||
|
const closeTime = String(form.closeTime || '').trim();
|
||||||
|
if (!openTime || !closeTime) return '请填写营业时间';
|
||||||
|
if (!TIME_RE.test(openTime) || !TIME_RE.test(closeTime)) return '营业时间格式须为 HH:MM';
|
||||||
|
if (timeToMinutes(openTime) >= timeToMinutes(closeTime)) return '营业结束时间须晚于开始时间';
|
||||||
|
|
||||||
|
const openTime2 = String(form.openTime2 || '').trim();
|
||||||
|
const closeTime2 = String(form.closeTime2 || '').trim();
|
||||||
|
if (openTime2 || closeTime2) {
|
||||||
|
if (!openTime2 || !closeTime2) return '请完整填写第二段营业时间';
|
||||||
|
if (!TIME_RE.test(openTime2) || !TIME_RE.test(closeTime2)) return '第二段时间格式须为 HH:MM';
|
||||||
|
if (timeToMinutes(openTime2) >= timeToMinutes(closeTime2)) return '第二段结束时间须晚于开始时间';
|
||||||
|
if (timeToMinutes(closeTime) >= timeToMinutes(openTime2)) return '第二段开始时间须晚于第一段结束时间';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (form.avgPrice != null && String(form.avgPrice).trim() !== '') {
|
||||||
|
const n = Number(form.avgPrice);
|
||||||
|
if (Number.isNaN(n) || n < 0) return '人均费用须为非负数字';
|
||||||
|
}
|
||||||
|
|
||||||
if (form.intro?.trim()) {
|
if (form.intro?.trim()) {
|
||||||
const len = form.intro.trim().length;
|
const len = form.intro.trim().length;
|
||||||
if (len < 10 || len > 500) return '门店简介须为 10~500 字';
|
if (len < 2 || len > 500) return '门店简介须为 2~500 字';
|
||||||
|
}
|
||||||
|
if (form.benefitUsageRule?.trim() && form.benefitUsageRule.trim().length > 1000) {
|
||||||
|
return '好客权益券使用规则最多 1000 字';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
export type TencentPickedLocation = {
|
||||||
|
latitude: number;
|
||||||
|
longitude: number;
|
||||||
|
address?: string;
|
||||||
|
name?: string;
|
||||||
|
cityname?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LbsPlaceItem = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
address: string;
|
||||||
|
latitude: number;
|
||||||
|
longitude: number;
|
||||||
|
city?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function placeToPicked(item: LbsPlaceItem): TencentPickedLocation {
|
||||||
|
return {
|
||||||
|
latitude: item.latitude,
|
||||||
|
longitude: item.longitude,
|
||||||
|
address: item.address || undefined,
|
||||||
|
name: item.title || undefined,
|
||||||
|
cityname: item.city || undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -33,6 +33,34 @@ type Row = {
|
|||||||
order?: { orderNo: string } | null;
|
order?: { orderNo: string } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type CouponRedeemRecord = {
|
||||||
|
id: string;
|
||||||
|
redeemNo: string;
|
||||||
|
amount: number;
|
||||||
|
settleAmount: number;
|
||||||
|
couponAmount?: number;
|
||||||
|
role?: 'PRIMARY' | 'SECONDARY';
|
||||||
|
createdAt: string;
|
||||||
|
store?: { id: string; name: string; cityName?: string | null } | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CouponRedeemSummary = {
|
||||||
|
couponNo: string;
|
||||||
|
totalAmount: number;
|
||||||
|
usedAmount: number;
|
||||||
|
balance: number;
|
||||||
|
status: string;
|
||||||
|
redeemCount: number;
|
||||||
|
redeemRecordSum: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CouponDetail = Row & {
|
||||||
|
redeemSummary?: CouponRedeemSummary | null;
|
||||||
|
redeemRecords?: CouponRedeemRecord[];
|
||||||
|
user?: { userNo?: string; phone?: string | null };
|
||||||
|
order?: { orderNo?: string } | null;
|
||||||
|
};
|
||||||
|
|
||||||
export default function BenefitCouponsPage() {
|
export default function BenefitCouponsPage() {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [grantForm] = Form.useForm<AdminBenefitGrantRequest>();
|
const [grantForm] = Form.useForm<AdminBenefitGrantRequest>();
|
||||||
@@ -50,8 +78,25 @@ export default function BenefitCouponsPage() {
|
|||||||
},
|
},
|
||||||
[filters],
|
[filters],
|
||||||
);
|
);
|
||||||
const [detail, setDetail] = useState<Record<string, unknown> | null>(null);
|
const [detail, setDetail] = useState<CouponDetail | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [redeemDetail, setRedeemDetail] = useState<Record<string, unknown> | null>(null);
|
||||||
|
const [redeemDrawerOpen, setRedeemDrawerOpen] = useState(false);
|
||||||
|
const [redeemDetailLoading, setRedeemDetailLoading] = useState(false);
|
||||||
|
|
||||||
|
async function openRedeemDetail(redeemId: string) {
|
||||||
|
setRedeemDetailLoading(true);
|
||||||
|
setRedeemDrawerOpen(true);
|
||||||
|
try {
|
||||||
|
const res = await request<Record<string, unknown>>(`/admin/redeem-records/${redeemId}`);
|
||||||
|
setRedeemDetail(res);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载核销详情失败');
|
||||||
|
setRedeemDrawerOpen(false);
|
||||||
|
} finally {
|
||||||
|
setRedeemDetailLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '券号', dataIndex: 'couponNo', width: 200, ellipsis: false },
|
{ title: '券号', dataIndex: 'couponNo', width: 200, ellipsis: false },
|
||||||
@@ -197,7 +242,7 @@ export default function BenefitCouponsPage() {
|
|||||||
|
|
||||||
<Drawer
|
<Drawer
|
||||||
title="权益券详情"
|
title="权益券详情"
|
||||||
width={560}
|
width={720}
|
||||||
open={drawerOpen}
|
open={drawerOpen}
|
||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={
|
extra={
|
||||||
@@ -218,25 +263,202 @@ export default function BenefitCouponsPage() {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
{detail && (
|
{detail && (
|
||||||
|
<>
|
||||||
|
<Descriptions column={1} bordered size="small">
|
||||||
|
<Descriptions.Item label="券号">{detail.couponNo}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="用户">{detail.user?.userNo ?? '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="手机号">{detail.user?.phone ?? '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="关联订单">{detail.order?.orderNo ?? '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="总额">¥{Number(detail.totalAmount).toFixed(2)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="余额">¥{Number(detail.balance).toFixed(2)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="状态">
|
||||||
|
{COUPON_STATUS_LABELS[detail.status] || detail.status}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="来源">{detail.sourceProduct}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 16, marginBottom: 8 }}>
|
||||||
|
权益核销
|
||||||
|
</Typography.Title>
|
||||||
|
{detail.redeemSummary ? (
|
||||||
|
<>
|
||||||
|
<Descriptions column={2} bordered size="small" style={{ marginBottom: 12 }}>
|
||||||
|
<Descriptions.Item label="权益券号">{detail.redeemSummary.couponNo}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="券状态">{detail.redeemSummary.status}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权益总额">
|
||||||
|
¥{Number(detail.redeemSummary.totalAmount).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="已核销">
|
||||||
|
<Typography.Text type="danger" strong>
|
||||||
|
¥{Number(detail.redeemSummary.usedAmount).toFixed(2)}
|
||||||
|
</Typography.Text>
|
||||||
|
<Typography.Text type="secondary" style={{ marginLeft: 8 }}>
|
||||||
|
({detail.redeemSummary.redeemCount} 笔核销单)
|
||||||
|
</Typography.Text>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="剩余余额">
|
||||||
|
¥{Number(detail.redeemSummary.balance).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="核销单合计额">
|
||||||
|
¥{Number(detail.redeemSummary.redeemRecordSum).toFixed(2)}
|
||||||
|
<Typography.Text type="secondary" style={{ marginLeft: 8 }}>
|
||||||
|
(本券分摊合计)
|
||||||
|
</Typography.Text>
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
locale={{ emptyText: '暂无关联核销单' }}
|
||||||
|
dataSource={detail.redeemRecords ?? []}
|
||||||
|
columns={[
|
||||||
|
{ title: '核销号', dataIndex: 'redeemNo', width: 160, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '角色',
|
||||||
|
dataIndex: 'role',
|
||||||
|
width: 70,
|
||||||
|
render: (v: string | undefined) =>
|
||||||
|
v === 'SECONDARY' ? <Tag color="orange">次券</Tag> : <Tag color="blue">主券</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: ['store', 'name'],
|
||||||
|
ellipsis: true,
|
||||||
|
render: (v: string | undefined, row: CouponRedeemRecord) =>
|
||||||
|
v ? `${v}${row.store?.cityName ? `(${row.store.cityName})` : ''}` : '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '本券分摊',
|
||||||
|
dataIndex: 'couponAmount',
|
||||||
|
width: 95,
|
||||||
|
render: (v: number | undefined, row: CouponRedeemRecord) =>
|
||||||
|
`¥${Number(v ?? row.amount).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '核销总额',
|
||||||
|
dataIndex: 'amount',
|
||||||
|
width: 90,
|
||||||
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '结算额',
|
||||||
|
dataIndex: 'settleAmount',
|
||||||
|
width: 90,
|
||||||
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '时间',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
width: 150,
|
||||||
|
render: (v: string) => fmtTime(v),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 70,
|
||||||
|
render: (_: unknown, row: CouponRedeemRecord) => (
|
||||||
|
<Button type="link" size="small" onClick={() => void openRedeemDetail(row.id)}>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">暂无核销摘要</Typography.Text>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title="核销单详情"
|
||||||
|
width={520}
|
||||||
|
open={redeemDrawerOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setRedeemDrawerOpen(false);
|
||||||
|
setRedeemDetail(null);
|
||||||
|
}}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{redeemDetailLoading ? (
|
||||||
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
|
) : redeemDetail ? (
|
||||||
<Descriptions column={1} bordered size="small">
|
<Descriptions column={1} bordered size="small">
|
||||||
<Descriptions.Item label="券号">{String(detail.couponNo)}</Descriptions.Item>
|
<Descriptions.Item label="核销号">{String(redeemDetail.redeemNo ?? '—')}</Descriptions.Item>
|
||||||
<Descriptions.Item label="用户">
|
<Descriptions.Item label="核销额">
|
||||||
{String((detail.user as { userNo?: string } | undefined)?.userNo ?? '—')}
|
¥{Number(redeemDetail.amount ?? 0).toFixed(2)}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="手机号">
|
<Descriptions.Item label="结算额">
|
||||||
{String((detail.user as { phone?: string } | undefined)?.phone ?? '—')}
|
¥{Number(redeemDetail.settleAmount ?? 0).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="时间">{fmtTime(String(redeemDetail.createdAt ?? ''))}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="用户">
|
||||||
|
{String((redeemDetail.user as { userNo?: string } | undefined)?.userNo ?? '—')}
|
||||||
|
{(redeemDetail.user as { phone?: string | null } | undefined)?.phone
|
||||||
|
? ` / ${(redeemDetail.user as { phone?: string | null }).phone}`
|
||||||
|
: ''}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店">
|
||||||
|
{String((redeemDetail.store as { name?: string } | undefined)?.name ?? '—')}
|
||||||
|
{(redeemDetail.store as { cityName?: string } | undefined)?.cityName
|
||||||
|
? `(${(redeemDetail.store as { cityName?: string }).cityName})`
|
||||||
|
: ''}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店地址">
|
||||||
|
{String((redeemDetail.store as { address?: string } | undefined)?.address ?? '—')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="合伙人">
|
||||||
|
{String(
|
||||||
|
(redeemDetail.store as { partnerAccount?: { companyName?: string } } | undefined)
|
||||||
|
?.partnerAccount?.companyName ?? '—',
|
||||||
|
)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权益券号">
|
||||||
|
{String((redeemDetail.coupon as { couponNo?: string } | undefined)?.couponNo ?? '—')}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="关联订单">
|
<Descriptions.Item label="关联订单">
|
||||||
{String((detail.order as { orderNo?: string } | null | undefined)?.orderNo ?? '—')}
|
{String(
|
||||||
|
(redeemDetail.coupon as { order?: { orderNo?: string } } | undefined)?.order?.orderNo ??
|
||||||
|
'—',
|
||||||
|
)}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="总额">¥{String(detail.totalAmount)}</Descriptions.Item>
|
{Array.isArray(redeemDetail.allocations) &&
|
||||||
<Descriptions.Item label="余额">¥{String(detail.balance)}</Descriptions.Item>
|
(redeemDetail.allocations as unknown[]).length > 0 ? (
|
||||||
<Descriptions.Item label="状态">
|
<Descriptions.Item label="券分摊">
|
||||||
{COUPON_STATUS_LABELS[String(detail.status)] || String(detail.status)}
|
{(
|
||||||
</Descriptions.Item>
|
redeemDetail.allocations as Array<{
|
||||||
<Descriptions.Item label="来源">{String(detail.sourceProduct)}</Descriptions.Item>
|
couponNo?: string;
|
||||||
|
orderNo?: string | null;
|
||||||
|
amount?: number;
|
||||||
|
sortOrder?: number;
|
||||||
|
}>
|
||||||
|
)
|
||||||
|
.map((a, idx) => {
|
||||||
|
const role = idx === 0 ? '主' : '次';
|
||||||
|
return `${role} ${a.couponNo ?? '—'}¥${Number(a.amount ?? 0).toFixed(2)}${
|
||||||
|
a.orderNo ? `(订单 ${a.orderNo})` : ''
|
||||||
|
}`;
|
||||||
|
})
|
||||||
|
.join(';')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{redeemDetail.payout ? (
|
||||||
|
<Descriptions.Item label="门店结算单">
|
||||||
|
¥{Number((redeemDetail.payout as { settleAmount?: number }).settleAmount ?? 0).toFixed(2)}
|
||||||
|
{' / '}
|
||||||
|
{String((redeemDetail.payout as { status?: string }).status ?? '—')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{redeemDetail.rating ? (
|
||||||
|
<Descriptions.Item label="评价">
|
||||||
|
服务 {(redeemDetail.rating as { serviceScore?: number }).serviceScore ?? '—'} 分 / 环境{' '}
|
||||||
|
{(redeemDetail.rating as { envScore?: number }).envScore ?? '—'} 分
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
)}
|
) : null}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Descriptions,
|
Descriptions,
|
||||||
@@ -17,7 +18,7 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { WAREHOUSE_MANAGER_LABELS, WarehouseManagerType } from '@dukang/shared-types';
|
import { WAREHOUSE_MANAGER_LABELS, WarehouseManagerType } from '@dukang/shared-types';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type HqProfile, type Paginated } from '../lib/api';
|
||||||
import { parseProvinceCityCodes, type ParsedProvinceCity } from '../lib/china-region';
|
import { parseProvinceCityCodes, type ParsedProvinceCity } from '../lib/china-region';
|
||||||
import { ADMIN_OPTIONS_PAGE_SIZE, CITY_STATUS_LABELS, fmtTime } from '../lib/constants';
|
import { ADMIN_OPTIONS_PAGE_SIZE, CITY_STATUS_LABELS, fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
@@ -50,6 +51,40 @@ type Row = {
|
|||||||
|
|
||||||
type PartnerOption = { id: string; companyName: string; cityId?: string | null };
|
type PartnerOption = { id: string; companyName: string; cityId?: string | null };
|
||||||
|
|
||||||
|
type CityDeletePreview = {
|
||||||
|
city: { id: string; code: string; name: string; province: string; status: string };
|
||||||
|
canDelete: boolean;
|
||||||
|
blockers: string[];
|
||||||
|
warnings: string[];
|
||||||
|
summary: {
|
||||||
|
primaryPartnerCount: number;
|
||||||
|
staffCount: number;
|
||||||
|
storeCount: number;
|
||||||
|
warehouseCount: number;
|
||||||
|
orderCount: number;
|
||||||
|
redeemCount: number;
|
||||||
|
partnerBillCount: number;
|
||||||
|
};
|
||||||
|
partners: Array<{
|
||||||
|
id: string;
|
||||||
|
phone: string;
|
||||||
|
name: string;
|
||||||
|
companyName?: string | null;
|
||||||
|
status: string;
|
||||||
|
staff: Array<{ id: string; phone: string; name: string; staffRole?: string | null }>;
|
||||||
|
}>;
|
||||||
|
orphanStaff: Array<{ id: string; phone: string; name: string }>;
|
||||||
|
stores: Array<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
phone: string;
|
||||||
|
status: string;
|
||||||
|
address: string;
|
||||||
|
partnerAccount?: { companyName?: string | null; phone?: string } | null;
|
||||||
|
}>;
|
||||||
|
warehouses: Array<{ id: string; name: string; status: string; address: string }>;
|
||||||
|
};
|
||||||
|
|
||||||
const MANAGER_OPTIONS = Object.entries(WAREHOUSE_MANAGER_LABELS).map(([value, label]) => ({ value, label }));
|
const MANAGER_OPTIONS = Object.entries(WAREHOUSE_MANAGER_LABELS).map(([value, label]) => ({ value, label }));
|
||||||
|
|
||||||
export default function CitiesPage() {
|
export default function CitiesPage() {
|
||||||
@@ -82,6 +117,18 @@ export default function CitiesPage() {
|
|||||||
const createRegionCodes = Form.useWatch('regionCodes', createForm);
|
const createRegionCodes = Form.useWatch('regionCodes', createForm);
|
||||||
const [warehouseManagerType, setWarehouseManagerType] = useState<WarehouseManagerType>(WarehouseManagerType.HQ);
|
const [warehouseManagerType, setWarehouseManagerType] = useState<WarehouseManagerType>(WarehouseManagerType.HQ);
|
||||||
const [editWarehouseManagerType, setEditWarehouseManagerType] = useState<WarehouseManagerType>(WarehouseManagerType.HQ);
|
const [editWarehouseManagerType, setEditWarehouseManagerType] = useState<WarehouseManagerType>(WarehouseManagerType.HQ);
|
||||||
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||||
|
const [deleteLoading, setDeleteLoading] = useState(false);
|
||||||
|
const [deleteSubmitting, setDeleteSubmitting] = useState(false);
|
||||||
|
const [deleteTarget, setDeleteTarget] = useState<Row | null>(null);
|
||||||
|
const [deletePreview, setDeletePreview] = useState<CityDeletePreview | null>(null);
|
||||||
|
const [confirmName, setConfirmName] = useState('');
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
|
const canDeleteCities = (profile?.permissionKeys ?? []).includes('cities_delete');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const loadPartners = useCallback(async (cityId: string) => {
|
const loadPartners = useCallback(async (cityId: string) => {
|
||||||
const res = await request<Paginated<PartnerOption>>(`/admin/partners?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}&cityId=${cityId}`);
|
const res = await request<Paginated<PartnerOption>>(`/admin/partners?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}&cityId=${cityId}`);
|
||||||
@@ -129,22 +176,85 @@ export default function CitiesPage() {
|
|||||||
setDrawerOpen(true);
|
setDrawerOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openDelete = async (row: Row) => {
|
||||||
|
setDeleteTarget(row);
|
||||||
|
setDeletePreview(null);
|
||||||
|
setConfirmName('');
|
||||||
|
setDeleteOpen(true);
|
||||||
|
setDeleteLoading(true);
|
||||||
|
try {
|
||||||
|
const preview = await request<CityDeletePreview>(`/admin/cities/${row.id}/delete-preview`);
|
||||||
|
setDeletePreview(preview);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载删除预览失败');
|
||||||
|
setDeleteOpen(false);
|
||||||
|
} finally {
|
||||||
|
setDeleteLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmDelete = async () => {
|
||||||
|
if (!deleteTarget || !deletePreview) return;
|
||||||
|
if (!deletePreview.canDelete) {
|
||||||
|
message.error(deletePreview.blockers.join(';') || '当前城市不可删除');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (confirmName.trim() !== deletePreview.city.name) {
|
||||||
|
message.warning(`请输入城市名称「${deletePreview.city.name}」确认删除`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setDeleteSubmitting(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/cities/${deleteTarget.id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
body: JSON.stringify({ confirmName: confirmName.trim() }),
|
||||||
|
});
|
||||||
|
message.success(`已删除城市「${deletePreview.city.name}」`);
|
||||||
|
setDeleteOpen(false);
|
||||||
|
setDeleteTarget(null);
|
||||||
|
setDeletePreview(null);
|
||||||
|
setConfirmName('');
|
||||||
|
if (detail?.id === deleteTarget.id) setDrawerOpen(false);
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
} finally {
|
||||||
|
setDeleteSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '编码', dataIndex: 'code', width: 90 },
|
{ title: '编码', dataIndex: 'code', width: 90 },
|
||||||
{ title: '城市', dataIndex: 'name', width: 100 },
|
{ title: '城市', dataIndex: 'name', width: 100 },
|
||||||
{ title: '省份', dataIndex: 'province', width: 90 },
|
{ title: '省份', dataIndex: 'province', width: 90 },
|
||||||
{ title: '状态', dataIndex: 'status', width: 90, render: (s) => <Tag>{CITY_STATUS_LABELS[s] || s}</Tag> },
|
{ title: '状态', dataIndex: 'status', width: 90, render: (s) => <Tag>{CITY_STATUS_LABELS[s] || s}</Tag> },
|
||||||
{ title: '合伙人', dataIndex: 'partnerBindingCount', width: 90 },
|
{ title: '合伙人', dataIndex: 'partnerBindingCount', width: 90 },
|
||||||
{ title: '门店', dataIndex: 'storeCount', width: 70 },
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: 'storeCount',
|
||||||
|
width: 70,
|
||||||
|
render: (n: number, row) => (
|
||||||
|
<Link to={`/stores?cityId=${row.id}`} title={`查看「${row.name}」门店`}>
|
||||||
|
{n ?? 0}
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ title: '订单', dataIndex: 'orderCount', width: 70 },
|
{ title: '订单', dataIndex: 'orderCount', width: 70 },
|
||||||
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 80,
|
width: 140,
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Button type="link" size="small" onClick={() => void openDetail(row)}>
|
<Space size={0}>
|
||||||
管理
|
<Button type="link" size="small" onClick={() => void openDetail(row)}>
|
||||||
</Button>
|
管理
|
||||||
|
</Button>
|
||||||
|
{canDeleteCities ? (
|
||||||
|
<Button type="link" size="small" danger onClick={() => void openDelete(row)}>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -264,6 +374,26 @@ export default function CitiesPage() {
|
|||||||
setDetail(refreshed);
|
setDetail(refreshed);
|
||||||
void reload();
|
void reload();
|
||||||
}}>保存</Button>
|
}}>保存</Button>
|
||||||
|
{canDeleteCities ? (
|
||||||
|
<Button
|
||||||
|
danger
|
||||||
|
style={{ marginLeft: 8 }}
|
||||||
|
onClick={() =>
|
||||||
|
void openDelete({
|
||||||
|
id: String(detail.id),
|
||||||
|
code: String(detail.code),
|
||||||
|
name: String(detail.name),
|
||||||
|
province: String(detail.province),
|
||||||
|
status: String(detail.status),
|
||||||
|
storeCount: Number(detail.storeCount ?? 0),
|
||||||
|
orderCount: Number(detail.orderCount ?? 0),
|
||||||
|
createdAt: String(detail.createdAt ?? ''),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
删除城市
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
</Form>
|
</Form>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
@@ -274,6 +404,7 @@ export default function CitiesPage() {
|
|||||||
children: detail?.id ? (
|
children: detail?.id ? (
|
||||||
<CityPartnersPanel
|
<CityPartnersPanel
|
||||||
cityId={String(detail.id)}
|
cityId={String(detail.id)}
|
||||||
|
cityCode={detail.code != null ? String(detail.code) : undefined}
|
||||||
maxPartnerCommissionRate={
|
maxPartnerCommissionRate={
|
||||||
detail.maxPartnerCommissionRate != null
|
detail.maxPartnerCommissionRate != null
|
||||||
? Number(detail.maxPartnerCommissionRate)
|
? Number(detail.maxPartnerCommissionRate)
|
||||||
@@ -406,6 +537,140 @@ export default function CitiesPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={deleteTarget ? `删除城市「${deleteTarget.name}」` : '删除城市'}
|
||||||
|
open={deleteOpen}
|
||||||
|
onCancel={() => {
|
||||||
|
if (deleteSubmitting) return;
|
||||||
|
setDeleteOpen(false);
|
||||||
|
}}
|
||||||
|
okText="确认删除"
|
||||||
|
okButtonProps={{
|
||||||
|
danger: true,
|
||||||
|
disabled:
|
||||||
|
!deletePreview?.canDelete ||
|
||||||
|
!deletePreview ||
|
||||||
|
confirmName.trim() !== (deletePreview?.city.name ?? ''),
|
||||||
|
loading: deleteSubmitting,
|
||||||
|
}}
|
||||||
|
confirmLoading={deleteSubmitting}
|
||||||
|
onOk={() => void confirmDelete()}
|
||||||
|
width={720}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{deleteLoading || !deletePreview ? (
|
||||||
|
<Typography.Text type="secondary">正在加载关联数据…</Typography.Text>
|
||||||
|
) : (
|
||||||
|
<Space direction="vertical" size="middle" style={{ width: '100%' }}>
|
||||||
|
<Descriptions size="small" bordered column={2}>
|
||||||
|
<Descriptions.Item label="编码">{deletePreview.city.code}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="省份">{deletePreview.city.province}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="合伙人主账号">{deletePreview.summary.primaryPartnerCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="子账号">{deletePreview.summary.staffCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店">{deletePreview.summary.storeCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="仓库">{deletePreview.summary.warehouseCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="订单">{deletePreview.summary.orderCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="核销">{deletePreview.summary.redeemCount}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
|
||||||
|
{deletePreview.blockers.length > 0 && (
|
||||||
|
<Typography.Paragraph type="danger" style={{ marginBottom: 0 }}>
|
||||||
|
{deletePreview.blockers.map((b) => (
|
||||||
|
<div key={b}>• {b}</div>
|
||||||
|
))}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
)}
|
||||||
|
{deletePreview.warnings.length > 0 && (
|
||||||
|
<Typography.Paragraph type="warning" style={{ marginBottom: 0 }}>
|
||||||
|
{deletePreview.warnings.map((w) => (
|
||||||
|
<div key={w}>• {w}</div>
|
||||||
|
))}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Typography.Text strong>合伙人及子账号</Typography.Text>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
style={{ marginTop: 8 }}
|
||||||
|
pagination={false}
|
||||||
|
rowKey="id"
|
||||||
|
locale={{ emptyText: '无合伙人' }}
|
||||||
|
dataSource={deletePreview.partners.flatMap((p) => [
|
||||||
|
{
|
||||||
|
id: p.id,
|
||||||
|
kind: '主账号',
|
||||||
|
name: p.companyName || p.name,
|
||||||
|
phone: p.phone,
|
||||||
|
parent: '—',
|
||||||
|
},
|
||||||
|
...p.staff.map((s) => ({
|
||||||
|
id: s.id,
|
||||||
|
kind: '子账号',
|
||||||
|
name: s.name,
|
||||||
|
phone: s.phone,
|
||||||
|
parent: p.companyName || p.name,
|
||||||
|
})),
|
||||||
|
]).concat(
|
||||||
|
deletePreview.orphanStaff.map((s) => ({
|
||||||
|
id: s.id,
|
||||||
|
kind: '子账号',
|
||||||
|
name: s.name,
|
||||||
|
phone: s.phone,
|
||||||
|
parent: '(无主账号)',
|
||||||
|
})),
|
||||||
|
)}
|
||||||
|
columns={[
|
||||||
|
{ title: '类型', dataIndex: 'kind', width: 80 },
|
||||||
|
{ title: '名称', dataIndex: 'name', ellipsis: true },
|
||||||
|
{ title: '手机号', dataIndex: 'phone', width: 120 },
|
||||||
|
{ title: '归属', dataIndex: 'parent', ellipsis: true },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Typography.Text strong>门店</Typography.Text>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
style={{ marginTop: 8 }}
|
||||||
|
pagination={false}
|
||||||
|
rowKey="id"
|
||||||
|
locale={{ emptyText: '无门店' }}
|
||||||
|
dataSource={deletePreview.stores}
|
||||||
|
columns={[
|
||||||
|
{ title: '门店名', dataIndex: 'name', ellipsis: true },
|
||||||
|
{ title: '电话', dataIndex: 'phone', width: 120 },
|
||||||
|
{ title: '状态', dataIndex: 'status', width: 90 },
|
||||||
|
{
|
||||||
|
title: '合伙人',
|
||||||
|
width: 140,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (_, r) => r.partnerAccount?.companyName || r.partnerAccount?.phone || '—',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{deletePreview.canDelete ? (
|
||||||
|
<Form.Item
|
||||||
|
label={`请输入城市名称「${deletePreview.city.name}」确认删除`}
|
||||||
|
style={{ marginBottom: 0 }}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
value={confirmName}
|
||||||
|
placeholder={deletePreview.city.name}
|
||||||
|
onChange={(e) => setConfirmName(e.target.value)}
|
||||||
|
disabled={deleteSubmitting}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">存在阻断项,无法删除。请先处理订单等关联数据。</Typography.Text>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Link } from 'react-router-dom';
|
|||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
Cascader,
|
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Descriptions,
|
Descriptions,
|
||||||
Drawer,
|
Drawer,
|
||||||
@@ -32,9 +31,10 @@ import {
|
|||||||
type PartnerPermissionKey,
|
type PartnerPermissionKey,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
import { CHINA_REGION_OPTIONS } from '../lib/china-region';
|
import { districtCodeLabel, formatDistrictLabels } from '../lib/china-region';
|
||||||
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import CityDistrictMultiSelect from '../components/CityDistrictMultiSelect';
|
||||||
import PartnerSubAccountList, { type PartnerSubAccountRow } from '../components/PartnerSubAccountList';
|
import PartnerSubAccountList, { type PartnerSubAccountRow } from '../components/PartnerSubAccountList';
|
||||||
|
|
||||||
type SubRow = PartnerSubAccountRow;
|
type SubRow = PartnerSubAccountRow;
|
||||||
@@ -48,6 +48,7 @@ type Row = {
|
|||||||
cityId?: string | null;
|
cityId?: string | null;
|
||||||
cityName?: string | null;
|
cityName?: string | null;
|
||||||
scopeType?: string;
|
scopeType?: string;
|
||||||
|
districtCodes?: string[] | null;
|
||||||
orderCommissionRate?: number;
|
orderCommissionRate?: number;
|
||||||
redeemCommissionRate?: number;
|
redeemCommissionRate?: number;
|
||||||
bindingStatus?: string;
|
bindingStatus?: string;
|
||||||
@@ -98,13 +99,25 @@ function flattenDistrictCodes(values: string[] | string[][] | undefined): string
|
|||||||
}
|
}
|
||||||
|
|
||||||
function commissionSumError(orderPercent: number, redeemPercent: number, maxRate: number): string | null {
|
function commissionSumError(orderPercent: number, redeemPercent: number, maxRate: number): string | null {
|
||||||
const sum = orderPercent / 100 + redeemPercent / 100;
|
// API 可能把 Prisma Decimal 序列化为字符串;`"0.05" + 1e-9` 会变成字符串拼接导致误判超限
|
||||||
if (sum > maxRate + 1e-9) {
|
const max = Number(maxRate);
|
||||||
return `订单佣金与核销佣金合计不得超过 ${(maxRate * 100).toFixed(2)}%(当前 ${(sum * 100).toFixed(2)}%)`;
|
const sum = Number(orderPercent) / 100 + Number(redeemPercent) / 100;
|
||||||
|
if (!Number.isFinite(max) || !Number.isFinite(sum)) return '佣金比例无效';
|
||||||
|
if (sum > max + 1e-9) {
|
||||||
|
return `订单佣金与核销佣金合计不得超过 ${(max * 100).toFixed(2)}%(当前 ${(sum * 100).toFixed(2)}%)`;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatApiError(err: unknown): string | null {
|
||||||
|
if (err && typeof err === 'object' && 'errorFields' in err) return null;
|
||||||
|
if (!(err instanceof Error)) return '操作失败';
|
||||||
|
return err.message.replace(/\b(\d{6})\b/g, (code) => {
|
||||||
|
const label = districtCodeLabel(code);
|
||||||
|
return label !== code ? `${label}(${code})` : code;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default function CityPartnersPage() {
|
export default function CityPartnersPage() {
|
||||||
const [filterForm] = Form.useForm();
|
const [filterForm] = Form.useForm();
|
||||||
const [editForm] = Form.useForm();
|
const [editForm] = Form.useForm();
|
||||||
@@ -135,6 +148,7 @@ export default function CityPartnersPage() {
|
|||||||
const [editScopeType, setEditScopeType] = useState<CityPartnerScopeType>(CityPartnerScopeType.CITY_WIDE);
|
const [editScopeType, setEditScopeType] = useState<CityPartnerScopeType>(CityPartnerScopeType.CITY_WIDE);
|
||||||
const [maxCommissionRate, setMaxCommissionRate] = useState(0.05);
|
const [maxCommissionRate, setMaxCommissionRate] = useState(0.05);
|
||||||
const [createMaxRate, setCreateMaxRate] = useState(0.05);
|
const [createMaxRate, setCreateMaxRate] = useState(0.05);
|
||||||
|
const [createCityCode, setCreateCityCode] = useState<string | undefined>();
|
||||||
|
|
||||||
const loadCities = useCallback(async () => {
|
const loadCities = useCallback(async () => {
|
||||||
const res = await request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
const res = await request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
||||||
@@ -145,11 +159,15 @@ export default function CityPartnersPage() {
|
|||||||
void loadCities();
|
void loadCities();
|
||||||
}, [loadCities]);
|
}, [loadCities]);
|
||||||
|
|
||||||
|
const editCityCode = detail?.cityId
|
||||||
|
? cities.find((c) => c.id === detail.cityId)?.code
|
||||||
|
: undefined;
|
||||||
|
|
||||||
async function openPartner(id: string) {
|
async function openPartner(id: string) {
|
||||||
const d = await request<PartnerDetail>(`/admin/partners/${id}`);
|
const d = await request<PartnerDetail>(`/admin/partners/${id}`);
|
||||||
setDetail(d);
|
setDetail(d);
|
||||||
setEditScopeType((d.scopeType as CityPartnerScopeType) || CityPartnerScopeType.CITY_WIDE);
|
setEditScopeType((d.scopeType as CityPartnerScopeType) || CityPartnerScopeType.CITY_WIDE);
|
||||||
setMaxCommissionRate(d.maxPartnerCommissionRate ?? 0.05);
|
setMaxCommissionRate(Number(d.maxPartnerCommissionRate ?? 0.05));
|
||||||
editForm.setFieldsValue({
|
editForm.setFieldsValue({
|
||||||
name: d.name,
|
name: d.name,
|
||||||
phone: d.phone,
|
phone: d.phone,
|
||||||
@@ -171,28 +189,33 @@ export default function CityPartnersPage() {
|
|||||||
|
|
||||||
async function savePartner() {
|
async function savePartner() {
|
||||||
if (!detail) return;
|
if (!detail) return;
|
||||||
const v = await editForm.validateFields();
|
try {
|
||||||
const err = commissionSumError(
|
const v = await editForm.validateFields();
|
||||||
Number(v.orderCommissionRate ?? 0),
|
const err = commissionSumError(
|
||||||
Number(v.redeemCommissionRate ?? 0),
|
Number(v.orderCommissionRate ?? 0),
|
||||||
maxCommissionRate,
|
Number(v.redeemCommissionRate ?? 0),
|
||||||
);
|
maxCommissionRate,
|
||||||
if (err) {
|
);
|
||||||
message.error(err);
|
if (err) {
|
||||||
return;
|
message.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request(`/admin/partners/${detail.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...v,
|
||||||
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
|
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已保存');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
}
|
}
|
||||||
await request(`/admin/partners/${detail.id}`, {
|
|
||||||
method: 'PUT',
|
|
||||||
body: JSON.stringify({
|
|
||||||
...v,
|
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
|
||||||
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
message.success('已保存');
|
|
||||||
setDrawerOpen(false);
|
|
||||||
void reload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshPartnerContext(parentId: string) {
|
async function refreshPartnerContext(parentId: string) {
|
||||||
@@ -229,13 +252,24 @@ export default function CityPartnersPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onCreateCityChange(cityId: string) {
|
async function onCreateCityChange(cityId: string) {
|
||||||
|
createForm.setFieldsValue({ districtCodes: undefined });
|
||||||
|
const matched = cities.find((c) => c.id === cityId);
|
||||||
|
setCreateCityCode(matched?.code);
|
||||||
const cityRes = await request<{ maxPartnerCommissionRate?: number }>(`/admin/cities/${cityId}`);
|
const cityRes = await request<{ maxPartnerCommissionRate?: number }>(`/admin/cities/${cityId}`);
|
||||||
setCreateMaxRate(cityRes.maxPartnerCommissionRate ?? 0.05);
|
setCreateMaxRate(Number(cityRes.maxPartnerCommissionRate ?? 0.05));
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
|
||||||
{ title: '城市', dataIndex: 'cityName', width: 90 },
|
{ title: '城市', dataIndex: 'cityName', width: 90 },
|
||||||
|
{
|
||||||
|
title: '区县',
|
||||||
|
dataIndex: 'districtCodes',
|
||||||
|
width: 160,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (codes: string[] | null | undefined, row) =>
|
||||||
|
row.scopeType === CityPartnerScopeType.CITY_WIDE ? '全城' : formatDistrictLabels(codes),
|
||||||
|
},
|
||||||
|
{ title: '公司名', dataIndex: 'companyName', ellipsis: true, width: 140 },
|
||||||
{ title: '主账号姓名', dataIndex: 'name', width: 100, ellipsis: true },
|
{ title: '主账号姓名', dataIndex: 'name', width: 100, ellipsis: true },
|
||||||
{ title: '登录手机', dataIndex: 'phone', width: 120 },
|
{ title: '登录手机', dataIndex: 'phone', width: 120 },
|
||||||
{
|
{
|
||||||
@@ -267,7 +301,16 @@ export default function CityPartnersPage() {
|
|||||||
ellipsis: true,
|
ellipsis: true,
|
||||||
render: (v) => v || '—',
|
render: (v) => v || '—',
|
||||||
},
|
},
|
||||||
{ title: '门店', dataIndex: 'storeCount', width: 60 },
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: 'storeCount',
|
||||||
|
width: 60,
|
||||||
|
render: (n: number, row) => (
|
||||||
|
<Link to={`/stores?partnerId=${row.id}`} title={`查看「${row.companyName || row.phone}」门店`}>
|
||||||
|
{n ?? 0}
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ title: '子账号', dataIndex: 'accountCount', width: 70, render: (n) => Math.max(0, n - 1) },
|
{ title: '子账号', dataIndex: 'accountCount', width: 70, render: (n) => Math.max(0, n - 1) },
|
||||||
{ title: '创建', dataIndex: 'createdAt', width: 150, render: fmtTime },
|
{ title: '创建', dataIndex: 'createdAt', width: 150, render: fmtTime },
|
||||||
{
|
{
|
||||||
@@ -299,6 +342,7 @@ export default function CityPartnersPage() {
|
|||||||
});
|
});
|
||||||
setCreateScopeType(CityPartnerScopeType.CITY_WIDE);
|
setCreateScopeType(CityPartnerScopeType.CITY_WIDE);
|
||||||
setCreateMaxRate(0.05);
|
setCreateMaxRate(0.05);
|
||||||
|
setCreateCityCode(undefined);
|
||||||
setCreateOpen(true);
|
setCreateOpen(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -327,12 +371,6 @@ export default function CityPartnersPage() {
|
|||||||
setPage(1);
|
setPage(1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form.Item name="companyName" label="公司">
|
|
||||||
<Input allowClear placeholder="公司名" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="phone" label="手机">
|
|
||||||
<Input allowClear placeholder="登录手机" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="cityId" label="城市">
|
<Form.Item name="cityId" label="城市">
|
||||||
<Select
|
<Select
|
||||||
allowClear
|
allowClear
|
||||||
@@ -343,6 +381,12 @@ export default function CityPartnersPage() {
|
|||||||
options={cities.map((c) => ({ value: c.id, label: c.name }))}
|
options={cities.map((c) => ({ value: c.id, label: c.name }))}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="companyName" label="公司">
|
||||||
|
<Input allowClear placeholder="公司名" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="phone" label="手机">
|
||||||
|
<Input allowClear placeholder="登录手机" />
|
||||||
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
@@ -409,7 +453,11 @@ export default function CityPartnersPage() {
|
|||||||
<>
|
<>
|
||||||
<Descriptions column={2} size="small" bordered style={{ marginBottom: 16 }}>
|
<Descriptions column={2} size="small" bordered style={{ marginBottom: 16 }}>
|
||||||
<Descriptions.Item label="城市">{detail.cityName ?? '—'}</Descriptions.Item>
|
<Descriptions.Item label="城市">{detail.cityName ?? '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="门店数">{detail.storeCount ?? 0}</Descriptions.Item>
|
<Descriptions.Item label="门店数">
|
||||||
|
<Link to={`/stores?partnerId=${detail.id}`} title="查看该城市合伙人门店">
|
||||||
|
{detail.storeCount ?? 0}
|
||||||
|
</Link>
|
||||||
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="管仓仓库" span={2}>
|
<Descriptions.Item label="管仓仓库" span={2}>
|
||||||
{detail.managedWarehouseName ?? (
|
{detail.managedWarehouseName ?? (
|
||||||
<Typography.Text type="secondary">
|
<Typography.Text type="secondary">
|
||||||
@@ -425,8 +473,8 @@ export default function CityPartnersPage() {
|
|||||||
label: '主账号',
|
label: '主账号',
|
||||||
children: (
|
children: (
|
||||||
<Form form={editForm} layout="vertical">
|
<Form form={editForm} layout="vertical">
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}>
|
<Form.Item name="companyName" label="公司名">
|
||||||
<Input />
|
<Input placeholder="选填" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}>
|
||||||
<Input />
|
<Input />
|
||||||
@@ -437,8 +485,8 @@ export default function CityPartnersPage() {
|
|||||||
<Form.Item name="contactPhone" label="业务联系电话">
|
<Form.Item name="contactPhone" label="业务联系电话">
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}>
|
<Form.Item name="address" label="地址">
|
||||||
<Input />
|
<Input placeholder="选填" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="bindingStatus" label="绑定状态" rules={[{ required: true }]}>
|
<Form.Item name="bindingStatus" label="绑定状态" rules={[{ required: true }]}>
|
||||||
<Select options={BINDING_OPTIONS} />
|
<Select options={BINDING_OPTIONS} />
|
||||||
@@ -447,8 +495,12 @@ export default function CityPartnersPage() {
|
|||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县">
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={editCityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
@@ -502,29 +554,34 @@ export default function CityPartnersPage() {
|
|||||||
width={560}
|
width={560}
|
||||||
onCancel={() => setCreateOpen(false)}
|
onCancel={() => setCreateOpen(false)}
|
||||||
onOk={async () => {
|
onOk={async () => {
|
||||||
const v = await createForm.validateFields();
|
try {
|
||||||
const err = commissionSumError(
|
const v = await createForm.validateFields();
|
||||||
Number(v.orderCommissionRate ?? 0),
|
const err = commissionSumError(
|
||||||
Number(v.redeemCommissionRate ?? 3),
|
Number(v.orderCommissionRate ?? 0),
|
||||||
createMaxRate,
|
Number(v.redeemCommissionRate ?? 3),
|
||||||
);
|
createMaxRate,
|
||||||
if (err) {
|
);
|
||||||
message.error(err);
|
if (err) {
|
||||||
return;
|
message.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request('/admin/partners', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...v,
|
||||||
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
|
districtCodes:
|
||||||
|
createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
}
|
}
|
||||||
await request('/admin/partners', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({
|
|
||||||
...v,
|
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
|
||||||
districtCodes:
|
|
||||||
createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
message.success('已创建');
|
|
||||||
setCreateOpen(false);
|
|
||||||
void reload();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form form={createForm} layout="vertical">
|
<Form form={createForm} layout="vertical">
|
||||||
@@ -536,8 +593,8 @@ export default function CityPartnersPage() {
|
|||||||
onChange={(id) => void onCreateCityChange(id)}
|
onChange={(id) => void onCreateCityChange(id)}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}>
|
<Form.Item name="companyName" label="公司名">
|
||||||
<Input />
|
<Input placeholder="选填" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}>
|
||||||
<Input />
|
<Input />
|
||||||
@@ -545,15 +602,19 @@ export default function CityPartnersPage() {
|
|||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}>
|
<Form.Item name="address" label="地址">
|
||||||
<Input />
|
<Input placeholder="选填" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县" rules={[{ required: true }]}>
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="选填;仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={createCityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
|
|||||||
@@ -52,8 +52,18 @@ export default function DashboardPage() {
|
|||||||
request<DashboardStats>('/admin/dashboard/stats')
|
request<DashboardStats>('/admin/dashboard/stats')
|
||||||
.then(setStats)
|
.then(setStats)
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
void loadVersion();
|
request<HqProfile>('/admin/auth/me')
|
||||||
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
.then((p) => {
|
||||||
|
setProfile(p);
|
||||||
|
if (p.adminRole === 'SUPER_ADMIN') {
|
||||||
|
void loadVersion();
|
||||||
|
} else {
|
||||||
|
setVersionLoading(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setVersionLoading(false);
|
||||||
|
});
|
||||||
}, [loadVersion]);
|
}, [loadVersion]);
|
||||||
|
|
||||||
function handleDeploy() {
|
function handleDeploy() {
|
||||||
@@ -83,6 +93,7 @@ export default function DashboardPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Typography.Title level={4}>数据概览</Typography.Title>
|
<Typography.Title level={4}>数据概览</Typography.Title>
|
||||||
|
|
||||||
|
{isSuperAdmin ? (
|
||||||
<Card
|
<Card
|
||||||
title="系统版本"
|
title="系统版本"
|
||||||
loading={versionLoading}
|
loading={versionLoading}
|
||||||
@@ -92,16 +103,14 @@ export default function DashboardPage() {
|
|||||||
<Button icon={<ReloadOutlined />} onClick={() => void loadVersion()}>
|
<Button icon={<ReloadOutlined />} onClick={() => void loadVersion()}>
|
||||||
刷新版本
|
刷新版本
|
||||||
</Button>
|
</Button>
|
||||||
{isSuperAdmin && (
|
<Button
|
||||||
<Button
|
type="primary"
|
||||||
type="primary"
|
icon={<CloudUploadOutlined />}
|
||||||
icon={<CloudUploadOutlined />}
|
loading={deploying}
|
||||||
loading={deploying}
|
onClick={handleDeploy}
|
||||||
onClick={handleDeploy}
|
>
|
||||||
>
|
发布更新
|
||||||
发布更新
|
</Button>
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -122,6 +131,7 @@ export default function DashboardPage() {
|
|||||||
<Typography.Text type="secondary">尚未记录发版信息</Typography.Text>
|
<Typography.Text type="secondary">尚未记录发版信息</Typography.Text>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
|
<Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
|
||||||
<Col xs={24} sm={12} lg={6}>
|
<Col xs={24} sm={12} lg={6}>
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
|
Divider,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
|
InputNumber,
|
||||||
Modal,
|
Modal,
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
@@ -14,10 +16,13 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import {
|
import {
|
||||||
|
DEFAULT_XFX_LOGISTICS_PRICING,
|
||||||
FULFILLMENT_PROVIDER_STATUS_LABELS,
|
FULFILLMENT_PROVIDER_STATUS_LABELS,
|
||||||
FULFILLMENT_PROVIDER_TYPE_LABELS,
|
FULFILLMENT_PROVIDER_TYPE_LABELS,
|
||||||
FulfillmentProviderStatus,
|
FulfillmentProviderStatus,
|
||||||
FulfillmentProviderType,
|
FulfillmentProviderType,
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS,
|
||||||
|
LogisticsSettlementMethod,
|
||||||
isXfxProviderCode,
|
isXfxProviderCode,
|
||||||
type FulfillmentProviderDto,
|
type FulfillmentProviderDto,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
@@ -32,6 +37,9 @@ const STATUS_OPTIONS = Object.entries(FULFILLMENT_PROVIDER_STATUS_LABELS).map(([
|
|||||||
value,
|
value,
|
||||||
label,
|
label,
|
||||||
}));
|
}));
|
||||||
|
const SETTLEMENT_OPTIONS = Object.entries(LOGISTICS_SETTLEMENT_METHOD_LABELS).map(
|
||||||
|
([value, label]) => ({ value, label }),
|
||||||
|
);
|
||||||
const SIGN_OPTIONS = [
|
const SIGN_OPTIONS = [
|
||||||
{ value: 'MD5', label: 'MD5' },
|
{ value: 'MD5', label: 'MD5' },
|
||||||
{ value: 'HMAC-SHA256', label: 'HMAC-SHA256' },
|
{ value: 'HMAC-SHA256', label: 'HMAC-SHA256' },
|
||||||
@@ -77,6 +85,12 @@ export default function FulfillmentProvidersPage() {
|
|||||||
status: FulfillmentProviderStatus.ACTIVE,
|
status: FulfillmentProviderStatus.ACTIVE,
|
||||||
apiUrl: DEFAULT_XFX_API_URL,
|
apiUrl: DEFAULT_XFX_API_URL,
|
||||||
signType: 'MD5',
|
signType: 'MD5',
|
||||||
|
settlementMethod: LogisticsSettlementMethod.PREPAID,
|
||||||
|
baseBottles: DEFAULT_XFX_LOGISTICS_PRICING.baseBottles,
|
||||||
|
baseFee: DEFAULT_XFX_LOGISTICS_PRICING.baseFee,
|
||||||
|
extraBottleFee: DEFAULT_XFX_LOGISTICS_PRICING.extraBottleFee,
|
||||||
|
boxBottles: DEFAULT_XFX_LOGISTICS_PRICING.boxBottles,
|
||||||
|
boxFee: DEFAULT_XFX_LOGISTICS_PRICING.boxFee,
|
||||||
});
|
});
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
}
|
}
|
||||||
@@ -84,6 +98,7 @@ export default function FulfillmentProvidersPage() {
|
|||||||
function openEdit(row: FulfillmentProviderDto) {
|
function openEdit(row: FulfillmentProviderDto) {
|
||||||
setEditRow(row);
|
setEditRow(row);
|
||||||
const xfx = row.xiaofeixiaConfig;
|
const xfx = row.xiaofeixiaConfig;
|
||||||
|
const pricing = row.pricingRules;
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
code: row.code,
|
code: row.code,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
@@ -94,6 +109,16 @@ export default function FulfillmentProvidersPage() {
|
|||||||
apiKey: '',
|
apiKey: '',
|
||||||
signType: xfx?.signType || 'MD5',
|
signType: xfx?.signType || 'MD5',
|
||||||
appId: xfx?.appId || '',
|
appId: xfx?.appId || '',
|
||||||
|
bankAccountName: row.bankAccountName || '',
|
||||||
|
bankName: row.bankName || '',
|
||||||
|
bankBranch: row.bankBranch || '',
|
||||||
|
bankAccountNo: row.bankAccountNo || '',
|
||||||
|
settlementMethod: row.settlementMethod || LogisticsSettlementMethod.PREPAID,
|
||||||
|
baseBottles: pricing?.baseBottles ?? DEFAULT_XFX_LOGISTICS_PRICING.baseBottles,
|
||||||
|
baseFee: pricing?.baseFee ?? DEFAULT_XFX_LOGISTICS_PRICING.baseFee,
|
||||||
|
extraBottleFee: pricing?.extraBottleFee ?? DEFAULT_XFX_LOGISTICS_PRICING.extraBottleFee,
|
||||||
|
boxBottles: pricing?.boxBottles ?? DEFAULT_XFX_LOGISTICS_PRICING.boxBottles,
|
||||||
|
boxFee: pricing?.boxFee ?? DEFAULT_XFX_LOGISTICS_PRICING.boxFee,
|
||||||
});
|
});
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
}
|
}
|
||||||
@@ -104,6 +129,18 @@ export default function FulfillmentProvidersPage() {
|
|||||||
name: v.name,
|
name: v.name,
|
||||||
type: v.type,
|
type: v.type,
|
||||||
status: v.status,
|
status: v.status,
|
||||||
|
bankAccountName: v.bankAccountName || null,
|
||||||
|
bankName: v.bankName || null,
|
||||||
|
bankBranch: v.bankBranch || null,
|
||||||
|
bankAccountNo: v.bankAccountNo || null,
|
||||||
|
settlementMethod: v.settlementMethod,
|
||||||
|
pricingRules: {
|
||||||
|
baseBottles: Number(v.baseBottles),
|
||||||
|
baseFee: Number(v.baseFee),
|
||||||
|
extraBottleFee: Number(v.extraBottleFee),
|
||||||
|
boxBottles: v.boxBottles != null ? Number(v.boxBottles) : undefined,
|
||||||
|
boxFee: v.boxFee != null ? Number(v.boxFee) : undefined,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isXfxProviderCode(String(v.code)) && v.type === FulfillmentProviderType.API) {
|
if (isXfxProviderCode(String(v.code)) && v.type === FulfillmentProviderType.API) {
|
||||||
@@ -144,6 +181,19 @@ export default function FulfillmentProvidersPage() {
|
|||||||
dataIndex: 'type',
|
dataIndex: 'type',
|
||||||
render: (v) => FULFILLMENT_PROVIDER_TYPE_LABELS[v as FulfillmentProviderType] || v,
|
render: (v) => FULFILLMENT_PROVIDER_TYPE_LABELS[v as FulfillmentProviderType] || v,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '结算',
|
||||||
|
dataIndex: 'settlementMethod',
|
||||||
|
width: 100,
|
||||||
|
render: (v) =>
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS[v as LogisticsSettlementMethod] || v || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '充值余额',
|
||||||
|
dataIndex: 'prepaidBalance',
|
||||||
|
width: 100,
|
||||||
|
render: (v) => `¥${Number(v || 0).toFixed(2)}`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '状态',
|
title: '状态',
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
@@ -188,7 +238,7 @@ export default function FulfillmentProvidersPage() {
|
|||||||
仓配管理
|
仓配管理
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
<Typography.Text type="secondary">
|
<Typography.Text type="secondary">
|
||||||
注册第三方履约接口并填写凭证;仓库绑定后,推单将使用此处配置的 API 地址与密钥
|
注册承运商接口凭证,并配置物流对账用的银行账户、结算方式与计价标准
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
</div>
|
</div>
|
||||||
<Button type="primary" onClick={openCreate}>
|
<Button type="primary" onClick={openCreate}>
|
||||||
@@ -200,7 +250,7 @@ export default function FulfillmentProvidersPage() {
|
|||||||
type="info"
|
type="info"
|
||||||
showIcon
|
showIcon
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
message="小飞侠配置已从「系统设置 → 同城配送」迁至本页。寄件地址以仓库联系人/地址为准。"
|
message="小飞侠默认计价:2瓶6元,加一瓶+2元,6瓶一箱14元。财务对账见「财务 → 物流对账」。"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Table rowKey="id" loading={loading} columns={columns} dataSource={rows} pagination={false} />
|
<Table rowKey="id" loading={loading} columns={columns} dataSource={rows} pagination={false} />
|
||||||
@@ -210,7 +260,7 @@ export default function FulfillmentProvidersPage() {
|
|||||||
open={open}
|
open={open}
|
||||||
onCancel={() => setOpen(false)}
|
onCancel={() => setOpen(false)}
|
||||||
onOk={() => void submit()}
|
onOk={() => void submit()}
|
||||||
width={560}
|
width={640}
|
||||||
destroyOnClose
|
destroyOnClose
|
||||||
>
|
>
|
||||||
<Form form={form} layout="vertical">
|
<Form form={form} layout="vertical">
|
||||||
@@ -227,11 +277,58 @@ export default function FulfillmentProvidersPage() {
|
|||||||
<Select options={STATUS_OPTIONS} />
|
<Select options={STATUS_OPTIONS} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
<Divider orientation="left">物流对账</Divider>
|
||||||
|
<Form.Item name="settlementMethod" label="结算方式" rules={[{ required: true }]}>
|
||||||
|
<Select options={SETTLEMENT_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankAccountName" label="收款户名">
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankName" label="开户银行">
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankBranch" label="开户支行">
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankAccountNo" label="银行账号">
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Space wrap style={{ width: '100%' }}>
|
||||||
|
<Form.Item
|
||||||
|
name="baseBottles"
|
||||||
|
label="起送瓶数"
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
>
|
||||||
|
<InputNumber min={1} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="baseFee"
|
||||||
|
label="起送费用(元)"
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
>
|
||||||
|
<InputNumber min={0} precision={2} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="extraBottleFee"
|
||||||
|
label="加一瓶(元)"
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
>
|
||||||
|
<InputNumber min={0} precision={2} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="boxBottles" label="箱规瓶数" style={{ marginBottom: 12 }}>
|
||||||
|
<InputNumber min={1} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="boxFee" label="一箱费用(元)" style={{ marginBottom: 12 }}>
|
||||||
|
<InputNumber min={0} precision={2} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
|
||||||
{showXfxFields && (
|
{showXfxFields && (
|
||||||
<>
|
<>
|
||||||
<Typography.Title level={5} style={{ marginTop: 8 }}>
|
<Divider orientation="left">小飞侠接口参数</Divider>
|
||||||
小飞侠接口参数
|
|
||||||
</Typography.Title>
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="apiUrl"
|
name="apiUrl"
|
||||||
label="API 地址"
|
label="API 地址"
|
||||||
|
|||||||
@@ -33,6 +33,15 @@ type AccountPermRes = {
|
|||||||
|
|
||||||
const ROLE_LABELS = Object.fromEntries(HQ_ADMIN_ROLES.map((r) => [r.value, r.label]));
|
const ROLE_LABELS = Object.fromEntries(HQ_ADMIN_ROLES.map((r) => [r.value, r.label]));
|
||||||
|
|
||||||
|
const CATALOG_GROUPS = [...new Set(HQ_PERMISSION_CATALOG.map((p) => p.group ?? '其他'))];
|
||||||
|
|
||||||
|
function groupColSpan(itemCount: number): number {
|
||||||
|
if (itemCount <= 2) return 12;
|
||||||
|
if (itemCount === 3) return 8;
|
||||||
|
if (itemCount === 4) return 6;
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
|
||||||
function PermissionChecklist({
|
function PermissionChecklist({
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
@@ -49,13 +58,44 @@ function PermissionChecklist({
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={(checked) => onChange(checked as string[])}
|
onChange={(checked) => onChange(checked as string[])}
|
||||||
>
|
>
|
||||||
<Row gutter={[8, 8]}>
|
{CATALOG_GROUPS.map((group) => {
|
||||||
{HQ_PERMISSION_CATALOG.map((item) => (
|
const items = HQ_PERMISSION_CATALOG.filter((p) => (p.group ?? '其他') === group);
|
||||||
<Col key={item.key} span={8}>
|
const span = groupColSpan(items.length);
|
||||||
<Checkbox value={item.key}>{item.label}</Checkbox>
|
const compact = items.length <= 3;
|
||||||
</Col>
|
return (
|
||||||
))}
|
<div
|
||||||
</Row>
|
key={group}
|
||||||
|
style={{
|
||||||
|
marginBottom: 16,
|
||||||
|
padding: '12px 16px',
|
||||||
|
background: '#fafafa',
|
||||||
|
borderRadius: 8,
|
||||||
|
border: '1px solid #f0f0f0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography.Text strong style={{ display: 'block', marginBottom: 10 }}>
|
||||||
|
{group}
|
||||||
|
</Typography.Text>
|
||||||
|
{compact ? (
|
||||||
|
<Space size={[24, 8]} wrap>
|
||||||
|
{items.map((item) => (
|
||||||
|
<Checkbox key={item.key} value={item.key}>
|
||||||
|
{item.label}
|
||||||
|
</Checkbox>
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<Row gutter={[12, 10]}>
|
||||||
|
{items.map((item) => (
|
||||||
|
<Col key={item.key} xs={24} sm={12} md={span}>
|
||||||
|
<Checkbox value={item.key}>{item.label}</Checkbox>
|
||||||
|
</Col>
|
||||||
|
))}
|
||||||
|
</Row>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</Checkbox.Group>
|
</Checkbox.Group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -74,6 +114,12 @@ export default function HqPermissionsPage() {
|
|||||||
const [accountLoading, setAccountLoading] = useState(false);
|
const [accountLoading, setAccountLoading] = useState(false);
|
||||||
const [accountSaving, setAccountSaving] = useState(false);
|
const [accountSaving, setAccountSaving] = useState(false);
|
||||||
|
|
||||||
|
const selectedAccount = useMemo(
|
||||||
|
() => accounts.find((a) => a.id === accountId),
|
||||||
|
[accounts, accountId],
|
||||||
|
);
|
||||||
|
const selectedIsSuperAdmin = selectedAccount?.adminRole === 'SUPER_ADMIN';
|
||||||
|
|
||||||
const previewEffectiveKeys = useMemo(
|
const previewEffectiveKeys = useMemo(
|
||||||
() => [...new Set([...roleInheritedKeys, ...accountKeys])],
|
() => [...new Set([...roleInheritedKeys, ...accountKeys])],
|
||||||
[roleInheritedKeys, accountKeys],
|
[roleInheritedKeys, accountKeys],
|
||||||
@@ -158,7 +204,9 @@ export default function HqPermissionsPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Typography.Title level={4}>权限分配</Typography.Title>
|
<Typography.Title level={4}>权限分配</Typography.Title>
|
||||||
<Typography.Paragraph type="secondary">
|
<Typography.Paragraph type="secondary">
|
||||||
按角色配置基础权限;按用户可追加专属权限。最终生效权限 = 角色权限 ∪ 用户权限(超级管理员始终拥有全部权限)。
|
按角色配置基础权限;按用户可追加专属权限。最终生效权限 = 角色权限 ∪ 用户权限。
|
||||||
|
超级管理员默认拥有除「危险操作」外的全部权限;删除用户/订单/城市需在「按用户分配」中单独勾选(默认均无)。
|
||||||
|
「系统设置」已拆分为各配置分组;「财务」对应门店/合伙人/酒厂账单。
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
|
|
||||||
<Tabs
|
<Tabs
|
||||||
@@ -183,7 +231,11 @@ export default function HqPermissionsPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
{role === 'SUPER_ADMIN' ? (
|
{role === 'SUPER_ADMIN' ? (
|
||||||
<Alert type="info" showIcon message="超级管理员拥有全部权限,无需配置" />
|
<Alert
|
||||||
|
type="info"
|
||||||
|
showIcon
|
||||||
|
message="超级管理员基础权限固定(不含危险操作)。删除用户/订单/城市请到「按用户分配」为具体账号勾选。"
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<PermissionChecklist value={roleKeys} onChange={setRoleKeys} />
|
<PermissionChecklist value={roleKeys} onChange={setRoleKeys} />
|
||||||
@@ -212,12 +264,10 @@ export default function HqPermissionsPage() {
|
|||||||
value={accountId}
|
value={accountId}
|
||||||
onChange={setAccountId}
|
onChange={setAccountId}
|
||||||
optionFilterProp="label"
|
optionFilterProp="label"
|
||||||
options={accounts
|
options={accounts.map((a) => ({
|
||||||
.filter((a) => a.adminRole !== 'SUPER_ADMIN')
|
value: a.id,
|
||||||
.map((a) => ({
|
label: `${a.name} · ${a.loginName || a.phone} · ${ROLE_LABELS[a.adminRole] || a.adminRole}`,
|
||||||
value: a.id,
|
}))}
|
||||||
label: `${a.name} · ${a.loginName || a.phone} · ${ROLE_LABELS[a.adminRole] || a.adminRole}`,
|
|
||||||
}))}
|
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
@@ -225,28 +275,57 @@ export default function HqPermissionsPage() {
|
|||||||
<Alert type="info" showIcon message="请先选择要配置的 HQ 账户" />
|
<Alert type="info" showIcon message="请先选择要配置的 HQ 账户" />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Space wrap style={{ marginBottom: 12 }}>
|
<div style={{ marginBottom: 12 }}>
|
||||||
<span>角色继承:</span>
|
<span style={{ marginRight: 8 }}>角色继承:</span>
|
||||||
{roleInheritedKeys.map((key) => {
|
{selectedIsSuperAdmin ? (
|
||||||
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === key);
|
<Tag color="blue">超级管理员基础权限(不含危险操作)</Tag>
|
||||||
return (
|
) : (
|
||||||
<Tag key={key} color="blue">
|
<Space wrap size={[4, 4]}>
|
||||||
{item?.label || key}
|
{roleInheritedKeys.map((key) => {
|
||||||
</Tag>
|
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === key);
|
||||||
);
|
return (
|
||||||
})}
|
<Tag key={key} color="blue">
|
||||||
</Space>
|
{item?.label || key}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{!roleInheritedKeys.length ? (
|
||||||
|
<Typography.Text type="secondary">无</Typography.Text>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<Typography.Paragraph type="secondary">
|
<Typography.Paragraph type="secondary">
|
||||||
下方勾选为用户专属追加权限(保存后与角色权限合并生效)。
|
下方勾选为用户专属追加权限(保存后与角色权限合并生效)。危险操作(删除用户/订单/城市)默认不授予,需在此勾选。
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
<PermissionChecklist value={accountKeys} onChange={setAccountKeys} />
|
<PermissionChecklist value={accountKeys} onChange={setAccountKeys} />
|
||||||
<Space wrap style={{ marginTop: 12 }}>
|
<div style={{ marginTop: 12 }}>
|
||||||
<span>合并生效:</span>
|
<span style={{ marginRight: 8 }}>合并生效:</span>
|
||||||
{previewEffectiveKeys.map((key) => {
|
{selectedIsSuperAdmin ? (
|
||||||
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === (key as HqPermissionKey));
|
<Space wrap size={[4, 4]}>
|
||||||
return <Tag key={key}>{item?.label || key}</Tag>;
|
<Tag>基础权限(全部)</Tag>
|
||||||
})}
|
{accountKeys.map((key) => {
|
||||||
</Space>
|
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === (key as HqPermissionKey));
|
||||||
|
return (
|
||||||
|
<Tag key={key} color="orange">
|
||||||
|
{item?.label || key}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<Space wrap size={[4, 4]}>
|
||||||
|
{previewEffectiveKeys.map((key) => {
|
||||||
|
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === (key as HqPermissionKey));
|
||||||
|
return (
|
||||||
|
<Tag key={key}>
|
||||||
|
{item?.label || key}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div style={{ marginTop: 16 }}>
|
<div style={{ marginTop: 16 }}>
|
||||||
<Button type="primary" loading={accountSaving} onClick={() => void saveAccountPermissions()}>
|
<Button type="primary" loading={accountSaving} onClick={() => void saveAccountPermissions()}>
|
||||||
保存用户权限
|
保存用户权限
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import {
|
|||||||
Drawer,
|
Drawer,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
|
Modal,
|
||||||
Select,
|
Select,
|
||||||
|
Space,
|
||||||
Table,
|
Table,
|
||||||
Tag,
|
Tag,
|
||||||
Typography,
|
Typography,
|
||||||
@@ -47,6 +49,19 @@ type Row = {
|
|||||||
remark?: string;
|
remark?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type CreateFormValues = {
|
||||||
|
orderNo: string;
|
||||||
|
titleType: InvoiceTitleType;
|
||||||
|
invoiceKind: InvoiceKind;
|
||||||
|
titleName: string;
|
||||||
|
taxNo?: string;
|
||||||
|
addressPhone?: string;
|
||||||
|
bankAccount?: string;
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
remark?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export default function InvoicesPage() {
|
export default function InvoicesPage() {
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
@@ -61,6 +76,11 @@ export default function InvoicesPage() {
|
|||||||
const [detail, setDetail] = useState<Row | null>(null);
|
const [detail, setDetail] = useState<Row | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
const [uploading, setUploading] = useState(false);
|
const [uploading, setUploading] = useState(false);
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const [creating, setCreating] = useState(false);
|
||||||
|
const [createForm] = Form.useForm<CreateFormValues>();
|
||||||
|
const invoiceKind = Form.useWatch('invoiceKind', createForm);
|
||||||
|
const titleType = Form.useWatch('titleType', createForm);
|
||||||
|
|
||||||
async function openDetail(id: string) {
|
async function openDetail(id: string) {
|
||||||
setDetail(await request(`/admin/invoices/${id}`));
|
setDetail(await request(`/admin/invoices/${id}`));
|
||||||
@@ -98,6 +118,36 @@ export default function InvoicesPage() {
|
|||||||
setDrawerOpen(false);
|
setDrawerOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function submitCreate() {
|
||||||
|
const values = await createForm.validateFields();
|
||||||
|
setCreating(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/invoices', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
orderNo: values.orderNo.trim(),
|
||||||
|
titleType: values.titleType,
|
||||||
|
invoiceKind: values.invoiceKind,
|
||||||
|
titleName: values.titleName.trim(),
|
||||||
|
taxNo: values.taxNo?.trim() || undefined,
|
||||||
|
addressPhone: values.addressPhone?.trim() || undefined,
|
||||||
|
bankAccount: values.bankAccount?.trim() || undefined,
|
||||||
|
email: values.email.trim(),
|
||||||
|
phone: values.phone.trim(),
|
||||||
|
remark: values.remark?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('发票申请已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
|
createForm.resetFields();
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '创建失败');
|
||||||
|
} finally {
|
||||||
|
setCreating(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '申请单号', dataIndex: 'invoiceNo', width: 180 },
|
{ title: '申请单号', dataIndex: 'invoiceNo', width: 180 },
|
||||||
{ title: '订单号', dataIndex: 'orderNo', width: 160 },
|
{ title: '订单号', dataIndex: 'orderNo', width: 160 },
|
||||||
@@ -138,7 +188,30 @@ export default function InvoicesPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Typography.Title level={4}>发票管理</Typography.Title>
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
marginBottom: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
发票管理
|
||||||
|
</Typography.Title>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => {
|
||||||
|
createForm.setFieldsValue({
|
||||||
|
titleType: 'PERSONAL',
|
||||||
|
invoiceKind: 'NORMAL',
|
||||||
|
});
|
||||||
|
setCreateOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
创建发票申请
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<Form
|
<Form
|
||||||
layout="inline"
|
layout="inline"
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
@@ -187,7 +260,7 @@ export default function InvoicesPage() {
|
|||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={
|
extra={
|
||||||
detail?.status === 'PENDING' ? (
|
detail?.status === 'PENDING' ? (
|
||||||
<>
|
<Space>
|
||||||
<Upload
|
<Upload
|
||||||
accept="image/*,.pdf"
|
accept="image/*,.pdf"
|
||||||
showUploadList={false}
|
showUploadList={false}
|
||||||
@@ -196,14 +269,14 @@ export default function InvoicesPage() {
|
|||||||
return false;
|
return false;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button type="primary" loading={uploading} style={{ marginRight: 8 }}>
|
<Button type="primary" loading={uploading}>
|
||||||
上传并开票
|
上传并开票
|
||||||
</Button>
|
</Button>
|
||||||
</Upload>
|
</Upload>
|
||||||
<Button danger onClick={() => void reject()}>
|
<Button danger onClick={() => void reject()}>
|
||||||
驳回
|
驳回
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</Space>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -242,6 +315,110 @@ export default function InvoicesPage() {
|
|||||||
</Descriptions>
|
</Descriptions>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="创建发票申请"
|
||||||
|
open={createOpen}
|
||||||
|
onCancel={() => setCreateOpen(false)}
|
||||||
|
onOk={() => void submitCreate()}
|
||||||
|
confirmLoading={creating}
|
||||||
|
destroyOnClose
|
||||||
|
okText="提交"
|
||||||
|
width={520}
|
||||||
|
>
|
||||||
|
<Form form={createForm} layout="vertical">
|
||||||
|
<Form.Item
|
||||||
|
name="orderNo"
|
||||||
|
label="订单号"
|
||||||
|
rules={[{ required: true, message: '请填写已完成订单号' }]}
|
||||||
|
extra="仅已完成订单可开票"
|
||||||
|
>
|
||||||
|
<Input placeholder="订单号" allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="invoiceKind"
|
||||||
|
label="发票类型"
|
||||||
|
rules={[{ required: true, message: '请选择发票类型' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
options={(Object.keys(INVOICE_KIND_LABELS) as InvoiceKind[]).map((k) => ({
|
||||||
|
value: k,
|
||||||
|
label: INVOICE_KIND_LABELS[k],
|
||||||
|
}))}
|
||||||
|
onChange={(k: InvoiceKind) => {
|
||||||
|
if (k === 'SPECIAL') createForm.setFieldValue('titleType', 'ENTERPRISE');
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="titleType"
|
||||||
|
label="抬头类型"
|
||||||
|
rules={[{ required: true, message: '请选择抬头类型' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
options={(Object.keys(INVOICE_TITLE_TYPE_LABELS) as InvoiceTitleType[]).map((t) => ({
|
||||||
|
value: t,
|
||||||
|
label: INVOICE_TITLE_TYPE_LABELS[t],
|
||||||
|
disabled: invoiceKind === 'SPECIAL' && t === 'PERSONAL',
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="titleName"
|
||||||
|
label="抬头名称"
|
||||||
|
rules={[{ required: true, message: '请填写抬头名称' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="个人姓名或企业全称" />
|
||||||
|
</Form.Item>
|
||||||
|
{(titleType === 'ENTERPRISE' || invoiceKind === 'SPECIAL') && (
|
||||||
|
<Form.Item
|
||||||
|
name="taxNo"
|
||||||
|
label="税号"
|
||||||
|
rules={[{ required: true, message: '企业抬头须填写税号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="纳税人识别号" />
|
||||||
|
</Form.Item>
|
||||||
|
)}
|
||||||
|
{invoiceKind === 'SPECIAL' && (
|
||||||
|
<>
|
||||||
|
<Form.Item
|
||||||
|
name="addressPhone"
|
||||||
|
label="地址电话"
|
||||||
|
rules={[{ required: true, message: '专用发票须填写地址电话' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="注册地址及电话" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="bankAccount"
|
||||||
|
label="开户行账号"
|
||||||
|
rules={[{ required: true, message: '专用发票须填写开户行账号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="开户行及账号" />
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<Form.Item
|
||||||
|
name="email"
|
||||||
|
label="接收邮箱"
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: '请填写邮箱' },
|
||||||
|
{ type: 'email', message: '邮箱格式不正确' },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input placeholder="发票发送邮箱" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="phone"
|
||||||
|
label="手机号"
|
||||||
|
rules={[{ required: true, message: '请填写手机号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="联系手机" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
|
<Input.TextArea rows={2} maxLength={512} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,403 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Space,
|
||||||
|
Switch,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
Upload,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import { UploadOutlined } from '@ant-design/icons';
|
||||||
|
import type {
|
||||||
|
KnowledgeBaseDto,
|
||||||
|
KnowledgeDocumentDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import { uploadFileToOss } from '../lib/upload';
|
||||||
|
|
||||||
|
type FormValues = {
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
enabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type DocForm = {
|
||||||
|
title: string;
|
||||||
|
contentText?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function KnowledgeBasesPage() {
|
||||||
|
const [filterForm] = Form.useForm();
|
||||||
|
const [form] = Form.useForm<FormValues>();
|
||||||
|
const [docForm] = Form.useForm<DocForm>();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [editing, setEditing] = useState<KnowledgeBaseDto | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [drawerKb, setDrawerKb] = useState<KnowledgeBaseDto | null>(null);
|
||||||
|
const [docs, setDocs] = useState<KnowledgeDocumentDto[]>([]);
|
||||||
|
const [docsLoading, setDocsLoading] = useState(false);
|
||||||
|
const [docModalOpen, setDocModalOpen] = useState(false);
|
||||||
|
const [docSaving, setDocSaving] = useState(false);
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } =
|
||||||
|
useAdminList<KnowledgeBaseDto>(
|
||||||
|
'/admin/knowledge-bases',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.name) qs.set('name', filters.name);
|
||||||
|
if (filters.enabled) qs.set('enabled', filters.enabled);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
const loadDocs = async (kb: KnowledgeBaseDto) => {
|
||||||
|
setDrawerKb(kb);
|
||||||
|
setDocsLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await request<{ items: KnowledgeDocumentDto[] }>(
|
||||||
|
`/admin/knowledge-bases/${kb.id}/documents`,
|
||||||
|
);
|
||||||
|
setDocs(res.items);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
setDocsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openCreate = () => {
|
||||||
|
setEditing(null);
|
||||||
|
form.setFieldsValue({ name: '', description: '', enabled: true });
|
||||||
|
setModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openEdit = (row: KnowledgeBaseDto) => {
|
||||||
|
setEditing(row);
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: row.name,
|
||||||
|
description: row.description || '',
|
||||||
|
enabled: row.enabled,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSave = async () => {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
if (editing) {
|
||||||
|
await request(`/admin/knowledge-bases/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
});
|
||||||
|
message.success('已保存');
|
||||||
|
} else {
|
||||||
|
await request('/admin/knowledge-bases', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
setModalOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: ColumnsType<KnowledgeBaseDto> = [
|
||||||
|
{ title: '名称', dataIndex: 'name' },
|
||||||
|
{ title: '说明', dataIndex: 'description', ellipsis: true },
|
||||||
|
{ title: '文档数', dataIndex: 'documentCount', width: 90 },
|
||||||
|
{
|
||||||
|
title: '启用',
|
||||||
|
dataIndex: 'enabled',
|
||||||
|
width: 90,
|
||||||
|
render: (v: boolean) => (v ? <Tag color="green">开</Tag> : <Tag>关</Tag>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建人',
|
||||||
|
dataIndex: 'createdByName',
|
||||||
|
width: 100,
|
||||||
|
render: (v: string | null, row) => v || row.createdByHqAccountId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '更新时间',
|
||||||
|
dataIndex: 'updatedAt',
|
||||||
|
width: 170,
|
||||||
|
render: (t: string) => fmtTime(t),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 240,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button type="link" size="small" onClick={() => void loadDocs(row)}>
|
||||||
|
文档
|
||||||
|
</Button>
|
||||||
|
{row.canEditFull ? (
|
||||||
|
<Button type="link" size="small" onClick={() => openEdit(row)}>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
{row.canEditFull ? (
|
||||||
|
<Popconfirm
|
||||||
|
title="确认删除知识库及全部文档?"
|
||||||
|
onConfirm={async () => {
|
||||||
|
try {
|
||||||
|
await request(`/admin/knowledge-bases/${row.id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const docColumns: ColumnsType<KnowledgeDocumentDto> = [
|
||||||
|
{ title: '标题', dataIndex: 'title' },
|
||||||
|
{ title: '文件', dataIndex: 'fileName', ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 90,
|
||||||
|
render: (s: string) =>
|
||||||
|
s === 'READY' ? <Tag color="green">可检索</Tag> : s === 'FAILED' ? <Tag color="red">失败</Tag> : <Tag>无正文</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '时间',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
width: 170,
|
||||||
|
render: (t: string) => fmtTime(t),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 80,
|
||||||
|
render: (_, row) =>
|
||||||
|
drawerKb?.canEditFull ? (
|
||||||
|
<Popconfirm
|
||||||
|
title="删除文档?"
|
||||||
|
onConfirm={async () => {
|
||||||
|
try {
|
||||||
|
await request(`/admin/knowledge-bases/${drawerKb.id}/documents/${row.id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
message.success('已删除');
|
||||||
|
void loadDocs(drawerKb);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
) : null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space style={{ marginBottom: 16 }} wrap>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
知识库
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
支持粘贴文本或上传 .txt/.md;可绑定到企微机器人供 AI 检索
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) =>
|
||||||
|
setFilters({
|
||||||
|
name: v.name || '',
|
||||||
|
enabled: v.enabled === undefined || v.enabled === null ? '' : String(v.enabled),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Form.Item name="name" label="名称">
|
||||||
|
<Input allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" onClick={openCreate}>
|
||||||
|
新建知识库
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? '编辑知识库' : '新建知识库'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={() => setModalOpen(false)}
|
||||||
|
onOk={() => void onSave()}
|
||||||
|
confirmLoading={saving}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="description" label="说明">
|
||||||
|
<Input.TextArea rows={2} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="启用" valuePropName="checked">
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title={drawerKb ? `文档 · ${drawerKb.name}` : '文档'}
|
||||||
|
open={!!drawerKb}
|
||||||
|
width={720}
|
||||||
|
onClose={() => setDrawerKb(null)}
|
||||||
|
extra={
|
||||||
|
drawerKb?.canEditFull ? (
|
||||||
|
<Button type="primary" onClick={() => { docForm.resetFields(); setDocModalOpen(true); }}>
|
||||||
|
上传/粘贴
|
||||||
|
</Button>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
size="small"
|
||||||
|
loading={docsLoading}
|
||||||
|
columns={docColumns}
|
||||||
|
dataSource={docs}
|
||||||
|
pagination={false}
|
||||||
|
/>
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="添加知识文档"
|
||||||
|
open={docModalOpen}
|
||||||
|
onCancel={() => setDocModalOpen(false)}
|
||||||
|
confirmLoading={docSaving}
|
||||||
|
onOk={async () => {
|
||||||
|
if (!drawerKb) return;
|
||||||
|
const values = await docForm.validateFields();
|
||||||
|
setDocSaving(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/knowledge-bases/${drawerKb.id}/documents`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
title: values.title,
|
||||||
|
contentText: values.contentText || null,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已添加');
|
||||||
|
setDocModalOpen(false);
|
||||||
|
void loadDocs(drawerKb);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
setDocSaving(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
destroyOnClose
|
||||||
|
width={640}
|
||||||
|
>
|
||||||
|
<Form form={docForm} layout="vertical">
|
||||||
|
<Form.Item name="title" label="标题" rules={[{ required: true }]}>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="contentText" label="正文(可粘贴)">
|
||||||
|
<Input.TextArea rows={8} placeholder="支持 Markdown / 纯文本" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="或上传文本文件">
|
||||||
|
<Upload
|
||||||
|
accept=".txt,.md,.markdown,.csv,.json,.log,text/*"
|
||||||
|
maxCount={1}
|
||||||
|
customRequest={async ({ file, onSuccess, onError }) => {
|
||||||
|
if (!drawerKb) return;
|
||||||
|
try {
|
||||||
|
const raw = file as File;
|
||||||
|
const uploaded = await uploadFileToOss(raw, {
|
||||||
|
bizType: 'KB_DOCUMENT',
|
||||||
|
mediaType: 'FILE',
|
||||||
|
});
|
||||||
|
const title =
|
||||||
|
docForm.getFieldValue('title') || raw.name.replace(/\.[^.]+$/, '');
|
||||||
|
await request(`/admin/knowledge-bases/${drawerKb.id}/documents`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
title,
|
||||||
|
fileName: raw.name,
|
||||||
|
fileUrl: uploaded.url,
|
||||||
|
mimeType: raw.type || null,
|
||||||
|
sizeBytes: raw.size,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('上传成功');
|
||||||
|
setDocModalOpen(false);
|
||||||
|
void loadDocs(drawerKb);
|
||||||
|
reload();
|
||||||
|
onSuccess?.(uploaded);
|
||||||
|
} catch (e) {
|
||||||
|
const err = e instanceof Error ? e : new Error(String(e));
|
||||||
|
message.error(err.message);
|
||||||
|
onError?.(err);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
showUploadList={false}
|
||||||
|
>
|
||||||
|
<Button icon={<UploadOutlined />}>上传到 OSS 并入库</Button>
|
||||||
|
</Upload>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,380 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Switch,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import {
|
||||||
|
LLM_PROVIDERS,
|
||||||
|
LLM_PROVIDER_LABELS,
|
||||||
|
LLM_PROVIDER_PRESETS,
|
||||||
|
type LlmApiConfigDto,
|
||||||
|
type LlmProvider,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
|
type FormValues = {
|
||||||
|
name: string;
|
||||||
|
provider: LlmProvider;
|
||||||
|
baseUrl?: string;
|
||||||
|
apiKey?: string;
|
||||||
|
modelName?: string;
|
||||||
|
temperature?: number | null;
|
||||||
|
maxTokens?: number | null;
|
||||||
|
systemPrompt?: string;
|
||||||
|
enabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function LlmConfigsPage() {
|
||||||
|
const [filterForm] = Form.useForm();
|
||||||
|
const [form] = Form.useForm<FormValues>();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [editing, setEditing] = useState<LlmApiConfigDto | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const providerWatch = Form.useWatch('provider', form);
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<LlmApiConfigDto>(
|
||||||
|
'/admin/llm-configs',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.name) qs.set('name', filters.name);
|
||||||
|
if (filters.enabled) qs.set('enabled', filters.enabled);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!providerWatch || editing) return;
|
||||||
|
const preset = LLM_PROVIDER_PRESETS[providerWatch as LlmProvider];
|
||||||
|
if (!preset) return;
|
||||||
|
form.setFieldsValue({
|
||||||
|
baseUrl: preset.defaultBaseUrl || undefined,
|
||||||
|
modelName: preset.defaultModel || undefined,
|
||||||
|
});
|
||||||
|
}, [providerWatch, editing, form]);
|
||||||
|
|
||||||
|
const openCreate = () => {
|
||||||
|
setEditing(null);
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: '',
|
||||||
|
provider: 'DEEPSEEK',
|
||||||
|
baseUrl: LLM_PROVIDER_PRESETS.DEEPSEEK.defaultBaseUrl,
|
||||||
|
apiKey: '',
|
||||||
|
modelName: LLM_PROVIDER_PRESETS.DEEPSEEK.defaultModel,
|
||||||
|
temperature: 0.3,
|
||||||
|
maxTokens: 1024,
|
||||||
|
systemPrompt: '',
|
||||||
|
enabled: true,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openEdit = (row: LlmApiConfigDto) => {
|
||||||
|
setEditing(row);
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: row.name,
|
||||||
|
provider: row.provider,
|
||||||
|
baseUrl: row.baseUrl,
|
||||||
|
apiKey: '',
|
||||||
|
modelName: row.modelName,
|
||||||
|
temperature: row.temperature,
|
||||||
|
maxTokens: row.maxTokens,
|
||||||
|
systemPrompt: row.systemPrompt || '',
|
||||||
|
enabled: row.enabled,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSave = async () => {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
if (editing) {
|
||||||
|
if (!editing.canEditFull) {
|
||||||
|
await request(`/admin/llm-configs/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ enabled: values.enabled }),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await request(`/admin/llm-configs/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: values.name,
|
||||||
|
provider: values.provider,
|
||||||
|
baseUrl: values.baseUrl,
|
||||||
|
apiKey: values.apiKey || undefined,
|
||||||
|
modelName: values.modelName,
|
||||||
|
temperature: values.temperature ?? null,
|
||||||
|
maxTokens: values.maxTokens ?? null,
|
||||||
|
systemPrompt: values.systemPrompt || null,
|
||||||
|
enabled: values.enabled,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
message.success('已保存');
|
||||||
|
} else {
|
||||||
|
await request('/admin/llm-configs', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: values.name,
|
||||||
|
provider: values.provider,
|
||||||
|
baseUrl: values.baseUrl,
|
||||||
|
apiKey: values.apiKey,
|
||||||
|
modelName: values.modelName,
|
||||||
|
temperature: values.temperature ?? null,
|
||||||
|
maxTokens: values.maxTokens ?? null,
|
||||||
|
systemPrompt: values.systemPrompt || null,
|
||||||
|
enabled: values.enabled,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
setModalOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: ColumnsType<LlmApiConfigDto> = [
|
||||||
|
{ title: '名称', dataIndex: 'name' },
|
||||||
|
{
|
||||||
|
title: '提供商',
|
||||||
|
dataIndex: 'provider',
|
||||||
|
width: 120,
|
||||||
|
render: (p: LlmProvider) => LLM_PROVIDER_LABELS[p] || p,
|
||||||
|
},
|
||||||
|
{ title: '模型', dataIndex: 'modelName', ellipsis: true },
|
||||||
|
{
|
||||||
|
title: 'Key',
|
||||||
|
dataIndex: 'apiKeyConfigured',
|
||||||
|
width: 80,
|
||||||
|
render: (v: boolean) => (v ? <Tag color="green">已配</Tag> : <Tag>无</Tag>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '生效',
|
||||||
|
dataIndex: 'enabled',
|
||||||
|
width: 90,
|
||||||
|
render: (v: boolean, row) => (
|
||||||
|
<Switch
|
||||||
|
checked={v}
|
||||||
|
disabled={!row.isOwner && !row.canEditFull}
|
||||||
|
onChange={async (checked) => {
|
||||||
|
try {
|
||||||
|
await request(`/admin/llm-configs/${row.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ enabled: checked }),
|
||||||
|
});
|
||||||
|
message.success(checked ? '已启用' : '已停用');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建人',
|
||||||
|
dataIndex: 'createdByName',
|
||||||
|
width: 100,
|
||||||
|
render: (v: string | null, row) => v || row.createdByHqAccountId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '更新时间',
|
||||||
|
dataIndex: 'updatedAt',
|
||||||
|
width: 170,
|
||||||
|
render: (t: string) => fmtTime(t),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 220,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={() => openEdit(row)}
|
||||||
|
>
|
||||||
|
{row.canEditFull ? '编辑' : '开关'}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
const res = await request<{ reply: string }>(`/admin/llm-configs/${row.id}/test`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: '{}',
|
||||||
|
});
|
||||||
|
message.success(res.reply || '测试成功');
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
测试
|
||||||
|
</Button>
|
||||||
|
{row.canEditFull ? (
|
||||||
|
<Popconfirm
|
||||||
|
title="确认删除?"
|
||||||
|
onConfirm={async () => {
|
||||||
|
try {
|
||||||
|
await request(`/admin/llm-configs/${row.id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const fullEdit = !editing || editing.canEditFull;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space style={{ marginBottom: 16 }} wrap>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
语言模型配置
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
非超管仅可见自己创建的配置,且创建后只能改是否生效
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) =>
|
||||||
|
setFilters({
|
||||||
|
name: v.name || '',
|
||||||
|
enabled: v.enabled === undefined || v.enabled === null ? '' : String(v.enabled),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Form.Item name="name" label="名称">
|
||||||
|
<Input allowClear placeholder="搜索" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="生效">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 100 }}
|
||||||
|
options={[
|
||||||
|
{ value: true, label: '开' },
|
||||||
|
{ value: false, label: '关' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" onClick={openCreate}>
|
||||||
|
新建配置
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? (fullEdit ? '编辑语言模型' : '修改是否生效') : '新建语言模型'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={() => setModalOpen(false)}
|
||||||
|
onOk={() => void onSave()}
|
||||||
|
confirmLoading={saving}
|
||||||
|
destroyOnClose
|
||||||
|
width={640}
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="name" label="名称" rules={[{ required: true, message: '必填' }]}>
|
||||||
|
<Input disabled={!fullEdit} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="provider" label="提供商" rules={[{ required: true }]}>
|
||||||
|
<Select
|
||||||
|
disabled={!fullEdit}
|
||||||
|
options={LLM_PROVIDERS.map((p) => ({ value: p, label: LLM_PROVIDER_LABELS[p] }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="baseUrl"
|
||||||
|
label="Base URL"
|
||||||
|
rules={[{ required: fullEdit, message: '必填' }]}
|
||||||
|
extra="填主机根地址即可,如 https://api.deepseek.com(不要带 /v1)"
|
||||||
|
>
|
||||||
|
<Input disabled={!fullEdit} placeholder="https://api.deepseek.com" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="apiKey"
|
||||||
|
label="API Key"
|
||||||
|
rules={editing ? [] : [{ required: true, message: '必填' }]}
|
||||||
|
extra={editing ? '留空表示不修改' : undefined}
|
||||||
|
>
|
||||||
|
<Input.Password disabled={!fullEdit} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="modelName" label="模型名" rules={[{ required: fullEdit, message: '必填' }]}>
|
||||||
|
<Input disabled={!fullEdit} />
|
||||||
|
</Form.Item>
|
||||||
|
<Space style={{ display: 'flex' }} size="large">
|
||||||
|
<Form.Item name="temperature" label="Temperature">
|
||||||
|
<InputNumber disabled={!fullEdit} min={0} max={2} step={0.1} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="maxTokens" label="Max Tokens">
|
||||||
|
<InputNumber disabled={!fullEdit} min={1} max={128000} style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
<Form.Item name="systemPrompt" label="系统提示词">
|
||||||
|
<Input.TextArea disabled={!fullEdit} rows={3} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="生效" valuePropName="checked">
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,625 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
DatePicker,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Modal,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Statistic,
|
||||||
|
Table,
|
||||||
|
Tabs,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import type { Dayjs } from 'dayjs';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import {
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS,
|
||||||
|
type LogisticsSettlementMethod,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { downloadExcelCsv } from '../lib/exportExcel';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
|
type BillRow = {
|
||||||
|
id: string;
|
||||||
|
billNo: string;
|
||||||
|
fulfillmentProviderId: string;
|
||||||
|
providerCode?: string;
|
||||||
|
providerName?: string;
|
||||||
|
periodStart: string;
|
||||||
|
periodEnd: string;
|
||||||
|
orderCount: number;
|
||||||
|
bottleCount: number;
|
||||||
|
logisticsAmount: number;
|
||||||
|
settlementMethod: string;
|
||||||
|
status: string;
|
||||||
|
paidAt?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type BillItem = {
|
||||||
|
id: string;
|
||||||
|
orderNo: string;
|
||||||
|
quantity: number;
|
||||||
|
logisticsAmount: number;
|
||||||
|
shippedAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProviderSummary = {
|
||||||
|
providerId: string;
|
||||||
|
providerCode: string;
|
||||||
|
providerName: string;
|
||||||
|
settlementMethod: string;
|
||||||
|
prepaidBalance: number;
|
||||||
|
bankAccountName?: string | null;
|
||||||
|
bankName?: string | null;
|
||||||
|
bankAccountNo?: string | null;
|
||||||
|
orderCount: number;
|
||||||
|
bottleCount: number;
|
||||||
|
logisticsAmount: number;
|
||||||
|
billId?: string | null;
|
||||||
|
billStatus?: string | null;
|
||||||
|
pricingRules?: {
|
||||||
|
baseBottles: number;
|
||||||
|
baseFee: number;
|
||||||
|
extraBottleFee: number;
|
||||||
|
boxBottles?: number;
|
||||||
|
boxFee?: number;
|
||||||
|
} | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
|
UNPAID: '未结算',
|
||||||
|
PAID: '已结算',
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_COLORS: Record<string, string> = {
|
||||||
|
UNPAID: 'red',
|
||||||
|
PAID: 'green',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function LogisticsBillsPage() {
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [summaryForm] = Form.useForm();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<BillRow>(
|
||||||
|
'/admin/logistics-bills',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
if (filters.providerId) qs.set('providerId', filters.providerId);
|
||||||
|
if (filters.year) qs.set('year', filters.year);
|
||||||
|
if (filters.month) qs.set('month', filters.month);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
const [exporting, setExporting] = useState(false);
|
||||||
|
const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
|
||||||
|
const [detail, setDetail] = useState<(BillRow & { items?: BillItem[] }) | null>(null);
|
||||||
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [providers, setProviders] = useState<Array<{ id: string; code: string; name: string }>>([]);
|
||||||
|
const [summaryRows, setSummaryRows] = useState<ProviderSummary[]>([]);
|
||||||
|
const [summaryLoading, setSummaryLoading] = useState(false);
|
||||||
|
const [summaryPeriod, setSummaryPeriod] = useState(() => dayjs().subtract(1, 'month'));
|
||||||
|
const [genOpen, setGenOpen] = useState(false);
|
||||||
|
const [genForm] = Form.useForm();
|
||||||
|
const [rechargeOpen, setRechargeOpen] = useState(false);
|
||||||
|
const [rechargeTarget, setRechargeTarget] = useState<ProviderSummary | null>(null);
|
||||||
|
const [rechargeForm] = Form.useForm();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<Array<{ id: string; code: string; name: string }>>('/admin/fulfillment-providers')
|
||||||
|
.then((rows) => setProviders(rows.map((r) => ({ id: r.id, code: r.code, name: r.name }))))
|
||||||
|
.catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function loadSummary(period: Dayjs) {
|
||||||
|
setSummaryLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await request<{ items: ProviderSummary[] }>(
|
||||||
|
`/admin/logistics-bills/provider-summary?year=${period.year()}&month=${period.month() + 1}`,
|
||||||
|
);
|
||||||
|
setSummaryRows(res.items ?? []);
|
||||||
|
} finally {
|
||||||
|
setSummaryLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadSummary(summaryPeriod);
|
||||||
|
}, [summaryPeriod]);
|
||||||
|
|
||||||
|
function confirmPay(ids: string[], amountHint?: number) {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认结算?',
|
||||||
|
content: `将确认 ${ids.length} 笔物流对账单${amountHint != null ? `,合计约 ¥${amountHint.toFixed(2)}` : ''}。充值模式将扣减余额,挂账模式标记已打款。`,
|
||||||
|
okText: '确认结算',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
if (ids.length === 1) {
|
||||||
|
await request(`/admin/logistics-bills/${ids[0]}/confirm`, { method: 'POST' });
|
||||||
|
} else {
|
||||||
|
await request('/admin/logistics-bills/batch-confirm', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ ids }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
message.success('已确认结算');
|
||||||
|
setSelectedKeys([]);
|
||||||
|
reload();
|
||||||
|
void loadSummary(summaryPeriod);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openDetail(id: string) {
|
||||||
|
const d = await request<BillRow & { items?: BillItem[] }>(`/admin/logistics-bills/${id}`);
|
||||||
|
setDetail(d);
|
||||||
|
setDrawerOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function exportExcel() {
|
||||||
|
setExporting(true);
|
||||||
|
try {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
if (filters.providerId) qs.set('providerId', filters.providerId);
|
||||||
|
if (filters.year) qs.set('year', filters.year);
|
||||||
|
if (filters.month) qs.set('month', filters.month);
|
||||||
|
const result = await request<{ csv: string; count: number }>(
|
||||||
|
`/admin/logistics-bills/export?${qs}`,
|
||||||
|
);
|
||||||
|
const suffix = filters.year && filters.month ? `${filters.year}-${filters.month}` : 'all';
|
||||||
|
downloadExcelCsv(result.csv, `物流对账单_${suffix}.csv`);
|
||||||
|
message.success(`已导出 ${result.count} 条`);
|
||||||
|
} finally {
|
||||||
|
setExporting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generateBills() {
|
||||||
|
const v = await genForm.validateFields();
|
||||||
|
const month = v.month as Dayjs;
|
||||||
|
await request('/admin/logistics-bills/generate', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
year: month.year(),
|
||||||
|
month: month.month() + 1,
|
||||||
|
providerId: v.providerId || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已生成物流对账单');
|
||||||
|
setGenOpen(false);
|
||||||
|
reload();
|
||||||
|
void loadSummary(summaryPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitRecharge() {
|
||||||
|
if (!rechargeTarget) return;
|
||||||
|
const v = await rechargeForm.validateFields();
|
||||||
|
await request(`/admin/fulfillment-providers/${rechargeTarget.providerId}/recharge`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ amount: v.amount, remark: v.remark }),
|
||||||
|
});
|
||||||
|
message.success('充值成功');
|
||||||
|
setRechargeOpen(false);
|
||||||
|
void loadSummary(summaryPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
const summary = data?.summary;
|
||||||
|
const selectedRows = (data?.items ?? []).filter((r) => selectedKeys.includes(r.id));
|
||||||
|
const selectedAmount = selectedRows.reduce((s, r) => s + Number(r.logisticsAmount), 0);
|
||||||
|
|
||||||
|
const billColumns: ColumnsType<BillRow> = [
|
||||||
|
{ title: '账单号', dataIndex: 'billNo', width: 170, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '承运商',
|
||||||
|
width: 140,
|
||||||
|
render: (_, r) => `${r.providerName || ''} (${r.providerCode || ''})`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '账期',
|
||||||
|
width: 200,
|
||||||
|
render: (_, r) =>
|
||||||
|
`${String(r.periodStart || '').slice(0, 10)} ~ ${String(r.periodEnd || '').slice(0, 10)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '结算方式',
|
||||||
|
dataIndex: 'settlementMethod',
|
||||||
|
width: 100,
|
||||||
|
render: (v) =>
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS[v as LogisticsSettlementMethod] || v,
|
||||||
|
},
|
||||||
|
{ title: '订单数', dataIndex: 'orderCount', width: 80 },
|
||||||
|
{ title: '瓶数', dataIndex: 'bottleCount', width: 80 },
|
||||||
|
{
|
||||||
|
title: '物流费',
|
||||||
|
dataIndex: 'logisticsAmount',
|
||||||
|
width: 110,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 90,
|
||||||
|
render: (s) => <Tag color={STATUS_COLORS[s] || 'default'}>{STATUS_LABELS[s] || s}</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 160,
|
||||||
|
fixed: 'right',
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space size={0}>
|
||||||
|
<Button type="link" size="small" onClick={() => void openDetail(row.id)}>
|
||||||
|
明细
|
||||||
|
</Button>
|
||||||
|
{row.status === 'UNPAID' && (
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={() => confirmPay([row.id], Number(row.logisticsAmount))}
|
||||||
|
>
|
||||||
|
确认结算
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const summaryColumns: ColumnsType<ProviderSummary> = [
|
||||||
|
{
|
||||||
|
title: '承运商',
|
||||||
|
render: (_, r) => `${r.providerName} (${r.providerCode})`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '结算方式',
|
||||||
|
dataIndex: 'settlementMethod',
|
||||||
|
width: 110,
|
||||||
|
render: (v) =>
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS[v as LogisticsSettlementMethod] || v,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '计价标准',
|
||||||
|
width: 220,
|
||||||
|
render: (_, r) => {
|
||||||
|
const p = r.pricingRules;
|
||||||
|
if (!p) return '—';
|
||||||
|
return `${p.baseBottles}瓶¥${p.baseFee},加瓶¥${p.extraBottleFee}${
|
||||||
|
p.boxBottles ? `,${p.boxBottles}瓶箱¥${p.boxFee}` : ''
|
||||||
|
}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '银行账户',
|
||||||
|
width: 180,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (_, r) =>
|
||||||
|
r.bankAccountName
|
||||||
|
? `${r.bankAccountName} / ${r.bankName || ''} ${r.bankAccountNo || ''}`
|
||||||
|
: '—',
|
||||||
|
},
|
||||||
|
{ title: '订单数', dataIndex: 'orderCount', width: 80 },
|
||||||
|
{ title: '瓶数', dataIndex: 'bottleCount', width: 80 },
|
||||||
|
{
|
||||||
|
title: '应付物流费',
|
||||||
|
dataIndex: 'logisticsAmount',
|
||||||
|
width: 110,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '充值余额',
|
||||||
|
dataIndex: 'prepaidBalance',
|
||||||
|
width: 110,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '账单',
|
||||||
|
width: 100,
|
||||||
|
render: (_, r) =>
|
||||||
|
r.billStatus ? (
|
||||||
|
<Tag color={STATUS_COLORS[r.billStatus] || 'default'}>
|
||||||
|
{STATUS_LABELS[r.billStatus] || r.billStatus}
|
||||||
|
</Tag>
|
||||||
|
) : (
|
||||||
|
'未生成'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 100,
|
||||||
|
render: (_, r) =>
|
||||||
|
r.settlementMethod === 'PREPAID' ? (
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
setRechargeTarget(r);
|
||||||
|
rechargeForm.resetFields();
|
||||||
|
setRechargeOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
充值
|
||||||
|
</Button>
|
||||||
|
) : null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space direction="vertical" size={0} style={{ marginBottom: 16 }}>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
物流对账
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
按快递承运商汇总月度物流费;计价与银行账户在「仓配管理」配置。前期充值扣款,后期可切挂账月结。
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Tabs
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
key: 'summary',
|
||||||
|
label: '按承运商汇总',
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<Form
|
||||||
|
form={summaryForm}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
initialValues={{ month: summaryPeriod }}
|
||||||
|
onFinish={(v: { month?: Dayjs }) => {
|
||||||
|
const m = v.month || dayjs().subtract(1, 'month');
|
||||||
|
setSummaryPeriod(m);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="month" label="账期">
|
||||||
|
<DatePicker picker="month" allowClear={false} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
<Table
|
||||||
|
rowKey="providerId"
|
||||||
|
loading={summaryLoading}
|
||||||
|
columns={summaryColumns}
|
||||||
|
dataSource={summaryRows}
|
||||||
|
pagination={false}
|
||||||
|
scroll={{ x: 1200 }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'bills',
|
||||||
|
label: '月账单',
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
{summary && (
|
||||||
|
<Card size="small" style={{ marginBottom: 16 }}>
|
||||||
|
<Space size="large" wrap>
|
||||||
|
<Statistic title="账单数" value={summary.count} />
|
||||||
|
<Statistic
|
||||||
|
title="瓶数合计"
|
||||||
|
value={summary.bottleCount ?? 0}
|
||||||
|
/>
|
||||||
|
<Statistic
|
||||||
|
title="物流费合计"
|
||||||
|
value={summary.logisticsAmount ?? summary.totalAmount ?? 0}
|
||||||
|
prefix="¥"
|
||||||
|
precision={2}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v: {
|
||||||
|
status?: string;
|
||||||
|
providerId?: string;
|
||||||
|
month?: Dayjs;
|
||||||
|
}) => {
|
||||||
|
setFilters({
|
||||||
|
status: v.status || '',
|
||||||
|
providerId: v.providerId || '',
|
||||||
|
year: v.month ? String(v.month.year()) : '',
|
||||||
|
month: v.month ? String(v.month.month() + 1) : '',
|
||||||
|
});
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="status" label="状态">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 120 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'UNPAID', label: '未结算' },
|
||||||
|
{ value: 'PAID', label: '已结算' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="providerId" label="承运商">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 180 }}
|
||||||
|
options={providers.map((p) => ({
|
||||||
|
value: p.id,
|
||||||
|
label: `${p.name} (${p.code})`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="month" label="账期">
|
||||||
|
<DatePicker picker="month" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Space>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
genForm.setFieldsValue({ month: dayjs().subtract(1, 'month') });
|
||||||
|
setGenOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
生成账单
|
||||||
|
</Button>
|
||||||
|
<Button loading={exporting} onClick={() => void exportExcel()}>
|
||||||
|
导出
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
disabled={!selectedKeys.length}
|
||||||
|
onClick={() =>
|
||||||
|
confirmPay(
|
||||||
|
selectedKeys.map(String),
|
||||||
|
selectedAmount,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
批量结算
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={billColumns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
rowSelection={{
|
||||||
|
selectedRowKeys: selectedKeys,
|
||||||
|
onChange: setSelectedKeys,
|
||||||
|
getCheckboxProps: (r) => ({ disabled: r.status !== 'UNPAID' }),
|
||||||
|
}}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
scroll={{ x: 1100 }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title="物流对账明细"
|
||||||
|
width={640}
|
||||||
|
open={drawerOpen}
|
||||||
|
onClose={() => setDrawerOpen(false)}
|
||||||
|
>
|
||||||
|
{detail && (
|
||||||
|
<>
|
||||||
|
<Descriptions column={1} size="small" style={{ marginBottom: 16 }}>
|
||||||
|
<Descriptions.Item label="账单号">{detail.billNo}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="承运商">
|
||||||
|
{detail.providerName} ({detail.providerCode})
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="账期">
|
||||||
|
{String(detail.periodStart).slice(0, 10)} ~ {String(detail.periodEnd).slice(0, 10)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="物流费">
|
||||||
|
¥{Number(detail.logisticsAmount).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="状态">
|
||||||
|
{STATUS_LABELS[detail.status] || detail.status}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="结算时间">
|
||||||
|
{detail.paidAt ? fmtTime(detail.paidAt) : '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
size="small"
|
||||||
|
pagination={false}
|
||||||
|
dataSource={detail.items ?? []}
|
||||||
|
columns={[
|
||||||
|
{ title: '订单号', dataIndex: 'orderNo' },
|
||||||
|
{ title: '瓶数', dataIndex: 'quantity', width: 70 },
|
||||||
|
{
|
||||||
|
title: '物流费',
|
||||||
|
dataIndex: 'logisticsAmount',
|
||||||
|
width: 90,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '发货时间',
|
||||||
|
dataIndex: 'shippedAt',
|
||||||
|
width: 160,
|
||||||
|
render: fmtTime,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="生成物流月账单"
|
||||||
|
open={genOpen}
|
||||||
|
onCancel={() => setGenOpen(false)}
|
||||||
|
onOk={() => void generateBills()}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={genForm} layout="vertical">
|
||||||
|
<Form.Item name="month" label="账期月" rules={[{ required: true }]}>
|
||||||
|
<DatePicker picker="month" style={{ width: '100%' }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="providerId" label="承运商(空=全部)">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
options={providers.map((p) => ({
|
||||||
|
value: p.id,
|
||||||
|
label: `${p.name} (${p.code})`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={rechargeTarget ? `充值 · ${rechargeTarget.providerName}` : '充值'}
|
||||||
|
open={rechargeOpen}
|
||||||
|
onCancel={() => setRechargeOpen(false)}
|
||||||
|
onOk={() => void submitRecharge()}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={rechargeForm} layout="vertical">
|
||||||
|
<Form.Item
|
||||||
|
name="amount"
|
||||||
|
label="金额"
|
||||||
|
rules={[{ required: true, message: '请输入充值金额' }]}
|
||||||
|
>
|
||||||
|
<InputNumber min={0.01} precision={2} style={{ width: '100%' }} prefix="¥" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
|
<Input placeholder="可选,如预充运费" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
message,
|
message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { request, type AdminOrderItem, type AdminOrderRow, type Paginated } from '../lib/api';
|
import { request, type AdminOrderItem, type AdminOrderRow, type HqProfile, type Paginated } from '../lib/api';
|
||||||
import {
|
import {
|
||||||
ADMIN_OPTIONS_PAGE_SIZE,
|
ADMIN_OPTIONS_PAGE_SIZE,
|
||||||
DELIVERY_PROVIDER_LABELS,
|
DELIVERY_PROVIDER_LABELS,
|
||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
ORDER_STATUS_LABELS,
|
ORDER_STATUS_LABELS,
|
||||||
fmtTime,
|
fmtTime,
|
||||||
} from '../lib/constants';
|
} from '../lib/constants';
|
||||||
|
import { FULFILLMENT_HOLD_REASON_LABELS } from '@dukang/shared-types';
|
||||||
|
|
||||||
type ShipDefaults = {
|
type ShipDefaults = {
|
||||||
provider: string;
|
provider: string;
|
||||||
@@ -55,6 +56,28 @@ type WarehouseOption = {
|
|||||||
lat?: number | null;
|
lat?: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type OrderRedeemRecord = {
|
||||||
|
id: string;
|
||||||
|
redeemNo: string;
|
||||||
|
amount: number;
|
||||||
|
settleAmount: number;
|
||||||
|
/** 本单权益券在该核销单中的分摊额 */
|
||||||
|
couponAmount?: number;
|
||||||
|
role?: 'PRIMARY' | 'SECONDARY';
|
||||||
|
createdAt: string;
|
||||||
|
store?: { id: string; name: string; cityName?: string | null } | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type OrderRedeemSummary = {
|
||||||
|
couponNo: string;
|
||||||
|
totalAmount: number;
|
||||||
|
usedAmount: number;
|
||||||
|
balance: number;
|
||||||
|
status: string;
|
||||||
|
redeemCount: number;
|
||||||
|
redeemRecordSum: number;
|
||||||
|
};
|
||||||
|
|
||||||
type OrderDetail = AdminOrderRow & {
|
type OrderDetail = AdminOrderRow & {
|
||||||
receiverAddress?: string;
|
receiverAddress?: string;
|
||||||
receiverProvince?: string;
|
receiverProvince?: string;
|
||||||
@@ -81,6 +104,8 @@ type OrderDetail = AdminOrderRow & {
|
|||||||
payment?: Record<string, unknown> | null;
|
payment?: Record<string, unknown> | null;
|
||||||
statusLogs?: Array<{ fromStatus: string | null; toStatus: string; createdAt: string }>;
|
statusLogs?: Array<{ fromStatus: string | null; toStatus: string; createdAt: string }>;
|
||||||
benefitCoupons?: Array<Record<string, unknown>>;
|
benefitCoupons?: Array<Record<string, unknown>>;
|
||||||
|
redeemSummary?: OrderRedeemSummary | null;
|
||||||
|
redeemRecords?: OrderRedeemRecord[];
|
||||||
fulfillmentWarehouse?: {
|
fulfillmentWarehouse?: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -129,12 +154,16 @@ export default function OrdersPage() {
|
|||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [shipForm] = Form.useForm();
|
const [shipForm] = Form.useForm();
|
||||||
const [logisticsForm] = Form.useForm();
|
const [logisticsForm] = Form.useForm();
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
const [data, setData] = useState<Paginated<AdminOrderRow> | null>(null);
|
const [data, setData] = useState<Paginated<AdminOrderRow> | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [pageSize, setPageSize] = useState(20);
|
const [pageSize, setPageSize] = useState(20);
|
||||||
const [detail, setDetail] = useState<OrderDetail | null>(null);
|
const [detail, setDetail] = useState<OrderDetail | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [redeemDetail, setRedeemDetail] = useState<Record<string, unknown> | null>(null);
|
||||||
|
const [redeemDrawerOpen, setRedeemDrawerOpen] = useState(false);
|
||||||
|
const [redeemDetailLoading, setRedeemDetailLoading] = useState(false);
|
||||||
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
||||||
const [batchDeleteOpen, setBatchDeleteOpen] = useState(false);
|
const [batchDeleteOpen, setBatchDeleteOpen] = useState(false);
|
||||||
const [batchDeleting, setBatchDeleting] = useState(false);
|
const [batchDeleting, setBatchDeleting] = useState(false);
|
||||||
@@ -146,12 +175,31 @@ export default function OrdersPage() {
|
|||||||
const [shipTarget, setShipTarget] = useState<OrderDetail | null>(null);
|
const [shipTarget, setShipTarget] = useState<OrderDetail | null>(null);
|
||||||
const [shipMode, setShipMode] = useState<ShipMode>('EXPRESS');
|
const [shipMode, setShipMode] = useState<ShipMode>('EXPRESS');
|
||||||
const [warehouses, setWarehouses] = useState<WarehouseOption[]>([]);
|
const [warehouses, setWarehouses] = useState<WarehouseOption[]>([]);
|
||||||
|
const canDeleteOrders = (profile?.permissionKeys ?? []).includes('orders_delete');
|
||||||
|
|
||||||
const selectedOrders = useMemo(
|
const selectedOrders = useMemo(
|
||||||
() => (data?.items ?? []).filter((row) => selectedRowKeys.includes(row.id)),
|
() => (data?.items ?? []).filter((row) => selectedRowKeys.includes(row.id)),
|
||||||
[data?.items, selectedRowKeys],
|
[data?.items, selectedRowKeys],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function openRedeemDetail(redeemId: string) {
|
||||||
|
setRedeemDetailLoading(true);
|
||||||
|
setRedeemDrawerOpen(true);
|
||||||
|
try {
|
||||||
|
const res = await request<Record<string, unknown>>(`/admin/redeem-records/${redeemId}`);
|
||||||
|
setRedeemDetail(res);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载核销详情失败');
|
||||||
|
setRedeemDrawerOpen(false);
|
||||||
|
} finally {
|
||||||
|
setRedeemDetailLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
@@ -161,6 +209,7 @@ export default function OrdersPage() {
|
|||||||
if (values.status) qs.set('status', values.status);
|
if (values.status) qs.set('status', values.status);
|
||||||
if (values.cityId) qs.set('cityId', values.cityId);
|
if (values.cityId) qs.set('cityId', values.cityId);
|
||||||
if (values.receiverPhone) qs.set('receiverPhone', values.receiverPhone);
|
if (values.receiverPhone) qs.set('receiverPhone', values.receiverPhone);
|
||||||
|
if (values.fulfillmentHold) qs.set('fulfillmentHold', 'true');
|
||||||
const res = await request<Paginated<AdminOrderRow>>(`/admin/orders?${qs}`);
|
const res = await request<Paginated<AdminOrderRow>>(`/admin/orders?${qs}`);
|
||||||
setData(res);
|
setData(res);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -354,9 +403,12 @@ export default function OrdersPage() {
|
|||||||
{
|
{
|
||||||
title: '状态',
|
title: '状态',
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
width: 100,
|
width: 140,
|
||||||
render: (s) => (
|
render: (s, row) => (
|
||||||
<Tag color={ORDER_STATUS_COLORS[s] || 'default'}>{ORDER_STATUS_LABELS[s] || s}</Tag>
|
<Space size={4} wrap>
|
||||||
|
<Tag color={ORDER_STATUS_COLORS[s] || 'default'}>{ORDER_STATUS_LABELS[s] || s}</Tag>
|
||||||
|
{row.fulfillmentHold ? <Tag color="orange">大单待确认</Tag> : null}
|
||||||
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -408,13 +460,15 @@ export default function OrdersPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
||||||
<Typography.Title level={4} style={{ margin: 0 }}>订单监控</Typography.Title>
|
<Typography.Title level={4} style={{ margin: 0 }}>订单监控</Typography.Title>
|
||||||
<Button
|
{canDeleteOrders ? (
|
||||||
danger
|
<Button
|
||||||
disabled={!selectedRowKeys.length}
|
danger
|
||||||
onClick={() => setBatchDeleteOpen(true)}
|
disabled={!selectedRowKeys.length}
|
||||||
>
|
onClick={() => setBatchDeleteOpen(true)}
|
||||||
批量删除{selectedRowKeys.length ? ` (${selectedRowKeys.length})` : ''}
|
>
|
||||||
</Button>
|
批量删除{selectedRowKeys.length ? ` (${selectedRowKeys.length})` : ''}
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
</Space>
|
</Space>
|
||||||
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={() => { setPage(1); void load(); }}>
|
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={() => { setPage(1); void load(); }}>
|
||||||
<Form.Item name="orderNo" label="订单号">
|
<Form.Item name="orderNo" label="订单号">
|
||||||
@@ -436,6 +490,14 @@ export default function OrdersPage() {
|
|||||||
<Form.Item name="receiverPhone" label="收货手机">
|
<Form.Item name="receiverPhone" label="收货手机">
|
||||||
<Input allowClear />
|
<Input allowClear />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="fulfillmentHold" label="大单拦截" valuePropName="checked">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 140 }}
|
||||||
|
placeholder="全部"
|
||||||
|
options={[{ value: true, label: '仅待确认大单' }]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="primary" htmlType="submit">查询</Button>
|
<Button type="primary" htmlType="submit">查询</Button>
|
||||||
@@ -450,10 +512,10 @@ export default function OrdersPage() {
|
|||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={data?.items ?? []}
|
dataSource={data?.items ?? []}
|
||||||
scroll={{ x: 1500 }}
|
scroll={{ x: 1500 }}
|
||||||
rowSelection={{
|
rowSelection={canDeleteOrders ? {
|
||||||
selectedRowKeys,
|
selectedRowKeys,
|
||||||
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
||||||
}}
|
} : undefined}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: page,
|
current: page,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -468,7 +530,7 @@ export default function OrdersPage() {
|
|||||||
|
|
||||||
<Drawer
|
<Drawer
|
||||||
title="订单详情"
|
title="订单详情"
|
||||||
width={640}
|
width={720}
|
||||||
open={drawerOpen}
|
open={drawerOpen}
|
||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={detail && (
|
extra={detail && (
|
||||||
@@ -509,9 +571,17 @@ export default function OrdersPage() {
|
|||||||
{detail.fulfillmentWarehouse?.name || '未分配'}
|
{detail.fulfillmentWarehouse?.name || '未分配'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="状态">
|
<Descriptions.Item label="状态">
|
||||||
<Tag color={ORDER_STATUS_COLORS[detail.status] || 'default'}>
|
<Space>
|
||||||
{ORDER_STATUS_LABELS[detail.status] || detail.status}
|
<Tag color={ORDER_STATUS_COLORS[detail.status] || 'default'}>
|
||||||
</Tag>
|
{ORDER_STATUS_LABELS[detail.status] || detail.status}
|
||||||
|
</Tag>
|
||||||
|
{detail.fulfillmentHold ? (
|
||||||
|
<Tag color="orange">
|
||||||
|
{FULFILLMENT_HOLD_REASON_LABELS[detail.fulfillmentHoldReason || ''] ||
|
||||||
|
'大单待确认'}
|
||||||
|
</Tag>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="用户">{detail.user?.userNo} / {detail.user?.nickname}</Descriptions.Item>
|
<Descriptions.Item label="用户">{detail.user?.userNo} / {detail.user?.nickname}</Descriptions.Item>
|
||||||
<Descriptions.Item label="商品额">¥{detail.productAmount}</Descriptions.Item>
|
<Descriptions.Item label="商品额">¥{detail.productAmount}</Descriptions.Item>
|
||||||
@@ -570,6 +640,98 @@ export default function OrdersPage() {
|
|||||||
<Descriptions.Item label="地址">{detail.receiverAddress}</Descriptions.Item>
|
<Descriptions.Item label="地址">{detail.receiverAddress}</Descriptions.Item>
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
|
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 16, marginBottom: 8 }}>
|
||||||
|
权益核销
|
||||||
|
</Typography.Title>
|
||||||
|
{detail.redeemSummary ? (
|
||||||
|
<>
|
||||||
|
<Descriptions column={2} bordered size="small" style={{ marginBottom: 12 }}>
|
||||||
|
<Descriptions.Item label="权益券号">{detail.redeemSummary.couponNo}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="券状态">{detail.redeemSummary.status}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权益总额">
|
||||||
|
¥{Number(detail.redeemSummary.totalAmount).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="已核销">
|
||||||
|
<Typography.Text type="danger" strong>
|
||||||
|
¥{Number(detail.redeemSummary.usedAmount).toFixed(2)}
|
||||||
|
</Typography.Text>
|
||||||
|
<Typography.Text type="secondary" style={{ marginLeft: 8 }}>
|
||||||
|
({detail.redeemSummary.redeemCount} 笔核销单)
|
||||||
|
</Typography.Text>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="剩余余额">
|
||||||
|
¥{Number(detail.redeemSummary.balance).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="核销单合计额">
|
||||||
|
¥{Number(detail.redeemSummary.redeemRecordSum).toFixed(2)}
|
||||||
|
<Typography.Text type="secondary" style={{ marginLeft: 8 }}>
|
||||||
|
(本券分摊合计)
|
||||||
|
</Typography.Text>
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
locale={{ emptyText: '暂无关联核销单' }}
|
||||||
|
dataSource={detail.redeemRecords ?? []}
|
||||||
|
columns={[
|
||||||
|
{ title: '核销号', dataIndex: 'redeemNo', width: 160, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '角色',
|
||||||
|
dataIndex: 'role',
|
||||||
|
width: 70,
|
||||||
|
render: (v: string | undefined) =>
|
||||||
|
v === 'SECONDARY' ? <Tag color="orange">次券</Tag> : <Tag color="blue">主券</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: ['store', 'name'],
|
||||||
|
ellipsis: true,
|
||||||
|
render: (v: string | undefined, row) =>
|
||||||
|
v ? `${v}${row.store?.cityName ? `(${row.store.cityName})` : ''}` : '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '本券分摊',
|
||||||
|
dataIndex: 'couponAmount',
|
||||||
|
width: 95,
|
||||||
|
render: (v: number | undefined, row) =>
|
||||||
|
`¥${Number(v ?? row.amount).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '核销总额',
|
||||||
|
dataIndex: 'amount',
|
||||||
|
width: 90,
|
||||||
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '结算额',
|
||||||
|
dataIndex: 'settleAmount',
|
||||||
|
width: 90,
|
||||||
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '时间',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
width: 150,
|
||||||
|
render: (v: string) => fmtTime(v),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 70,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Button type="link" size="small" onClick={() => void openRedeemDetail(row.id)}>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">该订单尚未生成权益券,无核销记录</Typography.Text>
|
||||||
|
)}
|
||||||
|
|
||||||
<Descriptions column={1} bordered size="small" title="位置快照(方案C)" style={{ marginTop: 16 }}>
|
<Descriptions column={1} bordered size="small" title="位置快照(方案C)" style={{ marginTop: 16 }}>
|
||||||
<Descriptions.Item label="clientIp">{detail.clientIp || '—'}</Descriptions.Item>
|
<Descriptions.Item label="clientIp">{detail.clientIp || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="IP解析">{[detail.ipProvince, detail.ipCity, detail.ipDistrict].filter(Boolean).join(' / ') || '—'}</Descriptions.Item>
|
<Descriptions.Item label="IP解析">{[detail.ipProvince, detail.ipCity, detail.ipDistrict].filter(Boolean).join(' / ') || '—'}</Descriptions.Item>
|
||||||
@@ -618,6 +780,95 @@ export default function OrdersPage() {
|
|||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title="核销单详情"
|
||||||
|
width={520}
|
||||||
|
open={redeemDrawerOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setRedeemDrawerOpen(false);
|
||||||
|
setRedeemDetail(null);
|
||||||
|
}}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{redeemDetailLoading ? (
|
||||||
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
|
) : redeemDetail ? (
|
||||||
|
<Descriptions column={1} bordered size="small">
|
||||||
|
<Descriptions.Item label="核销号">{String(redeemDetail.redeemNo ?? '—')}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="核销额">
|
||||||
|
¥{Number(redeemDetail.amount ?? 0).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="结算额">
|
||||||
|
¥{Number(redeemDetail.settleAmount ?? 0).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="时间">{fmtTime(String(redeemDetail.createdAt ?? ''))}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="用户">
|
||||||
|
{String((redeemDetail.user as { userNo?: string } | undefined)?.userNo ?? '—')}
|
||||||
|
{(redeemDetail.user as { phone?: string | null } | undefined)?.phone
|
||||||
|
? ` / ${(redeemDetail.user as { phone?: string | null }).phone}`
|
||||||
|
: ''}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店">
|
||||||
|
{String((redeemDetail.store as { name?: string } | undefined)?.name ?? '—')}
|
||||||
|
{(redeemDetail.store as { cityName?: string } | undefined)?.cityName
|
||||||
|
? `(${(redeemDetail.store as { cityName?: string }).cityName})`
|
||||||
|
: ''}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店地址">
|
||||||
|
{String((redeemDetail.store as { address?: string } | undefined)?.address ?? '—')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="合伙人">
|
||||||
|
{String(
|
||||||
|
(redeemDetail.store as { partnerAccount?: { companyName?: string } } | undefined)
|
||||||
|
?.partnerAccount?.companyName ?? '—',
|
||||||
|
)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权益券号">
|
||||||
|
{String((redeemDetail.coupon as { couponNo?: string } | undefined)?.couponNo ?? '—')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="关联订单">
|
||||||
|
{String(
|
||||||
|
(redeemDetail.coupon as { order?: { orderNo?: string } } | undefined)?.order?.orderNo ??
|
||||||
|
'—',
|
||||||
|
)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
{Array.isArray(redeemDetail.allocations) &&
|
||||||
|
(redeemDetail.allocations as unknown[]).length > 0 ? (
|
||||||
|
<Descriptions.Item label="券分摊">
|
||||||
|
{(
|
||||||
|
redeemDetail.allocations as Array<{
|
||||||
|
couponNo?: string;
|
||||||
|
orderNo?: string | null;
|
||||||
|
amount?: number;
|
||||||
|
sortOrder?: number;
|
||||||
|
}>
|
||||||
|
)
|
||||||
|
.map((a, idx) => {
|
||||||
|
const role = idx === 0 ? '主' : '次';
|
||||||
|
return `${role} ${a.couponNo ?? '—'}¥${Number(a.amount ?? 0).toFixed(2)}${
|
||||||
|
a.orderNo ? `(订单 ${a.orderNo})` : ''
|
||||||
|
}`;
|
||||||
|
})
|
||||||
|
.join(';')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{redeemDetail.payout ? (
|
||||||
|
<Descriptions.Item label="门店结算单">
|
||||||
|
¥{Number((redeemDetail.payout as { settleAmount?: number }).settleAmount ?? 0).toFixed(2)}
|
||||||
|
{' / '}
|
||||||
|
{String((redeemDetail.payout as { status?: string }).status ?? '—')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{redeemDetail.rating ? (
|
||||||
|
<Descriptions.Item label="评价">
|
||||||
|
服务 {(redeemDetail.rating as { serviceScore?: number }).serviceScore ?? '—'} 分 / 环境{' '}
|
||||||
|
{(redeemDetail.rating as { envScore?: number }).envScore ?? '—'} 分
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
</Descriptions>
|
||||||
|
) : null}
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
title={shipTarget ? `配送发货 · ${shipTarget.orderNo}` : '配送发货'}
|
title={shipTarget ? `配送发货 · ${shipTarget.orderNo}` : '配送发货'}
|
||||||
open={shipModalOpen}
|
open={shipModalOpen}
|
||||||
@@ -642,6 +893,18 @@ export default function OrdersPage() {
|
|||||||
>
|
>
|
||||||
{shipTarget && (
|
{shipTarget && (
|
||||||
<>
|
<>
|
||||||
|
{shipTarget.fulfillmentHold ? (
|
||||||
|
<Alert
|
||||||
|
type="warning"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
message="大单已拦截自动推小飞侠"
|
||||||
|
description={
|
||||||
|
FULFILLMENT_HOLD_REASON_LABELS[shipTarget.fulfillmentHoldReason || ''] ||
|
||||||
|
'≥10箱订单需总部确认:可选仓推小飞侠,或改用快递自配送。'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
<Descriptions size="small" column={1} style={{ marginBottom: 16 }}>
|
<Descriptions size="small" column={1} style={{ marginBottom: 16 }}>
|
||||||
<Descriptions.Item label="城市">{shipTarget.city?.name || '—'}</Descriptions.Item>
|
<Descriptions.Item label="城市">{shipTarget.city?.name || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="收货">
|
<Descriptions.Item label="收货">
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Cascader,
|
|
||||||
Drawer,
|
Drawer,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
@@ -24,9 +23,10 @@ import {
|
|||||||
type PartnerPermissionKey,
|
type PartnerPermissionKey,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
import { CHINA_REGION_OPTIONS } from '../lib/china-region';
|
import { districtCodeLabel, formatDistrictLabels } from '../lib/china-region';
|
||||||
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import CityDistrictMultiSelect from '../components/CityDistrictMultiSelect';
|
||||||
|
|
||||||
type Row = {
|
type Row = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -37,6 +37,7 @@ type Row = {
|
|||||||
cityId?: string | null;
|
cityId?: string | null;
|
||||||
cityName?: string | null;
|
cityName?: string | null;
|
||||||
scopeType?: string;
|
scopeType?: string;
|
||||||
|
districtCodes?: string[] | null;
|
||||||
orderCommissionRate?: number;
|
orderCommissionRate?: number;
|
||||||
redeemCommissionRate?: number;
|
redeemCommissionRate?: number;
|
||||||
storeCount: number;
|
storeCount: number;
|
||||||
@@ -102,6 +103,18 @@ export default function PartnersPage() {
|
|||||||
const [editScopeType, setEditScopeType] = useState<CityPartnerScopeType>(CityPartnerScopeType.CITY_WIDE);
|
const [editScopeType, setEditScopeType] = useState<CityPartnerScopeType>(CityPartnerScopeType.CITY_WIDE);
|
||||||
const [createCityId, setCreateCityId] = useState<string | undefined>();
|
const [createCityId, setCreateCityId] = useState<string | undefined>();
|
||||||
|
|
||||||
|
const createCityCode = createCityId ? cities.find((c) => c.id === createCityId)?.code : undefined;
|
||||||
|
const editCityCode = detail?.cityId ? cities.find((c) => c.id === detail.cityId)?.code : undefined;
|
||||||
|
|
||||||
|
function formatApiError(err: unknown): string | null {
|
||||||
|
if (err && typeof err === 'object' && 'errorFields' in err) return null;
|
||||||
|
if (!(err instanceof Error)) return '操作失败';
|
||||||
|
return err.message.replace(/\b(\d{6})\b/g, (code) => {
|
||||||
|
const label = districtCodeLabel(code);
|
||||||
|
return label !== code ? `${label}(${code})` : code;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const loadCities = useCallback(async () => {
|
const loadCities = useCallback(async () => {
|
||||||
const res = await request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
const res = await request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
||||||
setCities(res.items);
|
setCities(res.items);
|
||||||
@@ -142,22 +155,35 @@ export default function PartnersPage() {
|
|||||||
|
|
||||||
async function savePartner() {
|
async function savePartner() {
|
||||||
if (!detail) return;
|
if (!detail) return;
|
||||||
const v = await editForm.validateFields();
|
try {
|
||||||
const body = {
|
const v = await editForm.validateFields();
|
||||||
...v,
|
const body = {
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
...v,
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
};
|
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
await request(`/admin/partners/${detail.id}`, { method: 'PUT', body: JSON.stringify(body) });
|
};
|
||||||
message.success('已保存');
|
await request(`/admin/partners/${detail.id}`, { method: 'PUT', body: JSON.stringify(body) });
|
||||||
setDrawerOpen(false);
|
message.success('已保存');
|
||||||
void reload();
|
setDrawerOpen(false);
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
|
||||||
{ title: '城市', dataIndex: 'cityName', width: 100 },
|
{ title: '城市', dataIndex: 'cityName', width: 100 },
|
||||||
|
{
|
||||||
|
title: '区县',
|
||||||
|
dataIndex: 'districtCodes',
|
||||||
|
width: 160,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (codes: string[] | null | undefined, row) =>
|
||||||
|
row.scopeType === CityPartnerScopeType.CITY_WIDE ? '全城' : formatDistrictLabels(codes),
|
||||||
|
},
|
||||||
|
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
||||||
{ title: '主账号', dataIndex: 'phone', width: 130 },
|
{ title: '主账号', dataIndex: 'phone', width: 130 },
|
||||||
{
|
{
|
||||||
title: '管辖',
|
title: '管辖',
|
||||||
@@ -222,17 +248,21 @@ export default function PartnersPage() {
|
|||||||
label: '基本信息',
|
label: '基本信息',
|
||||||
children: (
|
children: (
|
||||||
<Form form={editForm} layout="vertical">
|
<Form form={editForm} layout="vertical">
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="companyName" label="公司名"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="contactPhone" label="业务联系电话"><Input /></Form.Item>
|
<Form.Item name="contactPhone" label="业务联系电话"><Input /></Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="address" label="地址"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县">
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={editCityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
@@ -286,39 +316,52 @@ export default function PartnersPage() {
|
|||||||
width={560}
|
width={560}
|
||||||
onCancel={() => setCreateOpen(false)}
|
onCancel={() => setCreateOpen(false)}
|
||||||
onOk={async () => {
|
onOk={async () => {
|
||||||
const v = await createForm.validateFields();
|
try {
|
||||||
await request('/admin/partners', {
|
const v = await createForm.validateFields();
|
||||||
method: 'POST',
|
await request('/admin/partners', {
|
||||||
body: JSON.stringify({
|
method: 'POST',
|
||||||
...v,
|
body: JSON.stringify({
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
...v,
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
districtCodes: createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
}),
|
districtCodes: createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
});
|
}),
|
||||||
message.success('已创建');
|
});
|
||||||
setCreateOpen(false);
|
message.success('已创建');
|
||||||
createForm.resetFields();
|
setCreateOpen(false);
|
||||||
void reload();
|
createForm.resetFields();
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form form={createForm} layout="vertical" initialValues={{ orderCommissionRate: 0, redeemCommissionRate: 3, scopeType: CityPartnerScopeType.CITY_WIDE }}>
|
<Form form={createForm} layout="vertical" initialValues={{ orderCommissionRate: 0, redeemCommissionRate: 3, scopeType: CityPartnerScopeType.CITY_WIDE }}>
|
||||||
<Form.Item name="cityId" label="开城城市" rules={[{ required: true }]}>
|
<Form.Item name="cityId" label="开城城市" rules={[{ required: true }]}>
|
||||||
<Select
|
<Select
|
||||||
options={cities.map((c) => ({ value: c.id, label: `${c.name} (${c.code})` }))}
|
options={cities.map((c) => ({ value: c.id, label: `${c.name} (${c.code})` }))}
|
||||||
onChange={(id) => { setCreateCityId(id); void loadWarehouses(id); }}
|
onChange={(id) => {
|
||||||
|
setCreateCityId(id);
|
||||||
|
createForm.setFieldsValue({ districtCodes: undefined });
|
||||||
|
void loadWarehouses(id);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="companyName" label="公司名"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="address" label="地址"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县" rules={[{ required: true }]}>
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="选填;仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={createCityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button, Descriptions, Divider, Drawer, Form, Input, InputNumber, Modal, Popconfirm, Select, Space,
|
Button, Descriptions, Divider, Drawer, Form, Input, InputNumber, Modal, Popconfirm, Select, Space,
|
||||||
Table, Tabs, Tag, Typography, message,
|
Switch, Table, Tabs, Tag, Typography, message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
@@ -31,6 +31,7 @@ type Row = {
|
|||||||
benefitAmount: number;
|
benefitAmount: number;
|
||||||
status: string;
|
status: string;
|
||||||
sortOrder: number;
|
sortOrder: number;
|
||||||
|
allowOnSitePickup?: boolean;
|
||||||
mainImageUrl?: string | null;
|
mainImageUrl?: string | null;
|
||||||
carouselUrls?: string[];
|
carouselUrls?: string[];
|
||||||
detailImageUrls?: string[];
|
detailImageUrls?: string[];
|
||||||
@@ -49,6 +50,7 @@ type ProductFormValues = {
|
|||||||
benefitAmount?: number;
|
benefitAmount?: number;
|
||||||
status?: string;
|
status?: string;
|
||||||
sortOrder?: number;
|
sortOrder?: number;
|
||||||
|
allowOnSitePickup?: boolean;
|
||||||
coverUrl?: string;
|
coverUrl?: string;
|
||||||
carouselUrls?: string[];
|
carouselUrls?: string[];
|
||||||
detailImageUrls?: string[];
|
detailImageUrls?: string[];
|
||||||
@@ -100,6 +102,7 @@ function buildProductPayload(v: ProductFormValues) {
|
|||||||
benefitAmount: v.benefitAmount,
|
benefitAmount: v.benefitAmount,
|
||||||
status: v.status,
|
status: v.status,
|
||||||
sortOrder: v.sortOrder,
|
sortOrder: v.sortOrder,
|
||||||
|
allowOnSitePickup: !!v.allowOnSitePickup,
|
||||||
coverUrl: v.coverUrl,
|
coverUrl: v.coverUrl,
|
||||||
carouselUrls,
|
carouselUrls,
|
||||||
detailImageUrls,
|
detailImageUrls,
|
||||||
@@ -217,6 +220,9 @@ function BaseInfoFields({ mode }: { mode: 'create' | 'edit' }) {
|
|||||||
<Form.Item name="sortOrder" label="排序">
|
<Form.Item name="sortOrder" label="排序">
|
||||||
<InputNumber min={0} style={{ width: '100%' }} />
|
<InputNumber min={0} style={{ width: '100%' }} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="allowOnSitePickup" label="允许现场取货" valuePropName="checked">
|
||||||
|
<Switch checkedChildren="开" unCheckedChildren="关" />
|
||||||
|
</Form.Item>
|
||||||
<Form.Item name="coverUrl" label="封面">
|
<Form.Item name="coverUrl" label="封面">
|
||||||
<OssUpload bizType="COVER" mediaType="IMAGE" />
|
<OssUpload bizType="COVER" mediaType="IMAGE" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -265,7 +271,15 @@ export default function ProductsPage() {
|
|||||||
{ title: '规格', dataIndex: 'spec', width: 120, ellipsis: true },
|
{ title: '规格', dataIndex: 'spec', width: 120, ellipsis: true },
|
||||||
{ title: '售价', dataIndex: 'price', width: 80, render: (v) => `¥${v}` },
|
{ title: '售价', dataIndex: 'price', width: 80, render: (v) => `¥${v}` },
|
||||||
{ title: '权益额', dataIndex: 'benefitAmount', width: 80, render: (v) => `¥${v}` },
|
{ title: '权益额', dataIndex: 'benefitAmount', width: 80, render: (v) => `¥${v}` },
|
||||||
{ title: '状态', dataIndex: 'status', width: 80, render: (s) => <Tag>{PRODUCT_STATUS_LABELS[s] || s}</Tag> },
|
{ title: '状态', dataIndex: 'status', width: 80, render: (s) => (
|
||||||
|
<Tag color={s === 'ON_SALE' ? 'green' : undefined}>{PRODUCT_STATUS_LABELS[s] || s}</Tag>
|
||||||
|
) },
|
||||||
|
{
|
||||||
|
title: '现场取货',
|
||||||
|
dataIndex: 'allowOnSitePickup',
|
||||||
|
width: 90,
|
||||||
|
render: (v: boolean) => (v ? <Tag color="green">允许</Tag> : <Tag>否</Tag>),
|
||||||
|
},
|
||||||
{ title: '排序', dataIndex: 'sortOrder', width: 60 },
|
{ title: '排序', dataIndex: 'sortOrder', width: 60 },
|
||||||
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
{
|
{
|
||||||
@@ -357,7 +371,7 @@ export default function ProductsPage() {
|
|||||||
void reload();
|
void reload();
|
||||||
}} width={720}>
|
}} width={720}>
|
||||||
<Form form={createForm} layout="vertical" initialValues={{
|
<Form form={createForm} layout="vertical" initialValues={{
|
||||||
aromaType: 'QINGXIANG', status: 'DRAFT', sortOrder: 0,
|
aromaType: 'QINGXIANG', status: 'DRAFT', sortOrder: 0, allowOnSitePickup: false,
|
||||||
carouselUrls: [''], detailImageUrls: [''],
|
carouselUrls: [''], detailImageUrls: [''],
|
||||||
features: [{ icon: 'water_drop', title: '', desc: '' }],
|
features: [{ icon: 'water_drop', title: '', desc: '' }],
|
||||||
}}>
|
}}>
|
||||||
|
|||||||
@@ -1,236 +1,244 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import {
|
||||||
|
Button, Form, Input, Modal, Select, Space, Table, Tag, Typography, message,
|
||||||
import {
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
Button, Form, Input, Modal, Select, Space, Table, Tag, Typography, message,
|
import {
|
||||||
|
PROMO_CODE_SCENE_LABELS,
|
||||||
} from 'antd';
|
PROMO_CODE_STATUS_LABELS,
|
||||||
|
promoConversion,
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
type PromoCodeItem,
|
||||||
|
type PromoCodeScene,
|
||||||
import {
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
PROMO_CODE_SCENE_LABELS,
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
PROMO_CODE_STATUS_LABELS,
|
|
||||||
|
type Row = PromoCodeItem;
|
||||||
promoConversion,
|
|
||||||
|
type SceneOption = { value: PromoCodeScene; label: string };
|
||||||
type PromoCodeItem,
|
|
||||||
|
async function downloadQrcode(url: string, filename: string) {
|
||||||
type PromoCodeScene,
|
try {
|
||||||
|
const res = await fetch(url);
|
||||||
} from '@dukang/shared-types';
|
const blob = await res.blob();
|
||||||
|
const objectUrl = URL.createObjectURL(blob);
|
||||||
import { request } from '../lib/api';
|
const a = document.createElement('a');
|
||||||
|
a.href = objectUrl;
|
||||||
import { fmtTime } from '../lib/constants';
|
a.download = filename;
|
||||||
|
a.click();
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
URL.revokeObjectURL(objectUrl);
|
||||||
|
} catch {
|
||||||
|
window.open(url, '_blank');
|
||||||
|
}
|
||||||
type Row = PromoCodeItem;
|
}
|
||||||
|
|
||||||
|
export default function PromoCodesPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
type SceneOption = { value: PromoCodeScene; label: string };
|
const [filterForm] = Form.useForm();
|
||||||
|
const [createForm] = Form.useForm();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [scenes, setScenes] = useState<SceneOption[]>(
|
||||||
async function downloadQrcode(url: string, filename: string) {
|
Object.entries(PROMO_CODE_SCENE_LABELS).map(([value, label]) => ({
|
||||||
|
value: value as PromoCodeScene,
|
||||||
try {
|
label,
|
||||||
|
})),
|
||||||
const res = await fetch(url);
|
);
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
const blob = await res.blob();
|
const [creating, setCreating] = useState(false);
|
||||||
|
|
||||||
const objectUrl = URL.createObjectURL(blob);
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
|
'/admin/promo-codes',
|
||||||
const a = document.createElement('a');
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
a.href = objectUrl;
|
if (filters.name) qs.set('name', filters.name);
|
||||||
|
if (filters.code) qs.set('code', filters.code);
|
||||||
a.download = filename;
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
if (filters.scene) qs.set('scene', filters.scene);
|
||||||
a.click();
|
return qs;
|
||||||
|
},
|
||||||
URL.revokeObjectURL(objectUrl);
|
[filters],
|
||||||
|
);
|
||||||
} catch {
|
|
||||||
|
async function loadScenes() {
|
||||||
window.open(url, '_blank');
|
try {
|
||||||
|
const list = await request<SceneOption[]>('/admin/promo-codes/scenes');
|
||||||
}
|
if (list.length) setScenes(list);
|
||||||
|
} catch {
|
||||||
}
|
/* 使用本地默认场景 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function PromoCodesPage() {
|
useEffect(() => {
|
||||||
|
void loadScenes();
|
||||||
const navigate = useNavigate();
|
}, []);
|
||||||
|
|
||||||
const [filterForm] = Form.useForm();
|
const columns: ColumnsType<Row> = [
|
||||||
|
{ title: '名称', dataIndex: 'name', width: 160, ellipsis: true },
|
||||||
const [createForm] = Form.useForm();
|
{ title: '码值', dataIndex: 'code', width: 110 },
|
||||||
|
{
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
title: '场景',
|
||||||
|
dataIndex: 'scene',
|
||||||
const [scenes, setScenes] = useState<SceneOption[]>(
|
width: 110,
|
||||||
|
render: (s: PromoCodeScene) => PROMO_CODE_SCENE_LABELS[s] || s,
|
||||||
Object.entries(PROMO_CODE_SCENE_LABELS).map(([value, label]) => ({
|
},
|
||||||
|
{
|
||||||
value: value as PromoCodeScene,
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
label,
|
width: 90,
|
||||||
|
render: (s) => (
|
||||||
})),
|
<Tag color={s === 'ACTIVE' ? 'green' : 'default'}>
|
||||||
|
{PROMO_CODE_STATUS_LABELS[s as keyof typeof PROMO_CODE_STATUS_LABELS] || s}
|
||||||
);
|
</Tag>
|
||||||
|
),
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
},
|
||||||
|
{ title: '扫码', dataIndex: 'scanCount', width: 70 },
|
||||||
const [creating, setCreating] = useState(false);
|
{ title: '订单', dataIndex: 'orderCount', width: 70 },
|
||||||
|
{
|
||||||
|
title: '转化率',
|
||||||
|
width: 90,
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
render: (_, row) => promoConversion(row.scanCount, row.orderCount),
|
||||||
|
},
|
||||||
'/admin/promo-codes',
|
{
|
||||||
|
title: '渠道负责人',
|
||||||
() => {
|
width: 120,
|
||||||
|
render: (_, row) => row.ownerUser?.userNo || row.ownerUser?.phone || '—',
|
||||||
const qs = new URLSearchParams();
|
},
|
||||||
|
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
if (filters.name) qs.set('name', filters.name);
|
{
|
||||||
|
title: '操作',
|
||||||
if (filters.code) qs.set('code', filters.code);
|
width: 220,
|
||||||
|
fixed: 'right',
|
||||||
if (filters.status) qs.set('status', filters.status);
|
render: (_, row) => (
|
||||||
|
<Space size="small" wrap>
|
||||||
if (filters.scene) qs.set('scene', filters.scene);
|
<Button type="link" size="small" onClick={() => navigate(`/promo-codes/${row.id}`)}>
|
||||||
|
详情
|
||||||
return qs;
|
</Button>
|
||||||
|
<Button
|
||||||
},
|
type="link"
|
||||||
|
size="small"
|
||||||
[filters],
|
disabled={!row.qrcodeUrl}
|
||||||
|
onClick={() => {
|
||||||
);
|
if (!row.qrcodeUrl) return;
|
||||||
|
void downloadQrcode(row.qrcodeUrl, `${row.code}-wxacode.png`);
|
||||||
|
}}
|
||||||
|
>
|
||||||
async function loadScenes() {
|
下载小程序码
|
||||||
|
</Button>
|
||||||
try {
|
<Button type="link" size="small" onClick={() => navigate(`/promo-codes/${row.id}/users`)}>
|
||||||
|
关联用户
|
||||||
const list = await request<SceneOption[]>('/admin/promo-codes/scenes');
|
</Button>
|
||||||
|
</Space>
|
||||||
if (list.length) setScenes(list);
|
),
|
||||||
|
},
|
||||||
} catch {
|
];
|
||||||
|
|
||||||
/* 使用本地默认场景 */
|
async function handleCreate(values: Record<string, string>) {
|
||||||
|
setCreating(true);
|
||||||
}
|
try {
|
||||||
|
const created = await request<PromoCodeItem>('/admin/promo-codes', {
|
||||||
}
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: values.name,
|
||||||
|
code: values.code?.trim() || undefined,
|
||||||
useEffect(() => {
|
scene: values.scene,
|
||||||
|
ownerUserId: values.ownerUserId?.trim() || undefined,
|
||||||
void loadScenes();
|
remark: values.remark?.trim() || undefined,
|
||||||
|
page: values.page?.trim() || undefined,
|
||||||
}, []);
|
}),
|
||||||
|
});
|
||||||
|
message.success('推广码已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
const columns: ColumnsType<Row> = [
|
createForm.resetFields();
|
||||||
|
void reload();
|
||||||
{ title: '名称', dataIndex: 'name', width: 160, ellipsis: true },
|
navigate(`/promo-codes/${created.id}`);
|
||||||
|
} catch (e) {
|
||||||
{ title: '码值', dataIndex: 'code', width: 110 },
|
message.error(e instanceof Error ? e.message : '创建失败');
|
||||||
|
} finally {
|
||||||
{
|
setCreating(false);
|
||||||
|
}
|
||||||
title: '场景',
|
}
|
||||||
|
|
||||||
dataIndex: 'scene',
|
return (
|
||||||
|
<div>
|
||||||
width: 110,
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>推广码管理</Typography.Title>
|
||||||
render: (s: PromoCodeScene) => PROMO_CODE_SCENE_LABELS[s] || s,
|
<Button type="primary" onClick={() => setCreateOpen(true)}>创建推广码</Button>
|
||||||
|
</div>
|
||||||
},
|
|
||||||
|
<Form
|
||||||
{
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
title: '状态',
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => { setFilters(v); setPage(1); }}
|
||||||
dataIndex: 'status',
|
>
|
||||||
|
<Form.Item name="name" label="名称"><Input allowClear /></Form.Item>
|
||||||
width: 90,
|
<Form.Item name="code" label="码值"><Input allowClear /></Form.Item>
|
||||||
|
<Form.Item name="scene" label="场景">
|
||||||
render: (s) => (
|
<Select allowClear style={{ width: 130 }} options={scenes} />
|
||||||
|
</Form.Item>
|
||||||
<Tag color={s === 'ACTIVE' ? 'green' : 'default'}>
|
<Form.Item name="status" label="状态">
|
||||||
|
<Select
|
||||||
{PROMO_CODE_STATUS_LABELS[s as keyof typeof PROMO_CODE_STATUS_LABELS] || s}
|
allowClear
|
||||||
|
style={{ width: 100 }}
|
||||||
</Tag>
|
options={Object.entries(PROMO_CODE_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
||||||
|
/>
|
||||||
),
|
</Form.Item>
|
||||||
|
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
||||||
},
|
</Form>
|
||||||
|
|
||||||
{ title: '扫码', dataIndex: 'scanCount', width: 70 },
|
<Table
|
||||||
|
rowKey="id"
|
||||||
{ title: '订单', dataIndex: 'orderCount', width: 70 },
|
className="admin-table-nowrap"
|
||||||
|
loading={loading}
|
||||||
{
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
title: '转化率',
|
scroll={{ x: 1200 }}
|
||||||
|
pagination={{
|
||||||
width: 90,
|
current: page,
|
||||||
|
pageSize,
|
||||||
render: (_, row) => promoConversion(row.scanCount, row.orderCount),
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
},
|
onChange: (p, ps) => { setPage(p); setPageSize(ps); },
|
||||||
|
}}
|
||||||
{
|
/>
|
||||||
|
|
||||||
title: '渠道负责人',
|
<Modal
|
||||||
|
title="创建推广码"
|
||||||
width: 120,
|
open={createOpen}
|
||||||
|
onCancel={() => setCreateOpen(false)}
|
||||||
render: (_, row) => row.ownerUser?.userNo || row.ownerUser?.phone || '—',
|
footer={null}
|
||||||
|
destroyOnClose
|
||||||
},
|
>
|
||||||
|
<Form form={createForm} layout="vertical" onFinish={handleCreate} initialValues={{ scene: 'ONLINE_LINK' }}>
|
||||||
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
<Form.Item name="name" label="推广码名称" rules={[{ required: true, message: '请填写名称' }]}>
|
||||||
|
<Input placeholder="如:郑州品鉴会、门店地推" />
|
||||||
{
|
</Form.Item>
|
||||||
|
<Form.Item name="scene" label="场景" rules={[{ required: true }]}>
|
||||||
title: '操作',
|
<Select options={scenes} />
|
||||||
|
</Form.Item>
|
||||||
width: 220,
|
<Form.Item name="code" label="自定义码值(选填)">
|
||||||
|
<Input placeholder="留空自动生成,如 DKDEMO1" />
|
||||||
fixed: 'right',
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
render: (_, row) => (
|
name="page"
|
||||||
|
label="小程序落地页(选填)"
|
||||||
<Space size="small" wrap>
|
extra="如 pages/home/index;留空则使用服务端环境变量 WX_MINI_PROMO_PAGE"
|
||||||
|
>
|
||||||
<Button type="link" size="small" onClick={() => navigate(`/promo-codes/${row.id}`)}>
|
<Input placeholder="pages/home/index" />
|
||||||
|
</Form.Item>
|
||||||
详情
|
<Form.Item name="ownerUserId" label="关联用户 ID(选填)">
|
||||||
|
<Input placeholder="渠道负责人,填写用户数据库 ID" />
|
||||||
</Button>
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
<Button
|
<Input.TextArea rows={2} placeholder="渠道说明、活动备注等" />
|
||||||
|
</Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit" loading={creating} block>
|
||||||
|
创建并生成小程序码
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button, Descriptions, Drawer, Form, Input, Modal, Select, Space, Table, Tag, Typography, message,
|
Button, Descriptions, Drawer, Form, Input, Modal, Popconfirm, Select, Space, Table, Tag, Typography, message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
@@ -45,12 +45,33 @@ export default function StoreAccountsPage() {
|
|||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
const [stores, setStores] = useState<StoreOption[]>([]);
|
const [stores, setStores] = useState<StoreOption[]>([]);
|
||||||
|
const [deletingStaffId, setDeletingStaffId] = useState<string | null>(null);
|
||||||
|
|
||||||
async function loadStores() {
|
async function loadStores() {
|
||||||
const res = await request<Paginated<StoreOption>>(`/admin/stores?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
const res = await request<Paginated<StoreOption>>(`/admin/stores?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
||||||
setStores(res.items);
|
setStores(res.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function refreshDetail(accountId: string) {
|
||||||
|
const d = await request<Row>(`/admin/store-accounts/${accountId}`);
|
||||||
|
setDetail(d);
|
||||||
|
void reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteStaff(staffId: string) {
|
||||||
|
if (!detail) return;
|
||||||
|
setDeletingStaffId(staffId);
|
||||||
|
try {
|
||||||
|
await request(`/admin/store-accounts/${detail.id}/staff/${staffId}`, { method: 'DELETE' });
|
||||||
|
message.success('子账号已删除');
|
||||||
|
await refreshDetail(detail.id);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
} finally {
|
||||||
|
setDeletingStaffId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '姓名', dataIndex: 'name', width: 100 },
|
{ title: '姓名', dataIndex: 'name', width: 100 },
|
||||||
{ title: '手机', dataIndex: 'phone', width: 120 },
|
{ title: '手机', dataIndex: 'phone', width: 120 },
|
||||||
@@ -218,10 +239,32 @@ export default function StoreAccountsPage() {
|
|||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
render: (s) => <Tag>{ACCOUNT_STATUS_LABELS[s] || s}</Tag>,
|
render: (s) => <Tag>{ACCOUNT_STATUS_LABELS[s] || s}</Tag>,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 80,
|
||||||
|
render: (_, staff) => (
|
||||||
|
<Popconfirm
|
||||||
|
title="确认删除该子账号?"
|
||||||
|
description={`${staff.name}(${staff.phone})删除后将无法登录门店端`}
|
||||||
|
okText="删除"
|
||||||
|
okButtonProps={{ danger: true, loading: deletingStaffId === staff.id }}
|
||||||
|
cancelText="取消"
|
||||||
|
onConfirm={() => void deleteStaff(staff.id)}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
),
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : (
|
||||||
|
<Typography.Paragraph type="secondary" style={{ marginTop: 24, marginBottom: 0 }}>
|
||||||
|
暂无子账号
|
||||||
|
</Typography.Paragraph>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
@@ -14,12 +14,13 @@ import {
|
|||||||
Space,
|
Space,
|
||||||
Steps,
|
Steps,
|
||||||
Table,
|
Table,
|
||||||
|
Tabs,
|
||||||
Tag,
|
Tag,
|
||||||
Typography,
|
Typography,
|
||||||
message,
|
message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { FilePdfOutlined, LinkOutlined } from '@ant-design/icons';
|
import { FilePdfOutlined, LinkOutlined, EnvironmentOutlined } from '@ant-design/icons';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
import {
|
import {
|
||||||
ADMIN_OPTIONS_PAGE_SIZE,
|
ADMIN_OPTIONS_PAGE_SIZE,
|
||||||
@@ -37,6 +38,7 @@ import { useAdminList } from '../lib/useAdminList';
|
|||||||
import { resolveRegionBinding } from '../lib/china-region';
|
import { resolveRegionBinding } from '../lib/china-region';
|
||||||
import ChinaRegionCascader from '../components/ChinaRegionCascader';
|
import ChinaRegionCascader from '../components/ChinaRegionCascader';
|
||||||
import OssUpload from '../components/OssUpload';
|
import OssUpload from '../components/OssUpload';
|
||||||
|
import TencentLocPickerModal from '../components/TencentLocPickerModal';
|
||||||
|
|
||||||
const CREATE_STEPS = [
|
const CREATE_STEPS = [
|
||||||
{ title: '基本信息' },
|
{ title: '基本信息' },
|
||||||
@@ -44,6 +46,31 @@ const CREATE_STEPS = [
|
|||||||
{ title: '结算资质' },
|
{ title: '结算资质' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function fillGeolocation(
|
||||||
|
setCoords: (lat: number, lng: number) => void,
|
||||||
|
setLoading: (v: boolean) => void,
|
||||||
|
) {
|
||||||
|
if (!navigator.geolocation) {
|
||||||
|
message.error('当前浏览器不支持定位');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLoading(true);
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
(pos) => {
|
||||||
|
setCoords(pos.coords.latitude, pos.coords.longitude);
|
||||||
|
message.success(
|
||||||
|
`已获取坐标 ${pos.coords.latitude.toFixed(6)}, ${pos.coords.longitude.toFixed(6)}`,
|
||||||
|
);
|
||||||
|
setLoading(false);
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
message.error(err.message || '定位失败');
|
||||||
|
setLoading(false);
|
||||||
|
},
|
||||||
|
{ enableHighAccuracy: true, timeout: 10000 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
type StoreMediaItem = {
|
type StoreMediaItem = {
|
||||||
id?: string;
|
id?: string;
|
||||||
bizType?: string;
|
bizType?: string;
|
||||||
@@ -262,7 +289,21 @@ type StoreRow = {
|
|||||||
createdAt: string;
|
createdAt: string;
|
||||||
cityRef?: { name: string; code: string };
|
cityRef?: { name: string; code: string };
|
||||||
partner?: { companyName: string };
|
partner?: { companyName: string };
|
||||||
account?: { phone: string; name: string; status: string };
|
account?: {
|
||||||
|
phone: string;
|
||||||
|
name: string;
|
||||||
|
status: string;
|
||||||
|
bankAccountName?: string | null;
|
||||||
|
bankAccountNo?: string | null;
|
||||||
|
bankBranch?: string | null;
|
||||||
|
};
|
||||||
|
openTime?: string | null;
|
||||||
|
closeTime?: string | null;
|
||||||
|
openTime2?: string | null;
|
||||||
|
closeTime2?: string | null;
|
||||||
|
avgPrice?: number | null;
|
||||||
|
settlementRate?: number;
|
||||||
|
category?: { id: string; name: string; parentId?: string | null } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
type PartnerOption = { id: string; companyName: string };
|
type PartnerOption = { id: string; companyName: string };
|
||||||
@@ -272,13 +313,27 @@ type CityOption = {
|
|||||||
code: string;
|
code: string;
|
||||||
partnerBindings?: Array<{ partnerAccountId: string; partnerCompanyName?: string }>;
|
partnerBindings?: Array<{ partnerAccountId: string; partnerCompanyName?: string }>;
|
||||||
};
|
};
|
||||||
|
type CategoryNode = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
status?: string;
|
||||||
|
children?: CategoryNode[];
|
||||||
|
};
|
||||||
|
|
||||||
export default function StoresPage() {
|
export default function StoresPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const initialCityId = searchParams.get('cityId') ?? '';
|
||||||
|
const initialPartnerId = searchParams.get('partnerId') ?? '';
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [editForm] = Form.useForm();
|
const [editForm] = Form.useForm();
|
||||||
const [createForm] = Form.useForm<StoreCreateForm>();
|
const [createForm] = Form.useForm<StoreCreateForm>();
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string>>(() => {
|
||||||
|
const init: Record<string, string> = {};
|
||||||
|
if (initialCityId) init.cityId = initialCityId;
|
||||||
|
if (initialPartnerId) init.partnerId = initialPartnerId;
|
||||||
|
return init;
|
||||||
|
});
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<StoreRow>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<StoreRow>(
|
||||||
'/admin/stores',
|
'/admin/stores',
|
||||||
() => {
|
() => {
|
||||||
@@ -287,10 +342,14 @@ export default function StoresPage() {
|
|||||||
if (filters.status) qs.set('status', filters.status);
|
if (filters.status) qs.set('status', filters.status);
|
||||||
if (filters.auditStatus) qs.set('auditStatus', filters.auditStatus);
|
if (filters.auditStatus) qs.set('auditStatus', filters.auditStatus);
|
||||||
if (filters.phone) qs.set('phone', filters.phone);
|
if (filters.phone) qs.set('phone', filters.phone);
|
||||||
|
if (filters.cityId) qs.set('cityId', filters.cityId);
|
||||||
|
if (filters.partnerId) qs.set('partnerId', filters.partnerId);
|
||||||
return qs;
|
return qs;
|
||||||
},
|
},
|
||||||
[filters],
|
[filters],
|
||||||
);
|
);
|
||||||
|
const [filterCities, setFilterCities] = useState<CityOption[]>([]);
|
||||||
|
const [filterPartners, setFilterPartners] = useState<PartnerOption[]>([]);
|
||||||
const [detail, setDetail] = useState<Record<string, unknown> | null>(null);
|
const [detail, setDetail] = useState<Record<string, unknown> | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
const [rejectOpen, setRejectOpen] = useState(false);
|
const [rejectOpen, setRejectOpen] = useState(false);
|
||||||
@@ -299,13 +358,203 @@ export default function StoresPage() {
|
|||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
const [createStep, setCreateStep] = useState(0);
|
const [createStep, setCreateStep] = useState(0);
|
||||||
const [createError, setCreateError] = useState('');
|
const [createError, setCreateError] = useState('');
|
||||||
|
const [locating, setLocating] = useState(false);
|
||||||
|
const [mapPickerOpen, setMapPickerOpen] = useState(false);
|
||||||
|
const [mapPickerTarget, setMapPickerTarget] = useState<'create' | 'edit'>('create');
|
||||||
const [partners, setPartners] = useState<PartnerOption[]>([]);
|
const [partners, setPartners] = useState<PartnerOption[]>([]);
|
||||||
const [cities, setCities] = useState<CityOption[]>([]);
|
const [cities, setCities] = useState<CityOption[]>([]);
|
||||||
|
const [categoryTree, setCategoryTree] = useState<CategoryNode[]>([]);
|
||||||
const [optionsLoading, setOptionsLoading] = useState(false);
|
const [optionsLoading, setOptionsLoading] = useState(false);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [phoneMismatch, setPhoneMismatch] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`)
|
||||||
|
.then((res) => setFilterCities(res.items))
|
||||||
|
.catch(() => {});
|
||||||
|
void request<Paginated<PartnerOption>>(`/admin/partners?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`)
|
||||||
|
.then((res) => setFilterPartners(res.items))
|
||||||
|
.catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const cityId = searchParams.get('cityId') ?? '';
|
||||||
|
const partnerId = searchParams.get('partnerId') ?? '';
|
||||||
|
let changed = false;
|
||||||
|
setFilters((prev) => {
|
||||||
|
const next = { ...prev };
|
||||||
|
if ((prev.cityId ?? '') !== cityId) {
|
||||||
|
changed = true;
|
||||||
|
if (cityId) next.cityId = cityId;
|
||||||
|
else delete next.cityId;
|
||||||
|
}
|
||||||
|
if ((prev.partnerId ?? '') !== partnerId) {
|
||||||
|
changed = true;
|
||||||
|
if (partnerId) next.partnerId = partnerId;
|
||||||
|
else delete next.partnerId;
|
||||||
|
}
|
||||||
|
return changed ? next : prev;
|
||||||
|
});
|
||||||
|
form.setFieldsValue({
|
||||||
|
cityId: cityId || undefined,
|
||||||
|
partnerId: partnerId || undefined,
|
||||||
|
});
|
||||||
|
if (cityId || partnerId) setPage(1);
|
||||||
|
}, [searchParams, form, setPage]);
|
||||||
|
|
||||||
const selectedPartnerId = Form.useWatch('partnerAccountId', createForm);
|
const selectedPartnerId = Form.useWatch('partnerAccountId', createForm);
|
||||||
const selectedRegionCodes = Form.useWatch('regionCodes', createForm);
|
const selectedRegionCodes = Form.useWatch('regionCodes', createForm);
|
||||||
const selectedCityId = Form.useWatch('cityId', createForm);
|
const selectedCityId = Form.useWatch('cityId', createForm);
|
||||||
|
const selectedCategoryParentId = Form.useWatch('categoryParentId', createForm);
|
||||||
|
const editCategoryParentId = Form.useWatch('categoryParentId', editForm);
|
||||||
|
|
||||||
|
const categoryParentOptions = useMemo(
|
||||||
|
() =>
|
||||||
|
categoryTree
|
||||||
|
.filter((n) => n.status !== 'INACTIVE')
|
||||||
|
.map((n) => ({ value: n.id, label: n.name })),
|
||||||
|
[categoryTree],
|
||||||
|
);
|
||||||
|
const categoryChildOptions = useMemo(() => {
|
||||||
|
const parent = categoryTree.find((n) => n.id === selectedCategoryParentId);
|
||||||
|
return (parent?.children ?? [])
|
||||||
|
.filter((n) => n.status !== 'INACTIVE')
|
||||||
|
.map((n) => ({ value: n.id, label: n.name }));
|
||||||
|
}, [categoryTree, selectedCategoryParentId]);
|
||||||
|
|
||||||
|
const editCategoryChildOptions = useMemo(() => {
|
||||||
|
const parent = categoryTree.find((n) => n.id === editCategoryParentId);
|
||||||
|
return (parent?.children ?? [])
|
||||||
|
.filter((n) => n.status !== 'INACTIVE')
|
||||||
|
.map((n) => ({ value: n.id, label: n.name }));
|
||||||
|
}, [categoryTree, editCategoryParentId]);
|
||||||
|
|
||||||
|
async function openStoreDetail(row: StoreRow) {
|
||||||
|
const [d, cats] = await Promise.all([
|
||||||
|
request<Record<string, unknown>>(`/admin/stores/${row.id}`),
|
||||||
|
request<CategoryNode[]>('/admin/store-categories').catch(() => [] as CategoryNode[]),
|
||||||
|
]);
|
||||||
|
setCategoryTree(Array.isArray(cats) ? cats : []);
|
||||||
|
setDetail(d);
|
||||||
|
const category = d.category && typeof d.category === 'object'
|
||||||
|
? (d.category as { id?: string; parentId?: string | null })
|
||||||
|
: null;
|
||||||
|
const account = d.account && typeof d.account === 'object'
|
||||||
|
? (d.account as {
|
||||||
|
phone?: string | null;
|
||||||
|
bankAccountName?: string | null;
|
||||||
|
bankAccountNo?: string | null;
|
||||||
|
bankBranch?: string | null;
|
||||||
|
})
|
||||||
|
: null;
|
||||||
|
const categoryId = category?.id != null ? String(category.id) : undefined;
|
||||||
|
let parentId = category?.parentId != null ? String(category.parentId) : undefined;
|
||||||
|
if (!parentId && categoryId) {
|
||||||
|
for (const parent of cats) {
|
||||||
|
if (parent.id === categoryId) {
|
||||||
|
parentId = parent.id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((parent.children ?? []).some((c) => c.id === categoryId)) {
|
||||||
|
parentId = parent.id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const loginPhone =
|
||||||
|
(typeof d.loginPhone === 'string' && d.loginPhone) ||
|
||||||
|
account?.phone ||
|
||||||
|
(typeof d.phone === 'string' ? d.phone : undefined);
|
||||||
|
const storePhone = typeof d.phone === 'string' ? d.phone : undefined;
|
||||||
|
const phoneMismatchNow = !!(loginPhone && storePhone && loginPhone !== storePhone);
|
||||||
|
setPhoneMismatch(phoneMismatchNow ? String(loginPhone) : null);
|
||||||
|
editForm.setFieldsValue({
|
||||||
|
name: d.name,
|
||||||
|
// 以门店手机号为准保存;若与账号登录号不一致,保存时会强制同步到登录账号
|
||||||
|
phone: storePhone || loginPhone,
|
||||||
|
intro: d.intro,
|
||||||
|
benefitUsageRule:
|
||||||
|
d.benefitUsageRule != null &&
|
||||||
|
String(d.benefitUsageRule).trim() &&
|
||||||
|
!/^null$/i.test(String(d.benefitUsageRule).trim())
|
||||||
|
? String(d.benefitUsageRule)
|
||||||
|
: '',
|
||||||
|
coverUrl: d.coverUrl,
|
||||||
|
province: d.province,
|
||||||
|
city: d.cityName,
|
||||||
|
district: d.district,
|
||||||
|
address: d.address,
|
||||||
|
categoryParentId: parentId,
|
||||||
|
categoryId,
|
||||||
|
latitude: d.latitude != null ? Number(d.latitude) : undefined,
|
||||||
|
longitude: d.longitude != null ? Number(d.longitude) : undefined,
|
||||||
|
settlementRate: d.settlementRate != null ? Number(d.settlementRate) * 100 : 60,
|
||||||
|
openTime: d.openTime || '10:00',
|
||||||
|
closeTime: d.closeTime || '22:00',
|
||||||
|
openTime2: d.openTime2 || undefined,
|
||||||
|
closeTime2: d.closeTime2 || undefined,
|
||||||
|
avgPrice: d.avgPrice != null ? Number(d.avgPrice) : undefined,
|
||||||
|
bankAccountName: account?.bankAccountName || undefined,
|
||||||
|
bankAccountNo: account?.bankAccountNo || undefined,
|
||||||
|
bankBranch: account?.bankBranch || undefined,
|
||||||
|
});
|
||||||
|
setDrawerOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveStoreDetail() {
|
||||||
|
if (!detail) return;
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
const v = await editForm.validateFields();
|
||||||
|
const hasCoords =
|
||||||
|
v.latitude != null &&
|
||||||
|
v.longitude != null &&
|
||||||
|
Number.isFinite(Number(v.latitude)) &&
|
||||||
|
Number.isFinite(Number(v.longitude));
|
||||||
|
const payload = {
|
||||||
|
name: v.name,
|
||||||
|
phone: v.phone,
|
||||||
|
coverUrl: v.coverUrl,
|
||||||
|
intro: v.intro,
|
||||||
|
benefitUsageRule:
|
||||||
|
typeof v.benefitUsageRule === 'string' &&
|
||||||
|
v.benefitUsageRule.trim() &&
|
||||||
|
!/^null$/i.test(v.benefitUsageRule.trim())
|
||||||
|
? v.benefitUsageRule.trim()
|
||||||
|
: null,
|
||||||
|
categoryId: v.categoryId,
|
||||||
|
province: v.province,
|
||||||
|
city: v.city,
|
||||||
|
district: v.district,
|
||||||
|
address: v.address,
|
||||||
|
avgPrice: v.avgPrice,
|
||||||
|
openTime: v.openTime,
|
||||||
|
closeTime: v.closeTime,
|
||||||
|
openTime2: v.openTime2 || null,
|
||||||
|
closeTime2: v.closeTime2 || null,
|
||||||
|
settlementRate: v.settlementRate != null ? Number(v.settlementRate) / 100 : undefined,
|
||||||
|
bankAccountName: v.bankAccountName ?? null,
|
||||||
|
bankAccountNo: v.bankAccountNo ?? null,
|
||||||
|
bankBranch: v.bankBranch ?? null,
|
||||||
|
...(hasCoords
|
||||||
|
? { latitude: Number(v.latitude), longitude: Number(v.longitude) }
|
||||||
|
: {}),
|
||||||
|
};
|
||||||
|
const updated = await request<Record<string, unknown>>(`/admin/stores/${detail.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
message.success('门店信息已保存');
|
||||||
|
setDetail(updated);
|
||||||
|
setPhoneMismatch(null);
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
if (e && typeof e === 'object' && 'errorFields' in e) return;
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function bindRegionSelection(codes: string[], partnerAccountId?: string) {
|
function bindRegionSelection(codes: string[], partnerAccountId?: string) {
|
||||||
const binding = resolveRegionBinding(codes, cities, partnerAccountId ?? selectedPartnerId);
|
const binding = resolveRegionBinding(codes, cities, partnerAccountId ?? selectedPartnerId);
|
||||||
@@ -333,20 +582,27 @@ export default function StoresPage() {
|
|||||||
return `区划 ${binding.cityCode} 暂未开城,请先在「开城 → 城市」添加`;
|
return `区划 ${binding.cityCode} 暂未开城,请先在「开城 → 城市」添加`;
|
||||||
}, [selectedRegionCodes, cities, selectedPartnerId]);
|
}, [selectedRegionCodes, cities, selectedPartnerId]);
|
||||||
|
|
||||||
async function loadOptions() {
|
async function loadOptions(opts?: { quiet?: boolean }) {
|
||||||
setOptionsLoading(true);
|
setOptionsLoading(true);
|
||||||
try {
|
try {
|
||||||
const qs = `pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`;
|
const qs = `pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`;
|
||||||
const [p, c] = await Promise.all([
|
const [p, c, cats] = await Promise.all([
|
||||||
request<Paginated<PartnerOption>>(`/admin/partners?${qs}`),
|
request<Paginated<PartnerOption>>(`/admin/partners?${qs}`),
|
||||||
request<Paginated<CityOption>>(`/admin/cities?${qs}`),
|
request<Paginated<CityOption>>(`/admin/cities?${qs}`),
|
||||||
|
request<CategoryNode[]>('/admin/store-categories'),
|
||||||
]);
|
]);
|
||||||
setPartners(p.items);
|
setPartners(p.items);
|
||||||
setCities(c.items);
|
setCities(c.items);
|
||||||
if (!p.items.length) message.warning('暂无开城合伙人,请先在「开城 → 城市」详情中创建合伙人');
|
setCategoryTree(Array.isArray(cats) ? cats : []);
|
||||||
if (!c.items.length) message.warning('暂无开城城市,请先在「开城 → 城市」中创建');
|
if (!opts?.quiet) {
|
||||||
|
if (!p.items.length) message.warning('暂无开城合伙人,请先在「开城 → 城市」详情中创建合伙人');
|
||||||
|
if (!c.items.length) message.warning('暂无开城城市,请先在「开城 → 城市」中创建');
|
||||||
|
if (!Array.isArray(cats) || !cats.length) {
|
||||||
|
message.warning('暂无门店分类,请先在「门店 → 门店分类」中配置');
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.error(e instanceof Error ? e.message : '加载合伙人/城市失败');
|
message.error(e instanceof Error ? e.message : '加载合伙人/城市/分类失败');
|
||||||
} finally {
|
} finally {
|
||||||
setOptionsLoading(false);
|
setOptionsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -364,6 +620,11 @@ export default function StoresPage() {
|
|||||||
createForm.setFieldsValue({
|
createForm.setFieldsValue({
|
||||||
envPhotoUrls: ['', '', ''],
|
envPhotoUrls: ['', '', ''],
|
||||||
settlementRate: 60,
|
settlementRate: 60,
|
||||||
|
openTime: '10:00',
|
||||||
|
closeTime: '22:00',
|
||||||
|
openTime2: undefined,
|
||||||
|
closeTime2: undefined,
|
||||||
|
avgPrice: undefined,
|
||||||
});
|
});
|
||||||
setCreateStep(0);
|
setCreateStep(0);
|
||||||
setCreateError('');
|
setCreateError('');
|
||||||
@@ -379,7 +640,16 @@ export default function StoresPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await createForm.validateFields(['partnerAccountId', 'regionCodes', 'cityId', 'name', 'phone', 'address']);
|
await createForm.validateFields([
|
||||||
|
'partnerAccountId',
|
||||||
|
'regionCodes',
|
||||||
|
'cityId',
|
||||||
|
'categoryParentId',
|
||||||
|
'categoryId',
|
||||||
|
'name',
|
||||||
|
'phone',
|
||||||
|
'address',
|
||||||
|
]);
|
||||||
} catch {
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -403,13 +673,32 @@ export default function StoresPage() {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
partnerAccountId: values.partnerAccountId,
|
partnerAccountId: values.partnerAccountId,
|
||||||
cityId: values.cityId,
|
cityId: values.cityId,
|
||||||
|
categoryId: values.categoryId,
|
||||||
province: values.province,
|
province: values.province,
|
||||||
city: values.city,
|
city: values.city,
|
||||||
name: values.name.trim(),
|
name: values.name.trim(),
|
||||||
phone: values.phone.trim(),
|
phone: values.phone.trim(),
|
||||||
district: values.district.trim(),
|
district: values.district.trim(),
|
||||||
address: values.address.trim(),
|
address: values.address.trim(),
|
||||||
|
...(values.latitude != null &&
|
||||||
|
values.longitude != null &&
|
||||||
|
Number.isFinite(Number(values.latitude)) &&
|
||||||
|
Number.isFinite(Number(values.longitude))
|
||||||
|
? {
|
||||||
|
latitude: Number(values.latitude),
|
||||||
|
longitude: Number(values.longitude),
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
intro: values.intro?.trim() || undefined,
|
intro: values.intro?.trim() || undefined,
|
||||||
|
benefitUsageRule: values.benefitUsageRule?.trim() || undefined,
|
||||||
|
openTime: values.openTime?.trim() || '10:00',
|
||||||
|
closeTime: values.closeTime?.trim() || '22:00',
|
||||||
|
...(values.openTime2?.trim() && values.closeTime2?.trim()
|
||||||
|
? { openTime2: values.openTime2.trim(), closeTime2: values.closeTime2.trim() }
|
||||||
|
: {}),
|
||||||
|
...(values.avgPrice != null && values.avgPrice !== ''
|
||||||
|
? { avgPrice: Number(values.avgPrice) }
|
||||||
|
: {}),
|
||||||
coverUrl: values.coverUrl?.trim() || undefined,
|
coverUrl: values.coverUrl?.trim() || undefined,
|
||||||
envPhotoUrls: envPhotoUrls.length ? envPhotoUrls : undefined,
|
envPhotoUrls: envPhotoUrls.length ? envPhotoUrls : undefined,
|
||||||
contractUrl: values.contractUrl?.trim() || undefined,
|
contractUrl: values.contractUrl?.trim() || undefined,
|
||||||
@@ -441,6 +730,11 @@ export default function StoresPage() {
|
|||||||
render: (url) => url ? <Image src={url} width={48} height={48} style={{ objectFit: 'cover', borderRadius: 4 }} /> : '—',
|
render: (url) => url ? <Image src={url} width={48} height={48} style={{ objectFit: 'cover', borderRadius: 4 }} /> : '—',
|
||||||
},
|
},
|
||||||
{ title: '门店名', dataIndex: 'name', width: 140 },
|
{ title: '门店名', dataIndex: 'name', width: 140 },
|
||||||
|
{
|
||||||
|
title: '分类',
|
||||||
|
width: 100,
|
||||||
|
render: (_, row) => row.category?.name || '—',
|
||||||
|
},
|
||||||
{ title: '城市', dataIndex: 'cityName', width: 80 },
|
{ title: '城市', dataIndex: 'cityName', width: 80 },
|
||||||
{ title: '电话', dataIndex: 'phone', width: 120 },
|
{ title: '电话', dataIndex: 'phone', width: 120 },
|
||||||
{
|
{
|
||||||
@@ -471,20 +765,7 @@ export default function StoresPage() {
|
|||||||
{
|
{
|
||||||
title: '操作', width: 80,
|
title: '操作', width: 80,
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Button type="link" size="small" onClick={async () => {
|
<Button type="link" size="small" onClick={() => void openStoreDetail(row)}>详情</Button>
|
||||||
const d = await request<Record<string, unknown>>(`/admin/stores/${row.id}`);
|
|
||||||
setDetail(d);
|
|
||||||
editForm.setFieldsValue({
|
|
||||||
name: d.name,
|
|
||||||
phone: d.phone,
|
|
||||||
intro: d.intro,
|
|
||||||
coverUrl: d.coverUrl,
|
|
||||||
address: d.address,
|
|
||||||
district: d.district,
|
|
||||||
settlementRate: d.settlementRate != null ? Number(d.settlementRate) * 100 : 60,
|
|
||||||
});
|
|
||||||
setDrawerOpen(true);
|
|
||||||
}}>详情</Button>
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -501,6 +782,26 @@ export default function StoresPage() {
|
|||||||
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={(v) => { setFilters(v); setPage(1); }}>
|
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={(v) => { setFilters(v); setPage(1); }}>
|
||||||
<Form.Item name="name" label="名称"><Input allowClear /></Form.Item>
|
<Form.Item name="name" label="名称"><Input allowClear /></Form.Item>
|
||||||
<Form.Item name="phone" label="电话"><Input allowClear /></Form.Item>
|
<Form.Item name="phone" label="电话"><Input allowClear /></Form.Item>
|
||||||
|
<Form.Item name="cityId" label="城市">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
style={{ width: 140 }}
|
||||||
|
placeholder="全部"
|
||||||
|
options={filterCities.map((c) => ({ value: c.id, label: c.name }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="partnerId" label="城市合伙人">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
style={{ width: 180 }}
|
||||||
|
placeholder="全部"
|
||||||
|
options={filterPartners.map((p) => ({ value: p.id, label: p.companyName || p.id }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item name="status" label="营业状态">
|
<Form.Item name="status" label="营业状态">
|
||||||
<Select allowClear style={{ width: 100 }} placeholder="全部" options={Object.entries(STORE_STATUS_LABELS).map(([value, label]) => ({ value, label }))} />
|
<Select allowClear style={{ width: 100 }} placeholder="全部" options={Object.entries(STORE_STATUS_LABELS).map(([value, label]) => ({ value, label }))} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -513,7 +814,20 @@ export default function StoresPage() {
|
|||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
||||||
<Form.Item><Button onClick={() => { form.resetFields(); setFilters({}); setPage(1); }}>重置</Button></Form.Item>
|
<Form.Item>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
form.resetFields();
|
||||||
|
setFilters({});
|
||||||
|
setPage(1);
|
||||||
|
if (searchParams.has('cityId') || searchParams.has('partnerId')) {
|
||||||
|
navigate('/stores', { replace: true });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
<Table rowKey="id" className="admin-table-nowrap" loading={loading} columns={columns} dataSource={data?.items ?? []} scroll={{ x: 1200 }}
|
<Table rowKey="id" className="admin-table-nowrap" loading={loading} columns={columns} dataSource={data?.items ?? []} scroll={{ x: 1200 }}
|
||||||
pagination={{ current: page, pageSize, total: data?.total ?? 0, showSizeChanger: true, onChange: (p, ps) => { setPage(p); setPageSize(ps); } }} />
|
pagination={{ current: page, pageSize, total: data?.total ?? 0, showSizeChanger: true, onChange: (p, ps) => { setPage(p); setPageSize(ps); } }} />
|
||||||
@@ -554,7 +868,7 @@ export default function StoresPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
<Select defaultValue={String(detail.status)} style={{ width: 120 }}
|
<Select value={String(detail.status)} style={{ width: 120 }}
|
||||||
options={Object.entries(STORE_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
options={Object.entries(STORE_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
||||||
onChange={async (status) => {
|
onChange={async (status) => {
|
||||||
await request(`/admin/stores/${detail.id}/status`, { method: 'PUT', body: JSON.stringify({ status }) });
|
await request(`/admin/stores/${detail.id}/status`, { method: 'PUT', body: JSON.stringify({ status }) });
|
||||||
@@ -562,71 +876,228 @@ export default function StoresPage() {
|
|||||||
setDetail({ ...detail, status });
|
setDetail({ ...detail, status });
|
||||||
void reload();
|
void reload();
|
||||||
}} />
|
}} />
|
||||||
<Button type="primary" onClick={async () => {
|
<Button type="primary" loading={saving} onClick={() => void saveStoreDetail()}>保存修改</Button>
|
||||||
const v = await editForm.validateFields();
|
|
||||||
const payload = {
|
|
||||||
...v,
|
|
||||||
settlementRate: v.settlementRate != null ? Number(v.settlementRate) / 100 : undefined,
|
|
||||||
};
|
|
||||||
await request(`/admin/stores/${detail.id}`, { method: 'PUT', body: JSON.stringify(payload) });
|
|
||||||
message.success('已保存');
|
|
||||||
setDetail({ ...detail, ...v });
|
|
||||||
void reload();
|
|
||||||
}}>保存</Button>
|
|
||||||
</Space>
|
</Space>
|
||||||
)}>
|
)}>
|
||||||
{detail && (
|
{detail && (
|
||||||
<>
|
<Form form={editForm} layout="vertical">
|
||||||
<StoreAuditMediaSection detail={detail} />
|
<Tabs
|
||||||
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
|
destroyInactiveTabPane={false}
|
||||||
<Descriptions.Item label="ID">{String(detail.id)}</Descriptions.Item>
|
items={[
|
||||||
<Descriptions.Item label="审核状态">
|
{
|
||||||
<Tag color={
|
key: 'basic',
|
||||||
String(detail.auditStatus) === 'PENDING' ? 'orange'
|
label: '基本信息',
|
||||||
: String(detail.auditStatus) === 'REJECTED' ? 'red' : 'green'
|
forceRender: true,
|
||||||
}>
|
children: (
|
||||||
{STORE_AUDIT_STATUS_LABELS[String(detail.auditStatus || 'APPROVED')] || String(detail.auditStatus)}
|
<>
|
||||||
</Tag>
|
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
|
||||||
</Descriptions.Item>
|
<Descriptions.Item label="ID">{String(detail.id)}</Descriptions.Item>
|
||||||
{String(detail.auditStatus) === 'REJECTED' ? (
|
<Descriptions.Item label="审核状态">
|
||||||
<Descriptions.Item label="驳回原因">{String(detail.rejectReason || '—')}</Descriptions.Item>
|
<Tag color={
|
||||||
) : null}
|
String(detail.auditStatus) === 'PENDING' ? 'orange'
|
||||||
<Descriptions.Item label="地址">{String(detail.province)}{String(detail.cityName)}{String(detail.district)}{String(detail.address)}</Descriptions.Item>
|
: String(detail.auditStatus) === 'REJECTED' ? 'red' : 'green'
|
||||||
<Descriptions.Item label="核销结算比例">
|
}>
|
||||||
{detail.settlementRate != null ? `${Math.round(Number(detail.settlementRate) * 100)}%` : '60%'}
|
{STORE_AUDIT_STATUS_LABELS[String(detail.auditStatus || 'APPROVED')] || String(detail.auditStatus)}
|
||||||
</Descriptions.Item>
|
</Tag>
|
||||||
<Descriptions.Item label="核销数">{String(detail.redeemCount ?? 0)}</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="操作">
|
{String(detail.auditStatus) === 'REJECTED' ? (
|
||||||
<Button type="link" size="small" style={{ padding: 0 }} onClick={() => navigate(`/logs/stores?storeId=${detail.id}`)}>
|
<Descriptions.Item label="驳回原因">{String(detail.rejectReason || '—')}</Descriptions.Item>
|
||||||
查看商户日志
|
) : null}
|
||||||
</Button>
|
<Descriptions.Item label="核销数">{String(detail.redeemCount ?? 0)}</Descriptions.Item>
|
||||||
</Descriptions.Item>
|
<Descriptions.Item label="操作">
|
||||||
{Array.isArray(detail.audits) && (detail.audits as Array<Record<string, unknown>>).length > 0 ? (
|
<Button type="link" size="small" style={{ padding: 0 }} onClick={() => navigate(`/logs/stores?storeId=${detail.id}`)}>
|
||||||
<Descriptions.Item label="审核记录">
|
查看商户日志
|
||||||
<Space direction="vertical" size={4} style={{ width: '100%' }}>
|
</Button>
|
||||||
{(detail.audits as Array<Record<string, unknown>>).map((a) => (
|
</Descriptions.Item>
|
||||||
<Typography.Text key={String(a.id)} style={{ fontSize: 12 }}>
|
{Array.isArray(detail.audits) && (detail.audits as Array<Record<string, unknown>>).length > 0 ? (
|
||||||
{fmtTime(String(a.createdAt))} · {String(a.status)} · {String(a.remark || '—')}
|
<Descriptions.Item label="审核记录">
|
||||||
</Typography.Text>
|
<Space direction="vertical" size={4} style={{ width: '100%' }}>
|
||||||
))}
|
{(detail.audits as Array<Record<string, unknown>>).map((a) => (
|
||||||
</Space>
|
<Typography.Text key={String(a.id)} style={{ fontSize: 12 }}>
|
||||||
</Descriptions.Item>
|
{fmtTime(String(a.createdAt))} · {String(a.status)} · {String(a.remark || '—')}
|
||||||
) : null}
|
</Typography.Text>
|
||||||
</Descriptions>
|
))}
|
||||||
<Form form={editForm} layout="vertical">
|
</Space>
|
||||||
<Form.Item name="name" label="名称" rules={[{ required: true }]}><Input /></Form.Item>
|
</Descriptions.Item>
|
||||||
<Form.Item name="phone" label="电话" rules={[{ required: true }]}><Input /></Form.Item>
|
) : null}
|
||||||
<Form.Item name="coverUrl" label="封面图">
|
</Descriptions>
|
||||||
<OssUpload bizType="STORE_TITLE" mediaType="IMAGE" />
|
<Typography.Title level={5} style={{ marginTop: 0 }}>编辑门店信息</Typography.Title>
|
||||||
</Form.Item>
|
{phoneMismatch ? (
|
||||||
<Form.Item name="intro" label="介绍"><Input.TextArea rows={4} /></Form.Item>
|
<Alert
|
||||||
<Form.Item name="district" label="区县"><Input /></Form.Item>
|
type="warning"
|
||||||
<Form.Item name="address" label="详细地址"><Input /></Form.Item>
|
showIcon
|
||||||
<Form.Item name="settlementRate" label="核销结算比例 %" initialValue={60} rules={[{ required: true }]}>
|
style={{ marginBottom: 16 }}
|
||||||
<InputNumber min={0} max={100} precision={2} style={{ width: '100%' }} addonAfter="%" />
|
message={`登录账号手机号仍为 ${phoneMismatch},与门店手机号不一致。请点击右上角「保存修改」同步,否则门店端无法用新号登录。`}
|
||||||
</Form.Item>
|
/>
|
||||||
</Form>
|
) : null}
|
||||||
</>
|
<Form.Item name="name" label="名称" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="phone"
|
||||||
|
label="登录手机号"
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
extra="门店端短信登录使用此号码;修改后需用新号重新登录"
|
||||||
|
>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="categoryParentId"
|
||||||
|
label="门店分类(大类)"
|
||||||
|
rules={[{ required: true, message: '请选择门店大类' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
showSearch
|
||||||
|
loading={optionsLoading}
|
||||||
|
optionFilterProp="label"
|
||||||
|
options={categoryParentOptions}
|
||||||
|
onChange={() => editForm.setFieldValue('categoryId', undefined)}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="categoryId"
|
||||||
|
label="门店分类(细类)"
|
||||||
|
rules={[{ required: true, message: '请选择门店细类' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
placeholder={editCategoryParentId ? '选择细类' : '请先选大类'}
|
||||||
|
disabled={!editCategoryParentId}
|
||||||
|
options={editCategoryChildOptions}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="coverUrl" label="封面图 / 门头照">
|
||||||
|
<OssUpload bizType="STORE_TITLE" mediaType="IMAGE" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="intro" label="介绍"><Input.TextArea rows={4} showCount maxLength={500} /></Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="benefitUsageRule"
|
||||||
|
label="好客权益券使用规则"
|
||||||
|
extra="展示在用户端门店详情「门店详情」下方"
|
||||||
|
>
|
||||||
|
<Input.TextArea rows={4} placeholder="选填,最多1000字" showCount maxLength={1000} />
|
||||||
|
</Form.Item>
|
||||||
|
<Space wrap style={{ width: '100%' }}>
|
||||||
|
<Form.Item name="province" label="省份" rules={[{ required: true }]}>
|
||||||
|
<Input style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="city" label="城市" rules={[{ required: true }]}>
|
||||||
|
<Input style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="district" label="区县" rules={[{ required: true }]}>
|
||||||
|
<Input style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
<Form.Item name="address" label="详细地址" rules={[{ required: true }]}>
|
||||||
|
<Input.TextArea rows={2} />
|
||||||
|
</Form.Item>
|
||||||
|
<Space wrap style={{ width: '100%' }}>
|
||||||
|
<Form.Item name="latitude" label="纬度" style={{ marginBottom: 8 }}>
|
||||||
|
<InputNumber
|
||||||
|
style={{ width: 180 }}
|
||||||
|
precision={7}
|
||||||
|
step={0.000001}
|
||||||
|
placeholder="如 34.7466000"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="longitude" label="经度" style={{ marginBottom: 8 }}>
|
||||||
|
<InputNumber
|
||||||
|
style={{ width: 180 }}
|
||||||
|
precision={7}
|
||||||
|
step={0.000001}
|
||||||
|
placeholder="如 113.6253000"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
<Space wrap style={{ marginBottom: 16 }}>
|
||||||
|
<Button
|
||||||
|
loading={locating}
|
||||||
|
onClick={() => {
|
||||||
|
fillGeolocation(
|
||||||
|
(lat, lng) => editForm.setFieldsValue({ latitude: lat, longitude: lng }),
|
||||||
|
setLocating,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
获取当前位置
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
icon={<EnvironmentOutlined />}
|
||||||
|
onClick={() => {
|
||||||
|
setMapPickerTarget('edit');
|
||||||
|
setMapPickerOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
腾讯地图选点
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
<Form.Item name="avgPrice" label="人均费用(选填)">
|
||||||
|
<InputNumber min={0} precision={0} style={{ width: '100%' }} addonAfter="元" placeholder="用户端展示" />
|
||||||
|
</Form.Item>
|
||||||
|
<Space wrap style={{ width: '100%' }}>
|
||||||
|
<Form.Item name="openTime" label="营业开始" rules={[{ required: true }]}>
|
||||||
|
<Input type="time" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="closeTime" label="营业结束" rules={[{ required: true }]}>
|
||||||
|
<Input type="time" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
<Space wrap style={{ width: '100%' }}>
|
||||||
|
<Form.Item name="openTime2" label="第二段开始(选填)">
|
||||||
|
<Input type="time" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="closeTime2" label="第二段结束">
|
||||||
|
<Input type="time" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'settlement',
|
||||||
|
label: '结算资质',
|
||||||
|
forceRender: true,
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<Form.Item name="settlementRate" label="核销结算比例 %" initialValue={60} rules={[{ required: true }]}>
|
||||||
|
<InputNumber min={0} max={100} precision={2} style={{ width: '100%' }} addonAfter="%" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankAccountName" label="结算户名">
|
||||||
|
<Input placeholder="开户名" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankBranch" label="开户银行">
|
||||||
|
<Input placeholder="如 中国工商银行某某支行" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="bankAccountNo"
|
||||||
|
label="银行卡号"
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
validator: async (_, value) => {
|
||||||
|
const v = String(value || '').trim();
|
||||||
|
if (!v) return;
|
||||||
|
if (!/^\d{16,19}$/.test(v)) {
|
||||||
|
throw new Error('银行卡号须为 16–19 位数字');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input placeholder="16–19 位数字" maxLength={19} />
|
||||||
|
</Form.Item>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
修改后点右上角「保存修改」一并提交。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'media',
|
||||||
|
label: '审核材料',
|
||||||
|
children: <StoreAuditMediaSection detail={detail} />,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
<Modal
|
<Modal
|
||||||
@@ -685,6 +1156,38 @@ export default function StoresPage() {
|
|||||||
<Form.Item name="city" hidden><Input /></Form.Item>
|
<Form.Item name="city" hidden><Input /></Form.Item>
|
||||||
<Form.Item name="district" hidden><Input /></Form.Item>
|
<Form.Item name="district" hidden><Input /></Form.Item>
|
||||||
<Form.Item name="districtCode" hidden><Input /></Form.Item>
|
<Form.Item name="districtCode" hidden><Input /></Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="categoryParentId"
|
||||||
|
label="门店分类(大类)"
|
||||||
|
rules={[{ required: true, message: '请选择门店大类' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
showSearch
|
||||||
|
loading={optionsLoading}
|
||||||
|
optionFilterProp="label"
|
||||||
|
placeholder={optionsLoading ? '加载中…' : '选择大类'}
|
||||||
|
options={categoryParentOptions}
|
||||||
|
onChange={() => createForm.setFieldValue('categoryId', undefined)}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="categoryId"
|
||||||
|
label="门店分类(细类)"
|
||||||
|
rules={[{ required: true, message: '请选择门店细类' }]}
|
||||||
|
extra={
|
||||||
|
<Typography.Link onClick={() => navigate('/store-categories')}>
|
||||||
|
去配置门店分类
|
||||||
|
</Typography.Link>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
placeholder={selectedCategoryParentId ? '选择细类' : '请先选大类'}
|
||||||
|
disabled={!selectedCategoryParentId}
|
||||||
|
options={categoryChildOptions}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item name="name" label="门店名称" rules={[{ required: true, message: '请填写门店名称' }]}>
|
<Form.Item name="name" label="门店名称" rules={[{ required: true, message: '请填写门店名称' }]}>
|
||||||
<Input placeholder="请输入门店名称" />
|
<Input placeholder="请输入门店名称" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -694,8 +1197,77 @@ export default function StoresPage() {
|
|||||||
<Form.Item name="address" label="详细地址" rules={[{ required: true, message: '请填写详细地址' }]}>
|
<Form.Item name="address" label="详细地址" rules={[{ required: true, message: '请填写详细地址' }]}>
|
||||||
<Input.TextArea rows={2} placeholder="请输入详细门牌号" />
|
<Input.TextArea rows={2} placeholder="请输入详细门牌号" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Space wrap style={{ width: '100%' }}>
|
||||||
|
<Form.Item name="latitude" label="纬度" style={{ marginBottom: 8 }}>
|
||||||
|
<InputNumber
|
||||||
|
style={{ width: 180 }}
|
||||||
|
precision={7}
|
||||||
|
step={0.000001}
|
||||||
|
placeholder="如 34.7466000"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="longitude" label="经度" style={{ marginBottom: 8 }}>
|
||||||
|
<InputNumber
|
||||||
|
style={{ width: 180 }}
|
||||||
|
precision={7}
|
||||||
|
step={0.000001}
|
||||||
|
placeholder="如 113.6253000"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
<Space wrap style={{ marginBottom: 16 }}>
|
||||||
|
<Button
|
||||||
|
loading={locating}
|
||||||
|
onClick={() => {
|
||||||
|
fillGeolocation(
|
||||||
|
(lat, lng) => createForm.setFieldsValue({ latitude: lat, longitude: lng }),
|
||||||
|
setLocating,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
获取当前位置
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
icon={<EnvironmentOutlined />}
|
||||||
|
onClick={() => {
|
||||||
|
setMapPickerTarget('create');
|
||||||
|
setMapPickerOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
腾讯地图选点
|
||||||
|
</Button>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
可手动填写 / 定位 / 腾讯地图选点填入坐标
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
<Space wrap style={{ width: '100%' }}>
|
||||||
|
<Form.Item name="openTime" label="营业开始" rules={[{ required: true, message: '请填写营业开始时间' }]}>
|
||||||
|
<Input type="time" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="closeTime" label="营业结束" rules={[{ required: true, message: '请填写营业结束时间' }]}>
|
||||||
|
<Input type="time" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
<Space wrap style={{ width: '100%' }}>
|
||||||
|
<Form.Item name="openTime2" label="第二段开始(选填)">
|
||||||
|
<Input type="time" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="closeTime2" label="第二段结束">
|
||||||
|
<Input type="time" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
<Form.Item name="avgPrice" label="人均费用(选填)">
|
||||||
|
<InputNumber min={0} precision={0} style={{ width: '100%' }} addonAfter="元" placeholder="用户端展示" />
|
||||||
|
</Form.Item>
|
||||||
<Form.Item name="intro" label="门店简介">
|
<Form.Item name="intro" label="门店简介">
|
||||||
<Input.TextArea rows={3} placeholder="选填,10~500字" showCount maxLength={500} />
|
<Input.TextArea rows={3} placeholder="选填,2~500字" showCount maxLength={500} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="benefitUsageRule"
|
||||||
|
label="好客权益券使用规则"
|
||||||
|
extra="展示在用户端门店详情"
|
||||||
|
>
|
||||||
|
<Input.TextArea rows={3} placeholder="选填,最多1000字" showCount maxLength={1000} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: createStep === 1 ? 'block' : 'none' }}>
|
<div style={{ display: createStep === 1 ? 'block' : 'none' }}>
|
||||||
@@ -776,6 +1348,42 @@ export default function StoresPage() {
|
|||||||
onChange={(e) => setRejectReason(e.target.value)}
|
onChange={(e) => setRejectReason(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
<TencentLocPickerModal
|
||||||
|
open={mapPickerOpen}
|
||||||
|
onClose={() => setMapPickerOpen(false)}
|
||||||
|
latitude={
|
||||||
|
mapPickerTarget === 'edit'
|
||||||
|
? Number(editForm.getFieldValue('latitude') ?? detail?.latitude)
|
||||||
|
: Number(createForm.getFieldValue('latitude'))
|
||||||
|
}
|
||||||
|
longitude={
|
||||||
|
mapPickerTarget === 'edit'
|
||||||
|
? Number(editForm.getFieldValue('longitude') ?? detail?.longitude)
|
||||||
|
: Number(createForm.getFieldValue('longitude'))
|
||||||
|
}
|
||||||
|
onPick={(loc) => {
|
||||||
|
if (mapPickerTarget === 'edit') {
|
||||||
|
editForm.setFieldsValue({
|
||||||
|
latitude: loc.latitude,
|
||||||
|
longitude: loc.longitude,
|
||||||
|
...(loc.address && !editForm.getFieldValue('address')
|
||||||
|
? { address: loc.address }
|
||||||
|
: {}),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
createForm.setFieldsValue({
|
||||||
|
latitude: loc.latitude,
|
||||||
|
longitude: loc.longitude,
|
||||||
|
...(loc.address && !createForm.getFieldValue('address')
|
||||||
|
? { address: loc.address }
|
||||||
|
: {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
message.success(
|
||||||
|
`已选点 ${loc.latitude.toFixed(6)}, ${loc.longitude.toFixed(6)}${loc.name ? `(${loc.name})` : ''}`,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,384 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import {
|
||||||
|
SUPPORT_TICKET_STATUS_LABELS,
|
||||||
|
SUPPORT_TICKET_TYPE_LABELS,
|
||||||
|
type SupportTicketDto,
|
||||||
|
type SupportTicketStatusDto,
|
||||||
|
type SupportTicketTypeDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request, type HqProfile } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
|
const STATUS_COLOR: Record<SupportTicketStatusDto, string> = {
|
||||||
|
PENDING_REVIEW: 'orange',
|
||||||
|
REJECTED: 'red',
|
||||||
|
DEVELOPING: 'blue',
|
||||||
|
TESTING: 'purple',
|
||||||
|
PASSED: 'green',
|
||||||
|
};
|
||||||
|
|
||||||
|
const TYPE_OPTIONS = (Object.keys(SUPPORT_TICKET_TYPE_LABELS) as SupportTicketTypeDto[]).map(
|
||||||
|
(value) => ({ value, label: SUPPORT_TICKET_TYPE_LABELS[value] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
const STATUS_OPTIONS = (Object.keys(SUPPORT_TICKET_STATUS_LABELS) as SupportTicketStatusDto[]).map(
|
||||||
|
(value) => ({ value, label: SUPPORT_TICKET_STATUS_LABELS[value] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
export default function SupportTicketsPage() {
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } =
|
||||||
|
useAdminList<SupportTicketDto>('/admin/support-tickets', () => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.ticketType) qs.set('ticketType', filters.ticketType);
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
return qs;
|
||||||
|
}, [filters]);
|
||||||
|
|
||||||
|
const [detail, setDetail] = useState<SupportTicketDto | null>(null);
|
||||||
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const [creating, setCreating] = useState(false);
|
||||||
|
const [acting, setActing] = useState(false);
|
||||||
|
const [rejectOpen, setRejectOpen] = useState(false);
|
||||||
|
const [createForm] = Form.useForm<{
|
||||||
|
ticketType: SupportTicketTypeDto;
|
||||||
|
title: string;
|
||||||
|
content?: string;
|
||||||
|
remark?: string;
|
||||||
|
}>();
|
||||||
|
const [rejectForm] = Form.useForm<{ rejectReason: string }>();
|
||||||
|
|
||||||
|
const isSuperAdmin = profile?.adminRole === 'SUPER_ADMIN';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function openDetail(id: string) {
|
||||||
|
setDetail(await request<SupportTicketDto>(`/admin/support-tickets/${id}`));
|
||||||
|
setDrawerOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitCreate() {
|
||||||
|
const values = await createForm.validateFields();
|
||||||
|
setCreating(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/support-tickets', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
ticketType: values.ticketType,
|
||||||
|
title: values.title.trim(),
|
||||||
|
content: values.content?.trim() || undefined,
|
||||||
|
remark: values.remark?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('技术支持工单已创建,等待最高管理员评审');
|
||||||
|
setCreateOpen(false);
|
||||||
|
createForm.resetFields();
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '创建失败');
|
||||||
|
} finally {
|
||||||
|
setCreating(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function approve() {
|
||||||
|
if (!detail) return;
|
||||||
|
setActing(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/support-tickets/${detail.id}/approve`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({}),
|
||||||
|
});
|
||||||
|
message.success('评审通过,已进入开发');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '操作失败');
|
||||||
|
} finally {
|
||||||
|
setActing(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitReject() {
|
||||||
|
if (!detail) return;
|
||||||
|
const values = await rejectForm.validateFields();
|
||||||
|
setActing(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/support-tickets/${detail.id}/reject`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ rejectReason: values.rejectReason.trim() }),
|
||||||
|
});
|
||||||
|
message.success('已驳回');
|
||||||
|
setRejectOpen(false);
|
||||||
|
rejectForm.resetFields();
|
||||||
|
setDrawerOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '操作失败');
|
||||||
|
} finally {
|
||||||
|
setActing(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startTesting() {
|
||||||
|
if (!detail) return;
|
||||||
|
setActing(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/support-tickets/${detail.id}/start-testing`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({}),
|
||||||
|
});
|
||||||
|
message.success('已转入测试');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '操作失败');
|
||||||
|
} finally {
|
||||||
|
setActing(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pass() {
|
||||||
|
if (!detail) return;
|
||||||
|
setActing(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/support-tickets/${detail.id}/pass`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({}),
|
||||||
|
});
|
||||||
|
message.success('测试通过');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '操作失败');
|
||||||
|
} finally {
|
||||||
|
setActing(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ColumnsType<SupportTicketDto> = [
|
||||||
|
{ title: '工单号', dataIndex: 'ticketNo', width: 180 },
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
dataIndex: 'ticketType',
|
||||||
|
width: 90,
|
||||||
|
render: (t: SupportTicketTypeDto) => SUPPORT_TICKET_TYPE_LABELS[t] ?? t,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
render: (s: SupportTicketStatusDto) => (
|
||||||
|
<Tag color={STATUS_COLOR[s]}>{SUPPORT_TICKET_STATUS_LABELS[s] ?? s}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ title: '标题', dataIndex: 'title', ellipsis: true },
|
||||||
|
{ title: '创建人', dataIndex: 'creatorName', width: 100 },
|
||||||
|
{ title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 80,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Button type="link" size="small" onClick={() => void openDetail(String(row.id))}>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const drawerExtra = (() => {
|
||||||
|
if (!detail) return null;
|
||||||
|
if (detail.status === 'PENDING_REVIEW' && isSuperAdmin) {
|
||||||
|
return (
|
||||||
|
<Space>
|
||||||
|
<Button type="primary" loading={acting} onClick={() => void approve()}>
|
||||||
|
评审通过
|
||||||
|
</Button>
|
||||||
|
<Button danger loading={acting} onClick={() => setRejectOpen(true)}>
|
||||||
|
驳回
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (detail.status === 'DEVELOPING') {
|
||||||
|
return (
|
||||||
|
<Button type="primary" loading={acting} onClick={() => void startTesting()}>
|
||||||
|
开发完成 · 转入测试
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (detail.status === 'TESTING') {
|
||||||
|
return (
|
||||||
|
<Button type="primary" loading={acting} onClick={() => void pass()}>
|
||||||
|
测试通过
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
marginBottom: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
技术支持
|
||||||
|
</Typography.Title>
|
||||||
|
<Button type="primary" onClick={() => setCreateOpen(true)}>
|
||||||
|
创建工单
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => {
|
||||||
|
setFilters(v);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="ticketType" label="类型">
|
||||||
|
<Select allowClear style={{ width: 120 }} options={TYPE_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="status" label="状态">
|
||||||
|
<Select allowClear style={{ width: 120 }} options={STATUS_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
筛选
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
scroll={{ x: 900 }}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title="技术支持详情"
|
||||||
|
width={520}
|
||||||
|
open={drawerOpen}
|
||||||
|
onClose={() => setDrawerOpen(false)}
|
||||||
|
extra={drawerExtra}
|
||||||
|
>
|
||||||
|
{detail && (
|
||||||
|
<Descriptions column={1} bordered size="small">
|
||||||
|
<Descriptions.Item label="工单号">{detail.ticketNo}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="类型">
|
||||||
|
{SUPPORT_TICKET_TYPE_LABELS[detail.ticketType] ?? detail.ticketType}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="状态">
|
||||||
|
<Tag color={STATUS_COLOR[detail.status]}>
|
||||||
|
{SUPPORT_TICKET_STATUS_LABELS[detail.status] ?? detail.status}
|
||||||
|
</Tag>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="标题">{detail.title}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="内容">
|
||||||
|
<div style={{ whiteSpace: 'pre-wrap' }}>{detail.content || '—'}</div>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="创建人">{detail.creatorName}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="创建时间">{fmtTime(detail.createdAt)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="评审人">{detail.reviewerName || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="评审时间">
|
||||||
|
{detail.reviewedAt ? fmtTime(detail.reviewedAt) : '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="驳回理由">{detail.rejectReason || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="备注">{detail.remark || '—'}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
)}
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="创建技术支持工单"
|
||||||
|
open={createOpen}
|
||||||
|
onCancel={() => setCreateOpen(false)}
|
||||||
|
onOk={() => void submitCreate()}
|
||||||
|
confirmLoading={creating}
|
||||||
|
destroyOnClose
|
||||||
|
okText="提交"
|
||||||
|
>
|
||||||
|
<Form form={createForm} layout="vertical" initialValues={{ ticketType: 'BUG' }}>
|
||||||
|
<Form.Item
|
||||||
|
name="ticketType"
|
||||||
|
label="类型"
|
||||||
|
rules={[{ required: true, message: '请选择类型' }]}
|
||||||
|
>
|
||||||
|
<Select options={TYPE_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="title"
|
||||||
|
label="标题"
|
||||||
|
rules={[{ required: true, message: '请填写标题' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="简要描述问题或建议" maxLength={128} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="content" label="详细说明">
|
||||||
|
<Input.TextArea rows={5} placeholder="复现步骤、期望结果等" maxLength={4000} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
|
<Input.TextArea rows={2} placeholder="可选" maxLength={512} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="驳回技术支持工单"
|
||||||
|
open={rejectOpen}
|
||||||
|
onCancel={() => setRejectOpen(false)}
|
||||||
|
onOk={() => void submitReject()}
|
||||||
|
confirmLoading={acting}
|
||||||
|
destroyOnClose
|
||||||
|
okText="确认驳回"
|
||||||
|
okButtonProps={{ danger: true }}
|
||||||
|
>
|
||||||
|
<Form form={rejectForm} layout="vertical">
|
||||||
|
<Form.Item
|
||||||
|
name="rejectReason"
|
||||||
|
label="驳回理由"
|
||||||
|
rules={[{ required: true, message: '请填写驳回理由' }]}
|
||||||
|
>
|
||||||
|
<Input.TextArea rows={4} placeholder="必填" maxLength={512} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,283 +1,182 @@
|
|||||||
import { useEffect, useMemo, useState, type ReactNode } from 'react';
|
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
|
|
||||||
Alert,
|
Alert,
|
||||||
|
|
||||||
Button,
|
Button,
|
||||||
|
|
||||||
Card,
|
Card,
|
||||||
|
|
||||||
Collapse,
|
Collapse,
|
||||||
|
|
||||||
Form,
|
Form,
|
||||||
|
|
||||||
Input,
|
Input,
|
||||||
|
|
||||||
InputNumber,
|
InputNumber,
|
||||||
|
Modal,
|
||||||
Space,
|
Space,
|
||||||
|
|
||||||
Switch,
|
Switch,
|
||||||
|
|
||||||
Table,
|
Table,
|
||||||
|
|
||||||
Tag,
|
Tag,
|
||||||
|
|
||||||
Typography,
|
Typography,
|
||||||
|
|
||||||
message,
|
message,
|
||||||
|
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
|
|
||||||
import type { MockSmsCodeItem, SystemConfigFieldMeta, SystemConfigFormResponse } from '@dukang/shared-types';
|
import type { MockSmsCodeItem, SystemConfigFieldMeta, SystemConfigFormResponse } from '@dukang/shared-types';
|
||||||
|
import { request, type HqProfile } from '../lib/api';
|
||||||
import { request } from '../lib/api';
|
import { ConfigImageField, ConfigImageListField } from '../components/ConfigMediaFields';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const { TextArea } = Input;
|
const { TextArea } = Input;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function MockSmsCodePanel({ codes, loading }: { codes: MockSmsCodeItem[]; loading?: boolean }) {
|
function MockSmsCodePanel({ codes, loading }: { codes: MockSmsCodeItem[]; loading?: boolean }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<div style={{ marginTop: -8, marginBottom: 16, marginLeft: 0 }}>
|
<div style={{ marginTop: -8, marginBottom: 16, marginLeft: 0 }}>
|
||||||
|
|
||||||
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
|
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
|
||||||
最近 Mock 验证码(写入数据库,最新 50 条)
|
最近 Mock 验证码(写入数据库,最新 50 条)
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
<Table<MockSmsCodeItem>
|
<Table<MockSmsCodeItem>
|
||||||
|
|
||||||
size="small"
|
size="small"
|
||||||
|
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
|
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
|
||||||
pagination={false}
|
pagination={false}
|
||||||
|
|
||||||
scroll={{ y: 240 }}
|
scroll={{ y: 240 }}
|
||||||
|
|
||||||
locale={{ emptyText: '暂无记录,触发短信发送后将显示在此' }}
|
locale={{ emptyText: '暂无记录,触发短信发送后将显示在此' }}
|
||||||
|
|
||||||
columns={[
|
columns={[
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
title: '时间',
|
title: '时间',
|
||||||
|
|
||||||
dataIndex: 'createdAt',
|
dataIndex: 'createdAt',
|
||||||
|
|
||||||
width: 168,
|
width: 168,
|
||||||
|
|
||||||
render: (v: string) => new Date(v).toLocaleString(),
|
render: (v: string) => new Date(v).toLocaleString(),
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{ title: '手机号', dataIndex: 'phone', width: 120 },
|
{ title: '手机号', dataIndex: 'phone', width: 120 },
|
||||||
|
|
||||||
{ title: '场景', dataIndex: 'scene', width: 160 },
|
{ title: '场景', dataIndex: 'scene', width: 160 },
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
title: '验证码',
|
title: '验证码',
|
||||||
|
|
||||||
dataIndex: 'code',
|
dataIndex: 'code',
|
||||||
|
|
||||||
width: 88,
|
width: 88,
|
||||||
|
|
||||||
render: (code: string) => (
|
render: (code: string) => (
|
||||||
|
|
||||||
<Typography.Text copyable strong>
|
<Typography.Text copyable strong>
|
||||||
|
|
||||||
{code}
|
{code}
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
]}
|
]}
|
||||||
|
|
||||||
dataSource={codes}
|
dataSource={codes}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function renderField(
|
function renderField(
|
||||||
|
|
||||||
field: SystemConfigFieldMeta,
|
field: SystemConfigFieldMeta,
|
||||||
|
|
||||||
configuredSecrets: string[],
|
configuredSecrets: string[],
|
||||||
|
|
||||||
extra?: ReactNode,
|
extra?: ReactNode,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const isConfiguredSecret = field.secret && configuredSecrets.includes(field.key);
|
const isConfiguredSecret = field.secret && configuredSecrets.includes(field.key);
|
||||||
|
|
||||||
if (field.type === 'boolean') {
|
if (field.type === 'boolean') {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<div key={field.key}>
|
<div key={field.key}>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|
||||||
name={field.key}
|
name={field.key}
|
||||||
|
|
||||||
label={
|
label={
|
||||||
|
|
||||||
<Space size={4}>
|
<Space size={4}>
|
||||||
|
|
||||||
<span>{field.label}</span>
|
<span>{field.label}</span>
|
||||||
|
|
||||||
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
||||||
|
|
||||||
{field.key}
|
{field.key}
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
||||||
|
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tooltip={field.description}
|
tooltip={field.description}
|
||||||
|
|
||||||
valuePropName="checked"
|
valuePropName="checked"
|
||||||
|
|
||||||
getValueFromEvent={(checked: boolean) => (checked ? 'true' : 'false')}
|
getValueFromEvent={(checked: boolean) => (checked ? 'true' : 'false')}
|
||||||
|
|
||||||
getValueProps={(v: string) => ({ checked: v === 'true' || v === '1' })}
|
getValueProps={(v: string) => ({ checked: v === 'true' || v === '1' })}
|
||||||
|
|
||||||
>
|
>
|
||||||
|
|
||||||
<Switch />
|
<Switch />
|
||||||
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
{extra}
|
{extra}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (field.type === 'image' || field.type === 'imageList') {
|
||||||
|
return (
|
||||||
|
<Form.Item
|
||||||
|
key={field.key}
|
||||||
|
name={field.key}
|
||||||
|
label={
|
||||||
|
<Space size={4} wrap>
|
||||||
|
<span>{field.label}</span>
|
||||||
|
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
||||||
|
{field.key}
|
||||||
|
</Typography.Text>
|
||||||
|
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
tooltip={field.description}
|
||||||
|
trigger="onChange"
|
||||||
|
getValueFromEvent={(v: unknown) => (typeof v === 'string' ? v : '')}
|
||||||
|
normalize={(v) => (typeof v === 'string' ? v : '')}
|
||||||
|
>
|
||||||
|
{field.type === 'image' ? (
|
||||||
|
<ConfigImageField bizType="footer" />
|
||||||
|
) : (
|
||||||
|
<ConfigImageListField bizType="swiper" />
|
||||||
|
)}
|
||||||
|
</Form.Item>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const input =
|
const input =
|
||||||
|
|
||||||
field.type === 'textarea' ? (
|
field.type === 'textarea' ? (
|
||||||
|
|
||||||
<TextArea rows={3} placeholder={field.placeholder} />
|
<TextArea rows={3} placeholder={field.placeholder} />
|
||||||
|
|
||||||
) : field.type === 'number' ? (
|
) : field.type === 'number' ? (
|
||||||
|
|
||||||
<InputNumber style={{ width: '100%' }} placeholder={field.placeholder} />
|
<InputNumber style={{ width: '100%' }} placeholder={field.placeholder} />
|
||||||
|
|
||||||
) : field.secret ? (
|
) : field.secret ? (
|
||||||
|
|
||||||
<Input.Password
|
<Input.Password
|
||||||
|
|
||||||
placeholder={isConfiguredSecret ? '已配置,留空则不修改' : field.placeholder}
|
placeholder={isConfiguredSecret ? '已配置,留空则不修改' : field.placeholder}
|
||||||
|
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
) : (
|
) : (
|
||||||
|
|
||||||
<Input placeholder={field.placeholder} />
|
<Input placeholder={field.placeholder} />
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|
||||||
key={field.key}
|
key={field.key}
|
||||||
|
|
||||||
name={field.key}
|
name={field.key}
|
||||||
|
|
||||||
label={
|
label={
|
||||||
|
|
||||||
<Space size={4} wrap>
|
<Space size={4} wrap>
|
||||||
|
|
||||||
<span>{field.label}</span>
|
<span>{field.label}</span>
|
||||||
|
|
||||||
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
||||||
|
|
||||||
{field.key}
|
{field.key}
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
||||||
|
|
||||||
{isConfiguredSecret ? <Tag>已配置</Tag> : null}
|
{isConfiguredSecret ? <Tag>已配置</Tag> : null}
|
||||||
|
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tooltip={field.description}
|
tooltip={field.description}
|
||||||
|
|
||||||
>
|
>
|
||||||
|
|
||||||
{input}
|
{input}
|
||||||
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function SystemSettingsPage() {
|
export default function SystemSettingsPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
const [form] = Form.useForm<Record<string, string>>();
|
const [form] = Form.useForm<Record<string, string>>();
|
||||||
|
|
||||||
const [meta, setMeta] = useState<SystemConfigFormResponse | null>(null);
|
const [meta, setMeta] = useState<SystemConfigFormResponse | null>(null);
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
const [syncing, setSyncing] = useState(false);
|
const [syncing, setSyncing] = useState(false);
|
||||||
|
const [dirty, setDirty] = useState(false);
|
||||||
|
const dirtyRef = useRef(false);
|
||||||
|
const bypassLeaveRef = useRef(false);
|
||||||
const mockSmsEnabled = Form.useWatch('MOCK_SMS', form) === 'true';
|
const mockSmsEnabled = Form.useWatch('MOCK_SMS', form) === 'true';
|
||||||
|
|
||||||
|
dirtyRef.current = dirty;
|
||||||
|
|
||||||
async function load(silent = false) {
|
async function load(silent = false) {
|
||||||
|
|
||||||
if (!silent) setLoading(true);
|
if (!silent) setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const data = await request<SystemConfigFormResponse>('/admin/system-config');
|
const data = await request<SystemConfigFormResponse>('/admin/system-config');
|
||||||
|
|
||||||
if (silent) {
|
if (silent) {
|
||||||
// 仅刷新 Mock 验证码列表,避免轮询用服务端值覆盖未保存的表单(含 MOCK_SMS 开关)
|
|
||||||
setMeta((prev) =>
|
setMeta((prev) =>
|
||||||
prev
|
prev
|
||||||
? { ...prev, mockSmsCodes: data.mockSmsCodes, updatedAt: data.updatedAt }
|
? { ...prev, mockSmsCodes: data.mockSmsCodes, updatedAt: data.updatedAt }
|
||||||
@@ -285,300 +184,226 @@ export default function SystemSettingsPage() {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setMeta(data);
|
setMeta(data);
|
||||||
|
|
||||||
form.setFieldsValue(data.values);
|
form.setFieldsValue(data.values);
|
||||||
|
setDirty(false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
if (!silent) message.error(e instanceof Error ? e.message : '加载失败');
|
if (!silent) message.error(e instanceof Error ? e.message : '加载失败');
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
if (!silent) setLoading(false);
|
if (!silent) setLoading(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
// 以表单开关为准展示验证码;轮询只刷列表,不回写表单
|
|
||||||
if (!mockSmsEnabled) return;
|
if (!mockSmsEnabled) return;
|
||||||
|
|
||||||
const timer = window.setInterval(() => void load(true), 5000);
|
const timer = window.setInterval(() => void load(true), 5000);
|
||||||
|
|
||||||
return () => window.clearInterval(timer);
|
return () => window.clearInterval(timer);
|
||||||
|
|
||||||
}, [mockSmsEnabled]);
|
}, [mockSmsEnabled]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onBeforeUnload = (e: BeforeUnloadEvent) => {
|
||||||
|
if (!dirtyRef.current) return;
|
||||||
|
e.preventDefault();
|
||||||
|
e.returnValue = '';
|
||||||
|
};
|
||||||
|
window.addEventListener('beforeunload', onBeforeUnload);
|
||||||
|
return () => window.removeEventListener('beforeunload', onBeforeUnload);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onDocClick = (e: MouseEvent) => {
|
||||||
|
if (!dirtyRef.current || bypassLeaveRef.current) return;
|
||||||
|
const target = e.target as HTMLElement | null;
|
||||||
|
const anchor = target?.closest?.('a');
|
||||||
|
if (!anchor || !(anchor instanceof HTMLAnchorElement)) return;
|
||||||
|
if (anchor.target === '_blank' || anchor.hasAttribute('download')) return;
|
||||||
|
const url = new URL(anchor.href, window.location.href);
|
||||||
|
if (url.origin !== window.location.origin) return;
|
||||||
|
if (url.pathname === window.location.pathname && url.search === window.location.search) return;
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
Modal.confirm({
|
||||||
|
title: '有未保存的更改',
|
||||||
|
content: '离开前请先保存,否则更改将丢失。',
|
||||||
|
okText: '仍要离开',
|
||||||
|
cancelText: '留下',
|
||||||
|
onOk: () => {
|
||||||
|
bypassLeaveRef.current = true;
|
||||||
|
setDirty(false);
|
||||||
|
navigate(`${url.pathname}${url.search}${url.hash}`);
|
||||||
|
window.setTimeout(() => {
|
||||||
|
bypassLeaveRef.current = false;
|
||||||
|
}, 0);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
document.addEventListener('click', onDocClick, true);
|
||||||
|
return () => document.removeEventListener('click', onDocClick, true);
|
||||||
|
}, [navigate]);
|
||||||
|
|
||||||
const collapseItems = useMemo(() => {
|
const collapseItems = useMemo(() => {
|
||||||
|
|
||||||
if (!meta) return [];
|
if (!meta) return [];
|
||||||
|
|
||||||
return meta.groups.map((group) => ({
|
return meta.groups.map((group) => ({
|
||||||
|
|
||||||
key: group.key,
|
key: group.key,
|
||||||
|
|
||||||
label: group.label,
|
label: group.label,
|
||||||
|
forceRender: true,
|
||||||
children: (
|
children: (
|
||||||
|
|
||||||
<div style={{ maxWidth: 720 }}>
|
<div style={{ maxWidth: 720 }}>
|
||||||
|
|
||||||
{meta.fields
|
{meta.fields
|
||||||
|
|
||||||
.filter((f) => f.group === group.key)
|
.filter((f) => f.group === group.key)
|
||||||
|
|
||||||
.map((f) =>
|
.map((f) =>
|
||||||
|
|
||||||
renderField(
|
renderField(
|
||||||
|
|
||||||
f,
|
f,
|
||||||
|
|
||||||
meta.configuredSecrets,
|
meta.configuredSecrets,
|
||||||
|
|
||||||
f.key === 'MOCK_SMS' && mockSmsEnabled ? (
|
f.key === 'MOCK_SMS' && mockSmsEnabled ? (
|
||||||
|
|
||||||
<MockSmsCodePanel codes={meta.mockSmsCodes ?? []} loading={loading} />
|
<MockSmsCodePanel codes={meta.mockSmsCodes ?? []} loading={loading} />
|
||||||
|
|
||||||
) : undefined,
|
) : undefined,
|
||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
}, [meta, mockSmsEnabled, loading]);
|
}, [meta, mockSmsEnabled, loading]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function onSave() {
|
async function onSave() {
|
||||||
|
await form.validateFields();
|
||||||
const values = await form.validateFields();
|
const values = form.getFieldsValue(true);
|
||||||
|
|
||||||
const payload: Record<string, string> = {};
|
const payload: Record<string, string> = {};
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(values)) {
|
for (const [k, v] of Object.entries(values)) {
|
||||||
|
|
||||||
payload[k] = v === undefined || v === null ? '' : String(v);
|
payload[k] = v === undefined || v === null ? '' : String(v);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const res = await request<{ updatedKeys: string[]; requiresRestartKeys: string[] }>(
|
const res = await request<{ updatedKeys: string[]; requiresRestartKeys: string[] }>(
|
||||||
|
|
||||||
'/admin/system-config',
|
'/admin/system-config',
|
||||||
|
|
||||||
{ method: 'PUT', body: JSON.stringify({ values: payload }) },
|
{ method: 'PUT', body: JSON.stringify({ values: payload }) },
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
message.success(`已保存 ${res.updatedKeys.length} 项`);
|
message.success(`已保存 ${res.updatedKeys.length} 项`);
|
||||||
|
|
||||||
if (res.requiresRestartKeys.length) {
|
if (res.requiresRestartKeys.length) {
|
||||||
|
|
||||||
message.warning(`以下配置需重启 API 后生效:${res.requiresRestartKeys.join(', ')}`);
|
message.warning(`以下配置需重启 API 后生效:${res.requiresRestartKeys.join(', ')}`);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
setDirty(false);
|
||||||
await load();
|
await load();
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
message.error(e instanceof Error ? e.message : '保存失败');
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function onSyncEnv() {
|
async function onSyncEnv() {
|
||||||
|
|
||||||
setSyncing(true);
|
setSyncing(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const res = await request<{ message: string; envFilePath: string }>(
|
const res = await request<{ message: string; envFilePath: string }>(
|
||||||
|
|
||||||
'/admin/system-config/sync-env',
|
'/admin/system-config/sync-env',
|
||||||
|
|
||||||
{ method: 'POST' },
|
{ method: 'POST' },
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
message.success(res.message || '已同步到 env 文件');
|
message.success(res.message || '已同步到 env 文件');
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
message.error(e instanceof Error ? e.message : '同步失败');
|
message.error(e instanceof Error ? e.message : '同步失败');
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
setSyncing(false);
|
setSyncing(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function onImportEnv() {
|
async function onImportEnv() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const res = await request<{ imported: number }>('/admin/system-config/import-env', {
|
const res = await request<{ imported: number }>('/admin/system-config/import-env', {
|
||||||
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
message.success(`已从当前进程环境导入 ${res.imported} 项`);
|
message.success(`已从当前进程环境导入 ${res.imported} 项`);
|
||||||
|
|
||||||
await load();
|
await load();
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
message.error(e instanceof Error ? e.message : '导入失败');
|
message.error(e instanceof Error ? e.message : '导入失败');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div style={{ paddingBottom: 88 }}>
|
||||||
<div>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 16 }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 16 }}>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
<Typography.Title level={4} style={{ margin: 0 }}>
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
|
||||||
系统设置
|
系统设置
|
||||||
|
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
|
|
||||||
<Typography.Paragraph type="secondary" style={{ marginBottom: 0, marginTop: 8 }}>
|
<Typography.Paragraph type="secondary" style={{ marginBottom: 0, marginTop: 8 }}>
|
||||||
|
|
||||||
配置存于 <code>system_config</code> 表;保存后写入进程环境。可同步到{' '}
|
配置存于 <code>system_config</code> 表;保存后写入进程环境。可同步到{' '}
|
||||||
|
|
||||||
<code>{meta?.envFilePath ?? '.env'}</code> 以便部署持久化。
|
<code>{meta?.envFilePath ?? '.env'}</code> 以便部署持久化。
|
||||||
|
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Space>
|
<Space>
|
||||||
|
{profile?.adminRole === 'SUPER_ADMIN' ? (
|
||||||
<Button onClick={() => void onImportEnv()}>从环境导入</Button>
|
<>
|
||||||
|
<Button onClick={() => void onImportEnv()}>从环境导入</Button>
|
||||||
<Button loading={syncing} onClick={() => void onSyncEnv()}>
|
<Button loading={syncing} onClick={() => void onSyncEnv()}>
|
||||||
|
同步到 env 文件
|
||||||
同步到 env 文件
|
</Button>
|
||||||
|
</>
|
||||||
</Button>
|
) : null}
|
||||||
|
|
||||||
<Button type="primary" loading={saving} onClick={() => void onSave()}>
|
|
||||||
|
|
||||||
保存
|
|
||||||
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<Alert
|
<Alert
|
||||||
|
|
||||||
type="info"
|
type="info"
|
||||||
|
|
||||||
showIcon
|
showIcon
|
||||||
|
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
|
|
||||||
message="生效说明"
|
message="生效说明"
|
||||||
|
|
||||||
description={
|
description={
|
||||||
|
|
||||||
<ul style={{ margin: '8px 0 0', paddingLeft: 20 }}>
|
<ul style={{ margin: '8px 0 0', paddingLeft: 20 }}>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
|
||||||
<Tag color="green">即时</Tag>:保存后写入 <code>process.env</code>,Mock 开关、短信模板等可立即生效。
|
<Tag color="green">即时</Tag>:保存后写入 <code>process.env</code>,Mock 开关、短信模板等可立即生效。
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
|
||||||
<Tag color="orange">需重启</Tag>:微信/OSS 密钥等集成凭证变更后,<strong>建议重启 API 进程</strong>。
|
<Tag color="orange">需重启</Tag>:微信/OSS 密钥等集成凭证变更后,<strong>建议重启 API 进程</strong>。
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>OSS 始终走阿里云配置;凭证缺失时上传接口将直接报错。</li>
|
<li>OSS 始终走阿里云配置;凭证缺失时上传接口将直接报错。</li>
|
||||||
|
<li>修改后请点击右下角「保存」;未保存离开页面将提示确认。</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
|
<Form form={form} layout="vertical" onValuesChange={() => setDirty(true)}>
|
||||||
<Form form={form} layout="vertical">
|
<Collapse defaultActiveKey={[]} items={collapseItems} />
|
||||||
|
|
||||||
<Collapse defaultActiveKey={meta?.groups.map((g) => g.key)} items={collapseItems} />
|
|
||||||
|
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
{meta?.updatedAt ? (
|
{meta?.updatedAt ? (
|
||||||
|
|
||||||
<Typography.Text type="secondary" style={{ display: 'block', marginTop: 16 }}>
|
<Typography.Text type="secondary" style={{ display: 'block', marginTop: 16 }}>
|
||||||
|
|
||||||
最近更新:{new Date(meta.updatedAt).toLocaleString()}
|
最近更新:{new Date(meta.updatedAt).toLocaleString()}
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
right: 32,
|
||||||
|
bottom: 32,
|
||||||
|
zIndex: 1000,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'flex-end',
|
||||||
|
gap: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{dirty ? <Tag color="orange">有未保存更改</Tag> : null}
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
size="large"
|
||||||
|
loading={saving}
|
||||||
|
onClick={() => void onSave()}
|
||||||
|
style={{
|
||||||
|
minWidth: 120,
|
||||||
|
boxShadow: '0 6px 16px rgba(0,0,0,0.18)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
保存
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Button, Descriptions, Drawer, Form, Image, Input, Select, Table, Typography, message } from 'antd';
|
import {
|
||||||
|
Button,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Image,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { TICKET_TYPE_LABELS, type TicketTypeDto } from '@dukang/shared-types';
|
import { TICKET_TYPE_LABELS, type TicketTypeDto } from '@dukang/shared-types';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
@@ -32,6 +45,13 @@ export default function TicketsPage() {
|
|||||||
);
|
);
|
||||||
const [detail, setDetail] = useState<Row | null>(null);
|
const [detail, setDetail] = useState<Row | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const [creating, setCreating] = useState(false);
|
||||||
|
const [createForm] = Form.useForm<{
|
||||||
|
ticketType: TicketTypeDto;
|
||||||
|
orderNo: string;
|
||||||
|
remark?: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
async function approve(id: string) {
|
async function approve(id: string) {
|
||||||
await request(`/admin/tickets/${id}/approve`, { method: 'POST', body: JSON.stringify({}) });
|
await request(`/admin/tickets/${id}/approve`, { method: 'POST', body: JSON.stringify({}) });
|
||||||
@@ -50,6 +70,29 @@ export default function TicketsPage() {
|
|||||||
setDrawerOpen(false);
|
setDrawerOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function submitCreate() {
|
||||||
|
const values = await createForm.validateFields();
|
||||||
|
setCreating(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/tickets', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
ticketType: values.ticketType,
|
||||||
|
orderNo: values.orderNo.trim(),
|
||||||
|
remark: values.remark?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('工单已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
|
createForm.resetFields();
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '创建失败');
|
||||||
|
} finally {
|
||||||
|
setCreating(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '工单号', dataIndex: 'ticketNo', width: 180 },
|
{ title: '工单号', dataIndex: 'ticketNo', width: 180 },
|
||||||
{
|
{
|
||||||
@@ -84,7 +127,21 @@ export default function TicketsPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Typography.Title level={4}>工单中心</Typography.Title>
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
marginBottom: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
工单中心
|
||||||
|
</Typography.Title>
|
||||||
|
<Button type="primary" onClick={() => setCreateOpen(true)}>
|
||||||
|
创建工单
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<Form
|
<Form
|
||||||
layout="inline"
|
layout="inline"
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
@@ -137,14 +194,14 @@ export default function TicketsPage() {
|
|||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={
|
extra={
|
||||||
detail && (detail.status === 'PENDING' || detail.status === 'OPEN') ? (
|
detail && (detail.status === 'PENDING' || detail.status === 'OPEN') ? (
|
||||||
<>
|
<Space>
|
||||||
<Button type="primary" onClick={() => approve(String(detail.id))} style={{ marginRight: 8 }}>
|
<Button type="primary" onClick={() => approve(String(detail.id))}>
|
||||||
通过
|
通过
|
||||||
</Button>
|
</Button>
|
||||||
<Button danger onClick={() => reject(String(detail.id))}>
|
<Button danger onClick={() => reject(String(detail.id))}>
|
||||||
驳回
|
驳回
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</Space>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -173,6 +230,44 @@ export default function TicketsPage() {
|
|||||||
</Descriptions>
|
</Descriptions>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="创建工单"
|
||||||
|
open={createOpen}
|
||||||
|
onCancel={() => setCreateOpen(false)}
|
||||||
|
onOk={() => void submitCreate()}
|
||||||
|
confirmLoading={creating}
|
||||||
|
destroyOnClose
|
||||||
|
okText="提交"
|
||||||
|
>
|
||||||
|
<Form form={createForm} layout="vertical" initialValues={{ ticketType: 'REFUND' }}>
|
||||||
|
<Form.Item
|
||||||
|
name="ticketType"
|
||||||
|
label="工单类型"
|
||||||
|
rules={[{ required: true, message: '请选择类型' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
options={[
|
||||||
|
{ value: 'REFUND', label: '仅退款' },
|
||||||
|
{ value: 'RESHIPMENT', label: '破损补发' },
|
||||||
|
{ value: 'DAMAGE_RETURN', label: '破损退货' },
|
||||||
|
{ value: 'RETURN_REFUND', label: '退货退款' },
|
||||||
|
{ value: 'ALERT', label: '异常' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="orderNo"
|
||||||
|
label="订单号"
|
||||||
|
rules={[{ required: true, message: '请填写订单号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="关联订单号" allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
|
<Input.TextArea rows={3} placeholder="可选" maxLength={512} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { USER_SOURCE_TYPE_LABELS, type UserSourceType } from '@dukang/shared-types';
|
import { USER_SOURCE_TYPE_LABELS, type UserSourceType } from '@dukang/shared-types';
|
||||||
import { request, type AdminUserRow, type Paginated } from '../lib/api';
|
import { request, type AdminUserRow, type HqProfile, type Paginated } from '../lib/api';
|
||||||
import { ORDER_STATUS_LABELS, fmtTime } from '../lib/constants';
|
import { ORDER_STATUS_LABELS, fmtTime, maskPhone } from '../lib/constants';
|
||||||
|
|
||||||
type UserOrderRow = {
|
type UserOrderRow = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -66,6 +66,7 @@ export default function UsersPage() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
const [data, setData] = useState<Paginated<AdminUserRow> | null>(null);
|
const [data, setData] = useState<Paginated<AdminUserRow> | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
@@ -82,6 +83,11 @@ export default function UsersPage() {
|
|||||||
const [batchPreviewLoading, setBatchPreviewLoading] = useState(false);
|
const [batchPreviewLoading, setBatchPreviewLoading] = useState(false);
|
||||||
const [batchDeleting, setBatchDeleting] = useState(false);
|
const [batchDeleting, setBatchDeleting] = useState(false);
|
||||||
const [batchRiskAck, setBatchRiskAck] = useState(false);
|
const [batchRiskAck, setBatchRiskAck] = useState(false);
|
||||||
|
const canDeleteUsers = (profile?.permissionKeys ?? []).includes('users_delete');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -222,7 +228,7 @@ export default function UsersPage() {
|
|||||||
title: '手机',
|
title: '手机',
|
||||||
dataIndex: 'phone',
|
dataIndex: 'phone',
|
||||||
width: 120,
|
width: 120,
|
||||||
render: (v) => v || '—',
|
render: (v) => maskPhone(v),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '验手机',
|
title: '验手机',
|
||||||
@@ -309,13 +315,15 @@ export default function UsersPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
||||||
<Typography.Title level={4} style={{ margin: 0 }}>用户监控</Typography.Title>
|
<Typography.Title level={4} style={{ margin: 0 }}>用户监控</Typography.Title>
|
||||||
<Button
|
{canDeleteUsers ? (
|
||||||
danger
|
<Button
|
||||||
disabled={!selectedRowKeys.length}
|
danger
|
||||||
onClick={() => void openBatchDeleteModal()}
|
disabled={!selectedRowKeys.length}
|
||||||
>
|
onClick={() => void openBatchDeleteModal()}
|
||||||
批量删除{selectedRowKeys.length ? ` (${selectedRowKeys.length})` : ''}
|
>
|
||||||
</Button>
|
批量删除{selectedRowKeys.length ? ` (${selectedRowKeys.length})` : ''}
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
</Space>
|
</Space>
|
||||||
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={() => { setPage(1); void load(); }}>
|
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={() => { setPage(1); void load(); }}>
|
||||||
<Form.Item name="phone" label="手机号">
|
<Form.Item name="phone" label="手机号">
|
||||||
@@ -353,11 +361,11 @@ export default function UsersPage() {
|
|||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={data?.items ?? []}
|
dataSource={data?.items ?? []}
|
||||||
scroll={{ x: 1500 }}
|
scroll={{ x: 1500 }}
|
||||||
rowSelection={{
|
rowSelection={canDeleteUsers ? {
|
||||||
selectedRowKeys,
|
selectedRowKeys,
|
||||||
preserveSelectedRowKeys: true,
|
preserveSelectedRowKeys: true,
|
||||||
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
||||||
}}
|
} : undefined}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: page,
|
current: page,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -375,9 +383,9 @@ export default function UsersPage() {
|
|||||||
width={640}
|
width={640}
|
||||||
open={drawerOpen}
|
open={drawerOpen}
|
||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={detail && (
|
extra={detail && canDeleteUsers ? (
|
||||||
<Button danger onClick={openDeleteModal}>删除用户</Button>
|
<Button danger onClick={openDeleteModal}>删除用户</Button>
|
||||||
)}
|
) : undefined}
|
||||||
>
|
>
|
||||||
{detail && (
|
{detail && (
|
||||||
<>
|
<>
|
||||||
@@ -385,7 +393,7 @@ export default function UsersPage() {
|
|||||||
<Descriptions.Item label="ID">{detail.id}</Descriptions.Item>
|
<Descriptions.Item label="ID">{detail.id}</Descriptions.Item>
|
||||||
<Descriptions.Item label="用户编号">{detail.userNo}</Descriptions.Item>
|
<Descriptions.Item label="用户编号">{detail.userNo}</Descriptions.Item>
|
||||||
<Descriptions.Item label="昵称">{detail.nickname || '—'}</Descriptions.Item>
|
<Descriptions.Item label="昵称">{detail.nickname || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="手机号">{detail.phone || '—'}</Descriptions.Item>
|
<Descriptions.Item label="手机号">{maskPhone(detail.phone)}</Descriptions.Item>
|
||||||
<Descriptions.Item label="验手机时间">
|
<Descriptions.Item label="验手机时间">
|
||||||
{detail.phoneVerifiedAt ? new Date(detail.phoneVerifiedAt).toLocaleString('zh-CN') : '未验证'}
|
{detail.phoneVerifiedAt ? new Date(detail.phoneVerifiedAt).toLocaleString('zh-CN') : '未验证'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
@@ -419,7 +427,7 @@ export default function UsersPage() {
|
|||||||
<Descriptions.Item label="deviceKey">{detail.deviceKey || '—'}</Descriptions.Item>
|
<Descriptions.Item label="deviceKey">{detail.deviceKey || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="合并至">
|
<Descriptions.Item label="合并至">
|
||||||
{detail.mergedInto
|
{detail.mergedInto
|
||||||
? `${detail.mergedInto.userNo} (${detail.mergedInto.phone || '无手机'})`
|
? `${detail.mergedInto.userNo} (${detail.mergedInto.phone ? maskPhone(detail.mergedInto.phone) : '无手机'})`
|
||||||
: '—'}
|
: '—'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="被合并访客数">{detail.mergedFromCount ?? 0}</Descriptions.Item>
|
<Descriptions.Item label="被合并访客数">{detail.mergedFromCount ?? 0}</Descriptions.Item>
|
||||||
@@ -593,7 +601,7 @@ export default function UsersPage() {
|
|||||||
columns={[
|
columns={[
|
||||||
{ title: '用户编号', dataIndex: 'userNo', width: 120 },
|
{ title: '用户编号', dataIndex: 'userNo', width: 120 },
|
||||||
{ title: '昵称', dataIndex: 'nickname', width: 100, render: (v) => v || '—' },
|
{ title: '昵称', dataIndex: 'nickname', width: 100, render: (v) => v || '—' },
|
||||||
{ title: '手机', dataIndex: 'phone', width: 120, render: (v) => v || '—' },
|
{ title: '手机', dataIndex: 'phone', width: 120, render: (v) => maskPhone(v) },
|
||||||
{
|
{
|
||||||
title: '风险',
|
title: '风险',
|
||||||
width: 200,
|
width: 200,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { AdminCellLine } from '../components/AdminCellLine';
|
import { AdminCellLine } from '../components/AdminCellLine';
|
||||||
import { fmtTime } from '../lib/constants';
|
import { fmtTime, maskPhone } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
type ActorType = 'USER' | 'STORE' | 'PARTNER' | 'HQ';
|
type ActorType = 'USER' | 'STORE' | 'PARTNER' | 'HQ';
|
||||||
@@ -119,7 +119,7 @@ export default function WechatBindingsPage() {
|
|||||||
title: '手机号',
|
title: '手机号',
|
||||||
dataIndex: 'primaryPhone',
|
dataIndex: 'primaryPhone',
|
||||||
width: 140,
|
width: 140,
|
||||||
render: (v) => v || '—',
|
render: (v) => maskPhone(v),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '身份摘要',
|
title: '身份摘要',
|
||||||
@@ -128,7 +128,7 @@ export default function WechatBindingsPage() {
|
|||||||
<AdminCellLine
|
<AdminCellLine
|
||||||
primary={r.identities.map((i) => ACTOR_TYPE_LABELS[i.actorType]).join(' / ')}
|
primary={r.identities.map((i) => ACTOR_TYPE_LABELS[i.actorType]).join(' / ')}
|
||||||
secondary={r.identities
|
secondary={r.identities
|
||||||
.map((i) => i.refLabel || i.name || i.phone)
|
.map((i) => i.refLabel || i.name || (i.phone ? maskPhone(i.phone) : ''))
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(' · ')}
|
.join(' · ')}
|
||||||
/>
|
/>
|
||||||
@@ -164,7 +164,7 @@ export default function WechatBindingsPage() {
|
|||||||
render: (_, r) => (
|
render: (_, r) => (
|
||||||
<AdminCellLine
|
<AdminCellLine
|
||||||
primary={r.name || '—'}
|
primary={r.name || '—'}
|
||||||
secondary={[r.phone, `#${r.actorId}`].filter(Boolean).join(' ')}
|
secondary={[r.phone ? maskPhone(r.phone) : null, `#${r.actorId}`].filter(Boolean).join(' ')}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,512 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Avatar,
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Switch,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import {
|
||||||
|
WECOM_BOT_PERMISSIONS,
|
||||||
|
WECOM_BOT_PERMISSION_LABELS,
|
||||||
|
WECOM_BOT_ROLE_DEFAULT_PERMISSIONS,
|
||||||
|
WECOM_BOT_ROLE_LABELS,
|
||||||
|
WECOM_BOT_ROLES,
|
||||||
|
type LlmApiConfigOptionDto,
|
||||||
|
type KnowledgeBaseOptionDto,
|
||||||
|
type WecomBotDto,
|
||||||
|
type WecomBotPermission,
|
||||||
|
type WecomBotRole,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import OssUpload from '../components/OssUpload';
|
||||||
|
|
||||||
|
type ListRes = {
|
||||||
|
items: WecomBotDto[];
|
||||||
|
total: number;
|
||||||
|
page: number;
|
||||||
|
pageSize: number;
|
||||||
|
runtime?: {
|
||||||
|
masterEnabled: boolean;
|
||||||
|
bots: Array<{ id: string; connected: boolean; lastError: string | null }>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
type FormValues = {
|
||||||
|
name: string;
|
||||||
|
role: WecomBotRole;
|
||||||
|
botId: string;
|
||||||
|
secret?: string;
|
||||||
|
avatarUrl?: string;
|
||||||
|
welcome?: string;
|
||||||
|
permissions: WecomBotPermission[];
|
||||||
|
aiEnabled: boolean;
|
||||||
|
llmConfigId?: string | null;
|
||||||
|
knowledgeBaseId?: string | null;
|
||||||
|
enabled: boolean;
|
||||||
|
sortOrder: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function WecomBotsPage() {
|
||||||
|
const [filterForm] = Form.useForm();
|
||||||
|
const [form] = Form.useForm<FormValues>();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [editing, setEditing] = useState<WecomBotDto | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [detail, setDetail] = useState<WecomBotDto | null>(null);
|
||||||
|
const [runtime, setRuntime] = useState<ListRes['runtime']>();
|
||||||
|
const [llmOptions, setLlmOptions] = useState<LlmApiConfigOptionDto[]>([]);
|
||||||
|
const [kbOptions, setKbOptions] = useState<KnowledgeBaseOptionDto[]>([]);
|
||||||
|
const roleWatch = Form.useWatch('role', form);
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<WecomBotDto>(
|
||||||
|
'/admin/wecom-bots',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.name) qs.set('name', filters.name);
|
||||||
|
if (filters.role) qs.set('role', filters.role);
|
||||||
|
if (filters.enabled) qs.set('enabled', filters.enabled);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// useAdminList returns items; runtime comes from same API — fetch once for banner
|
||||||
|
void request<ListRes>('/admin/wecom-bots?page=1&pageSize=1')
|
||||||
|
.then((res) => setRuntime(res.runtime))
|
||||||
|
.catch(() => {});
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void request<{
|
||||||
|
llmConfigs: LlmApiConfigOptionDto[];
|
||||||
|
knowledgeBases: KnowledgeBaseOptionDto[];
|
||||||
|
}>('/admin/wecom-bots/ai-options')
|
||||||
|
.then((res) => {
|
||||||
|
setLlmOptions(res.llmConfigs);
|
||||||
|
setKbOptions(res.knowledgeBases);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setLlmOptions([]);
|
||||||
|
setKbOptions([]);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
setEditing(null);
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: '',
|
||||||
|
role: 'CUSTOMER_SERVICE',
|
||||||
|
botId: '',
|
||||||
|
secret: '',
|
||||||
|
avatarUrl: '',
|
||||||
|
welcome: '',
|
||||||
|
permissions: [...WECOM_BOT_ROLE_DEFAULT_PERMISSIONS.CUSTOMER_SERVICE],
|
||||||
|
aiEnabled: false,
|
||||||
|
llmConfigId: null,
|
||||||
|
knowledgeBaseId: null,
|
||||||
|
enabled: true,
|
||||||
|
sortOrder: 0,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEdit(row: WecomBotDto) {
|
||||||
|
setEditing(row);
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: row.name,
|
||||||
|
role: row.role,
|
||||||
|
botId: row.botId,
|
||||||
|
secret: '',
|
||||||
|
avatarUrl: row.avatarUrl || '',
|
||||||
|
welcome: row.welcome || '',
|
||||||
|
permissions: row.permissions,
|
||||||
|
aiEnabled: row.aiEnabled,
|
||||||
|
llmConfigId: row.llmConfigId,
|
||||||
|
knowledgeBaseId: row.knowledgeBaseId,
|
||||||
|
enabled: row.enabled,
|
||||||
|
sortOrder: row.sortOrder,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
name: values.name.trim(),
|
||||||
|
role: values.role,
|
||||||
|
botId: values.botId.trim(),
|
||||||
|
avatarUrl: values.avatarUrl?.trim() || null,
|
||||||
|
welcome: values.welcome?.trim() || null,
|
||||||
|
permissions: values.permissions,
|
||||||
|
aiEnabled: values.aiEnabled,
|
||||||
|
llmConfigId: values.llmConfigId || null,
|
||||||
|
knowledgeBaseId: values.knowledgeBaseId || null,
|
||||||
|
enabled: values.enabled,
|
||||||
|
sortOrder: values.sortOrder,
|
||||||
|
};
|
||||||
|
if (editing) {
|
||||||
|
await request(`/admin/wecom-bots/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...payload,
|
||||||
|
secret: values.secret?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已更新');
|
||||||
|
} else {
|
||||||
|
if (!values.secret?.trim()) {
|
||||||
|
message.error('请填写 Secret');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request('/admin/wecom-bots', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...payload,
|
||||||
|
secret: values.secret.trim(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
setModalOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(id: string) {
|
||||||
|
try {
|
||||||
|
await request(`/admin/wecom-bots/${id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reloadConnections() {
|
||||||
|
try {
|
||||||
|
const st = await request<{
|
||||||
|
masterEnabled: boolean;
|
||||||
|
bots: Array<{ id: string; connected: boolean; lastError: string | null }>;
|
||||||
|
}>('/admin/wecom-bots/reload', { method: 'POST', body: '{}' });
|
||||||
|
message.success('已重载长连接');
|
||||||
|
setRuntime(st);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '重载失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const runtimeMap = new Map((runtime?.bots ?? []).map((b) => [b.id, b]));
|
||||||
|
|
||||||
|
const columns: ColumnsType<WecomBotDto> = [
|
||||||
|
{
|
||||||
|
title: '头像',
|
||||||
|
dataIndex: 'avatarUrl',
|
||||||
|
width: 64,
|
||||||
|
render: (url: string | null, row) => (
|
||||||
|
<Avatar src={url || undefined} shape="square" size={40}>
|
||||||
|
{row.name.slice(0, 1)}
|
||||||
|
</Avatar>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ title: '名称', dataIndex: 'name', width: 140, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '角色',
|
||||||
|
dataIndex: 'role',
|
||||||
|
width: 120,
|
||||||
|
render: (r: WecomBotRole) => WECOM_BOT_ROLE_LABELS[r] || r,
|
||||||
|
},
|
||||||
|
{ title: 'BotID', dataIndex: 'botId', width: 160, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '权限',
|
||||||
|
dataIndex: 'permissions',
|
||||||
|
ellipsis: true,
|
||||||
|
render: (perms: WecomBotPermission[]) =>
|
||||||
|
perms.map((p) => (
|
||||||
|
<Tag key={p} style={{ marginBottom: 2 }}>
|
||||||
|
{WECOM_BOT_PERMISSION_LABELS[p] || p}
|
||||||
|
</Tag>
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'AI',
|
||||||
|
width: 100,
|
||||||
|
render: (_, row) =>
|
||||||
|
row.aiEnabled ? (
|
||||||
|
<Tag color="blue">{row.llmConfigName || '已开'}</Tag>
|
||||||
|
) : (
|
||||||
|
<Tag>关</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '启用',
|
||||||
|
dataIndex: 'enabled',
|
||||||
|
width: 70,
|
||||||
|
render: (v: boolean) => <Tag color={v ? 'green' : 'default'}>{v ? '是' : '否'}</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '连接',
|
||||||
|
width: 80,
|
||||||
|
render: (_, row) => {
|
||||||
|
const rt = runtimeMap.get(row.id);
|
||||||
|
if (!runtime?.masterEnabled) return <Tag>总开关关</Tag>;
|
||||||
|
if (!row.enabled) return <Tag>未启用</Tag>;
|
||||||
|
return (
|
||||||
|
<Tag color={rt?.connected ? 'green' : 'orange'}>{rt?.connected ? '已连接' : '未连接'}</Tag>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ title: '更新', dataIndex: 'updatedAt', width: 160, render: fmtTime },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 180,
|
||||||
|
fixed: 'right',
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button type="link" size="small" onClick={() => openEdit(row)}>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={async () => {
|
||||||
|
setDetail(await request<WecomBotDto>(`/admin/wecom-bots/${row.id}`));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
<Popconfirm title="确认删除该机器人?" onConfirm={() => remove(row.id)}>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space style={{ width: '100%', justifyContent: 'space-between', marginBottom: 16 }} wrap>
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
企微机器人
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
并列创建多个智能机器人,配置 BotID / Secret / 权限 / 角色 / 头像。总开关在「系统设置 → 功能开关」。
|
||||||
|
{runtime ? ` 当前总开关:${runtime.masterEnabled ? '开' : '关'}` : ''}
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<Space>
|
||||||
|
<Button onClick={() => void reloadConnections()}>重载连接</Button>
|
||||||
|
<Button type="primary" onClick={openCreate}>
|
||||||
|
创建机器人
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => {
|
||||||
|
setFilters(v);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="name" label="名称">
|
||||||
|
<Input allowClear placeholder="名称" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="role" label="角色">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 160 }}
|
||||||
|
options={WECOM_BOT_ROLES.map((r) => ({ value: r, label: WECOM_BOT_ROLE_LABELS[r] }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="启用">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 100 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'true', label: '是' },
|
||||||
|
{ value: 'false', label: '否' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
scroll={{ x: 1200 }}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? '编辑企微机器人' : '创建企微机器人'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={() => setModalOpen(false)}
|
||||||
|
onOk={() => void submit()}
|
||||||
|
confirmLoading={saving}
|
||||||
|
width={640}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="name" label="名称" rules={[{ required: true, message: '请填写名称' }]}>
|
||||||
|
<Input placeholder="如:客服机器人" maxLength={64} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="role" label="角色" rules={[{ required: true }]}>
|
||||||
|
<Select
|
||||||
|
options={WECOM_BOT_ROLES.map((r) => ({ value: r, label: WECOM_BOT_ROLE_LABELS[r] }))}
|
||||||
|
onChange={(role: WecomBotRole) => {
|
||||||
|
form.setFieldValue('permissions', [...WECOM_BOT_ROLE_DEFAULT_PERMISSIONS[role]]);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="avatarUrl" label="头像">
|
||||||
|
<OssUpload bizType="WECOM_BOT_AVATAR" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="botId" label="BotID" rules={[{ required: true, message: '请填写 BotID' }]}>
|
||||||
|
<Input placeholder="企业微信后台长连接 BotID" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="secret"
|
||||||
|
label="Secret"
|
||||||
|
rules={editing ? [] : [{ required: true, message: '请填写 Secret' }]}
|
||||||
|
extra={editing ? '留空表示不修改' : undefined}
|
||||||
|
>
|
||||||
|
<Input.Password placeholder={editing ? '留空不修改' : '长连接专用 Secret'} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="permissions"
|
||||||
|
label="权限"
|
||||||
|
rules={[{ required: true, message: '请至少选择一项权限' }]}
|
||||||
|
extra={
|
||||||
|
roleWatch
|
||||||
|
? `角色默认:${WECOM_BOT_ROLE_DEFAULT_PERMISSIONS[roleWatch as WecomBotRole]?.map((p) => WECOM_BOT_PERMISSION_LABELS[p]).join('、') || '无'}`
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Checkbox.Group
|
||||||
|
options={WECOM_BOT_PERMISSIONS.map((p) => ({
|
||||||
|
value: p,
|
||||||
|
label: WECOM_BOT_PERMISSION_LABELS[p],
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="welcome" label="欢迎语">
|
||||||
|
<Input.TextArea rows={3} placeholder="进入会话时的欢迎语,可空" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="aiEnabled"
|
||||||
|
label="启用 AI 问答"
|
||||||
|
valuePropName="checked"
|
||||||
|
extra="开启后,未匹配指令的自然语言将调用绑定的语言模型(可挂知识库)"
|
||||||
|
>
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="llmConfigId" label="语言模型">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="选择已生效的配置"
|
||||||
|
options={llmOptions.map((o) => ({
|
||||||
|
value: o.id,
|
||||||
|
label: `${o.name}(${o.modelName})`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="knowledgeBaseId" label="知识库">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="可选,供 AI 检索"
|
||||||
|
options={kbOptions.map((o) => ({
|
||||||
|
value: o.id,
|
||||||
|
label: `${o.name}(${o.documentCount} 篇)`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Space size="large">
|
||||||
|
<Form.Item name="enabled" label="启用" valuePropName="checked">
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="sortOrder" label="排序">
|
||||||
|
<InputNumber style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Drawer title="机器人详情" width={480} open={!!detail} onClose={() => setDetail(null)}>
|
||||||
|
{detail && (
|
||||||
|
<Descriptions column={1} size="small" bordered>
|
||||||
|
<Descriptions.Item label="头像">
|
||||||
|
<Avatar src={detail.avatarUrl || undefined} size={64} shape="square">
|
||||||
|
{detail.name.slice(0, 1)}
|
||||||
|
</Avatar>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="名称">{detail.name}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="角色">
|
||||||
|
{WECOM_BOT_ROLE_LABELS[detail.role] || detail.role}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="BotID">{detail.botId}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="Secret">
|
||||||
|
{detail.secretConfigured ? '已配置' : '未配置'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权限">
|
||||||
|
{detail.permissions.map((p) => WECOM_BOT_PERMISSION_LABELS[p] || p).join('、')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="欢迎语">{detail.welcome || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="AI 问答">{detail.aiEnabled ? '开' : '关'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="语言模型">{detail.llmConfigName || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="知识库">{detail.knowledgeBaseName || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="启用">{detail.enabled ? '是' : '否'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="排序">{detail.sortOrder}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="创建">{fmtTime(detail.createdAt)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="更新">{fmtTime(detail.updatedAt)}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
)}
|
||||||
|
</Drawer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
Descriptions,
|
Descriptions,
|
||||||
Drawer,
|
Drawer,
|
||||||
Form,
|
Form,
|
||||||
|
Input,
|
||||||
Modal,
|
Modal,
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
@@ -17,10 +18,13 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import type { Dayjs } from 'dayjs';
|
import type { Dayjs } from 'dayjs';
|
||||||
import { WINERY_SETTLEMENT_RATE } from '@dukang/shared-types';
|
import {
|
||||||
|
WINERY_SETTLEMENT_RATE,
|
||||||
|
type SystemConfigFormResponse,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
import { fmtTime } from '../lib/constants';
|
import { fmtTime } from '../lib/constants';
|
||||||
import { downloadExcelCsv } from '../lib/exportExcel';
|
import { downloadExcelCsv } from '../lib/exportExcel';
|
||||||
import { request } from '../lib/api';
|
import { request, type HqProfile } from '../lib/api';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
type Row = {
|
type Row = {
|
||||||
@@ -59,8 +63,16 @@ const DELIVERY_LABELS: Record<string, string> = {
|
|||||||
CROSS_CITY: '跨城',
|
CROSS_CITY: '跨城',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const WINERY_BANK_KEYS = [
|
||||||
|
'WINERY_BANK_ACCOUNT_NAME',
|
||||||
|
'WINERY_BANK_NAME',
|
||||||
|
'WINERY_BANK_BRANCH',
|
||||||
|
'WINERY_BANK_ACCOUNT_NO',
|
||||||
|
] as const;
|
||||||
|
|
||||||
export default function WineryBillsPage() {
|
export default function WineryBillsPage() {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
const [bankForm] = Form.useForm<Record<string, string>>();
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
'/admin/winery-bills',
|
'/admin/winery-bills',
|
||||||
@@ -79,6 +91,18 @@ export default function WineryBillsPage() {
|
|||||||
const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
|
const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
|
||||||
const [detail, setDetail] = useState<(Row & { items?: BillItem[] }) | null>(null);
|
const [detail, setDetail] = useState<(Row & { items?: BillItem[] }) | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
|
const [bankOpen, setBankOpen] = useState(false);
|
||||||
|
const [bankLoading, setBankLoading] = useState(false);
|
||||||
|
const [bankSaving, setBankSaving] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const canEditWineryBank =
|
||||||
|
profile?.adminRole === 'SUPER_ADMIN' ||
|
||||||
|
(profile?.permissionKeys ?? []).includes('system_settings_winery_bank');
|
||||||
|
|
||||||
function confirmPay(ids: string[], amountHint?: number) {
|
function confirmPay(ids: string[], amountHint?: number) {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
@@ -126,6 +150,41 @@ export default function WineryBillsPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function openBankModal() {
|
||||||
|
setBankOpen(true);
|
||||||
|
setBankLoading(true);
|
||||||
|
try {
|
||||||
|
const cfg = await request<SystemConfigFormResponse>('/admin/system-config');
|
||||||
|
const values: Record<string, string> = {};
|
||||||
|
for (const key of WINERY_BANK_KEYS) {
|
||||||
|
values[key] = cfg.values[key] ?? '';
|
||||||
|
}
|
||||||
|
bankForm.setFieldsValue(values);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载失败');
|
||||||
|
setBankOpen(false);
|
||||||
|
} finally {
|
||||||
|
setBankLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveBank() {
|
||||||
|
const values = await bankForm.validateFields();
|
||||||
|
setBankSaving(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/system-config', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ values }),
|
||||||
|
});
|
||||||
|
message.success('酒厂银行账户已保存');
|
||||||
|
setBankOpen(false);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setBankSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const summary = data?.summary;
|
const summary = data?.summary;
|
||||||
const ratePct = Math.round(WINERY_SETTLEMENT_RATE * 100);
|
const ratePct = Math.round(WINERY_SETTLEMENT_RATE * 100);
|
||||||
const selectedRows = (data?.items ?? []).filter((r) => selectedKeys.includes(r.id));
|
const selectedRows = (data?.items ?? []).filter((r) => selectedKeys.includes(r.id));
|
||||||
@@ -185,14 +244,29 @@ export default function WineryBillsPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Space direction="vertical" size={0} style={{ marginBottom: 16 }}>
|
<div
|
||||||
<Typography.Title level={4} style={{ margin: 0 }}>
|
style={{
|
||||||
酒厂对账单
|
display: 'flex',
|
||||||
</Typography.Title>
|
justifyContent: 'space-between',
|
||||||
<Typography.Text type="secondary">
|
alignItems: 'flex-start',
|
||||||
每日 8:00 汇总昨日已付订单(实付 × {ratePct}%);未打款红色、已打款绿色,可展开订单明细
|
marginBottom: 16,
|
||||||
</Typography.Text>
|
gap: 16,
|
||||||
</Space>
|
}}
|
||||||
|
>
|
||||||
|
<Space direction="vertical" size={0}>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
酒厂对账单
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
每日 8:00 汇总昨日已付订单(实付 × {ratePct}%);未打款红色、已打款绿色,可展开订单明细
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
{canEditWineryBank ? (
|
||||||
|
<Button type="default" onClick={() => void openBankModal()}>
|
||||||
|
酒厂银行账户信息配置
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
{summary && (
|
{summary && (
|
||||||
<Card size="small" style={{ marginBottom: 16 }}>
|
<Card size="small" style={{ marginBottom: 16 }}>
|
||||||
@@ -337,6 +411,43 @@ export default function WineryBillsPage() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="酒厂银行账户信息配置"
|
||||||
|
open={bankOpen}
|
||||||
|
onCancel={() => setBankOpen(false)}
|
||||||
|
onOk={() => void saveBank()}
|
||||||
|
confirmLoading={bankSaving}
|
||||||
|
destroyOnClose
|
||||||
|
okText="保存"
|
||||||
|
>
|
||||||
|
<Form form={bankForm} layout="vertical" disabled={bankLoading}>
|
||||||
|
<Form.Item
|
||||||
|
name="WINERY_BANK_ACCOUNT_NAME"
|
||||||
|
label="户名"
|
||||||
|
rules={[{ required: true, message: '请填写户名' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="收款账户户名" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="WINERY_BANK_NAME"
|
||||||
|
label="开户银行"
|
||||||
|
rules={[{ required: true, message: '请填写开户银行' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="如:中国工商银行" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="WINERY_BANK_BRANCH" label="开户支行">
|
||||||
|
<Input placeholder="可选" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="WINERY_BANK_ACCOUNT_NO"
|
||||||
|
label="银行账号"
|
||||||
|
rules={[{ required: true, message: '请填写银行账号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="银行卡号" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useState, type CSSProperties } from 'react';
|
||||||
import { useOutletContext } from 'react-router-dom';
|
import { useOutletContext } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -25,6 +25,15 @@ import { request } from '../../lib/api';
|
|||||||
import { fmtTime } from '../../lib/constants';
|
import { fmtTime } from '../../lib/constants';
|
||||||
import type { PromoCodeDetailContext } from './PromoCodeDetailLayout';
|
import type { PromoCodeDetailContext } from './PromoCodeDetailLayout';
|
||||||
|
|
||||||
|
const descLabelStyle: CSSProperties = {
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
width: 108,
|
||||||
|
};
|
||||||
|
|
||||||
|
const descContentStyle: CSSProperties = {
|
||||||
|
wordBreak: 'break-all',
|
||||||
|
};
|
||||||
|
|
||||||
async function downloadQrcode(url: string, filename: string) {
|
async function downloadQrcode(url: string, filename: string) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(url);
|
const res = await fetch(url);
|
||||||
@@ -72,46 +81,25 @@ export default function PromoCodeDetailPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]} align="top">
|
||||||
<Col xs={24} lg={8}>
|
<Col flex="1 1 480px" style={{ minWidth: 0 }}>
|
||||||
<Card title="推广二维码" size="small">
|
|
||||||
{detail.qrcodeUrl ? (
|
|
||||||
<div style={{ textAlign: 'center' }}>
|
|
||||||
<img
|
|
||||||
src={detail.qrcodeUrl}
|
|
||||||
alt="推广二维码"
|
|
||||||
style={{ width: 200, height: 200, marginBottom: 12 }}
|
|
||||||
/>
|
|
||||||
<Space direction="vertical" style={{ width: '100%' }}>
|
|
||||||
<Button
|
|
||||||
block
|
|
||||||
onClick={() => void downloadQrcode(detail.qrcodeUrl!, `${detail.code}-qrcode.png`)}
|
|
||||||
>
|
|
||||||
下载二维码
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Typography.Text type="secondary">暂无二维码</Typography.Text>
|
|
||||||
)}
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<Col xs={24} lg={16}>
|
|
||||||
<Card
|
<Card
|
||||||
title="基础信息"
|
title="基础信息"
|
||||||
size="small"
|
size="small"
|
||||||
|
styles={{ body: { paddingTop: 12 } }}
|
||||||
extra={(
|
extra={(
|
||||||
<Space>
|
<Space>
|
||||||
<Button size="small" onClick={() => {
|
<Button
|
||||||
editForm.setFieldsValue({
|
size="small"
|
||||||
name: detail.name,
|
onClick={() => {
|
||||||
scene: detail.scene,
|
editForm.setFieldsValue({
|
||||||
remark: detail.remark,
|
name: detail.name,
|
||||||
ownerUserId: detail.ownerUser?.id,
|
scene: detail.scene,
|
||||||
});
|
remark: detail.remark,
|
||||||
setEditOpen(true);
|
ownerUserId: detail.ownerUser?.id,
|
||||||
}}
|
});
|
||||||
|
setEditOpen(true);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
编辑
|
编辑
|
||||||
</Button>
|
</Button>
|
||||||
@@ -135,7 +123,18 @@ export default function PromoCodeDetailPage() {
|
|||||||
</Space>
|
</Space>
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Descriptions column={{ xs: 1, sm: 2 }} bordered size="small">
|
<Descriptions
|
||||||
|
column={2}
|
||||||
|
bordered
|
||||||
|
size="small"
|
||||||
|
layout="horizontal"
|
||||||
|
labelStyle={descLabelStyle}
|
||||||
|
contentStyle={descContentStyle}
|
||||||
|
styles={{
|
||||||
|
label: descLabelStyle,
|
||||||
|
content: descContentStyle,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Descriptions.Item label="名称">{detail.name}</Descriptions.Item>
|
<Descriptions.Item label="名称">{detail.name}</Descriptions.Item>
|
||||||
<Descriptions.Item label="码值">{detail.code}</Descriptions.Item>
|
<Descriptions.Item label="码值">{detail.code}</Descriptions.Item>
|
||||||
<Descriptions.Item label="场景">
|
<Descriptions.Item label="场景">
|
||||||
@@ -144,34 +143,81 @@ export default function PromoCodeDetailPage() {
|
|||||||
<Descriptions.Item label="状态">
|
<Descriptions.Item label="状态">
|
||||||
{PROMO_CODE_STATUS_LABELS[detail.status] || detail.status}
|
{PROMO_CODE_STATUS_LABELS[detail.status] || detail.status}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="二维码 ID" span={2}>
|
<Descriptions.Item label="活动 ID">
|
||||||
<Typography.Text copyable={{ text: detail.qrcodeId }}>{detail.qrcodeId}</Typography.Text>
|
<Typography.Text copyable={{ text: String(detail.id) }} style={{ whiteSpace: 'nowrap' }}>
|
||||||
|
{detail.id}
|
||||||
|
</Typography.Text>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="落地链接" span={2}>
|
<Descriptions.Item label="二维码 ID">
|
||||||
<Typography.Text copyable={{ text: detail.landingUrl }}>{detail.landingUrl}</Typography.Text>
|
<Typography.Text copyable={{ text: detail.qrcodeId }} style={{ whiteSpace: 'nowrap' }}>
|
||||||
|
{detail.qrcodeId}
|
||||||
|
</Typography.Text>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="OSS 地址" span={2}>
|
<Descriptions.Item label="小程序码 OSS" span={2}>
|
||||||
{detail.qrcodeUrl ? (
|
{detail.qrcodeUrl ? (
|
||||||
<Typography.Text copyable={{ text: detail.qrcodeUrl }} ellipsis>
|
<Typography.Text copyable={{ text: detail.qrcodeUrl }} ellipsis style={{ maxWidth: '100%' }}>
|
||||||
{detail.qrcodeUrl}
|
{detail.qrcodeUrl}
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
) : '—'}
|
) : '—'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="渠道负责人">
|
<Descriptions.Item label="渠道负责人">
|
||||||
{detail.ownerUser?.userNo || detail.ownerUser?.phone || '—'}
|
<span style={{ whiteSpace: 'nowrap' }}>
|
||||||
|
{detail.ownerUser?.userNo || detail.ownerUser?.phone || '—'}
|
||||||
|
</span>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="备注">{detail.remark || '—'}</Descriptions.Item>
|
<Descriptions.Item label="备注">{detail.remark || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="创建时间">{fmtTime(detail.createdAt)}</Descriptions.Item>
|
<Descriptions.Item label="创建时间">
|
||||||
<Descriptions.Item label="更新时间">{fmtTime(detail.updatedAt)}</Descriptions.Item>
|
<span style={{ whiteSpace: 'nowrap' }}>{fmtTime(detail.createdAt)}</span>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="更新时间">
|
||||||
|
<span style={{ whiteSpace: 'nowrap' }}>{fmtTime(detail.updatedAt)}</span>
|
||||||
|
</Descriptions.Item>
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
|
<Col flex="0 0 220px">
|
||||||
|
<Card title="小程序码" size="small" styles={{ body: { textAlign: 'center', padding: 12 } }}>
|
||||||
|
{detail.qrcodeUrl ? (
|
||||||
|
<>
|
||||||
|
<img
|
||||||
|
src={detail.qrcodeUrl}
|
||||||
|
alt="推广小程序码"
|
||||||
|
style={{ width: 168, height: 168, display: 'block', margin: '0 auto 8px' }}
|
||||||
|
/>
|
||||||
|
<Typography.Paragraph
|
||||||
|
type="secondary"
|
||||||
|
style={{ marginBottom: 8, fontSize: 12, whiteSpace: 'nowrap' }}
|
||||||
|
>
|
||||||
|
scene={detail.id}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
<Button
|
||||||
|
block
|
||||||
|
size="small"
|
||||||
|
onClick={() => void downloadQrcode(detail.qrcodeUrl!, `${detail.code}-wxacode.png`)}
|
||||||
|
>
|
||||||
|
下载小程序码
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">暂无小程序码</Typography.Text>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Row gutter={16} style={{ marginTop: 16 }}>
|
<Row gutter={16} style={{ marginTop: 16 }}>
|
||||||
<Col xs={12} sm={6}>
|
<Col xs={12} sm={6}>
|
||||||
<Card size="small">
|
<Card size="small">
|
||||||
<Statistic title="扫码次数" value={stats?.scanCount ?? detail.scanCount} />
|
<Statistic title="扫码进入次数" value={stats?.scanCount ?? detail.scanCount} />
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
<Col xs={12} sm={6}>
|
||||||
|
<Card size="small">
|
||||||
|
<Statistic
|
||||||
|
title="扫码注册用户数"
|
||||||
|
value={stats?.registerCount ?? stats?.sourceMarkedCount ?? 0}
|
||||||
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xs={12} sm={6}>
|
<Col xs={12} sm={6}>
|
||||||
@@ -187,11 +233,6 @@ export default function PromoCodeDetailPage() {
|
|||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xs={12} sm={6}>
|
|
||||||
<Card size="small">
|
|
||||||
<Statistic title="来源标记用户" value={stats?.sourceMarkedCount ?? '—'} />
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import BillsPage from './pages/BillsPage';
|
|||||||
import SettlementPage from './pages/SettlementPage';
|
import SettlementPage from './pages/SettlementPage';
|
||||||
import WeeklyReportPage from './pages/WeeklyReportPage';
|
import WeeklyReportPage from './pages/WeeklyReportPage';
|
||||||
import ProxyOrderPage from './pages/ProxyOrderPage';
|
import ProxyOrderPage from './pages/ProxyOrderPage';
|
||||||
|
import ProxyOrderProductsPage from './pages/ProxyOrderProductsPage';
|
||||||
import StaffListPage from './pages/StaffListPage';
|
import StaffListPage from './pages/StaffListPage';
|
||||||
import StaffCreatePage from './pages/StaffCreatePage';
|
import StaffCreatePage from './pages/StaffCreatePage';
|
||||||
import LeaderboardPage from './pages/LeaderboardPage';
|
import LeaderboardPage from './pages/LeaderboardPage';
|
||||||
@@ -33,6 +34,7 @@ function PrimaryRoutes() {
|
|||||||
<Route path="/center/staff" element={<StaffListPage />} />
|
<Route path="/center/staff" element={<StaffListPage />} />
|
||||||
<Route path="/center/staff/new" element={<StaffCreatePage />} />
|
<Route path="/center/staff/new" element={<StaffCreatePage />} />
|
||||||
<Route path="/proxy-order" element={<ProxyOrderPage />} />
|
<Route path="/proxy-order" element={<ProxyOrderPage />} />
|
||||||
|
<Route path="/proxy-order/products" element={<ProxyOrderProductsPage />} />
|
||||||
<Route path="/reports/weekly" element={<WeeklyReportPage />} />
|
<Route path="/reports/weekly" element={<WeeklyReportPage />} />
|
||||||
<Route path="/leaderboard" element={<LeaderboardPage />} />
|
<Route path="/leaderboard" element={<LeaderboardPage />} />
|
||||||
<Route path="/stores/:id" element={<StoreDetailPage />} />
|
<Route path="/stores/:id" element={<StoreDetailPage />} />
|
||||||
|
|||||||
@@ -0,0 +1,264 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import {
|
||||||
|
placeToPicked,
|
||||||
|
type LbsPlaceItem,
|
||||||
|
type TencentPickedLocation,
|
||||||
|
} from '../lib/tencentLocPicker';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onPick: (loc: TencentPickedLocation) => void;
|
||||||
|
latitude?: number | null;
|
||||||
|
longitude?: number | null;
|
||||||
|
region?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function TencentLocPickerOverlay({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
onPick,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
region,
|
||||||
|
}: Props) {
|
||||||
|
const [keyword, setKeyword] = useState('');
|
||||||
|
const [items, setItems] = useState<LbsPlaceItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [pending, setPending] = useState<TencentPickedLocation | null>(null);
|
||||||
|
const [hint, setHint] = useState('输入地点名称搜索');
|
||||||
|
const seqRef = useRef(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) {
|
||||||
|
setKeyword('');
|
||||||
|
setItems([]);
|
||||||
|
setPending(null);
|
||||||
|
setHint('输入地点名称搜索');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const lat = latitude != null ? Number(latitude) : NaN;
|
||||||
|
const lng = longitude != null ? Number(longitude) : NaN;
|
||||||
|
if (Number.isFinite(lat) && Number.isFinite(lng) && !(lat === 0 && lng === 0)) {
|
||||||
|
void loadNearby(lat, lng);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
async function loadNearby(lat: number, lng: number) {
|
||||||
|
const seq = ++seqRef.current;
|
||||||
|
setLoading(true);
|
||||||
|
setHint('正在加载附近地点…');
|
||||||
|
try {
|
||||||
|
const res = await request<{ items: LbsPlaceItem[] }>(
|
||||||
|
'PARTNER_H5',
|
||||||
|
`/common/lbs/nearby?lat=${encodeURIComponent(String(lat))}&lng=${encodeURIComponent(String(lng))}`,
|
||||||
|
{ silent: true },
|
||||||
|
);
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
setItems(res.items ?? []);
|
||||||
|
setHint(res.items?.length ? `附近 ${res.items.length} 个地点` : '附近暂无地点,请搜索');
|
||||||
|
} catch (e) {
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
setItems([]);
|
||||||
|
setHint(e instanceof Error ? e.message : '加载附近地点失败');
|
||||||
|
} finally {
|
||||||
|
if (seq === seqRef.current) setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runSearch() {
|
||||||
|
const trimmed = keyword.trim();
|
||||||
|
if (!trimmed) {
|
||||||
|
setHint('请输入搜索关键词');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const seq = ++seqRef.current;
|
||||||
|
setLoading(true);
|
||||||
|
setHint('搜索中…');
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams({ keyword: trimmed });
|
||||||
|
if (region?.trim()) params.set('region', region.trim());
|
||||||
|
const lat = latitude != null ? Number(latitude) : NaN;
|
||||||
|
const lng = longitude != null ? Number(longitude) : NaN;
|
||||||
|
if (Number.isFinite(lat) && Number.isFinite(lng)) {
|
||||||
|
params.set('lat', String(lat));
|
||||||
|
params.set('lng', String(lng));
|
||||||
|
}
|
||||||
|
const res = await request<{ items: LbsPlaceItem[] }>(
|
||||||
|
'PARTNER_H5',
|
||||||
|
`/common/lbs/suggest?${params.toString()}`,
|
||||||
|
{ silent: true },
|
||||||
|
);
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
setItems(res.items ?? []);
|
||||||
|
setHint(res.items?.length ? `找到 ${res.items.length} 个结果` : '无匹配结果');
|
||||||
|
} catch (e) {
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
setItems([]);
|
||||||
|
setHint(e instanceof Error ? e.message : '搜索失败');
|
||||||
|
} finally {
|
||||||
|
if (seq === seqRef.current) setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function useBrowserLocation() {
|
||||||
|
if (!navigator.geolocation) {
|
||||||
|
setHint('当前浏览器不支持定位');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLoading(true);
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
(pos) => {
|
||||||
|
const lat = pos.coords.latitude;
|
||||||
|
const lng = pos.coords.longitude;
|
||||||
|
setPending({ latitude: lat, longitude: lng, name: '当前位置' });
|
||||||
|
void loadNearby(lat, lng);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
setLoading(false);
|
||||||
|
setHint('定位失败,请检查定位权限');
|
||||||
|
},
|
||||||
|
{ enableHighAccuracy: true, timeout: 12000 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!open) return null;
|
||||||
|
|
||||||
|
function confirmPick() {
|
||||||
|
if (!pending) return;
|
||||||
|
onPick(pending);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
inset: 0,
|
||||||
|
zIndex: 1000,
|
||||||
|
background: '#fff',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
padding: '12px 16px',
|
||||||
|
borderBottom: '1px solid rgba(0,0,0,0.06)',
|
||||||
|
flexShrink: 0,
|
||||||
|
gap: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<button type="button" className="partner-btn-outline" style={{ padding: '6px 12px' }} onClick={onClose}>
|
||||||
|
关闭
|
||||||
|
</button>
|
||||||
|
<span style={{ fontWeight: 600 }}>地图选点</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-primary"
|
||||||
|
style={{ padding: '6px 12px', opacity: pending ? 1 : 0.45, width: 'auto' }}
|
||||||
|
disabled={!pending}
|
||||||
|
onClick={confirmPick}
|
||||||
|
>
|
||||||
|
确认
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ padding: '12px 16px', borderBottom: '1px solid rgba(0,0,0,0.04)', flexShrink: 0 }}>
|
||||||
|
<div style={{ display: 'flex', gap: 8 }}>
|
||||||
|
<input
|
||||||
|
value={keyword}
|
||||||
|
onChange={(e) => setKeyword(e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') void runSearch();
|
||||||
|
}}
|
||||||
|
placeholder="输入小区 / 写字楼 / 门店名称"
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
padding: '10px 12px',
|
||||||
|
border: '1px solid rgba(0,0,0,0.12)',
|
||||||
|
borderRadius: 8,
|
||||||
|
fontSize: 14,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-primary"
|
||||||
|
style={{ width: 'auto', padding: '8px 14px' }}
|
||||||
|
disabled={loading}
|
||||||
|
onClick={() => void runSearch()}
|
||||||
|
>
|
||||||
|
搜索
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', gap: 8, marginTop: 8, alignItems: 'center' }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
style={{ padding: '6px 12px' }}
|
||||||
|
disabled={loading}
|
||||||
|
onClick={useBrowserLocation}
|
||||||
|
>
|
||||||
|
定位当前位置
|
||||||
|
</button>
|
||||||
|
<span className="label-md text-muted">{hint}</span>
|
||||||
|
</div>
|
||||||
|
{pending ? (
|
||||||
|
<p className="label-md text-muted" style={{ margin: '8px 0 0' }}>
|
||||||
|
已选 {pending.latitude.toFixed(6)}, {pending.longitude.toFixed(6)}
|
||||||
|
{pending.name ? ` · ${pending.name}` : ''}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ flex: 1, minHeight: 0, overflow: 'auto', WebkitOverflowScrolling: 'touch' }}>
|
||||||
|
{loading && !items.length ? (
|
||||||
|
<p className="label-md text-muted" style={{ padding: 24, textAlign: 'center' }}>
|
||||||
|
加载中…
|
||||||
|
</p>
|
||||||
|
) : items.length ? (
|
||||||
|
<ul style={{ listStyle: 'none', margin: 0, padding: 0 }}>
|
||||||
|
{items.map((item) => {
|
||||||
|
const active =
|
||||||
|
pending?.latitude === item.latitude && pending?.longitude === item.longitude;
|
||||||
|
return (
|
||||||
|
<li key={`${item.id}-${item.latitude}-${item.longitude}`}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setPending(placeToPicked(item))}
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
textAlign: 'left',
|
||||||
|
padding: '12px 16px',
|
||||||
|
border: 0,
|
||||||
|
borderBottom: '1px solid rgba(0,0,0,0.06)',
|
||||||
|
background: active ? 'rgba(166, 29, 36, 0.06)' : '#fff',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ fontWeight: 600, fontSize: 15 }}>{item.title}</div>
|
||||||
|
<div className="label-md text-muted" style={{ marginTop: 4 }}>
|
||||||
|
{item.address}
|
||||||
|
</div>
|
||||||
|
<div className="label-md text-muted" style={{ marginTop: 2, fontSize: 12 }}>
|
||||||
|
{item.latitude.toFixed(6)}, {item.longitude.toFixed(6)}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
) : (
|
||||||
|
<p className="label-md text-muted" style={{ padding: 24, textAlign: 'center' }}>
|
||||||
|
{hint}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -6,13 +6,23 @@ export type StoreDraftForm = {
|
|||||||
district: string;
|
district: string;
|
||||||
name: string;
|
name: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
storeSmsCode: string;
|
|
||||||
address: string;
|
address: string;
|
||||||
|
/** 门店坐标(定位或地理编码) */
|
||||||
|
latitude: string;
|
||||||
|
longitude: string;
|
||||||
openTime: string;
|
openTime: string;
|
||||||
closeTime: string;
|
closeTime: string;
|
||||||
|
/** 是否启用第二段营业时间 */
|
||||||
|
dualHours: boolean;
|
||||||
|
openTime2: string;
|
||||||
|
closeTime2: string;
|
||||||
|
/** 人均费用(选填) */
|
||||||
|
avgPrice: string;
|
||||||
categoryParentId: string;
|
categoryParentId: string;
|
||||||
categoryId: string;
|
categoryId: string;
|
||||||
intro: string;
|
intro: string;
|
||||||
|
/** 好客权益券使用规则 */
|
||||||
|
benefitUsageRule: string;
|
||||||
coverUrl: string;
|
coverUrl: string;
|
||||||
envPhotoUrls: string[];
|
envPhotoUrls: string[];
|
||||||
contractUrl: string;
|
contractUrl: string;
|
||||||
@@ -39,13 +49,19 @@ export const defaultStoreForm = (): StoreDraftForm => ({
|
|||||||
cityId: '',
|
cityId: '',
|
||||||
name: '',
|
name: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
storeSmsCode: '',
|
|
||||||
address: '',
|
address: '',
|
||||||
|
latitude: '',
|
||||||
|
longitude: '',
|
||||||
openTime: '10:00',
|
openTime: '10:00',
|
||||||
closeTime: '22:00',
|
closeTime: '22:00',
|
||||||
|
dualHours: false,
|
||||||
|
openTime2: '17:00',
|
||||||
|
closeTime2: '21:00',
|
||||||
|
avgPrice: '',
|
||||||
categoryParentId: '',
|
categoryParentId: '',
|
||||||
categoryId: '',
|
categoryId: '',
|
||||||
intro: '',
|
intro: '',
|
||||||
|
benefitUsageRule: '',
|
||||||
coverUrl: '',
|
coverUrl: '',
|
||||||
envPhotoUrls: ['', '', ''],
|
envPhotoUrls: ['', '', ''],
|
||||||
contractUrl: '',
|
contractUrl: '',
|
||||||
@@ -54,39 +70,38 @@ export const defaultStoreForm = (): StoreDraftForm => ({
|
|||||||
bankBranch: '',
|
bankBranch: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
export function normalizeStringArray(raw: unknown, length: number): string[] {
|
const TIME_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
||||||
if (!Array.isArray(raw)) return Array.from({ length }, () => '');
|
const PHONE_RE = /^1[3-9]\d{9}$/;
|
||||||
const items = raw.map((item) => String(item ?? ''));
|
const BANK_RE = /^\d{16,19}$/;
|
||||||
while (items.length < length) items.push('');
|
|
||||||
return items.slice(0, length);
|
function timeToMinutes(hhmm: string): number {
|
||||||
|
const [h, m] = hhmm.split(':').map(Number);
|
||||||
|
return h * 60 + m;
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeForm(raw: Record<string, unknown>): StoreDraftForm {
|
export function normalizeStringArray(urls: unknown, minLen: number): string[] {
|
||||||
|
const arr = Array.isArray(urls) ? urls.map((u) => String(u ?? '')) : [];
|
||||||
|
while (arr.length < minLen) arr.push('');
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeStoreDraftForm(raw: Partial<StoreDraftForm> | null | undefined): StoreDraftForm {
|
||||||
const base = defaultStoreForm();
|
const base = defaultStoreForm();
|
||||||
const regionCodes = Array.isArray(raw.regionCodes) && raw.regionCodes.length >= 3
|
if (!raw) return base;
|
||||||
? raw.regionCodes.map((code) => String(code))
|
|
||||||
: base.regionCodes;
|
|
||||||
return {
|
return {
|
||||||
regionCodes,
|
...base,
|
||||||
|
...raw,
|
||||||
|
regionCodes: Array.isArray(raw.regionCodes) ? raw.regionCodes.map(String) : base.regionCodes,
|
||||||
cityId: String(raw.cityId ?? base.cityId),
|
cityId: String(raw.cityId ?? base.cityId),
|
||||||
province: String(raw.province ?? base.province),
|
latitude: raw.latitude != null && raw.latitude !== '' ? String(raw.latitude) : base.latitude,
|
||||||
city: String(raw.city ?? base.city),
|
longitude: raw.longitude != null && raw.longitude !== '' ? String(raw.longitude) : base.longitude,
|
||||||
district: String(raw.district ?? base.district),
|
|
||||||
name: String(raw.name ?? base.name),
|
|
||||||
phone: String(raw.phone ?? base.phone),
|
|
||||||
storeSmsCode: String(raw.storeSmsCode ?? base.storeSmsCode),
|
|
||||||
address: String(raw.address ?? base.address),
|
|
||||||
openTime: String(raw.openTime ?? base.openTime),
|
openTime: String(raw.openTime ?? base.openTime),
|
||||||
closeTime: String(raw.closeTime ?? base.closeTime),
|
closeTime: String(raw.closeTime ?? base.closeTime),
|
||||||
categoryParentId: String(raw.categoryParentId ?? base.categoryParentId),
|
dualHours: Boolean(raw.dualHours),
|
||||||
categoryId: String(raw.categoryId ?? base.categoryId),
|
openTime2: String(raw.openTime2 ?? base.openTime2),
|
||||||
intro: String(raw.intro ?? base.intro),
|
closeTime2: String(raw.closeTime2 ?? base.closeTime2),
|
||||||
coverUrl: String(raw.coverUrl ?? base.coverUrl),
|
avgPrice: String(raw.avgPrice ?? base.avgPrice),
|
||||||
envPhotoUrls: normalizeStringArray(raw.envPhotoUrls, 3),
|
envPhotoUrls: normalizeStringArray(raw.envPhotoUrls, 3),
|
||||||
contractUrl: String(raw.contractUrl ?? base.contractUrl),
|
|
||||||
bankAccountName: String(raw.bankAccountName ?? base.bankAccountName),
|
|
||||||
bankAccountNo: String(raw.bankAccountNo ?? base.bankAccountNo),
|
|
||||||
bankBranch: String(raw.bankBranch ?? base.bankBranch),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,14 +117,11 @@ export function loadStoreDraft(accountId?: string): StoreDraft | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!raw) return null;
|
if (!raw) return null;
|
||||||
const parsed = JSON.parse(raw) as Record<string, unknown>;
|
const parsed = JSON.parse(raw) as StoreDraft;
|
||||||
if (parsed.form && typeof parsed.form === 'object') {
|
return {
|
||||||
return {
|
step: Number(parsed.step) || 0,
|
||||||
step: Math.min(3, Math.max(1, Number(parsed.step) || 1)),
|
form: normalizeStoreDraftForm(parsed.form),
|
||||||
form: normalizeForm(parsed.form as Record<string, unknown>),
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
return { step: 1, form: normalizeForm(parsed) };
|
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -129,15 +141,6 @@ export function clearAllStoreDrafts(accountId?: string) {
|
|||||||
localStorage.removeItem(STORE_DRAFT_KEY);
|
localStorage.removeItem(STORE_DRAFT_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
const PHONE_RE = /^1\d{10}$/;
|
|
||||||
const BANK_RE = /^\d{16,19}$/;
|
|
||||||
const TIME_RE = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
||||||
|
|
||||||
function timeToMinutes(value: string): number {
|
|
||||||
const [h, m] = value.split(':').map(Number);
|
|
||||||
return h * 60 + m;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function validateStoreStep1(
|
export function validateStoreStep1(
|
||||||
form: Pick<
|
form: Pick<
|
||||||
StoreDraftForm,
|
StoreDraftForm,
|
||||||
@@ -147,8 +150,13 @@ export function validateStoreStep1(
|
|||||||
| 'address'
|
| 'address'
|
||||||
| 'openTime'
|
| 'openTime'
|
||||||
| 'closeTime'
|
| 'closeTime'
|
||||||
|
| 'dualHours'
|
||||||
|
| 'openTime2'
|
||||||
|
| 'closeTime2'
|
||||||
|
| 'avgPrice'
|
||||||
| 'categoryId'
|
| 'categoryId'
|
||||||
| 'intro'
|
| 'intro'
|
||||||
|
| 'benefitUsageRule'
|
||||||
>,
|
>,
|
||||||
): string | null {
|
): string | null {
|
||||||
if (!form.regionCodes || form.regionCodes.length < 3) return '请选择省 / 市 / 区县';
|
if (!form.regionCodes || form.regionCodes.length < 3) return '请选择省 / 市 / 区县';
|
||||||
@@ -162,10 +170,29 @@ export function validateStoreStep1(
|
|||||||
if (timeToMinutes(form.openTime.trim()) >= timeToMinutes(form.closeTime.trim())) {
|
if (timeToMinutes(form.openTime.trim()) >= timeToMinutes(form.closeTime.trim())) {
|
||||||
return '营业结束时间须晚于开始时间';
|
return '营业结束时间须晚于开始时间';
|
||||||
}
|
}
|
||||||
|
if (form.dualHours) {
|
||||||
|
if (!form.openTime2.trim() || !form.closeTime2.trim()) return '请完整填写第二段营业时间';
|
||||||
|
if (!TIME_RE.test(form.openTime2.trim()) || !TIME_RE.test(form.closeTime2.trim())) {
|
||||||
|
return '第二段时间格式须为 HH:MM';
|
||||||
|
}
|
||||||
|
if (timeToMinutes(form.openTime2.trim()) >= timeToMinutes(form.closeTime2.trim())) {
|
||||||
|
return '第二段结束时间须晚于开始时间';
|
||||||
|
}
|
||||||
|
if (timeToMinutes(form.closeTime.trim()) >= timeToMinutes(form.openTime2.trim())) {
|
||||||
|
return '第二段开始时间须晚于第一段结束时间';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (form.avgPrice.trim()) {
|
||||||
|
const n = Number(form.avgPrice);
|
||||||
|
if (Number.isNaN(n) || n < 0) return '人均费用须为非负数字';
|
||||||
|
}
|
||||||
if (!form.categoryId.trim()) return '请选择店铺类型';
|
if (!form.categoryId.trim()) return '请选择店铺类型';
|
||||||
if (form.intro.trim()) {
|
if (form.intro.trim()) {
|
||||||
const len = form.intro.trim().length;
|
const len = form.intro.trim().length;
|
||||||
if (len < 10 || len > 500) return '门店简介须为 10~500 字';
|
if (len < 2 || len > 500) return '门店简介须为 2~500 字';
|
||||||
|
}
|
||||||
|
if (form.benefitUsageRule.trim().length > 1000) {
|
||||||
|
return '好客权益券使用规则最多 1000 字';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -189,7 +216,7 @@ export function patchEnvPhotoAt(urls: string[], index: number, url: string): str
|
|||||||
export function validateStoreStep3(
|
export function validateStoreStep3(
|
||||||
form: Pick<
|
form: Pick<
|
||||||
StoreDraftForm,
|
StoreDraftForm,
|
||||||
'bankAccountName' | 'bankAccountNo' | 'bankBranch' | 'phone' | 'storeSmsCode'
|
'bankAccountName' | 'bankAccountNo' | 'bankBranch' | 'phone'
|
||||||
>,
|
>,
|
||||||
): string | null {
|
): string | null {
|
||||||
if (!form.bankAccountName.trim()) return '请填写户主姓名';
|
if (!form.bankAccountName.trim()) return '请填写户主姓名';
|
||||||
@@ -198,7 +225,5 @@ export function validateStoreStep3(
|
|||||||
if (!form.bankBranch.trim()) return '请填写开户支行';
|
if (!form.bankBranch.trim()) return '请填写开户支行';
|
||||||
if (!form.phone.trim()) return '请填写联系电话';
|
if (!form.phone.trim()) return '请填写联系电话';
|
||||||
if (!PHONE_RE.test(form.phone.trim())) return '联系电话须为11位手机号';
|
if (!PHONE_RE.test(form.phone.trim())) return '联系电话须为11位手机号';
|
||||||
if (!form.storeSmsCode.trim()) return '请输入门店手机号验证码';
|
|
||||||
if (!/^\d{4,6}$/.test(form.storeSmsCode.trim())) return '验证码格式不正确';
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { weixinSdk } from './weixin';
|
||||||
|
|
||||||
|
export type StorePosition = {
|
||||||
|
latitude: number;
|
||||||
|
longitude: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 获取当前 GPS 坐标(微信 JSSDK / 浏览器 Geolocation) */
|
||||||
|
export async function locateStorePosition(): Promise<StorePosition> {
|
||||||
|
const outcome = await weixinSdk.getLocationDetailed();
|
||||||
|
if (!outcome.location) {
|
||||||
|
throw new Error(outcome.errMsg || '定位失败,请允许位置权限后重试');
|
||||||
|
}
|
||||||
|
const { latitude, longitude } = outcome.location;
|
||||||
|
if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) {
|
||||||
|
throw new Error('定位结果无效');
|
||||||
|
}
|
||||||
|
return { latitude, longitude };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatStoreCoords(lat?: string | number | null, lng?: string | number | null): string {
|
||||||
|
const a = lat != null && lat !== '' ? Number(lat) : NaN;
|
||||||
|
const b = lng != null && lng !== '' ? Number(lng) : NaN;
|
||||||
|
if (!Number.isFinite(a) || !Number.isFinite(b)) return '';
|
||||||
|
return `${a.toFixed(6)}, ${b.toFixed(6)}`;
|
||||||
|
}
|
||||||
@@ -8,12 +8,4 @@ export function checkStorePhoneAvailable(phone: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendStorePhoneSms(phone: string) {
|
|
||||||
return request<{ ok: boolean; maskedPhone: string }>('PARTNER_H5', '/partner/stores/send-phone-sms', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({ phone: phone.trim() }),
|
|
||||||
silent: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export type { PartnerStorePhoneAvailableResponse };
|
export type { PartnerStorePhoneAvailableResponse };
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ export type StoreStatusValue = 'OPEN' | 'PAUSED' | 'CLOSED';
|
|||||||
export function storeStatusLabel(status: string): string {
|
export function storeStatusLabel(status: string): string {
|
||||||
const s = String(status).toUpperCase();
|
const s = String(status).toUpperCase();
|
||||||
if (s === 'OPEN') return '营业中';
|
if (s === 'OPEN') return '营业中';
|
||||||
if (s === 'PAUSED') return '暂时闭店';
|
if (s === 'PAUSED') return '临时闭店';
|
||||||
if (s === 'CLOSED') return '关闭';
|
if (s === 'CLOSED') return '永久关闭';
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
export type TencentPickedLocation = {
|
||||||
|
latitude: number;
|
||||||
|
longitude: number;
|
||||||
|
address?: string;
|
||||||
|
name?: string;
|
||||||
|
cityname?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LbsPlaceItem = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
address: string;
|
||||||
|
latitude: number;
|
||||||
|
longitude: number;
|
||||||
|
city?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function placeToPicked(item: LbsPlaceItem): TencentPickedLocation {
|
||||||
|
return {
|
||||||
|
latitude: item.latitude,
|
||||||
|
longitude: item.longitude,
|
||||||
|
address: item.address || undefined,
|
||||||
|
name: item.title || undefined,
|
||||||
|
cityname: item.city || undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import PageHeader from '@dukang/shared-ui/PageHeader';
|
import PageHeader from '@dukang/shared-ui/PageHeader';
|
||||||
import ChinaRegionPicker from '../components/ChinaRegionPicker';
|
import ChinaRegionPicker from '../components/ChinaRegionPicker';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { formatRegionLabel, parseRegionCodes } from '../lib/china-region';
|
import { formatRegionLabel, parseRegionCodes } from '../lib/china-region';
|
||||||
import { toastError, toastSuccess } from '../lib/toast';
|
import { toastError, toastSuccess } from '../lib/toast';
|
||||||
import type {
|
import type {
|
||||||
|
PartnerProxyDeliveryMode,
|
||||||
PartnerProxyOrderCreateRequest,
|
PartnerProxyOrderCreateRequest,
|
||||||
PartnerProxyOrderOptions,
|
PartnerProxyOrderOptions,
|
||||||
PartnerProxyOrderPreviewResult,
|
PartnerProxyOrderPreviewResult,
|
||||||
@@ -17,19 +18,25 @@ function fmtMoney(n: number) {
|
|||||||
|
|
||||||
export default function ProxyOrderPage() {
|
export default function ProxyOrderPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
const [options, setOptions] = useState<PartnerProxyOrderOptions | null>(null);
|
const [options, setOptions] = useState<PartnerProxyOrderOptions | null>(null);
|
||||||
const [loadingOptions, setLoadingOptions] = useState(true);
|
const [loadingOptions, setLoadingOptions] = useState(true);
|
||||||
const [phone, setPhone] = useState('');
|
const [phone, setPhone] = useState('');
|
||||||
const [smsCode, setSmsCode] = useState('');
|
const [customerSmsCode, setCustomerSmsCode] = useState('');
|
||||||
|
const [partnerSmsCode, setPartnerSmsCode] = useState('');
|
||||||
const [receiverName, setReceiverName] = useState('');
|
const [receiverName, setReceiverName] = useState('');
|
||||||
const [regionCodes, setRegionCodes] = useState<string[]>([]);
|
const [regionCodes, setRegionCodes] = useState<string[]>([]);
|
||||||
const [addressDetail, setAddressDetail] = useState('');
|
const [addressDetail, setAddressDetail] = useState('');
|
||||||
const [productId, setProductId] = useState('');
|
const [productId, setProductId] = useState('');
|
||||||
const [quantity, setQuantity] = useState(2);
|
const [quantity, setQuantity] = useState(2);
|
||||||
const [promoCodeId, setPromoCodeId] = useState('');
|
const [promoCodeId, setPromoCodeId] = useState('');
|
||||||
|
const [deliveryMode, setDeliveryMode] = useState<PartnerProxyDeliveryMode>('ADDRESS');
|
||||||
|
const [autoReceive, setAutoReceive] = useState(false);
|
||||||
|
const [confirmStep, setConfirmStep] = useState(false);
|
||||||
const [preview, setPreview] = useState<PartnerProxyOrderPreviewResult | null>(null);
|
const [preview, setPreview] = useState<PartnerProxyOrderPreviewResult | null>(null);
|
||||||
const [previewLoading, setPreviewLoading] = useState(false);
|
const [previewLoading, setPreviewLoading] = useState(false);
|
||||||
const [smsCooldown, setSmsCooldown] = useState(0);
|
const [customerCooldown, setCustomerCooldown] = useState(0);
|
||||||
|
const [partnerCooldown, setPartnerCooldown] = useState(0);
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [msg, setMsg] = useState('');
|
const [msg, setMsg] = useState('');
|
||||||
|
|
||||||
@@ -39,12 +46,26 @@ export default function ProxyOrderPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
request<PartnerProxyOrderOptions>('PARTNER_H5', '/partner/proxy-orders/options')
|
request<PartnerProxyOrderOptions>('PARTNER_H5', '/partner/proxy-orders/options')
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setOptions(data);
|
setOptions({
|
||||||
if (data.products[0]) setProductId(data.products[0].id);
|
...data,
|
||||||
|
stores: Array.isArray(data.stores) ? data.stores : [],
|
||||||
|
});
|
||||||
|
const fromQuery = searchParams.get('productId');
|
||||||
|
if (fromQuery && data.products.some((p) => p.id === fromQuery)) {
|
||||||
|
setProductId(fromQuery);
|
||||||
|
} else if (data.products[0] && !productId) {
|
||||||
|
setProductId(data.products[0].id);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((e) => toastError(e instanceof Error ? e.message : '加载失败'))
|
.catch((e) => toastError(e instanceof Error ? e.message : '加载失败'))
|
||||||
.finally(() => setLoadingOptions(false));
|
.finally(() => setLoadingOptions(false));
|
||||||
}, []);
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- hydrate once; productId from query
|
||||||
|
}, [searchParams]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fromQuery = searchParams.get('productId');
|
||||||
|
if (fromQuery) setProductId(fromQuery);
|
||||||
|
}, [searchParams]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!productId || quantity < 1) {
|
if (!productId || quantity < 1) {
|
||||||
@@ -58,8 +79,9 @@ export default function ProxyOrderPage() {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
productId,
|
productId,
|
||||||
quantity,
|
quantity,
|
||||||
receiverCity: region.city || undefined,
|
deliveryMode,
|
||||||
receiverDistrict: region.district || undefined,
|
receiverCity: deliveryMode === 'ADDRESS' ? region?.city || undefined : undefined,
|
||||||
|
receiverDistrict: deliveryMode === 'ADDRESS' ? region?.district || undefined : undefined,
|
||||||
}),
|
}),
|
||||||
silent: true,
|
silent: true,
|
||||||
})
|
})
|
||||||
@@ -68,67 +90,109 @@ export default function ProxyOrderPage() {
|
|||||||
.finally(() => setPreviewLoading(false));
|
.finally(() => setPreviewLoading(false));
|
||||||
}, 300);
|
}, 300);
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [productId, quantity, region.city, region.district]);
|
}, [productId, quantity, deliveryMode, region?.city, region?.district]);
|
||||||
|
|
||||||
async function sendSms() {
|
function startCooldown(setter: (n: number | ((s: number) => number)) => void) {
|
||||||
|
setter(60);
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
setter((s) => {
|
||||||
|
if (s <= 1) {
|
||||||
|
clearInterval(timer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return s - 1;
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendCustomerSms() {
|
||||||
setMsg('');
|
setMsg('');
|
||||||
if (!/^1\d{10}$/.test(phone.trim())) {
|
if (!/^1\d{10}$/.test(phone.trim())) {
|
||||||
setMsg('请输入有效手机号');
|
setMsg('请输入有效手机号');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const res = await request<{ maskedPhone: string }>('PARTNER_H5', '/partner/proxy-orders/send-sms', {
|
const res = await request<{ maskedPhone: string }>(
|
||||||
method: 'POST',
|
'PARTNER_H5',
|
||||||
body: JSON.stringify({ phone: phone.trim() }),
|
'/partner/proxy-orders/send-customer-sms',
|
||||||
silent: true,
|
{
|
||||||
});
|
method: 'POST',
|
||||||
setMsg(`验证码已发送至 ${res.maskedPhone}`);
|
body: JSON.stringify({ phone: phone.trim() }),
|
||||||
setSmsCooldown(60);
|
silent: true,
|
||||||
const timer = setInterval(() => {
|
},
|
||||||
setSmsCooldown((s) => {
|
);
|
||||||
if (s <= 1) {
|
setMsg(`客户验证码已发送至 ${res.maskedPhone}`);
|
||||||
clearInterval(timer);
|
startCooldown(setCustomerCooldown);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return s - 1;
|
|
||||||
});
|
|
||||||
}, 1000);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setMsg(e instanceof Error ? e.message : '发送失败');
|
setMsg(e instanceof Error ? e.message : '发送失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendPartnerSms() {
|
||||||
|
setMsg('');
|
||||||
|
try {
|
||||||
|
const res = await request<{ maskedPhone: string }>(
|
||||||
|
'PARTNER_H5',
|
||||||
|
'/partner/proxy-orders/send-partner-sms',
|
||||||
|
{ method: 'POST', body: '{}', silent: true },
|
||||||
|
);
|
||||||
|
setMsg(`确认验证码已发送至合伙人手机 ${res.maskedPhone}`);
|
||||||
|
startCooldown(setPartnerCooldown);
|
||||||
|
} catch (e) {
|
||||||
|
setMsg(e instanceof Error ? e.message : '发送失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateForm(): string | null {
|
||||||
|
if (!/^1\d{10}$/.test(phone.trim())) return '请输入有效手机号';
|
||||||
|
if (!customerSmsCode.trim()) return '请输入客户验证码';
|
||||||
|
if (!productId) return '请选择商品';
|
||||||
|
if (deliveryMode !== 'ADDRESS') {
|
||||||
|
// 现场提货不需要地址与门店
|
||||||
|
} else {
|
||||||
|
if (!region?.province || !region?.city || !region?.district) return '请选择省市区';
|
||||||
|
if (!addressDetail.trim()) return '请填写详细地址';
|
||||||
|
if (!autoReceive) return '配送到址须勾选同意自动收货';
|
||||||
|
}
|
||||||
|
if (!preview) return '请等待费用计算完成';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openConfirmStep() {
|
||||||
|
setMsg('');
|
||||||
|
const err = validateForm();
|
||||||
|
if (err) {
|
||||||
|
setMsg(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setConfirmStep(true);
|
||||||
|
setPartnerSmsCode('');
|
||||||
|
await sendPartnerSms();
|
||||||
|
}
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
setMsg('');
|
setMsg('');
|
||||||
if (!/^1\d{10}$/.test(phone.trim())) {
|
const err = validateForm();
|
||||||
setMsg('请输入有效手机号');
|
if (err) {
|
||||||
|
setMsg(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!smsCode.trim()) {
|
if (!partnerSmsCode.trim()) {
|
||||||
setMsg('请输入验证码');
|
setMsg('请输入合伙人确认验证码');
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!region?.province || !region.city || !region.district) {
|
|
||||||
setMsg('请选择省市区');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!addressDetail.trim()) {
|
|
||||||
setMsg('请填写详细地址');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!productId) {
|
|
||||||
setMsg('请选择商品');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload: PartnerProxyOrderCreateRequest = {
|
const payload: PartnerProxyOrderCreateRequest = {
|
||||||
phone: phone.trim(),
|
phone: phone.trim(),
|
||||||
smsCode: smsCode.trim(),
|
customerSmsCode: customerSmsCode.trim(),
|
||||||
|
partnerSmsCode: partnerSmsCode.trim(),
|
||||||
|
deliveryMode,
|
||||||
|
autoReceive: deliveryMode === 'ADDRESS' ? true : undefined,
|
||||||
receiverName: receiverName.trim() || undefined,
|
receiverName: receiverName.trim() || undefined,
|
||||||
province: region.province,
|
province: deliveryMode === 'ADDRESS' ? region?.province : undefined,
|
||||||
city: region.city,
|
city: deliveryMode === 'ADDRESS' ? region?.city : undefined,
|
||||||
district: region.district,
|
district: deliveryMode === 'ADDRESS' ? region?.district : undefined,
|
||||||
addressDetail: addressDetail.trim(),
|
addressDetail: deliveryMode === 'ADDRESS' ? addressDetail.trim() : undefined,
|
||||||
productId,
|
productId,
|
||||||
quantity,
|
quantity,
|
||||||
promoCodeId: promoCodeId || undefined,
|
promoCodeId: promoCodeId || undefined,
|
||||||
@@ -151,6 +215,12 @@ export default function ProxyOrderPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const selectedProduct = options?.products.find((p) => p.id === productId);
|
const selectedProduct = options?.products.find((p) => p.id === productId);
|
||||||
|
const deliveryLabel =
|
||||||
|
preview?.deliveryType === 'ON_SITE_PICKUP'
|
||||||
|
? '现场提货'
|
||||||
|
: preview?.deliveryType === 'CROSS_CITY'
|
||||||
|
? '跨城配送'
|
||||||
|
: '同城配送';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="page partner-proxy-order-page">
|
<div className="page partner-proxy-order-page">
|
||||||
@@ -158,7 +228,7 @@ export default function ProxyOrderPage() {
|
|||||||
|
|
||||||
<main className="partner-form-card" style={{ margin: '0 16px 24px' }}>
|
<main className="partner-form-card" style={{ margin: '0 16px 24px' }}>
|
||||||
{loadingOptions ? (
|
{loadingOptions ? (
|
||||||
<p className="label-md text-muted">加载商品与推广码…</p>
|
<p className="label-md text-muted">加载商品…</p>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<section className="partner-form-section">
|
<section className="partner-form-section">
|
||||||
@@ -175,70 +245,49 @@ export default function ProxyOrderPage() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-secondary"
|
className="btn btn-secondary"
|
||||||
disabled={smsCooldown > 0}
|
disabled={customerCooldown > 0}
|
||||||
onClick={() => void sendSms()}
|
onClick={() => void sendCustomerSms()}
|
||||||
>
|
>
|
||||||
{smsCooldown > 0 ? `${smsCooldown}s` : '获取验证码'}
|
{customerCooldown > 0 ? `${customerCooldown}s` : '获取验证码'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className="partner-form-section">
|
<section className="partner-form-section">
|
||||||
<label className="partner-form-label">短信验证码</label>
|
<label className="partner-form-label">客户验证码</label>
|
||||||
<div className="partner-input-wrap">
|
<div className="partner-input-wrap">
|
||||||
<input
|
<input
|
||||||
className="partner-input"
|
className="partner-input"
|
||||||
placeholder="线下代发货确认码"
|
placeholder="发至客户手机"
|
||||||
value={smsCode}
|
value={customerSmsCode}
|
||||||
onChange={(e) => setSmsCode(e.target.value.replace(/\D/g, '').slice(0, 6))}
|
onChange={(e) => setCustomerSmsCode(e.target.value.replace(/\D/g, '').slice(0, 6))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className="partner-form-section">
|
<section className="partner-form-section">
|
||||||
<label className="partner-form-label">收货人(选填)</label>
|
<label className="partner-form-label">酒品</label>
|
||||||
<div className="partner-input-wrap">
|
<button
|
||||||
<input
|
type="button"
|
||||||
className="partner-input"
|
className="partner-proxy-product-picker"
|
||||||
placeholder="默认:用户+手机尾号"
|
onClick={() =>
|
||||||
value={receiverName}
|
navigate(
|
||||||
onChange={(e) => setReceiverName(e.target.value)}
|
`/proxy-order/products${productId ? `?selected=${encodeURIComponent(productId)}` : ''}`,
|
||||||
/>
|
)
|
||||||
</div>
|
}
|
||||||
</section>
|
|
||||||
|
|
||||||
<section className="partner-form-section">
|
|
||||||
<label className="partner-form-label">收货地区</label>
|
|
||||||
<ChinaRegionPicker value={regionCodes} onChange={setRegionCodes} />
|
|
||||||
{regionLabel && <p className="label-md text-muted" style={{ marginTop: 8 }}>{regionLabel}</p>}
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section className="partner-form-section">
|
|
||||||
<label className="partner-form-label">详细地址</label>
|
|
||||||
<div className="partner-field-input partner-field-input--block">
|
|
||||||
<textarea
|
|
||||||
rows={3}
|
|
||||||
placeholder="街道、门牌号等"
|
|
||||||
value={addressDetail}
|
|
||||||
onChange={(e) => setAddressDetail(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section className="partner-form-section">
|
|
||||||
<label className="partner-form-label">商品</label>
|
|
||||||
<select
|
|
||||||
className="partner-input"
|
|
||||||
value={productId}
|
|
||||||
onChange={(e) => setProductId(e.target.value)}
|
|
||||||
style={{ width: '100%', padding: '12px 14px', borderRadius: 12, border: '1px solid var(--color-border)' }}
|
|
||||||
>
|
>
|
||||||
{(options?.products ?? []).map((p) => (
|
{selectedProduct ? (
|
||||||
<option key={p.id} value={p.id}>
|
<>
|
||||||
{p.name}({p.spec})¥{fmtMoney(p.price)}
|
<span className="partner-proxy-product-name">{selectedProduct.name}</span>
|
||||||
</option>
|
<span className="label-md text-muted">
|
||||||
))}
|
{selectedProduct.spec} · ¥{fmtMoney(selectedProduct.price)}
|
||||||
</select>
|
</span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<span className="label-md text-muted">点击选择酒品</span>
|
||||||
|
)}
|
||||||
|
<span className="partner-proxy-product-picker-arrow">›</span>
|
||||||
|
</button>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className="partner-form-section">
|
<section className="partner-form-section">
|
||||||
@@ -261,7 +310,12 @@ export default function ProxyOrderPage() {
|
|||||||
className="partner-input"
|
className="partner-input"
|
||||||
value={promoCodeId}
|
value={promoCodeId}
|
||||||
onChange={(e) => setPromoCodeId(e.target.value)}
|
onChange={(e) => setPromoCodeId(e.target.value)}
|
||||||
style={{ width: '100%', padding: '12px 14px', borderRadius: 12, border: '1px solid var(--color-border)' }}
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
padding: '12px 14px',
|
||||||
|
borderRadius: 12,
|
||||||
|
border: '1px solid var(--color-border)',
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<option value="">不绑定</option>
|
<option value="">不绑定</option>
|
||||||
{options!.promoCodes.map((p) => (
|
{options!.promoCodes.map((p) => (
|
||||||
@@ -273,6 +327,73 @@ export default function ProxyOrderPage() {
|
|||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<section className="partner-form-section">
|
||||||
|
<label className="partner-form-label">履约方式</label>
|
||||||
|
<div className="partner-proxy-mode-tabs">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`partner-proxy-mode-tab${deliveryMode === 'ADDRESS' ? ' is-active' : ''}`}
|
||||||
|
onClick={() => setDeliveryMode('ADDRESS')}
|
||||||
|
>
|
||||||
|
配送到址
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`partner-proxy-mode-tab${deliveryMode === 'ON_SITE_PICKUP' ? ' is-active' : ''}`}
|
||||||
|
onClick={() => setDeliveryMode('ON_SITE_PICKUP')}
|
||||||
|
>
|
||||||
|
现场提货
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{deliveryMode === 'ADDRESS' ? (
|
||||||
|
<>
|
||||||
|
<section className="partner-form-section">
|
||||||
|
<label className="partner-form-label">收货人(选填)</label>
|
||||||
|
<div className="partner-input-wrap">
|
||||||
|
<input
|
||||||
|
className="partner-input"
|
||||||
|
placeholder="默认:用户+手机尾号"
|
||||||
|
value={receiverName}
|
||||||
|
onChange={(e) => setReceiverName(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="partner-form-section">
|
||||||
|
<label className="partner-form-label">收货地区</label>
|
||||||
|
<ChinaRegionPicker value={regionCodes} onChange={setRegionCodes} />
|
||||||
|
{regionLabel ? (
|
||||||
|
<p className="label-md text-muted" style={{ marginTop: 8 }}>
|
||||||
|
{regionLabel}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="partner-form-section">
|
||||||
|
<label className="partner-form-label">详细地址</label>
|
||||||
|
<div className="partner-field-input partner-field-input--block">
|
||||||
|
<textarea
|
||||||
|
rows={3}
|
||||||
|
placeholder="街道、门牌号等"
|
||||||
|
value={addressDetail}
|
||||||
|
onChange={(e) => setAddressDetail(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<label className="partner-proxy-auto-receive">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={autoReceive}
|
||||||
|
onChange={(e) => setAutoReceive(e.target.checked)}
|
||||||
|
/>
|
||||||
|
<span>同意自动收货(线下代下单提交后视为已送达并发放权益)</span>
|
||||||
|
</label>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<section className="partner-proxy-fee-card">
|
<section className="partner-proxy-fee-card">
|
||||||
<h3 className="headline-md">费用明细</h3>
|
<h3 className="headline-md">费用明细</h3>
|
||||||
{previewLoading ? (
|
{previewLoading ? (
|
||||||
@@ -288,8 +409,8 @@ export default function ProxyOrderPage() {
|
|||||||
<span className="body-md">×{quantity}</span>
|
<span className="body-md">×{quantity}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="partner-proxy-fee-row">
|
<div className="partner-proxy-fee-row">
|
||||||
<span className="label-md text-muted">配送类型</span>
|
<span className="label-md text-muted">履约类型</span>
|
||||||
<span className="body-md">{preview.deliveryType === 'LOCAL' ? '同城' : '跨城'}</span>
|
<span className="body-md">{deliveryLabel}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="partner-proxy-fee-row">
|
<div className="partner-proxy-fee-row">
|
||||||
<span className="label-md text-muted">权益额</span>
|
<span className="label-md text-muted">权益额</span>
|
||||||
@@ -302,25 +423,78 @@ export default function ProxyOrderPage() {
|
|||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<p className="label-md text-muted">
|
<p className="label-md text-muted">
|
||||||
{selectedProduct ? '请确认数量与地址后查看费用' : '请选择商品'}
|
{selectedProduct ? '请确认数量与履约信息后查看费用' : '请选择商品'}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{msg && <p className="partner-form-error" role="alert">{msg}</p>}
|
{confirmStep ? (
|
||||||
|
<section className="partner-form-section partner-proxy-confirm">
|
||||||
|
<label className="partner-form-label">合伙人确认验证码</label>
|
||||||
|
<p className="label-md text-muted" style={{ marginBottom: 8 }}>
|
||||||
|
确认线下已收款后,将向您的登录手机号发送验证码
|
||||||
|
</p>
|
||||||
|
<div className="partner-input-row">
|
||||||
|
<div className="partner-input-wrap" style={{ flex: 1 }}>
|
||||||
|
<input
|
||||||
|
className="partner-input"
|
||||||
|
placeholder="发至合伙人手机"
|
||||||
|
value={partnerSmsCode}
|
||||||
|
onChange={(e) => setPartnerSmsCode(e.target.value.replace(/\D/g, '').slice(0, 6))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-secondary"
|
||||||
|
disabled={partnerCooldown > 0}
|
||||||
|
onClick={() => void sendPartnerSms()}
|
||||||
|
>
|
||||||
|
{partnerCooldown > 0 ? `${partnerCooldown}s` : '重新发送'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<button
|
{msg ? (
|
||||||
type="button"
|
<p className="partner-form-error" role="alert">
|
||||||
className="btn btn-primary btn-block"
|
{msg}
|
||||||
disabled={submitting || !preview}
|
</p>
|
||||||
onClick={() => void submit()}
|
) : null}
|
||||||
style={{ marginTop: 16 }}
|
|
||||||
>
|
{!confirmStep ? (
|
||||||
{submitting ? '提交中…' : '验证码确认并代下单'}
|
<button
|
||||||
</button>
|
type="button"
|
||||||
|
className="btn btn-primary btn-block"
|
||||||
|
disabled={!preview}
|
||||||
|
onClick={() => void openConfirmStep()}
|
||||||
|
style={{ marginTop: 16 }}
|
||||||
|
>
|
||||||
|
确认代下单
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<div style={{ display: 'flex', gap: 8, marginTop: 16 }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-secondary"
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
onClick={() => setConfirmStep(false)}
|
||||||
|
>
|
||||||
|
返回修改
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-primary"
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
disabled={submitting || !preview}
|
||||||
|
onClick={() => void submit()}
|
||||||
|
>
|
||||||
|
{submitting ? '提交中…' : '验证并提交'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<p className="label-md text-muted" style={{ marginTop: 12, lineHeight: 1.5 }}>
|
<p className="label-md text-muted" style={{ marginTop: 12, lineHeight: 1.5 }}>
|
||||||
提交后将自动创建/关联用户,订单类型为「线下代下单」,状态直接标记为已收货,并发放对应权益。
|
线下已收款确认后,将自动创建/关联用户,订单标记为代下单并直接完成,同时发放对应权益。客户订单列表会显示您的姓名。
|
||||||
</p>
|
</p>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
|
import PageHeader from '@dukang/shared-ui/PageHeader';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { toastError } from '../lib/toast';
|
||||||
|
import type { PartnerProxyOrderOptions, PartnerProxyOrderProductOption } from '@dukang/shared-types';
|
||||||
|
|
||||||
|
function fmtMoney(n: number) {
|
||||||
|
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ProxyOrderProductsPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const selectedId = searchParams.get('selected') || '';
|
||||||
|
const [products, setProducts] = useState<PartnerProxyOrderProductOption[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<PartnerProxyOrderOptions>('PARTNER_H5', '/partner/proxy-orders/options')
|
||||||
|
.then((data) => setProducts(Array.isArray(data.products) ? data.products : []))
|
||||||
|
.catch((e) => toastError(e instanceof Error ? e.message : '加载失败'))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
function pick(product: PartnerProxyOrderProductOption) {
|
||||||
|
navigate(`/proxy-order?productId=${encodeURIComponent(product.id)}`, { replace: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="page partner-proxy-order-page">
|
||||||
|
<PageHeader title="选择酒品" onBack={() => navigate(-1)} />
|
||||||
|
<main className="partner-proxy-product-list">
|
||||||
|
{loading ? <p className="label-md text-muted">加载中…</p> : null}
|
||||||
|
{!loading && products.length === 0 ? (
|
||||||
|
<p className="label-md text-muted">暂无可售商品</p>
|
||||||
|
) : null}
|
||||||
|
{products.map((p) => {
|
||||||
|
const benefit = p.benefitAmount != null ? Number(p.benefitAmount) : Number(p.price);
|
||||||
|
const active = p.id === selectedId;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={p.id}
|
||||||
|
type="button"
|
||||||
|
className={`partner-proxy-product-card${active ? ' partner-proxy-product-card--active' : ''}`}
|
||||||
|
onClick={() => pick(p)}
|
||||||
|
>
|
||||||
|
<div className="partner-proxy-product-thumb">
|
||||||
|
{p.coverUrl ? (
|
||||||
|
<img src={p.coverUrl} alt="" />
|
||||||
|
) : (
|
||||||
|
<span className="partner-proxy-product-thumb-empty" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="partner-proxy-product-main">
|
||||||
|
<div className="partner-proxy-product-row">
|
||||||
|
<span className="partner-proxy-product-name">{p.name}</span>
|
||||||
|
<span className="partner-proxy-product-price">¥{fmtMoney(p.price)}</span>
|
||||||
|
</div>
|
||||||
|
<p className="partner-proxy-product-spec">{p.spec}</p>
|
||||||
|
<p className="partner-proxy-product-benefit">好客权益 ¥{fmtMoney(benefit)}</p>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -11,12 +11,16 @@ import { toastError, toastSuccess } from '../lib/toast';
|
|||||||
|
|
||||||
import { resolveRegionBinding } from '../lib/china-region';
|
import { resolveRegionBinding } from '../lib/china-region';
|
||||||
|
|
||||||
import { checkStorePhoneAvailable, sendStorePhoneSms } from '../lib/storePhone';
|
import { checkStorePhoneAvailable } from '../lib/storePhone';
|
||||||
|
|
||||||
|
import { formatStoreCoords, locateStorePosition } from '../lib/storeLocate';
|
||||||
|
|
||||||
import { fetchPartnerCities, type OpenCityOption } from '../lib/upload';
|
import { fetchPartnerCities, type OpenCityOption } from '../lib/upload';
|
||||||
|
|
||||||
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
||||||
|
|
||||||
|
import TencentLocPickerOverlay from '../components/TencentLocPickerOverlay';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
||||||
clearAllStoreDrafts,
|
clearAllStoreDrafts,
|
||||||
@@ -51,7 +55,6 @@ type StoreCategoryNode = {
|
|||||||
|
|
||||||
type FieldErrors = {
|
type FieldErrors = {
|
||||||
phone?: string;
|
phone?: string;
|
||||||
storeSmsCode?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -66,7 +69,7 @@ function isPhoneConflictMessage(message: string) {
|
|||||||
|
|
||||||
function isPhoneValidationMessage(message: string) {
|
function isPhoneValidationMessage(message: string) {
|
||||||
|
|
||||||
return message.includes('联系电话') || message.includes('手机号') || message.includes('验证码');
|
return message.includes('联系电话') || message.includes('手机号');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,12 +99,12 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
const [citiesError, setCitiesError] = useState('');
|
const [citiesError, setCitiesError] = useState('');
|
||||||
|
|
||||||
const [smsCooldown, setSmsCooldown] = useState(0);
|
|
||||||
|
|
||||||
const [smsHint, setSmsHint] = useState('');
|
|
||||||
|
|
||||||
const [categoryTree, setCategoryTree] = useState<StoreCategoryNode[]>([]);
|
const [categoryTree, setCategoryTree] = useState<StoreCategoryNode[]>([]);
|
||||||
|
|
||||||
|
const [locating, setLocating] = useState(false);
|
||||||
|
|
||||||
|
const [mapPickerOpen, setMapPickerOpen] = useState(false);
|
||||||
|
|
||||||
const draftSaveDisabledRef = useRef(false);
|
const draftSaveDisabledRef = useRef(false);
|
||||||
|
|
||||||
function reportFormError(message: string) {
|
function reportFormError(message: string) {
|
||||||
@@ -222,25 +225,13 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
setSubmitError('');
|
setSubmitError('');
|
||||||
|
|
||||||
let nextPatch = patch;
|
|
||||||
|
|
||||||
if ('phone' in patch) {
|
if ('phone' in patch) {
|
||||||
|
|
||||||
setFieldErrors((prev) => ({ ...prev, phone: undefined, storeSmsCode: undefined }));
|
setFieldErrors((prev) => ({ ...prev, phone: undefined }));
|
||||||
|
|
||||||
setSmsHint('');
|
|
||||||
|
|
||||||
nextPatch = { ...patch, storeSmsCode: '' };
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('storeSmsCode' in patch) {
|
setForm((prev) => ({ ...prev, ...patch }));
|
||||||
|
|
||||||
setFieldErrors((prev) => ({ ...prev, storeSmsCode: undefined }));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
setForm((prev) => ({ ...prev, ...nextPatch }));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,72 +291,6 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function sendStorePhoneCode() {
|
|
||||||
|
|
||||||
const phone = form.phone.trim();
|
|
||||||
|
|
||||||
if (!/^1\d{10}$/.test(phone)) {
|
|
||||||
|
|
||||||
setFieldErrors({ phone: '请先填写正确的11位手机号' });
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
setSmsHint('');
|
|
||||||
|
|
||||||
setFieldErrors((prev) => ({ ...prev, phone: undefined }));
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
const phoneCheck = await checkStorePhoneAvailable(phone);
|
|
||||||
|
|
||||||
if (!phoneCheck.available) {
|
|
||||||
|
|
||||||
setFieldErrors({ phone: phoneCheck.message ?? '该手机号不可用于门店账号' });
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await sendStorePhoneSms(phone);
|
|
||||||
|
|
||||||
setSmsHint(`验证码已发送至 ${res.maskedPhone}`);
|
|
||||||
|
|
||||||
setSmsCooldown(60);
|
|
||||||
|
|
||||||
const timer = setInterval(() => {
|
|
||||||
|
|
||||||
setSmsCooldown((s) => {
|
|
||||||
|
|
||||||
if (s <= 1) {
|
|
||||||
|
|
||||||
clearInterval(timer);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return s - 1;
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
|
|
||||||
const msg = e instanceof Error ? e.message : '验证码发送失败';
|
|
||||||
|
|
||||||
setFieldErrors({ phone: msg });
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function handleNext() {
|
async function handleNext() {
|
||||||
|
|
||||||
if (step === 1) {
|
if (step === 1) {
|
||||||
@@ -402,11 +327,7 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
if (isPhoneValidationMessage(msg)) {
|
if (isPhoneValidationMessage(msg)) {
|
||||||
if (msg.includes('验证码')) {
|
setFieldErrors({ phone: msg });
|
||||||
setFieldErrors({ storeSmsCode: msg });
|
|
||||||
} else {
|
|
||||||
setFieldErrors({ phone: msg });
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reportFormError(msg);
|
reportFormError(msg);
|
||||||
@@ -502,19 +423,31 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
phone: form.phone.trim(),
|
phone: form.phone.trim(),
|
||||||
|
|
||||||
smsCode: form.storeSmsCode.trim(),
|
|
||||||
|
|
||||||
district: form.district.trim(),
|
district: form.district.trim(),
|
||||||
|
|
||||||
address: form.address.trim(),
|
address: form.address.trim(),
|
||||||
|
|
||||||
|
...(form.latitude.trim() && form.longitude.trim()
|
||||||
|
? {
|
||||||
|
latitude: Number(form.latitude),
|
||||||
|
longitude: Number(form.longitude),
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
|
||||||
openTime: form.openTime.trim(),
|
openTime: form.openTime.trim(),
|
||||||
|
|
||||||
closeTime: form.closeTime.trim(),
|
closeTime: form.closeTime.trim(),
|
||||||
|
|
||||||
|
...(form.dualHours
|
||||||
|
? { openTime2: form.openTime2.trim(), closeTime2: form.closeTime2.trim() }
|
||||||
|
: {}),
|
||||||
|
|
||||||
|
...(form.avgPrice.trim() ? { avgPrice: Number(form.avgPrice) } : {}),
|
||||||
|
|
||||||
categoryId: form.categoryId.trim(),
|
categoryId: form.categoryId.trim(),
|
||||||
|
|
||||||
intro: form.intro.trim() || undefined,
|
intro: form.intro.trim() || undefined,
|
||||||
|
benefitUsageRule: form.benefitUsageRule.trim() || undefined,
|
||||||
|
|
||||||
coverUrl: form.coverUrl.trim() || undefined,
|
coverUrl: form.coverUrl.trim() || undefined,
|
||||||
|
|
||||||
@@ -539,7 +472,6 @@ export default function StoreCreatePage() {
|
|||||||
setForm(defaultStoreForm());
|
setForm(defaultStoreForm());
|
||||||
setFieldErrors({});
|
setFieldErrors({});
|
||||||
setSubmitError('');
|
setSubmitError('');
|
||||||
setSmsHint('');
|
|
||||||
setParams({ step: '1' }, { replace: true });
|
setParams({ step: '1' }, { replace: true });
|
||||||
toastSuccess('门店录入成功');
|
toastSuccess('门店录入成功');
|
||||||
navigate(`/stores/${result.store.id}`);
|
navigate(`/stores/${result.store.id}`);
|
||||||
@@ -549,11 +481,6 @@ export default function StoreCreatePage() {
|
|||||||
setFieldErrors({ phone: message });
|
setFieldErrors({ phone: message });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (/验证码/.test(message)) {
|
|
||||||
setFieldErrors({ storeSmsCode: message });
|
|
||||||
goStep(3);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setSubmitError(message);
|
setSubmitError(message);
|
||||||
toastError(message);
|
toastError(message);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -734,13 +661,54 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
<textarea rows={2} placeholder="请输入详细门牌号" value={form.address} onChange={(e) => patchForm({ address: e.target.value })} />
|
<textarea rows={2} placeholder="请输入详细门牌号" value={form.address} onChange={(e) => patchForm({ address: e.target.value })} />
|
||||||
|
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 8, flexWrap: 'wrap' }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
style={{ padding: '8px 12px', fontSize: 13 }}
|
||||||
|
disabled={locating}
|
||||||
|
onClick={() => {
|
||||||
|
void (async () => {
|
||||||
|
setLocating(true);
|
||||||
|
try {
|
||||||
|
const pos = await locateStorePosition();
|
||||||
|
patchForm({
|
||||||
|
latitude: String(pos.latitude),
|
||||||
|
longitude: String(pos.longitude),
|
||||||
|
});
|
||||||
|
toastSuccess('已获取当前坐标');
|
||||||
|
} catch (e) {
|
||||||
|
toastError(e instanceof Error ? e.message : '定位失败');
|
||||||
|
} finally {
|
||||||
|
setLocating(false);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{locating ? '定位中…' : '获取当前位置'}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
style={{ padding: '8px 12px', fontSize: 13 }}
|
||||||
|
onClick={() => setMapPickerOpen(true)}
|
||||||
|
>
|
||||||
|
地图选点
|
||||||
|
</button>
|
||||||
|
<span className="label-md text-muted">
|
||||||
|
{formatStoreCoords(form.latitude, form.longitude)
|
||||||
|
? `坐标:${formatStoreCoords(form.latitude, form.longitude)}`
|
||||||
|
: '未定位(可定位或地图选点)'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="partner-field">
|
<div className="partner-field">
|
||||||
|
|
||||||
<label>营业时间 <span className="text-primary">*</span></label>
|
<label>营业时间 <span className="text-primary">*</span></label>
|
||||||
|
|
||||||
<div className="partner-input-row" style={{ alignItems: 'center', gap: 8 }}>
|
<div className="partner-input-row" style={{ alignItems: 'center', gap: 8, marginBottom: 8 }}>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
|
||||||
@@ -774,19 +742,97 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label className="partner-checkbox-row" style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
|
||||||
|
|
||||||
|
<input
|
||||||
|
|
||||||
|
type="checkbox"
|
||||||
|
|
||||||
|
checked={form.dualHours}
|
||||||
|
|
||||||
|
onChange={(e) => patchForm({ dualHours: e.target.checked })}
|
||||||
|
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className="label-md">启用第二段营业时间(如午市/晚市)</span>
|
||||||
|
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{form.dualHours ? (
|
||||||
|
|
||||||
|
<div className="partner-input-row" style={{ alignItems: 'center', gap: 8 }}>
|
||||||
|
|
||||||
|
<input
|
||||||
|
|
||||||
|
className="partner-field-input partner-field-input--block"
|
||||||
|
|
||||||
|
type="time"
|
||||||
|
|
||||||
|
value={form.openTime2}
|
||||||
|
|
||||||
|
onChange={(e) => patchForm({ openTime2: e.target.value })}
|
||||||
|
|
||||||
|
aria-label="第二段开始"
|
||||||
|
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className="label-md text-muted">至</span>
|
||||||
|
|
||||||
|
<input
|
||||||
|
|
||||||
|
className="partner-field-input partner-field-input--block"
|
||||||
|
|
||||||
|
type="time"
|
||||||
|
|
||||||
|
value={form.closeTime2}
|
||||||
|
|
||||||
|
onChange={(e) => patchForm({ closeTime2: e.target.value })}
|
||||||
|
|
||||||
|
aria-label="第二段结束"
|
||||||
|
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
) : null}
|
||||||
|
|
||||||
<p className="label-md text-muted" style={{ marginTop: 8 }}>
|
<p className="label-md text-muted" style={{ marginTop: 8 }}>
|
||||||
|
|
||||||
将展示给用户端与门店端,默认 10:00–22:00,可按实际调整。
|
支持 1 段(如 09:00-22:00)或 2 段(如 09:00-14:00,17:00-21:00)。
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="partner-field">
|
||||||
|
|
||||||
|
<label>人均费用(选填)</label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
|
||||||
|
className="partner-field-input partner-field-input--block"
|
||||||
|
|
||||||
|
type="number"
|
||||||
|
|
||||||
|
min={0}
|
||||||
|
|
||||||
|
step={1}
|
||||||
|
|
||||||
|
placeholder="如 88,用户端门店页展示"
|
||||||
|
|
||||||
|
value={form.avgPrice}
|
||||||
|
|
||||||
|
onChange={(e) => patchForm({ avgPrice: e.target.value })}
|
||||||
|
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="partner-field">
|
<div className="partner-field">
|
||||||
|
|
||||||
<label>门店简介</label>
|
<label>门店简介</label>
|
||||||
|
|
||||||
<textarea rows={4} placeholder="请输入门店简介 (10-500字)" value={form.intro} onChange={(e) => patchForm({ intro: e.target.value })} />
|
<textarea rows={4} placeholder="请输入门店简介 (2-500字)" value={form.intro} onChange={(e) => patchForm({ intro: e.target.value })} />
|
||||||
|
|
||||||
<div style={{ textAlign: 'right', marginTop: 4 }}>
|
<div style={{ textAlign: 'right', marginTop: 4 }}>
|
||||||
|
|
||||||
@@ -796,6 +842,26 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="partner-field">
|
||||||
|
|
||||||
|
<label>好客权益券使用规则</label>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
rows={4}
|
||||||
|
placeholder="选填,展示在用户端门店详情,最多1000字"
|
||||||
|
maxLength={1000}
|
||||||
|
value={form.benefitUsageRule}
|
||||||
|
onChange={(e) => patchForm({ benefitUsageRule: e.target.value })}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div style={{ textAlign: 'right', marginTop: 4 }}>
|
||||||
|
|
||||||
|
<span className="label-md text-muted">{form.benefitUsageRule.length} / 1000</span>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div className="partner-info-banner">
|
<div className="partner-info-banner">
|
||||||
@@ -1040,74 +1106,11 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
<p className="label-md text-muted" style={{ marginTop: 8 }}>
|
<p className="label-md text-muted" style={{ marginTop: 8 }}>
|
||||||
|
|
||||||
该手机号将作为门店端登录账号,验证码发送至该号确认后方可提交。
|
该手机号将作为门店端登录账号。
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="partner-field">
|
|
||||||
|
|
||||||
<label>门店账号验证码 <span className="text-primary">*</span></label>
|
|
||||||
|
|
||||||
<div className="partner-input-row">
|
|
||||||
|
|
||||||
<div className="partner-input-wrap" style={{ flex: 1 }}>
|
|
||||||
|
|
||||||
<span className="material-symbols-outlined partner-input-icon">shield</span>
|
|
||||||
|
|
||||||
<input
|
|
||||||
|
|
||||||
className="partner-input"
|
|
||||||
|
|
||||||
type="text"
|
|
||||||
|
|
||||||
inputMode="numeric"
|
|
||||||
|
|
||||||
maxLength={6}
|
|
||||||
|
|
||||||
placeholder="请输入短信验证码"
|
|
||||||
|
|
||||||
value={form.storeSmsCode}
|
|
||||||
|
|
||||||
onChange={(e) => patchForm({ storeSmsCode: e.target.value.replace(/\D/g, '') })}
|
|
||||||
|
|
||||||
/>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
|
|
||||||
type="button"
|
|
||||||
|
|
||||||
className="partner-code-btn"
|
|
||||||
|
|
||||||
disabled={smsCooldown > 0 || submitting}
|
|
||||||
|
|
||||||
onClick={() => void sendStorePhoneCode()}
|
|
||||||
|
|
||||||
>
|
|
||||||
|
|
||||||
{smsCooldown > 0 ? `${smsCooldown}s` : '获取验证码'}
|
|
||||||
|
|
||||||
</button>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{smsHint && (
|
|
||||||
|
|
||||||
<p className="label-md text-muted" style={{ marginTop: 8 }}>{smsHint}</p>
|
|
||||||
|
|
||||||
)}
|
|
||||||
|
|
||||||
{fieldErrors.storeSmsCode && (
|
|
||||||
|
|
||||||
<p className="partner-field-error" role="alert">{fieldErrors.storeSmsCode}</p>
|
|
||||||
|
|
||||||
)}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
@@ -1150,6 +1153,23 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<TencentLocPickerOverlay
|
||||||
|
open={mapPickerOpen}
|
||||||
|
onClose={() => setMapPickerOpen(false)}
|
||||||
|
latitude={form.latitude ? Number(form.latitude) : undefined}
|
||||||
|
longitude={form.longitude ? Number(form.longitude) : undefined}
|
||||||
|
onPick={(loc) => {
|
||||||
|
patchForm({
|
||||||
|
latitude: String(loc.latitude),
|
||||||
|
longitude: String(loc.longitude),
|
||||||
|
...(loc.address && !form.address.trim() ? { address: loc.address } : {}),
|
||||||
|
});
|
||||||
|
toastSuccess(
|
||||||
|
`已选点 ${loc.latitude.toFixed(6)}, ${loc.longitude.toFixed(6)}${loc.name ? `(${loc.name})` : ''}`,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import AppImage from '@dukang/shared-ui/AppImage';
|
import AppImage from '@dukang/shared-ui/AppImage';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { toastSuccess } from '../lib/toast';
|
import { toastError, toastSuccess } from '../lib/toast';
|
||||||
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
||||||
import { canManagePartnerStore } from '../lib/partnerAccess';
|
import { canManagePartnerStore } from '../lib/partnerAccess';
|
||||||
import { normalizeStringArray, patchEnvPhotoAt } from '../lib/storeDraft';
|
import { normalizeStringArray, patchEnvPhotoAt } from '../lib/storeDraft';
|
||||||
|
import { formatStoreCoords, locateStorePosition } from '../lib/storeLocate';
|
||||||
import OssUploadField from '../components/OssUploadField';
|
import OssUploadField from '../components/OssUploadField';
|
||||||
|
import TencentLocPickerOverlay from '../components/TencentLocPickerOverlay';
|
||||||
import {
|
import {
|
||||||
canPartnerOpenStore,
|
canPartnerOpenStore,
|
||||||
storeAuditLabel,
|
storeAuditLabel,
|
||||||
@@ -38,13 +40,23 @@ export default function StoreDetailPage() {
|
|||||||
const canMutate = canManagePartnerStore(account);
|
const canMutate = canManagePartnerStore(account);
|
||||||
const [store, setStore] = useState<Record<string, unknown> | null>(null);
|
const [store, setStore] = useState<Record<string, unknown> | null>(null);
|
||||||
const [loadError, setLoadError] = useState('');
|
const [loadError, setLoadError] = useState('');
|
||||||
const [form, setForm] = useState({ name: '', phone: '', address: '', intro: '' });
|
const [form, setForm] = useState({
|
||||||
|
name: '',
|
||||||
|
phone: '',
|
||||||
|
address: '',
|
||||||
|
intro: '',
|
||||||
|
benefitUsageRule: '',
|
||||||
|
latitude: '',
|
||||||
|
longitude: '',
|
||||||
|
});
|
||||||
const [coverUrl, setCoverUrl] = useState('');
|
const [coverUrl, setCoverUrl] = useState('');
|
||||||
const [envPhotoUrls, setEnvPhotoUrls] = useState<string[]>(['', '', '']);
|
const [envPhotoUrls, setEnvPhotoUrls] = useState<string[]>(['', '', '']);
|
||||||
const [status, setStatus] = useState<StoreStatusValue>('OPEN');
|
const [status, setStatus] = useState<StoreStatusValue>('OPEN');
|
||||||
const [statusSaving, setStatusSaving] = useState(false);
|
const [statusSaving, setStatusSaving] = useState(false);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [mediaSaving, setMediaSaving] = useState(false);
|
const [mediaSaving, setMediaSaving] = useState(false);
|
||||||
|
const [locating, setLocating] = useState(false);
|
||||||
|
const [mapPickerOpen, setMapPickerOpen] = useState(false);
|
||||||
const [actionError, setActionError] = useState('');
|
const [actionError, setActionError] = useState('');
|
||||||
const [closeConfirmOpen, setCloseConfirmOpen] = useState(false);
|
const [closeConfirmOpen, setCloseConfirmOpen] = useState(false);
|
||||||
|
|
||||||
@@ -55,6 +67,12 @@ export default function StoreDetailPage() {
|
|||||||
phone: String(data.phone || ''),
|
phone: String(data.phone || ''),
|
||||||
address: String(data.address || ''),
|
address: String(data.address || ''),
|
||||||
intro: String(data.intro || ''),
|
intro: String(data.intro || ''),
|
||||||
|
benefitUsageRule: (() => {
|
||||||
|
const raw = String(data.benefitUsageRule || '').trim();
|
||||||
|
return raw && !/^null$/i.test(raw) ? raw : '';
|
||||||
|
})(),
|
||||||
|
latitude: data.latitude != null && data.latitude !== '' ? String(data.latitude) : '',
|
||||||
|
longitude: data.longitude != null && data.longitude !== '' ? String(data.longitude) : '',
|
||||||
});
|
});
|
||||||
setStatus(String(data.status || 'OPEN').toUpperCase() as StoreStatusValue);
|
setStatus(String(data.status || 'OPEN').toUpperCase() as StoreStatusValue);
|
||||||
setCoverUrl(String(data.coverUrl || ''));
|
setCoverUrl(String(data.coverUrl || ''));
|
||||||
@@ -149,6 +167,13 @@ export default function StoreDetailPage() {
|
|||||||
phone: form.phone.trim(),
|
phone: form.phone.trim(),
|
||||||
address: form.address.trim(),
|
address: form.address.trim(),
|
||||||
intro: form.intro.trim(),
|
intro: form.intro.trim(),
|
||||||
|
benefitUsageRule: form.benefitUsageRule.trim() || null,
|
||||||
|
...(form.latitude.trim() && form.longitude.trim()
|
||||||
|
? {
|
||||||
|
latitude: Number(form.latitude),
|
||||||
|
longitude: Number(form.longitude),
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
applyStore(data);
|
applyStore(data);
|
||||||
@@ -319,14 +344,78 @@ export default function StoreDetailPage() {
|
|||||||
<div className="partner-field">
|
<div className="partner-field">
|
||||||
<label>门店地址</label>
|
<label>门店地址</label>
|
||||||
<textarea disabled={readOnly} rows={2} value={form.address} onChange={(e) => setForm({ ...form, address: e.target.value })} />
|
<textarea disabled={readOnly} rows={2} value={form.address} onChange={(e) => setForm({ ...form, address: e.target.value })} />
|
||||||
|
{!readOnly ? (
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 8, flexWrap: 'wrap' }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
style={{ padding: '8px 12px', fontSize: 13 }}
|
||||||
|
disabled={locating}
|
||||||
|
onClick={() => {
|
||||||
|
void (async () => {
|
||||||
|
setLocating(true);
|
||||||
|
setActionError('');
|
||||||
|
try {
|
||||||
|
const pos = await locateStorePosition();
|
||||||
|
setForm((prev) => ({
|
||||||
|
...prev,
|
||||||
|
latitude: String(pos.latitude),
|
||||||
|
longitude: String(pos.longitude),
|
||||||
|
}));
|
||||||
|
toastSuccess('已获取当前坐标');
|
||||||
|
} catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : '定位失败';
|
||||||
|
setActionError(msg);
|
||||||
|
toastError(msg);
|
||||||
|
} finally {
|
||||||
|
setLocating(false);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{locating ? '定位中…' : '获取当前位置'}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
style={{ padding: '8px 12px', fontSize: 13 }}
|
||||||
|
onClick={() => setMapPickerOpen(true)}
|
||||||
|
>
|
||||||
|
地图选点
|
||||||
|
</button>
|
||||||
|
<span className="label-md text-muted">
|
||||||
|
{formatStoreCoords(form.latitude, form.longitude)
|
||||||
|
? `坐标:${formatStoreCoords(form.latitude, form.longitude)}`
|
||||||
|
: '未定位'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : formatStoreCoords(form.latitude, form.longitude) ? (
|
||||||
|
<p className="label-md text-muted" style={{ marginTop: 6 }}>
|
||||||
|
坐标:{formatStoreCoords(form.latitude, form.longitude)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
<div className="partner-field">
|
<div className="partner-field">
|
||||||
<label>门店简介</label>
|
<label>门店简介</label>
|
||||||
<textarea disabled={readOnly} rows={4} placeholder="请输入门店简介(10-500字)" value={form.intro} onChange={(e) => setForm({ ...form, intro: e.target.value })} />
|
<textarea disabled={readOnly} rows={4} placeholder="请输入门店简介(2-500字)" value={form.intro} onChange={(e) => setForm({ ...form, intro: e.target.value })} />
|
||||||
<div style={{ textAlign: 'right', marginTop: 4 }}>
|
<div style={{ textAlign: 'right', marginTop: 4 }}>
|
||||||
<span className="label-md text-muted">{form.intro.length} / 500</span>
|
<span className="label-md text-muted">{form.intro.length} / 500</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="partner-field">
|
||||||
|
<label>好客权益券使用规则</label>
|
||||||
|
<textarea
|
||||||
|
disabled={readOnly}
|
||||||
|
rows={4}
|
||||||
|
placeholder="选填,展示在用户端门店详情,最多1000字"
|
||||||
|
maxLength={1000}
|
||||||
|
value={form.benefitUsageRule}
|
||||||
|
onChange={(e) => setForm({ ...form, benefitUsageRule: e.target.value })}
|
||||||
|
/>
|
||||||
|
<div style={{ textAlign: 'right', marginTop: 4 }}>
|
||||||
|
<span className="label-md text-muted">{form.benefitUsageRule.length} / 1000</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className="partner-form-card" style={{ margin: '0 0 16px' }}>
|
<section className="partner-form-card" style={{ margin: '0 0 16px' }}>
|
||||||
@@ -421,6 +510,24 @@ export default function StoreDetailPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<TencentLocPickerOverlay
|
||||||
|
open={mapPickerOpen}
|
||||||
|
onClose={() => setMapPickerOpen(false)}
|
||||||
|
latitude={form.latitude ? Number(form.latitude) : undefined}
|
||||||
|
longitude={form.longitude ? Number(form.longitude) : undefined}
|
||||||
|
onPick={(loc) => {
|
||||||
|
setForm((prev) => ({
|
||||||
|
...prev,
|
||||||
|
latitude: String(loc.latitude),
|
||||||
|
longitude: String(loc.longitude),
|
||||||
|
...(loc.address && !prev.address.trim() ? { address: loc.address } : {}),
|
||||||
|
}));
|
||||||
|
toastSuccess(
|
||||||
|
`已选点 ${loc.latitude.toFixed(6)}, ${loc.longitude.toFixed(6)}${loc.name ? `(${loc.name})` : ''}`,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3315,6 +3315,145 @@ body {
|
|||||||
border-top: 1px dashed rgba(166, 29, 36, 0.15);
|
border-top: 1px dashed rgba(166, 29, 36, 0.15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.partner-proxy-mode-tabs {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-mode-tab {
|
||||||
|
flex: 1;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
background: #fff;
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--color-ink-black);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-mode-tab.is-active {
|
||||||
|
border-color: var(--color-heritage-red);
|
||||||
|
color: var(--color-heritage-red);
|
||||||
|
background: rgba(166, 29, 36, 0.06);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-auto-receive {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 8px;
|
||||||
|
margin: 4px 0 16px;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.45;
|
||||||
|
color: var(--color-ink-black);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-auto-receive input {
|
||||||
|
margin-top: 3px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-picker {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
padding: 12px 36px 12px 14px;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
background: #fff;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-picker-arrow {
|
||||||
|
position: absolute;
|
||||||
|
right: 14px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
font-size: 22px;
|
||||||
|
color: var(--color-muted, #999);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-list {
|
||||||
|
padding: 0 16px 24px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-card {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 16px;
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-card--active {
|
||||||
|
border-color: var(--color-heritage-red);
|
||||||
|
box-shadow: 0 0 0 1px rgba(166, 29, 36, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-thumb {
|
||||||
|
width: 72px;
|
||||||
|
height: 72px;
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #f3f1ee;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-thumb img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-thumb-empty {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: linear-gradient(135deg, #f3f1ee, #e8e4de);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-main {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-name {
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 15px;
|
||||||
|
color: var(--color-ink-black);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-price {
|
||||||
|
color: var(--color-heritage-red);
|
||||||
|
font-weight: 600;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-product-spec,
|
||||||
|
.partner-proxy-product-benefit {
|
||||||
|
margin: 4px 0 0;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--color-muted, #888);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-proxy-confirm {
|
||||||
|
padding-top: 8px;
|
||||||
|
border-top: 1px dashed rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
.partner-warehouse-denied {
|
.partner-warehouse-denied {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -10,13 +10,11 @@ function formatMoney(n: number) {
|
|||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [dash, setDash] = useState<Record<string, unknown> | null>(null);
|
const [dash, setDash] = useState<Record<string, unknown> | null>(null);
|
||||||
const [open, setOpen] = useState(true);
|
|
||||||
|
|
||||||
const loadDashboard = useCallback(() => {
|
const loadDashboard = useCallback(() => {
|
||||||
return request<Record<string, unknown>>('SHOP_H5', '/shop/dashboard')
|
return request<Record<string, unknown>>('SHOP_H5', '/shop/dashboard')
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
setDash(d);
|
setDash(d);
|
||||||
setOpen(String((d.store as Record<string, unknown>)?.status) === 'OPEN');
|
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
@@ -44,8 +42,14 @@ export default function HomePage() {
|
|||||||
|
|
||||||
const store = dash?.store as Record<string, unknown> | undefined;
|
const store = dash?.store as Record<string, unknown> | undefined;
|
||||||
const recent = (dash?.recentRecords as Array<Record<string, unknown>>) || [];
|
const recent = (dash?.recentRecords as Array<Record<string, unknown>>) || [];
|
||||||
const openTime = String(store?.openTime || '10:00');
|
const status = String(store?.status || '');
|
||||||
const closeTime = String(store?.closeTime || '22:00');
|
const open = status === 'OPEN';
|
||||||
|
const hoursParts: string[] = [];
|
||||||
|
if (store?.openTime && store?.closeTime) hoursParts.push(`${store.openTime} - ${store.closeTime}`);
|
||||||
|
if (store?.openTime2 && store?.closeTime2) hoursParts.push(`${store.openTime2} - ${store.closeTime2}`);
|
||||||
|
const hoursText = hoursParts.length ? hoursParts.join(',') : '10:00 - 22:00';
|
||||||
|
const statusText =
|
||||||
|
status === 'CLOSED' ? '永久关闭' : open ? '当前正在营业中' : '当前临时闭店';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PullToRefresh onRefresh={loadDashboard} className="shop-home-page">
|
<PullToRefresh onRefresh={loadDashboard} className="shop-home-page">
|
||||||
@@ -91,12 +95,12 @@ export default function HomePage() {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p className="shop-home-status-title">营业状态</p>
|
<p className="shop-home-status-title">营业状态</p>
|
||||||
<p className="shop-home-status-sub">{open ? '当前正在营业中' : '当前已停止营业'}</p>
|
<p className="shop-home-status-sub">{statusText}</p>
|
||||||
<p className="shop-home-status-sub">营业时间: {openTime} - {closeTime}</p>
|
<p className="shop-home-status-sub">营业时间: {hoursText}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<label className="shop-home-switch" onClick={() => navigate('/status')}>
|
<label className="shop-home-switch" onClick={() => navigate('/status')}>
|
||||||
<input type="checkbox" checked={open} readOnly tabIndex={-1} />
|
<input type="checkbox" checked={open && status !== 'CLOSED'} readOnly tabIndex={-1} />
|
||||||
<span className="shop-home-switch-track" />
|
<span className="shop-home-switch-track" />
|
||||||
</label>
|
</label>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -58,8 +58,10 @@ export default function MinePage() {
|
|||||||
.catch((e) => setBindMsg(e instanceof Error ? e.message : '微信绑定失败'));
|
.catch((e) => setBindMsg(e instanceof Error ? e.message : '微信绑定失败'));
|
||||||
}, [applySession, searchParams, setSearchParams, wxAuthorize]);
|
}, [applySession, searchParams, setSearchParams, wxAuthorize]);
|
||||||
|
|
||||||
const openTime = String(store?.openTime || '09:30');
|
const hoursParts: string[] = [];
|
||||||
const closeTime = String(store?.closeTime || '22:00');
|
if (store?.openTime && store?.closeTime) hoursParts.push(`${store.openTime} - ${store.closeTime}`);
|
||||||
|
if (store?.openTime2 && store?.closeTime2) hoursParts.push(`${store.openTime2} - ${store.closeTime2}`);
|
||||||
|
const hoursText = hoursParts.length ? hoursParts.join(',') : '09:30 - 22:00';
|
||||||
const multiStore = (profile?.stores?.length ?? 0) > 1;
|
const multiStore = (profile?.stores?.length ?? 0) > 1;
|
||||||
const showBindWechat = wxAuthorize && hasWechat === false;
|
const showBindWechat = wxAuthorize && hasWechat === false;
|
||||||
|
|
||||||
@@ -126,7 +128,7 @@ export default function MinePage() {
|
|||||||
<div className="shop-mine-info-row">
|
<div className="shop-mine-info-row">
|
||||||
<div>
|
<div>
|
||||||
<p className="shop-mine-info-label">营业时间</p>
|
<p className="shop-mine-info-label">营业时间</p>
|
||||||
<p className="shop-mine-info-value">{openTime} - {closeTime}</p>
|
<p className="shop-mine-info-value">{hoursText}</p>
|
||||||
</div>
|
</div>
|
||||||
<span className="material-symbols-outlined shop-mine-lock">lock</span>
|
<span className="material-symbols-outlined shop-mine-lock">lock</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ export default function SelectStorePage() {
|
|||||||
|
|
||||||
function statusLabel(status: string) {
|
function statusLabel(status: string) {
|
||||||
if (status === 'OPEN') return '营业中';
|
if (status === 'OPEN') return '营业中';
|
||||||
if (status === 'PAUSED') return '暂停营业';
|
if (status === 'PAUSED') return '临时闭店';
|
||||||
|
if (status === 'CLOSED') return '永久关闭';
|
||||||
return status || '门店';
|
return status || '门店';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,35 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import { useStoreSession } from '../contexts/StoreSessionContext';
|
import { useStoreSession } from '../contexts/StoreSessionContext';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
|
||||||
|
function formatShopHours(store: Record<string, unknown> | null) {
|
||||||
|
const parts: string[] = [];
|
||||||
|
const openTime = store?.openTime ? String(store.openTime) : '';
|
||||||
|
const closeTime = store?.closeTime ? String(store.closeTime) : '';
|
||||||
|
const openTime2 = store?.openTime2 ? String(store.openTime2) : '';
|
||||||
|
const closeTime2 = store?.closeTime2 ? String(store.closeTime2) : '';
|
||||||
|
if (openTime && closeTime) parts.push(`${openTime} - ${closeTime}`);
|
||||||
|
if (openTime2 && closeTime2) parts.push(`${openTime2} - ${closeTime2}`);
|
||||||
|
return parts.length ? parts.join(',') : '09:30 - 22:00';
|
||||||
|
}
|
||||||
|
|
||||||
export default function StatusPage() {
|
export default function StatusPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { resetSession } = useStoreSession();
|
const { resetSession } = useStoreSession();
|
||||||
const [open, setOpen] = useState(true);
|
const [open, setOpen] = useState(true);
|
||||||
|
const [permanentlyClosed, setPermanentlyClosed] = useState(false);
|
||||||
const [store, setStore] = useState<Record<string, unknown> | null>(null);
|
const [store, setStore] = useState<Record<string, unknown> | null>(null);
|
||||||
const [lastUpdate, setLastUpdate] = useState('');
|
const [lastUpdate, setLastUpdate] = useState('');
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
const [pendingOpen, setPendingOpen] = useState<boolean | null>(null);
|
const [pendingOpen, setPendingOpen] = useState<boolean | null>(null);
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
request('SHOP_H5', '/shop/dashboard').then((d) => {
|
request('SHOP_H5', '/shop/dashboard').then((d) => {
|
||||||
const s = d.store as Record<string, unknown>;
|
const s = d.store as Record<string, unknown>;
|
||||||
setStore(s);
|
setStore(s);
|
||||||
setOpen(String(s?.status) === 'OPEN');
|
const status = String(s?.status || '');
|
||||||
|
setPermanentlyClosed(status === 'CLOSED');
|
||||||
|
setOpen(status === 'OPEN');
|
||||||
if (s?.updatedAt) {
|
if (s?.updatedAt) {
|
||||||
setLastUpdate(new Date(String(s.updatedAt)).toLocaleString('zh-CN'));
|
setLastUpdate(new Date(String(s.updatedAt)).toLocaleString('zh-CN'));
|
||||||
}
|
}
|
||||||
@@ -24,31 +39,33 @@ export default function StatusPage() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function requestToggle(next: boolean) {
|
function requestToggle(next: boolean) {
|
||||||
|
if (permanentlyClosed) return;
|
||||||
if (next === open) return;
|
if (next === open) return;
|
||||||
setPendingOpen(next);
|
setPendingOpen(next);
|
||||||
setShowModal(true);
|
setShowModal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function confirmToggle() {
|
async function confirmToggle() {
|
||||||
if (pendingOpen === null) return;
|
if (pendingOpen === null || permanentlyClosed) return;
|
||||||
const next = pendingOpen ? 'OPEN' : 'PAUSED';
|
const next = pendingOpen ? 'OPEN' : 'PAUSED';
|
||||||
try {
|
try {
|
||||||
|
setError('');
|
||||||
await request('SHOP_H5', '/shop/store/status', {
|
await request('SHOP_H5', '/shop/store/status', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify({ status: next }),
|
body: JSON.stringify({ status: next }),
|
||||||
});
|
});
|
||||||
setOpen(pendingOpen);
|
setOpen(pendingOpen);
|
||||||
setLastUpdate(new Date().toLocaleString('zh-CN'));
|
setLastUpdate(new Date().toLocaleString('zh-CN'));
|
||||||
} catch {
|
} catch (e) {
|
||||||
/* keep current state */
|
setError(e instanceof Error ? e.message : '状态切换失败');
|
||||||
} finally {
|
} finally {
|
||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
setPendingOpen(null);
|
setPendingOpen(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const openTime = String(store?.openTime || '09:30');
|
const hoursText = formatShopHours(store);
|
||||||
const closeTime = String(store?.closeTime || '22:00');
|
const statusLabel = permanentlyClosed ? '永久关闭' : open ? '营业中' : '临时闭店';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="shop-status-page">
|
<div className="shop-status-page">
|
||||||
@@ -70,46 +87,61 @@ export default function StatusPage() {
|
|||||||
<div className="shop-status-content">
|
<div className="shop-status-content">
|
||||||
<section className="shop-status-card">
|
<section className="shop-status-card">
|
||||||
<div className="shop-status-icon-wrap">
|
<div className="shop-status-icon-wrap">
|
||||||
<div className={`shop-status-icon-outer${open ? ' open' : ' closed'}`}>
|
<div className={`shop-status-icon-outer${open && !permanentlyClosed ? ' open' : ' closed'}`}>
|
||||||
<div className={`shop-status-icon-inner${open ? ' open' : ' closed'}`}>
|
<div className={`shop-status-icon-inner${open && !permanentlyClosed ? ' open' : ' closed'}`}>
|
||||||
<span className="material-symbols-outlined">storefront</span>
|
<span className="material-symbols-outlined">storefront</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span className="shop-status-check">
|
<span className="shop-status-check">
|
||||||
<span className={`material-symbols-outlined shop-fill-icon${open ? '' : ''}`} style={{ fontSize: 14, color: open ? 'var(--color-success-green)' : 'var(--color-subtle-gray)' }}>
|
<span
|
||||||
{open ? 'check_circle' : 'cancel'}
|
className="material-symbols-outlined shop-fill-icon"
|
||||||
|
style={{
|
||||||
|
fontSize: 14,
|
||||||
|
color: open && !permanentlyClosed ? 'var(--color-success-green)' : 'var(--color-subtle-gray)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{open && !permanentlyClosed ? 'check_circle' : 'cancel'}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2 className={`shop-status-label${open ? ' open' : ' closed'}`}>
|
<h2 className={`shop-status-label${open && !permanentlyClosed ? ' open' : ' closed'}`}>
|
||||||
{open ? '营业中' : '临时闭店'}
|
{statusLabel}
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<label className={`shop-status-switch${open ? ' open' : ' closed'}`}>
|
{permanentlyClosed ? (
|
||||||
<input
|
<p className="shop-status-switch-caption" style={{ marginTop: 12 }}>
|
||||||
type="checkbox"
|
总部已永久关闭本店,门店端无法自行恢复营业
|
||||||
checked={open}
|
</p>
|
||||||
onChange={(e) => requestToggle(e.target.checked)}
|
) : (
|
||||||
aria-label={open ? '切换为临时闭店' : '切换为营业中'}
|
<label className={`shop-status-switch${open ? ' open' : ' closed'}`}>
|
||||||
/>
|
<input
|
||||||
<span className="shop-status-switch-track" />
|
type="checkbox"
|
||||||
<span className="shop-status-switch-caption">
|
checked={open}
|
||||||
{open ? '点击可临时闭店' : '点击恢复营业'}
|
onChange={(e) => requestToggle(e.target.checked)}
|
||||||
</span>
|
aria-label={open ? '切换为临时闭店' : '切换为营业中'}
|
||||||
</label>
|
/>
|
||||||
|
<span className="shop-status-switch-track" />
|
||||||
|
<span className="shop-status-switch-caption">
|
||||||
|
{open ? '点击可临时闭店' : '点击恢复营业'}
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
|
||||||
<p className="shop-status-hours-label">营业时间</p>
|
<p className="shop-status-hours-label">营业时间</p>
|
||||||
<p className="shop-status-hours">{openTime} - {closeTime}</p>
|
<p className="shop-status-hours">{hoursText}</p>
|
||||||
{lastUpdate && <p className="shop-status-updated">最后修改于 {lastUpdate}</p>}
|
{lastUpdate && <p className="shop-status-updated">最后修改于 {lastUpdate}</p>}
|
||||||
|
{error ? <p className="shop-status-updated" style={{ color: 'var(--color-error, #c62828)' }}>{error}</p> : null}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div className={`shop-status-hint${open ? ' open' : ' closed'}`}>
|
<div className={`shop-status-hint${open && !permanentlyClosed ? ' open' : ' closed'}`}>
|
||||||
<span className="material-symbols-outlined">info</span>
|
<span className="material-symbols-outlined">info</span>
|
||||||
<p>
|
<p>
|
||||||
{open
|
{permanentlyClosed
|
||||||
? '当前处于营业状态,用户可在您的门店核销餐券。'
|
? '门店已永久关闭。如需重新营业,请联系总部或合伙人处理。'
|
||||||
: '当前处于休息状态,用户将无法看到您的门店或进行核销。'}
|
: open
|
||||||
|
? '当前处于营业状态,用户可在您的门店核销餐券。'
|
||||||
|
: '当前处于临时闭店状态,用户将无法看到您的门店或进行核销。'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ type Order = {
|
|||||||
id: string;
|
id: string;
|
||||||
orderNo: string;
|
orderNo: string;
|
||||||
orderType?: string;
|
orderType?: string;
|
||||||
|
isProxyOrder?: boolean;
|
||||||
|
proxyPartnerName?: string | null;
|
||||||
status: string;
|
status: string;
|
||||||
originOrderId?: string | null;
|
originOrderId?: string | null;
|
||||||
remark?: string | null;
|
remark?: string | null;
|
||||||
@@ -138,6 +140,7 @@ export default function OrderDetailPage() {
|
|||||||
const [trackNodes, setTrackNodes] = useState<TrackNode[]>([]);
|
const [trackNodes, setTrackNodes] = useState<TrackNode[]>([]);
|
||||||
|
|
||||||
const isReship = order?.orderType === 'RESHIPMENT';
|
const isReship = order?.orderType === 'RESHIPMENT';
|
||||||
|
const isProxy = order?.orderType === 'PROXY' || order?.isProxyOrder === true;
|
||||||
|
|
||||||
async function loadTrack() {
|
async function loadTrack() {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@@ -240,6 +243,11 @@ export default function OrderDetailPage() {
|
|||||||
<h2>{banner.title}</h2>
|
<h2>{banner.title}</h2>
|
||||||
</div>
|
</div>
|
||||||
<p>{banner.subtitle}</p>
|
<p>{banner.subtitle}</p>
|
||||||
|
{isProxy && order?.proxyPartnerName ? (
|
||||||
|
<p className="label-md text-muted" style={{ marginTop: 8 }}>
|
||||||
|
代下单 · 由合伙人 {order.proxyPartnerName} 代下
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,14 @@ const TABS = [
|
|||||||
|
|
||||||
const STATUS_LABEL: Record<string, string> = {
|
const STATUS_LABEL: Record<string, string> = {
|
||||||
PENDING_PAY: '待付款',
|
PENDING_PAY: '待付款',
|
||||||
PENDING_SHIP: '已付款',
|
PENDING_SHIP: '待发货',
|
||||||
OUT_WAREHOUSE: '已付款',
|
OUT_WAREHOUSE: '已出库',
|
||||||
SHIPPING: '已付款',
|
SHIPPING: '配送中',
|
||||||
PENDING_RECEIVE: '已付款',
|
PENDING_RECEIVE: '待收货',
|
||||||
COMPLETED: '已完成',
|
COMPLETED: '已完成',
|
||||||
|
CANCELLED: '已取消',
|
||||||
|
REFUNDING: '退款中',
|
||||||
|
REFUNDED: '已退款',
|
||||||
};
|
};
|
||||||
|
|
||||||
function isReshipOrder(order: Record<string, unknown>) {
|
function isReshipOrder(order: Record<string, unknown>) {
|
||||||
@@ -49,6 +52,7 @@ export default function OrderListPage() {
|
|||||||
const items = (o.items as Array<Record<string, unknown>>) || [];
|
const items = (o.items as Array<Record<string, unknown>>) || [];
|
||||||
const item = items[0];
|
const item = items[0];
|
||||||
const isReship = isReshipOrder(o);
|
const isReship = isReshipOrder(o);
|
||||||
|
const isProxy = String(o.orderType) === 'PROXY' || o.isProxyOrder === true;
|
||||||
const isPendingPay = String(o.status) === 'PENDING_PAY';
|
const isPendingPay = String(o.status) === 'PENDING_PAY';
|
||||||
return (
|
return (
|
||||||
<div key={String(o.id)} className="card">
|
<div key={String(o.id)} className="card">
|
||||||
@@ -60,9 +64,19 @@ export default function OrderListPage() {
|
|||||||
补发单
|
补发单
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
{isProxy && (
|
||||||
|
<span className="tag-reship" style={{ marginLeft: 8 }}>
|
||||||
|
代下单
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
<span className="status-tag">{orderStatusLabel(o)}</span>
|
<span className="status-tag">{orderStatusLabel(o)}</span>
|
||||||
</div>
|
</div>
|
||||||
|
{isProxy && o.proxyPartnerName ? (
|
||||||
|
<div className="label-md text-muted" style={{ marginBottom: 8 }}>
|
||||||
|
由合伙人 {String(o.proxyPartnerName)} 代下
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
{item && (
|
{item && (
|
||||||
<div className="card-row">
|
<div className="card-row">
|
||||||
<AppImage
|
<AppImage
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ type StoreDetail = {
|
|||||||
status: string;
|
status: string;
|
||||||
openTime?: string | null;
|
openTime?: string | null;
|
||||||
closeTime?: string | null;
|
closeTime?: string | null;
|
||||||
|
openTime2?: string | null;
|
||||||
|
closeTime2?: string | null;
|
||||||
|
avgPrice?: number | null;
|
||||||
category?: { name: string } | null;
|
category?: { name: string } | null;
|
||||||
media?: StoreMedia[];
|
media?: StoreMedia[];
|
||||||
};
|
};
|
||||||
@@ -41,8 +44,10 @@ const DEFAULT_INTRO =
|
|||||||
'作为本地优质餐饮合作伙伴,门店融合地域饮食文化与高端社交场景,设有杜康文化体验区,让宾客在用餐之余领略中华酒祖的千年传承。主打精品地方菜与创意融合菜,氛围庄重而不失亲和力,是商务宴请、亲友小聚以及文化交流的理想场所。';
|
'作为本地优质餐饮合作伙伴,门店融合地域饮食文化与高端社交场景,设有杜康文化体验区,让宾客在用餐之余领略中华酒祖的千年传承。主打精品地方菜与创意融合菜,氛围庄重而不失亲和力,是商务宴请、亲友小聚以及文化交流的理想场所。';
|
||||||
|
|
||||||
function formatHours(store: StoreDetail) {
|
function formatHours(store: StoreDetail) {
|
||||||
if (store.openTime && store.closeTime) return `${store.openTime} - ${store.closeTime}`;
|
const parts: string[] = [];
|
||||||
return '09:30 - 22:00';
|
if (store.openTime && store.closeTime) parts.push(`${store.openTime}-${store.closeTime}`);
|
||||||
|
if (store.openTime2 && store.closeTime2) parts.push(`${store.openTime2}-${store.closeTime2}`);
|
||||||
|
return parts.length ? parts.join(',') : '09:30-22:00';
|
||||||
}
|
}
|
||||||
|
|
||||||
function fullAddress(store: StoreDetail) {
|
function fullAddress(store: StoreDetail) {
|
||||||
@@ -135,6 +140,9 @@ export default function StoreDetailPage() {
|
|||||||
<div>
|
<div>
|
||||||
<h2 className="store-detail-name">{store.name}</h2>
|
<h2 className="store-detail-name">{store.name}</h2>
|
||||||
<p className="store-detail-hours">营业时间:{formatHours(store)}</p>
|
<p className="store-detail-hours">营业时间:{formatHours(store)}</p>
|
||||||
|
{store.avgPrice != null && Number(store.avgPrice) > 0 ? (
|
||||||
|
<p className="store-detail-hours">人均约 ¥{Number(store.avgPrice).toFixed(0)}</p>
|
||||||
|
) : null}
|
||||||
{store.category?.name && (
|
{store.category?.name && (
|
||||||
<span className="store-detail-category">{store.category.name}</span>
|
<span className="store-detail-category">{store.category.name}</span>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ type StoreItem = {
|
|||||||
status: string;
|
status: string;
|
||||||
openTime?: string | null;
|
openTime?: string | null;
|
||||||
closeTime?: string | null;
|
closeTime?: string | null;
|
||||||
|
openTime2?: string | null;
|
||||||
|
closeTime2?: string | null;
|
||||||
|
avgPrice?: number | null;
|
||||||
category?: { name: string } | null;
|
category?: { name: string } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -50,10 +53,10 @@ function storeCover(store: StoreItem, index: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatHours(store: StoreItem) {
|
function formatHours(store: StoreItem) {
|
||||||
if (store.openTime && store.closeTime) {
|
const parts: string[] = [];
|
||||||
return `营业时间: ${store.openTime}-${store.closeTime}`;
|
if (store.openTime && store.closeTime) parts.push(`${store.openTime}-${store.closeTime}`);
|
||||||
}
|
if (store.openTime2 && store.closeTime2) parts.push(`${store.openTime2}-${store.closeTime2}`);
|
||||||
return '营业时间: 10:00-22:00';
|
return parts.length ? `营业时间: ${parts.join(',')}` : '营业时间: 10:00-22:00';
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function StoreListPage() {
|
export default function StoreListPage() {
|
||||||
@@ -238,6 +241,9 @@ export default function StoreListPage() {
|
|||||||
<div className="store-card-meta">
|
<div className="store-card-meta">
|
||||||
<span className="status-open">营业中</span>
|
<span className="status-open">营业中</span>
|
||||||
<span className="store-card-hours">{formatHours(s)}</span>
|
<span className="store-card-hours">{formatHours(s)}</span>
|
||||||
|
{s.avgPrice != null && Number(s.avgPrice) > 0 ? (
|
||||||
|
<span className="store-card-hours">人均¥{Number(s.avgPrice).toFixed(0)}</span>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="store-card-bottom">
|
<div className="store-card-bottom">
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ export default defineAppConfig({
|
|||||||
'pages/product-detail/index',
|
'pages/product-detail/index',
|
||||||
'pages/store-detail/index',
|
'pages/store-detail/index',
|
||||||
'pages/order-confirm/index',
|
'pages/order-confirm/index',
|
||||||
|
'pages/order-confirm-pickup/index',
|
||||||
'pages/pay/index',
|
'pages/pay/index',
|
||||||
'pages/orders/index',
|
'pages/orders/index',
|
||||||
'pages/order-detail/index',
|
'pages/order-detail/index',
|
||||||
|
'pages/pickup-receive/index',
|
||||||
'pages/addresses/index',
|
'pages/addresses/index',
|
||||||
'pages/address-edit/index',
|
'pages/address-edit/index',
|
||||||
'pages/customer-service/index',
|
'pages/customer-service/index',
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
import { View, Text, ScrollView } from '@tarojs/components';
|
||||||
|
|
||||||
|
export type StoreCategoryNode = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
children?: StoreCategoryNode[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CategorySelection = {
|
||||||
|
parentId: string;
|
||||||
|
parentName: string;
|
||||||
|
childId: string;
|
||||||
|
childName: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const EMPTY_CATEGORY: CategorySelection = {
|
||||||
|
parentId: '',
|
||||||
|
parentName: '',
|
||||||
|
childId: '',
|
||||||
|
childName: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function formatCategoryLabel(sel: CategorySelection): string {
|
||||||
|
if (sel.childName) return sel.childName;
|
||||||
|
if (sel.parentName) return sel.parentName;
|
||||||
|
return '全部分类';
|
||||||
|
}
|
||||||
|
|
||||||
|
type CategoryPickerProps = {
|
||||||
|
open: boolean;
|
||||||
|
tree: StoreCategoryNode[];
|
||||||
|
value: CategorySelection;
|
||||||
|
onClose: () => void;
|
||||||
|
onConfirm: (next: CategorySelection) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type TabKey = 'parent' | 'child';
|
||||||
|
|
||||||
|
export default function CategoryPicker({
|
||||||
|
open,
|
||||||
|
tree,
|
||||||
|
value,
|
||||||
|
onClose,
|
||||||
|
onConfirm,
|
||||||
|
}: CategoryPickerProps) {
|
||||||
|
const [draft, setDraft] = useState<CategorySelection>(value);
|
||||||
|
const [activeTab, setActiveTab] = useState<TabKey>('parent');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
setDraft(value);
|
||||||
|
setActiveTab(value.parentId ? 'child' : 'parent');
|
||||||
|
}, [open, value]);
|
||||||
|
|
||||||
|
const children = useMemo(() => {
|
||||||
|
const parent = tree.find((n) => n.id === draft.parentId);
|
||||||
|
return parent?.children ?? [];
|
||||||
|
}, [tree, draft.parentId]);
|
||||||
|
|
||||||
|
if (!open) return null;
|
||||||
|
|
||||||
|
function selectParent(node: StoreCategoryNode | null) {
|
||||||
|
if (!node) {
|
||||||
|
setDraft(EMPTY_CATEGORY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setDraft({
|
||||||
|
parentId: node.id,
|
||||||
|
parentName: node.name,
|
||||||
|
childId: '',
|
||||||
|
childName: '',
|
||||||
|
});
|
||||||
|
setActiveTab('child');
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectChild(node: StoreCategoryNode | null) {
|
||||||
|
if (!node) {
|
||||||
|
setDraft((prev) => ({ ...prev, childId: '', childName: '' }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setDraft((prev) => ({
|
||||||
|
...prev,
|
||||||
|
childId: node.id,
|
||||||
|
childName: node.name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleConfirm() {
|
||||||
|
onConfirm(draft);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View className="region-picker-overlay" onClick={onClose}>
|
||||||
|
<View className="region-picker-sheet" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<View className="region-picker-toolbar">
|
||||||
|
<View className="region-picker-tabs">
|
||||||
|
<Text
|
||||||
|
className={`region-picker-tab${activeTab === 'parent' ? ' active' : ''}`}
|
||||||
|
onClick={() => setActiveTab('parent')}
|
||||||
|
>
|
||||||
|
{draft.parentName || '大类'}
|
||||||
|
</Text>
|
||||||
|
<Text
|
||||||
|
className={`region-picker-tab${activeTab === 'child' ? ' active' : ''}${!draft.parentId ? ' disabled' : ''}`}
|
||||||
|
onClick={() => draft.parentId && setActiveTab('child')}
|
||||||
|
>
|
||||||
|
{draft.childName || '细类'}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
<Text className="region-picker-confirm ready" onClick={handleConfirm}>
|
||||||
|
确定
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<ScrollView className="region-picker-list" scrollY showScrollbar={false}>
|
||||||
|
{activeTab === 'parent' ? (
|
||||||
|
<>
|
||||||
|
<View
|
||||||
|
className={`region-picker-option${!draft.parentId ? ' selected' : ''} region-picker-option--all`}
|
||||||
|
onClick={() => selectParent(null)}
|
||||||
|
>
|
||||||
|
<Text>全部分类</Text>
|
||||||
|
</View>
|
||||||
|
{tree.map((item) => (
|
||||||
|
<View
|
||||||
|
key={item.id}
|
||||||
|
className={`region-picker-option${draft.parentId === item.id ? ' selected' : ''}`}
|
||||||
|
onClick={() => selectParent(item)}
|
||||||
|
>
|
||||||
|
<Text>{item.name}</Text>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<View
|
||||||
|
className={`region-picker-option${!draft.childId ? ' selected' : ''} region-picker-option--all`}
|
||||||
|
onClick={() => selectChild(null)}
|
||||||
|
>
|
||||||
|
<Text>全部细类</Text>
|
||||||
|
</View>
|
||||||
|
{children.map((item) => (
|
||||||
|
<View
|
||||||
|
key={item.id}
|
||||||
|
className={`region-picker-option${draft.childId === item.id ? ' selected' : ''}`}
|
||||||
|
onClick={() => selectChild(item)}
|
||||||
|
>
|
||||||
|
<Text>{item.name}</Text>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ScrollView>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -7,10 +7,11 @@ type CouponBadgeProps = {
|
|||||||
|
|
||||||
/** Taro 友好版权益角标(对齐 shared-ui CouponBadge) */
|
/** Taro 友好版权益角标(对齐 shared-ui CouponBadge) */
|
||||||
export default function CouponBadge({ amount, label = '好客权益' }: CouponBadgeProps) {
|
export default function CouponBadge({ amount, label = '好客权益' }: CouponBadgeProps) {
|
||||||
|
const n = Number(amount);
|
||||||
|
const display = Number.isFinite(n) ? (Number.isInteger(n) ? String(n) : n.toFixed(0)) : String(amount);
|
||||||
return (
|
return (
|
||||||
<Text className="coupon-badge">
|
<Text className="coupon-badge">
|
||||||
¥{amount}
|
享 ¥{display} {label}
|
||||||
{label}
|
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export default function PageShell({
|
|||||||
'page-shell',
|
'page-shell',
|
||||||
`page-shell--${variant}`,
|
`page-shell--${variant}`,
|
||||||
hasFixedFooter ? 'page-shell--fixed-footer' : '',
|
hasFixedFooter ? 'page-shell--fixed-footer' : '',
|
||||||
|
variant === 'tab' && process.env.TARO_ENV === 'weapp' ? 'page-shell--native-tabbar' : '',
|
||||||
className,
|
className,
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { captureIosJssdkEntryUrl } from '@dukang/weixin-sdk';
|
|||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { finishLoginNavigate, forceReloadAfterAccountMerge, goLogin } from '../lib/auth-nav';
|
import { finishLoginNavigate, forceReloadAfterAccountMerge, goLogin } from '../lib/auth-nav';
|
||||||
import { toast } from '../lib/api';
|
import { toast } from '../lib/api';
|
||||||
|
import { capturePromoSceneAndTouchScan } from '../lib/promo';
|
||||||
import { saveWechatLoginResult } from '../lib/pay-wechat';
|
import { saveWechatLoginResult } from '../lib/pay-wechat';
|
||||||
import { applyWechatShare } from '../lib/wechat-share';
|
import { applyWechatShare } from '../lib/wechat-share';
|
||||||
import { handleWechatAuthCallback } from '../lib/wechat-auth';
|
import { handleWechatAuthCallback } from '../lib/wechat-auth';
|
||||||
@@ -29,13 +30,16 @@ function currentPagePathWithQuery(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* H5 App 根节点专用:不可用 useDidShow(App 无页面 Context)。
|
* H5 App 根节点:iOS 签名 URL + 默认分享 + OAuth code 回调。
|
||||||
* - 首次进页:捕获 iOS 签名 URL + 默认分享 + OAuth code 回调
|
* 小程序:冷启动时捕获推广码 scene 并回传扫码埋点。
|
||||||
* - 路由/回前台:刷新默认分享卡片
|
|
||||||
*/
|
*/
|
||||||
export default function WechatShareBootstrap() {
|
export default function WechatShareBootstrap() {
|
||||||
const handlingCode = useRef(false);
|
const handlingCode = useRef(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void capturePromoSceneAndTouchScan();
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (process.env.TARO_ENV !== 'h5') return;
|
if (process.env.TARO_ENV !== 'h5') return;
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/** 球面距离(米) */
|
||||||
|
export function haversineMeters(
|
||||||
|
lat1: number,
|
||||||
|
lng1: number,
|
||||||
|
lat2: number,
|
||||||
|
lng2: number,
|
||||||
|
): number {
|
||||||
|
const toRad = (d: number) => (d * Math.PI) / 180;
|
||||||
|
const R = 6371000;
|
||||||
|
const dLat = toRad(lat2 - lat1);
|
||||||
|
const dLng = toRad(lng2 - lng1);
|
||||||
|
const a =
|
||||||
|
Math.sin(dLat / 2) ** 2 +
|
||||||
|
Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLng / 2) ** 2;
|
||||||
|
return 2 * R * Math.asin(Math.min(1, Math.sqrt(a)));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatDistanceMeters(meters: number | null | undefined): string {
|
||||||
|
if (meters == null || !Number.isFinite(meters) || meters < 0) return '—';
|
||||||
|
if (meters < 1000) return `${Math.max(1, Math.round(meters))}m`;
|
||||||
|
const km = meters / 1000;
|
||||||
|
return `${km < 10 ? km.toFixed(1) : Math.round(km)}km`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import Taro from '@tarojs/taro';
|
||||||
|
import { request } from './api';
|
||||||
|
|
||||||
|
const PROMO_ID_KEY = 'dukang_promo_id';
|
||||||
|
|
||||||
|
/** 同一次进入只 touch 一次扫码计数,避免首页反复 onShow 刷量 */
|
||||||
|
let lastScanTouchKey = '';
|
||||||
|
|
||||||
|
function safeDecode(raw: string): string {
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(raw);
|
||||||
|
} catch {
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizePromoId(raw: unknown): string | null {
|
||||||
|
if (raw == null || raw === '') return null;
|
||||||
|
const s = safeDecode(String(raw)).trim();
|
||||||
|
// 小程序码 scene 写入的是推广活动数字 ID
|
||||||
|
if (!/^\d+$/.test(s)) return null;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
type EnterOptionsLike = {
|
||||||
|
scene?: string | number;
|
||||||
|
query?: Record<string, string | undefined>;
|
||||||
|
path?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 从启动/进入参数解析推广活动 ID(优先 query.scene,与 getwxacodeunlimit 一致) */
|
||||||
|
export function extractPromoIdFromEnterOptions(opts?: EnterOptionsLike | null): string | null {
|
||||||
|
if (!opts) return null;
|
||||||
|
const q = opts.query ?? {};
|
||||||
|
return (
|
||||||
|
normalizePromoId(q.scene) ||
|
||||||
|
normalizePromoId(q.promoId) ||
|
||||||
|
normalizePromoId(q.pid) ||
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStoredPromoId(): string | null {
|
||||||
|
try {
|
||||||
|
const v = Taro.getStorageSync(PROMO_ID_KEY);
|
||||||
|
return normalizePromoId(v);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setStoredPromoId(promoId: string) {
|
||||||
|
const id = normalizePromoId(promoId);
|
||||||
|
if (!id) return;
|
||||||
|
try {
|
||||||
|
Taro.setStorageSync(PROMO_ID_KEY, id);
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function readEnterOptions(): EnterOptionsLike | null {
|
||||||
|
try {
|
||||||
|
if (typeof Taro.getEnterOptionsSync === 'function') {
|
||||||
|
return Taro.getEnterOptionsSync() as EnterOptionsLike;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (typeof Taro.getLaunchOptionsSync === 'function') {
|
||||||
|
return Taro.getLaunchOptionsSync() as EnterOptionsLike;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
// H5:从 URL query 读取
|
||||||
|
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
return {
|
||||||
|
query: {
|
||||||
|
scene: params.get('scene') || undefined,
|
||||||
|
promoId: params.get('promoId') || undefined,
|
||||||
|
pid: params.get('pid') || undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主页面进入时:取出 scene(活动 ID)本地缓存,并回传 /promo/touch 累加扫码次数。
|
||||||
|
* 同一进入会话只计一次扫码。
|
||||||
|
*/
|
||||||
|
export async function capturePromoSceneAndTouchScan(): Promise<void> {
|
||||||
|
const opts = readEnterOptions();
|
||||||
|
const fromEnter = extractPromoIdFromEnterOptions(opts);
|
||||||
|
if (fromEnter) {
|
||||||
|
setStoredPromoId(fromEnter);
|
||||||
|
const touchKey = `${fromEnter}|${opts?.path || ''}|${JSON.stringify(opts?.query || {})}|${String(opts?.scene ?? '')}`;
|
||||||
|
if (touchKey === lastScanTouchKey) return;
|
||||||
|
lastScanTouchKey = touchKey;
|
||||||
|
await touchPromo({ promoId: fromEnter, countScan: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 无新 scene 时不重复扫码计数
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 登录成功后:用已缓存的活动 ID 做归因(不重复加扫码次数) */
|
||||||
|
export async function touchStoredPromoAfterLogin(): Promise<void> {
|
||||||
|
const promoId = getStoredPromoId();
|
||||||
|
if (!promoId) return;
|
||||||
|
await touchPromo({ promoId, countScan: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function touchPromo(input: { promoId: string; countScan: boolean }): Promise<void> {
|
||||||
|
try {
|
||||||
|
await request('/promo/touch', {
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
promoId: input.promoId,
|
||||||
|
countScan: input.countScan,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
/* 静默失败,不阻断浏览 */
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,7 +105,7 @@ export function normalizeRegionSelection(selection: RegionSelection): RegionSele
|
|||||||
export const DEFAULT_REGION: RegionSelection = {
|
export const DEFAULT_REGION: RegionSelection = {
|
||||||
province: '河南省',
|
province: '河南省',
|
||||||
city: '郑州市',
|
city: '郑州市',
|
||||||
district: '金水区',
|
district: REGION_ALL,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function regionFromGeo(province: string, city: string, district?: string): RegionSelection {
|
export function regionFromGeo(province: string, city: string, district?: string): RegionSelection {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import Taro from '@tarojs/taro';
|
import Taro from '@tarojs/taro';
|
||||||
import { getWechatLocationDetailed } from '@dukang/weixin-sdk';
|
import { getWechatLocationDetailed } from '@dukang/weixin-sdk';
|
||||||
import { API_BASE, CLIENT_APP, getToken, request } from './api';
|
import { API_BASE, CLIENT_APP, getToken, request } from './api';
|
||||||
import { DEFAULT_REGION, regionFromGeo, type RegionSelection } from './region-data';
|
import { DEFAULT_REGION, REGION_ALL, regionFromGeo, type RegionSelection } from './region-data';
|
||||||
import { FALLBACK_CITY_CODE } from './product-images';
|
import { FALLBACK_CITY_CODE } from './product-images';
|
||||||
|
|
||||||
export const GPS_CITY_STORAGE_KEY = 'dukang_gps_city';
|
export const GPS_CITY_STORAGE_KEY = 'dukang_gps_city';
|
||||||
|
const USER_COORDS_KEY = 'dukang_user_coords';
|
||||||
/** 用户拒绝定位后持久化,避免首页/门店每次 useDidShow 再弹授权 */
|
/** 用户拒绝定位后持久化,避免首页/门店每次 useDidShow 再弹授权 */
|
||||||
const LOCATION_DENIED_KEY = 'dukang_location_denied';
|
const LOCATION_DENIED_KEY = 'dukang_location_denied';
|
||||||
|
|
||||||
@@ -19,12 +20,14 @@ export type ResolvedUserCity = {
|
|||||||
displayCity: string;
|
displayCity: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type UserCoords = { latitude: number; longitude: number };
|
||||||
|
|
||||||
type GpsCityCache = ResolvedUserCity & { timestamp: number };
|
type GpsCityCache = ResolvedUserCity & { timestamp: number };
|
||||||
|
|
||||||
const FALLBACK_CITY: ResolvedUserCity = {
|
const FALLBACK_CITY: ResolvedUserCity = {
|
||||||
province: DEFAULT_REGION.province,
|
province: DEFAULT_REGION.province,
|
||||||
city: DEFAULT_REGION.city,
|
city: DEFAULT_REGION.city,
|
||||||
district: DEFAULT_REGION.district,
|
district: REGION_ALL,
|
||||||
cityCode: FALLBACK_CITY_CODE,
|
cityCode: FALLBACK_CITY_CODE,
|
||||||
cityName: '郑州市',
|
cityName: '郑州市',
|
||||||
openCity: true,
|
openCity: true,
|
||||||
@@ -85,6 +88,39 @@ function writeCache(data: ResolvedUserCity) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function writeUserCoords(latitude: number, longitude: number) {
|
||||||
|
try {
|
||||||
|
Taro.setStorageSync(
|
||||||
|
USER_COORDS_KEY,
|
||||||
|
JSON.stringify({ latitude, longitude, timestamp: Date.now() }),
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function readCachedUserCoords(): UserCoords | null {
|
||||||
|
try {
|
||||||
|
const raw = Taro.getStorageSync(USER_COORDS_KEY);
|
||||||
|
if (!raw) return null;
|
||||||
|
const parsed = JSON.parse(String(raw)) as UserCoords & { timestamp?: number };
|
||||||
|
if (parsed.timestamp && Date.now() - parsed.timestamp > 30 * 60 * 1000) return null;
|
||||||
|
if (!Number.isFinite(parsed.latitude) || !Number.isFinite(parsed.longitude)) return null;
|
||||||
|
return { latitude: parsed.latitude, longitude: parsed.longitude };
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 门店列表默认用市级全市筛选 */
|
||||||
|
export function toCityWideRegion(region: RegionSelection): RegionSelection {
|
||||||
|
return {
|
||||||
|
province: region.province,
|
||||||
|
city: region.city,
|
||||||
|
district: REGION_ALL,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/** 拒绝或失败后写入兜底城市,避免短时间内反复调起定位 */
|
/** 拒绝或失败后写入兜底城市,避免短时间内反复调起定位 */
|
||||||
function cacheFallbackAndMaybeDeny(denied: boolean) {
|
function cacheFallbackAndMaybeDeny(denied: boolean) {
|
||||||
if (denied) markLocationDenied();
|
if (denied) markLocationDenied();
|
||||||
@@ -167,12 +203,12 @@ async function resolveViaH5Jssdk(): Promise<ResolvedUserCity | null> {
|
|||||||
status: 'fail',
|
status: 'fail',
|
||||||
errMsg: outcome.errMsg,
|
errMsg: outcome.errMsg,
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
// 失败一律缓存兜底,避免首页/门店每次进入再次调起微信定位弹窗
|
|
||||||
cacheFallbackAndMaybeDeny(denied);
|
cacheFallbackAndMaybeDeny(denied);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
writeUserCoords(outcome.location.latitude, outcome.location.longitude);
|
||||||
const data = await reportLocationToServer({
|
const data = await reportLocationToServer({
|
||||||
latitude: outcome.location.latitude,
|
latitude: outcome.location.latitude,
|
||||||
longitude: outcome.location.longitude,
|
longitude: outcome.location.longitude,
|
||||||
@@ -213,6 +249,7 @@ export async function resolveUserCity(force = false): Promise<ResolvedUserCity>
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const loc = await getMiniLocation();
|
const loc = await getMiniLocation();
|
||||||
|
writeUserCoords(loc.latitude, loc.longitude);
|
||||||
const data = await reportLocationToServer({
|
const data = await reportLocationToServer({
|
||||||
latitude: loc.latitude,
|
latitude: loc.latitude,
|
||||||
longitude: loc.longitude,
|
longitude: loc.longitude,
|
||||||
|
|||||||
@@ -5,9 +5,15 @@ import PageShell from '../../components/PageShell';
|
|||||||
import SubPageHeader from '../../components/SubPageHeader';
|
import SubPageHeader from '../../components/SubPageHeader';
|
||||||
import RegionPicker from '../../components/RegionPicker';
|
import RegionPicker from '../../components/RegionPicker';
|
||||||
import { buildAddressListUrl, readCheckoutContext } from '../../lib/checkout-nav';
|
import { buildAddressListUrl, readCheckoutContext } from '../../lib/checkout-nav';
|
||||||
import { DEFAULT_REGION, formatRegion, type RegionSelection } from '../../lib/region-data';
|
import {
|
||||||
|
DEFAULT_REGION,
|
||||||
|
REGION_ALL,
|
||||||
|
formatRegion,
|
||||||
|
type RegionSelection,
|
||||||
|
} from '../../lib/region-data';
|
||||||
import { normalizePhoneInput, validateMobilePhone } from '../../lib/phone';
|
import { normalizePhoneInput, validateMobilePhone } from '../../lib/phone';
|
||||||
import { getStoredUserPhone, resolveDefaultUserPhone } from '../../lib/user-phone';
|
import { getStoredUserPhone, resolveDefaultUserPhone } from '../../lib/user-phone';
|
||||||
|
import { resolveUserCity } from '../../lib/user-location';
|
||||||
import { request, toast, type UserProfile } from '../../lib/api';
|
import { request, toast, type UserProfile } from '../../lib/api';
|
||||||
|
|
||||||
type AddressForm = {
|
type AddressForm = {
|
||||||
@@ -27,6 +33,7 @@ export default function AddressEditPage() {
|
|||||||
const checkoutCtx = readCheckoutContext(router.params);
|
const checkoutCtx = readCheckoutContext(router.params);
|
||||||
const [pickerOpen, setPickerOpen] = useState(false);
|
const [pickerOpen, setPickerOpen] = useState(false);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [locating, setLocating] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [form, setForm] = useState<AddressForm>(() => ({
|
const [form, setForm] = useState<AddressForm>(() => ({
|
||||||
receiverName: '',
|
receiverName: '',
|
||||||
@@ -49,6 +56,35 @@ export default function AddressEditPage() {
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (id) return;
|
||||||
|
let cancelled = false;
|
||||||
|
setLocating(true);
|
||||||
|
void resolveUserCity(true)
|
||||||
|
.then((resolved) => {
|
||||||
|
if (cancelled) return;
|
||||||
|
const district =
|
||||||
|
resolved.region.district && resolved.region.district !== REGION_ALL
|
||||||
|
? resolved.region.district
|
||||||
|
: resolved.district && resolved.district !== REGION_ALL
|
||||||
|
? resolved.district
|
||||||
|
: DEFAULT_REGION.district;
|
||||||
|
setForm((prev) => ({
|
||||||
|
...prev,
|
||||||
|
province: resolved.region.province || prev.province,
|
||||||
|
city: resolved.region.city || prev.city,
|
||||||
|
district: district || prev.district,
|
||||||
|
}));
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
.finally(() => {
|
||||||
|
if (!cancelled) setLocating(false);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
request<Array<Record<string, unknown>>>('/user/addresses').then((list) => {
|
request<Array<Record<string, unknown>>>('/user/addresses').then((list) => {
|
||||||
@@ -161,7 +197,11 @@ export default function AddressEditPage() {
|
|||||||
style={{ display: 'flex', alignItems: 'center' }}
|
style={{ display: 'flex', alignItems: 'center' }}
|
||||||
onClick={() => setPickerOpen(true)}
|
onClick={() => setPickerOpen(true)}
|
||||||
>
|
>
|
||||||
<Text>{regionText || '请选择省市区'}</Text>
|
<Text>
|
||||||
|
{locating && !isEdit
|
||||||
|
? '定位中…'
|
||||||
|
: regionText || '请选择省市区'}
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className="address-form-field">
|
<View className="address-form-field">
|
||||||
|
|||||||
@@ -3,4 +3,6 @@ export default definePageConfig({
|
|||||||
navigationBarTitleText: '好客权益',
|
navigationBarTitleText: '好客权益',
|
||||||
enablePullDownRefresh: true,
|
enablePullDownRefresh: true,
|
||||||
backgroundTextStyle: 'dark',
|
backgroundTextStyle: 'dark',
|
||||||
|
enableShareAppMessage: true,
|
||||||
|
enableShareTimeline: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
import { View, Text } from '@tarojs/components';
|
import { View, Text } from '@tarojs/components';
|
||||||
import Taro, { useDidShow, usePullDownRefresh } from '@tarojs/taro';
|
import Taro, { useDidShow, usePullDownRefresh, useShareAppMessage, useShareTimeline } from '@tarojs/taro';
|
||||||
import PageShell from '../../components/PageShell';
|
import PageShell from '../../components/PageShell';
|
||||||
|
import ShareNavButton from '../../components/ShareNavButton';
|
||||||
|
import WechatShareReady from '../../components/WechatShareReady';
|
||||||
import UserTabBar, { shouldRenderPageTabBar, syncTabBarSelected } from '../../components/UserTabBar';
|
import UserTabBar, { shouldRenderPageTabBar, syncTabBarSelected } from '../../components/UserTabBar';
|
||||||
import { goLogin } from '../../lib/auth-nav';
|
import { goLogin } from '../../lib/auth-nav';
|
||||||
import { isLoggedIn, request, toast } from '../../lib/api';
|
import { isLoggedIn, request, toast } from '../../lib/api';
|
||||||
import { navBarStyle, tabNavContentStyle, useNavBarMetrics } from '../../lib/nav-bar';
|
import { navBarStyle, tabNavContentStyle, useNavBarMetrics } from '../../lib/nav-bar';
|
||||||
|
import {
|
||||||
|
DEFAULT_SHARE_DESC,
|
||||||
|
DEFAULT_SHARE_TITLE,
|
||||||
|
toWeappShareMessage,
|
||||||
|
} from '../../lib/wechat-share';
|
||||||
|
|
||||||
type BenefitSummary = {
|
type BenefitSummary = {
|
||||||
totalBalance: number;
|
totalBalance: number;
|
||||||
@@ -35,17 +42,18 @@ function usagePercent(coupon: CouponItem) {
|
|||||||
|
|
||||||
export default function BenefitPage() {
|
export default function BenefitPage() {
|
||||||
const metrics = useNavBarMetrics();
|
const metrics = useNavBarMetrics();
|
||||||
const loggedIn = isLoggedIn();
|
const [loggedIn, setLoggedIn] = useState(() => isLoggedIn());
|
||||||
const [summary, setSummary] = useState<BenefitSummary | null>(null);
|
const [summary, setSummary] = useState<BenefitSummary | null>(null);
|
||||||
const [coupons, setCoupons] = useState<CouponItem[]>([]);
|
const [coupons, setCoupons] = useState<CouponItem[]>([]);
|
||||||
const [tab, setTab] = useState<'available' | 'history'>('available');
|
const [tab, setTab] = useState<'available' | 'history'>('available');
|
||||||
|
|
||||||
useDidShow(() => {
|
const resetGuestState = useCallback(() => {
|
||||||
syncTabBarSelected(2);
|
setSummary(null);
|
||||||
});
|
setCoupons([]);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const loadBenefit = useCallback(() => {
|
const loadBenefit = useCallback(() => {
|
||||||
if (!loggedIn) return Promise.resolve();
|
if (!isLoggedIn()) return Promise.resolve();
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
request<BenefitSummary>('/benefit/summary'),
|
request<BenefitSummary>('/benefit/summary'),
|
||||||
request<CouponItem[]>('/benefit/coupons'),
|
request<CouponItem[]>('/benefit/coupons'),
|
||||||
@@ -55,13 +63,27 @@ export default function BenefitPage() {
|
|||||||
setCoupons(Array.isArray(list) ? list : []);
|
setCoupons(Array.isArray(list) ? list : []);
|
||||||
})
|
})
|
||||||
.catch((e) => toast(e instanceof Error ? e.message : '加载失败'));
|
.catch((e) => toast(e instanceof Error ? e.message : '加载失败'));
|
||||||
}, [loggedIn]);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useDidShow(() => {
|
||||||
void loadBenefit();
|
syncTabBarSelected(2);
|
||||||
}, [loadBenefit]);
|
const loggedInNow = isLoggedIn();
|
||||||
|
setLoggedIn(loggedInNow);
|
||||||
|
if (loggedInNow) {
|
||||||
|
void loadBenefit();
|
||||||
|
} else {
|
||||||
|
resetGuestState();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
usePullDownRefresh(() => {
|
usePullDownRefresh(() => {
|
||||||
|
const loggedInNow = isLoggedIn();
|
||||||
|
setLoggedIn(loggedInNow);
|
||||||
|
if (!loggedInNow) {
|
||||||
|
resetGuestState();
|
||||||
|
Taro.stopPullDownRefresh();
|
||||||
|
return;
|
||||||
|
}
|
||||||
void loadBenefit().finally(() => Taro.stopPullDownRefresh());
|
void loadBenefit().finally(() => Taro.stopPullDownRefresh());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -69,8 +91,25 @@ export default function BenefitPage() {
|
|||||||
const history = coupons.filter((c) => c.status === 'USED_UP' || c.status === 'VOID');
|
const history = coupons.filter((c) => c.status === 'USED_UP' || c.status === 'VOID');
|
||||||
const visible = tab === 'available' ? available : history;
|
const visible = tab === 'available' ? available : history;
|
||||||
|
|
||||||
|
const sharePayload = useMemo(
|
||||||
|
() => ({
|
||||||
|
title: '好客权益 · 杜康好客',
|
||||||
|
desc: DEFAULT_SHARE_DESC,
|
||||||
|
path: '/pages/benefit/index',
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
useShareAppMessage(() => toWeappShareMessage(sharePayload));
|
||||||
|
useShareTimeline(() => ({
|
||||||
|
title: sharePayload.title || DEFAULT_SHARE_TITLE,
|
||||||
|
query: '',
|
||||||
|
imageUrl: sharePayload.imgUrl,
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageShell variant="tab" className="benefit-page">
|
<PageShell variant="tab" className="benefit-page">
|
||||||
|
<WechatShareReady payload={sharePayload} />
|
||||||
<View className="benefit-header" style={navBarStyle(metrics)} aria-label="好客权益">
|
<View className="benefit-header" style={navBarStyle(metrics)} aria-label="好客权益">
|
||||||
{process.env.TARO_ENV !== 'h5' ? (
|
{process.env.TARO_ENV !== 'h5' ? (
|
||||||
<Text className="benefit-header-title">好客权益</Text>
|
<Text className="benefit-header-title">好客权益</Text>
|
||||||
@@ -83,6 +122,9 @@ export default function BenefitPage() {
|
|||||||
<View className="benefit-header-city-pin" />
|
<View className="benefit-header-city-pin" />
|
||||||
<Text>郑州市</Text>
|
<Text>郑州市</Text>
|
||||||
</View>
|
</View>
|
||||||
|
<View className="benefit-header__share page-nav-bar__right-slot">
|
||||||
|
<ShareNavButton payload={sharePayload} />
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|||||||
@@ -2,4 +2,6 @@ export default definePageConfig({
|
|||||||
navigationBarTitleText: '杜康好客',
|
navigationBarTitleText: '杜康好客',
|
||||||
enablePullDownRefresh: true,
|
enablePullDownRefresh: true,
|
||||||
backgroundTextStyle: 'dark',
|
backgroundTextStyle: 'dark',
|
||||||
|
enableShareAppMessage: true,
|
||||||
|
enableShareTimeline: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,29 +1,45 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { View, Text } from '@tarojs/components';
|
import { View, Text, Image, Swiper, SwiperItem } from '@tarojs/components';
|
||||||
import Taro, { useDidShow, usePullDownRefresh } from '@tarojs/taro';
|
import Taro, { useDidShow, usePullDownRefresh, useShareAppMessage, useShareTimeline } from '@tarojs/taro';
|
||||||
import PageShell from '../../components/PageShell';
|
import PageShell from '../../components/PageShell';
|
||||||
import TabMainHeader from '../../components/TabMainHeader';
|
import TabMainHeader from '../../components/TabMainHeader';
|
||||||
import CouponBadge from '../../components/CouponBadge';
|
import CouponBadge from '../../components/CouponBadge';
|
||||||
import ProductCarousel from '../../components/ProductCarousel';
|
import WechatShareReady from '../../components/WechatShareReady';
|
||||||
import UserTabBar, { shouldRenderPageTabBar, syncTabBarSelected } from '../../components/UserTabBar';
|
import UserTabBar, { shouldRenderPageTabBar, syncTabBarSelected } from '../../components/UserTabBar';
|
||||||
import { request, toast } from '../../lib/api';
|
import { goLogin } from '../../lib/auth-nav';
|
||||||
import { getProductImages } from '../../lib/product-images';
|
import { isLoggedIn, request, toast } from '../../lib/api';
|
||||||
|
import { ensurePayReady } from '../../lib/pay-ready';
|
||||||
|
import { capturePromoSceneAndTouchScan } from '../../lib/promo';
|
||||||
|
import { getProductMainImage } from '../../lib/product-images';
|
||||||
import { getCityCodeForCatalog, resolveUserCity } from '../../lib/user-location';
|
import { getCityCodeForCatalog, resolveUserCity } from '../../lib/user-location';
|
||||||
|
import {
|
||||||
|
DEFAULT_SHARE_DESC,
|
||||||
|
DEFAULT_SHARE_TITLE,
|
||||||
|
toWeappShareMessage,
|
||||||
|
} from '../../lib/wechat-share';
|
||||||
|
|
||||||
type Product = {
|
type Product = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
subtitle?: string;
|
subtitle?: string;
|
||||||
|
spec?: string;
|
||||||
price: number;
|
price: number;
|
||||||
benefitDisplay?: number;
|
benefitDisplay?: number;
|
||||||
mainImageUrl?: string | null;
|
mainImageUrl?: string | null;
|
||||||
carouselUrls?: string[] | null;
|
carouselUrls?: string[] | null;
|
||||||
aromaType: string;
|
aromaType: string;
|
||||||
|
allowOnSitePickup?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type MiniHomeConfig = {
|
||||||
|
banners: string[];
|
||||||
|
footerUrl: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const AROMA_TABS = [
|
const AROMA_TABS = [
|
||||||
{ key: 'QINGXIANG', label: '清香型' },
|
{ key: 'QINGXIANG', label: '清香型' },
|
||||||
{ key: 'JIANGXIANG', label: '酱香型' },
|
|
||||||
{ key: 'NONGXIANG', label: '浓香型' },
|
{ key: 'NONGXIANG', label: '浓香型' },
|
||||||
|
{ key: 'JIANGXIANG', label: '酱香型' },
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
@@ -32,9 +48,29 @@ export default function HomePage() {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [displayCity, setDisplayCity] = useState('郑州市');
|
const [displayCity, setDisplayCity] = useState('郑州市');
|
||||||
const [cityCode, setCityCode] = useState('410100');
|
const [cityCode, setCityCode] = useState('410100');
|
||||||
|
const [miniHome, setMiniHome] = useState<MiniHomeConfig>({ banners: [], footerUrl: null });
|
||||||
|
|
||||||
|
const loadMiniHome = useCallback(() => {
|
||||||
|
return request<{ miniHome?: MiniHomeConfig }>('/common/client-config')
|
||||||
|
.then((cfg) => {
|
||||||
|
const banners = Array.isArray(cfg.miniHome?.banners)
|
||||||
|
? cfg.miniHome!.banners.filter((u) => typeof u === 'string' && !!u.trim())
|
||||||
|
: [];
|
||||||
|
const footerUrl =
|
||||||
|
typeof cfg.miniHome?.footerUrl === 'string' && cfg.miniHome.footerUrl.trim()
|
||||||
|
? cfg.miniHome.footerUrl.trim()
|
||||||
|
: null;
|
||||||
|
setMiniHome({ banners, footerUrl });
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
/* 首页装饰图失败不阻断商品列表 */
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
useDidShow(() => {
|
useDidShow(() => {
|
||||||
syncTabBarSelected(0);
|
syncTabBarSelected(0);
|
||||||
|
void capturePromoSceneAndTouchScan();
|
||||||
|
void loadMiniHome();
|
||||||
void resolveUserCity().then((resolved) => {
|
void resolveUserCity().then((resolved) => {
|
||||||
setDisplayCity(resolved.displayCity);
|
setDisplayCity(resolved.displayCity);
|
||||||
setCityCode(getCityCodeForCatalog(resolved));
|
setCityCode(getCityCodeForCatalog(resolved));
|
||||||
@@ -61,9 +97,10 @@ export default function HomePage() {
|
|||||||
const nextCode = getCityCodeForCatalog(resolved);
|
const nextCode = getCityCodeForCatalog(resolved);
|
||||||
setCityCode(nextCode);
|
setCityCode(nextCode);
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const list = await request<Product[]>(
|
const [list] = await Promise.all([
|
||||||
`/catalog/products?cityCode=${encodeURIComponent(nextCode)}`,
|
request<Product[]>(`/catalog/products?cityCode=${encodeURIComponent(nextCode)}`),
|
||||||
);
|
loadMiniHome(),
|
||||||
|
]);
|
||||||
setProducts(Array.isArray(list) ? list : []);
|
setProducts(Array.isArray(list) ? list : []);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast(e instanceof Error ? e.message : '加载失败');
|
toast(e instanceof Error ? e.message : '加载失败');
|
||||||
@@ -93,12 +130,61 @@ export default function HomePage() {
|
|||||||
Taro.navigateTo({ url: `/pages/product-detail/index?id=${id}` });
|
Taro.navigateTo({ url: `/pages/product-detail/index?id=${id}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function goOnSitePickup(productId: string) {
|
||||||
|
const returnPath = `/pages/order-confirm-pickup/index?productId=${productId}&qty=1`;
|
||||||
|
if (!isLoggedIn()) {
|
||||||
|
goLogin(returnPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ready = await ensurePayReady(returnPath);
|
||||||
|
if (!ready) return;
|
||||||
|
Taro.navigateTo({ url: returnPath });
|
||||||
|
}
|
||||||
|
|
||||||
const filtered = products.filter((p) => p.aromaType === tab);
|
const filtered = products.filter((p) => p.aromaType === tab);
|
||||||
|
const banners = miniHome.banners;
|
||||||
|
const footerUrl = miniHome.footerUrl;
|
||||||
|
|
||||||
|
const sharePayload = useMemo(
|
||||||
|
() => ({
|
||||||
|
title: DEFAULT_SHARE_TITLE,
|
||||||
|
desc: DEFAULT_SHARE_DESC,
|
||||||
|
path: '/pages/home/index',
|
||||||
|
imgUrl: banners[0] || undefined,
|
||||||
|
}),
|
||||||
|
[banners],
|
||||||
|
);
|
||||||
|
|
||||||
|
useShareAppMessage(() => toWeappShareMessage(sharePayload));
|
||||||
|
useShareTimeline(() => ({
|
||||||
|
title: sharePayload.title || DEFAULT_SHARE_TITLE,
|
||||||
|
query: '',
|
||||||
|
imageUrl: sharePayload.imgUrl,
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageShell variant="tab" className="home-page no-tab-header">
|
<PageShell variant="tab" className="home-page no-tab-header">
|
||||||
|
<WechatShareReady payload={sharePayload} />
|
||||||
<TabMainHeader title="杜康好客" />
|
<TabMainHeader title="杜康好客" />
|
||||||
|
|
||||||
|
{banners.length > 0 ? (
|
||||||
|
<View className="home-promo-banner">
|
||||||
|
<Swiper
|
||||||
|
className="home-promo-banner-swiper"
|
||||||
|
indicatorDots={banners.length > 1}
|
||||||
|
autoplay={banners.length > 1}
|
||||||
|
circular={banners.length > 1}
|
||||||
|
interval={2500}
|
||||||
|
>
|
||||||
|
{banners.map((url) => (
|
||||||
|
<SwiperItem key={url}>
|
||||||
|
<Image className="home-promo-banner-img" src={url} mode="aspectFill" />
|
||||||
|
</SwiperItem>
|
||||||
|
))}
|
||||||
|
</Swiper>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<View className="home-aroma-nav">
|
<View className="home-aroma-nav">
|
||||||
<View className="home-aroma-tabs">
|
<View className="home-aroma-tabs">
|
||||||
{availableAromas.map((t) => (
|
{availableAromas.map((t) => (
|
||||||
@@ -121,32 +207,65 @@ export default function HomePage() {
|
|||||||
) : null}
|
) : null}
|
||||||
{!loading &&
|
{!loading &&
|
||||||
filtered.map((p) => {
|
filtered.map((p) => {
|
||||||
const images = getProductImages(p);
|
const thumb = getProductMainImage(p);
|
||||||
|
const spec = p.subtitle || p.spec || '';
|
||||||
return (
|
return (
|
||||||
<View key={p.id} className="home-product-card">
|
<View key={p.id} className="home-product-card">
|
||||||
<View onClick={() => openProductDetail(p.id)}>
|
<View
|
||||||
<ProductCarousel images={images} alt={p.name} variant="home" />
|
className="home-product-card-inner"
|
||||||
<View className="home-product-body">
|
onClick={() => openProductDetail(p.id)}
|
||||||
|
>
|
||||||
|
<View className="home-product-thumb-wrap">
|
||||||
|
{thumb ? (
|
||||||
|
<Image className="home-product-thumb" src={thumb} mode="aspectFill" />
|
||||||
|
) : (
|
||||||
|
<View className="home-product-thumb home-product-thumb--empty" />
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
<View className="home-product-main">
|
||||||
<View className="home-product-row">
|
<View className="home-product-row">
|
||||||
<Text className="home-product-name">{p.name}</Text>
|
<Text className="home-product-name">{p.name}</Text>
|
||||||
<Text className="home-product-price">¥{Number(p.price).toFixed(2)}</Text>
|
<Text className="home-product-price">¥{Number(p.price).toFixed(0)}</Text>
|
||||||
</View>
|
</View>
|
||||||
{p.subtitle ? <Text className="home-product-sub">{p.subtitle}</Text> : null}
|
{spec ? <Text className="home-product-sub">{spec}</Text> : null}
|
||||||
<View className="home-product-footer">
|
<View className="home-product-footer">
|
||||||
<CouponBadge amount={p.benefitDisplay ?? p.price} label="好客权益" />
|
<CouponBadge amount={p.benefitDisplay ?? p.price} label="好客权益" />
|
||||||
</View>
|
</View>
|
||||||
|
<View className="home-product-actions">
|
||||||
|
{p.allowOnSitePickup ? (
|
||||||
|
<Text
|
||||||
|
className="home-pickup-btn"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation?.();
|
||||||
|
void goOnSitePickup(p.id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
现场取货
|
||||||
|
</Text>
|
||||||
|
) : null}
|
||||||
|
<Text
|
||||||
|
className="home-buy-btn"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation?.();
|
||||||
|
openProductDetail(p.id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
立即购买
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className="home-product-actions">
|
|
||||||
<Text className="home-buy-btn" onClick={() => openProductDetail(p.id)}>
|
|
||||||
立即购买
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{footerUrl ? (
|
||||||
|
<View className="home-promo-footer">
|
||||||
|
<Image className="home-promo-footer-img" src={footerUrl} mode="aspectFill" />
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{shouldRenderPageTabBar() ? <UserTabBar selected={0} /> : null}
|
{shouldRenderPageTabBar() ? <UserTabBar selected={0} /> : null}
|
||||||
</PageShell>
|
</PageShell>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
type MiniWechatProfile,
|
type MiniWechatProfile,
|
||||||
} from '../../lib/mini-wechat-profile';
|
} from '../../lib/mini-wechat-profile';
|
||||||
import { isLoggedIn, request, saveAuth, toast, type SessionPayload } from '../../lib/api';
|
import { isLoggedIn, request, saveAuth, toast, type SessionPayload } from '../../lib/api';
|
||||||
|
import { touchStoredPromoAfterLogin } from '../../lib/promo';
|
||||||
|
|
||||||
const IS_WEAPP = process.env.TARO_ENV === 'weapp';
|
const IS_WEAPP = process.env.TARO_ENV === 'weapp';
|
||||||
|
|
||||||
@@ -176,6 +177,7 @@ export default function LoginPage() {
|
|||||||
refreshToken: data.refreshToken,
|
refreshToken: data.refreshToken,
|
||||||
});
|
});
|
||||||
void syncMiniWechatProfile(wxInfo ?? getCachedWxProfile());
|
void syncMiniWechatProfile(wxInfo ?? getCachedWxProfile());
|
||||||
|
void touchStoredPromoAfterLogin();
|
||||||
if (!phoneValue) {
|
if (!phoneValue) {
|
||||||
void fetchUserProfile()
|
void fetchUserProfile()
|
||||||
.then((me) => resolveDefaultUserPhone(me))
|
.then((me) => resolveDefaultUserPhone(me))
|
||||||
|
|||||||
@@ -2,4 +2,6 @@ export default definePageConfig({
|
|||||||
navigationBarTitleText: '我的',
|
navigationBarTitleText: '我的',
|
||||||
enablePullDownRefresh: true,
|
enablePullDownRefresh: true,
|
||||||
backgroundTextStyle: 'dark',
|
backgroundTextStyle: 'dark',
|
||||||
|
enableShareAppMessage: true,
|
||||||
|
enableShareTimeline: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { View, Text, Image, Button, Input } from '@tarojs/components';
|
import { View, Text, Image, Button, Input, ScrollView } from '@tarojs/components';
|
||||||
import Taro, { useDidShow, usePullDownRefresh } from '@tarojs/taro';
|
import Taro, { useDidShow, usePullDownRefresh, useShareAppMessage, useShareTimeline } from '@tarojs/taro';
|
||||||
import { isWxAuthorizeEnabled, type ClientRuntimeConfig } from '@dukang/shared-types';
|
import {
|
||||||
|
BRAND_LOGO_MARK_URL,
|
||||||
|
QUALIFICATION_DISCLOSURE_URL,
|
||||||
|
isWxAuthorizeEnabled,
|
||||||
|
type ClientRuntimeConfig,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
import PageShell from '../../components/PageShell';
|
import PageShell from '../../components/PageShell';
|
||||||
import TabMainHeader from '../../components/TabMainHeader';
|
import TabMainHeader from '../../components/TabMainHeader';
|
||||||
|
import WechatShareReady from '../../components/WechatShareReady';
|
||||||
import UserTabBar, { shouldRenderPageTabBar, syncTabBarSelected } from '../../components/UserTabBar';
|
import UserTabBar, { shouldRenderPageTabBar, syncTabBarSelected } from '../../components/UserTabBar';
|
||||||
import { BRAND_LOGO_MARK_URL } from '@dukang/shared-types';
|
|
||||||
import { goLogin } from '../../lib/auth-nav';
|
import { goLogin } from '../../lib/auth-nav';
|
||||||
import { bindWechatForUser } from '../../lib/wechat-auth';
|
import { bindWechatForUser } from '../../lib/wechat-auth';
|
||||||
import {
|
import {
|
||||||
@@ -18,6 +23,11 @@ import {
|
|||||||
} from '../../lib/mini-wechat-profile';
|
} from '../../lib/mini-wechat-profile';
|
||||||
import { isLoggedIn, logout, request, toast, type UserProfile } from '../../lib/api';
|
import { isLoggedIn, logout, request, toast, type UserProfile } from '../../lib/api';
|
||||||
import { isWechatEnv } from '../../lib/weixin';
|
import { isWechatEnv } from '../../lib/weixin';
|
||||||
|
import {
|
||||||
|
DEFAULT_SHARE_DESC,
|
||||||
|
DEFAULT_SHARE_TITLE,
|
||||||
|
toWeappShareMessage,
|
||||||
|
} from '../../lib/wechat-share';
|
||||||
|
|
||||||
const ORDER_SHORTCUTS = [
|
const ORDER_SHORTCUTS = [
|
||||||
{ tab: 'pending_pay', icon: '付', label: '待付款' },
|
{ tab: 'pending_pay', icon: '付', label: '待付款' },
|
||||||
@@ -29,6 +39,7 @@ const SERVICES = [
|
|||||||
{ icon: '址', label: '地址管理', url: '/pages/addresses/index' },
|
{ icon: '址', label: '地址管理', url: '/pages/addresses/index' },
|
||||||
{ icon: '店', label: '可用门店', tab: '/pages/stores/index' },
|
{ icon: '店', label: '可用门店', tab: '/pages/stores/index' },
|
||||||
{ icon: '服', label: '联系客服', url: '/pages/customer-service/index' },
|
{ icon: '服', label: '联系客服', url: '/pages/customer-service/index' },
|
||||||
|
{ icon: '资', label: '资质公示', action: 'qualification' as const },
|
||||||
{ icon: '关', label: '关于我们', action: 'about' as const },
|
{ icon: '关', label: '关于我们', action: 'about' as const },
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
@@ -51,6 +62,7 @@ export default function MinePage() {
|
|||||||
const [draftNickname, setDraftNickname] = useState('');
|
const [draftNickname, setDraftNickname] = useState('');
|
||||||
const [savingProfile, setSavingProfile] = useState(false);
|
const [savingProfile, setSavingProfile] = useState(false);
|
||||||
const [profileLoadError, setProfileLoadError] = useState('');
|
const [profileLoadError, setProfileLoadError] = useState('');
|
||||||
|
const [qualificationOpen, setQualificationOpen] = useState(false);
|
||||||
|
|
||||||
function resetGuestState() {
|
function resetGuestState() {
|
||||||
setProfile(null);
|
setProfile(null);
|
||||||
@@ -126,6 +138,21 @@ export default function MinePage() {
|
|||||||
.catch(() => setWxAuthorize(true));
|
.catch(() => setWxAuthorize(true));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const sharePayload = useMemo(
|
||||||
|
() => ({
|
||||||
|
title: '杜康好客 · 我的',
|
||||||
|
desc: DEFAULT_SHARE_DESC,
|
||||||
|
path: '/pages/mine/index',
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
useShareAppMessage(() => toWeappShareMessage(sharePayload));
|
||||||
|
useShareTimeline(() => ({
|
||||||
|
title: sharePayload.title || DEFAULT_SHARE_TITLE,
|
||||||
|
query: '',
|
||||||
|
}));
|
||||||
|
|
||||||
async function ensureWechatBound(): Promise<boolean> {
|
async function ensureWechatBound(): Promise<boolean> {
|
||||||
if (profile?.hasWechat) return true;
|
if (profile?.hasWechat) return true;
|
||||||
if (!wxAuthorize) {
|
if (!wxAuthorize) {
|
||||||
@@ -254,6 +281,10 @@ export default function MinePage() {
|
|||||||
Taro.switchTab({ url: item.tab });
|
Taro.switchTab({ url: item.tab });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ('action' in item && item.action === 'qualification') {
|
||||||
|
setQualificationOpen(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ('action' in item && item.action === 'about') {
|
if ('action' in item && item.action === 'about') {
|
||||||
toast('杜康好客 · 传承千年酒文化');
|
toast('杜康好客 · 传承千年酒文化');
|
||||||
}
|
}
|
||||||
@@ -269,6 +300,7 @@ export default function MinePage() {
|
|||||||
if (!authed) {
|
if (!authed) {
|
||||||
return (
|
return (
|
||||||
<PageShell variant="tab" className="mine-page no-tab-header">
|
<PageShell variant="tab" className="mine-page no-tab-header">
|
||||||
|
<WechatShareReady payload={sharePayload} />
|
||||||
<TabMainHeader title="我的" />
|
<TabMainHeader title="我的" />
|
||||||
<View className="mine-header">
|
<View className="mine-header">
|
||||||
<View className="mine-header-texture" />
|
<View className="mine-header-texture" />
|
||||||
@@ -321,6 +353,7 @@ export default function MinePage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<PageShell variant="tab" className="mine-page no-tab-header">
|
<PageShell variant="tab" className="mine-page no-tab-header">
|
||||||
|
<WechatShareReady payload={sharePayload} />
|
||||||
<TabMainHeader title="我的" />
|
<TabMainHeader title="我的" />
|
||||||
<View className="mine-header">
|
<View className="mine-header">
|
||||||
<View className="mine-header-texture" />
|
<View className="mine-header-texture" />
|
||||||
@@ -507,14 +540,41 @@ export default function MinePage() {
|
|||||||
</View>
|
</View>
|
||||||
<View
|
<View
|
||||||
className={`mine-profile-sheet-save${savingProfile ? ' is-disabled' : ''}`}
|
className={`mine-profile-sheet-save${savingProfile ? ' is-disabled' : ''}`}
|
||||||
onClick={savingProfile ? undefined : () => void saveWxProfile()}
|
onClick={() => {
|
||||||
|
if (!savingProfile) void saveWxProfile();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Text>{savingProfile ? '保存中...' : '保存'}</Text>
|
<Text>{savingProfile ? '保存中…' : '保存'}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
{qualificationOpen ? (
|
||||||
|
<View
|
||||||
|
className="mine-qualification-mask"
|
||||||
|
onClick={() => setQualificationOpen(false)}
|
||||||
|
>
|
||||||
|
<ScrollView
|
||||||
|
scrollY
|
||||||
|
enableFlex
|
||||||
|
className="mine-qualification-scroll"
|
||||||
|
style={{ height: '100%' }}
|
||||||
|
enhanced
|
||||||
|
showScrollbar
|
||||||
|
>
|
||||||
|
<View className="mine-qualification-body">
|
||||||
|
<Image
|
||||||
|
className="mine-qualification-img"
|
||||||
|
src={QUALIFICATION_DISCLOSURE_URL}
|
||||||
|
mode="widthFix"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</ScrollView>
|
||||||
|
<Text className="mine-qualification-hint">点击任意处关闭</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
</PageShell>
|
</PageShell>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export default definePageConfig({
|
||||||
|
navigationStyle: 'custom',
|
||||||
|
navigationBarTitleText: '现场取货确认',
|
||||||
|
});
|
||||||
@@ -0,0 +1,251 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { View, Text, Image } from '@tarojs/components';
|
||||||
|
import Taro, { useRouter } from '@tarojs/taro';
|
||||||
|
import PageShell from '../../components/PageShell';
|
||||||
|
import SubPageHeader from '../../components/SubPageHeader';
|
||||||
|
import { goLogin } from '../../lib/auth-nav';
|
||||||
|
import { buildPayUrl } from '../../lib/checkout-nav';
|
||||||
|
import { ensurePayReady } from '../../lib/pay-ready';
|
||||||
|
import { fetchUserProfile } from '../../lib/pay-wechat';
|
||||||
|
import { request } from '../../lib/api';
|
||||||
|
import { getProductMainImage } from '../../lib/product-images';
|
||||||
|
|
||||||
|
type PreviewProduct = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
spec?: string;
|
||||||
|
subtitle?: string;
|
||||||
|
price: number;
|
||||||
|
mainImageUrl?: string | null;
|
||||||
|
carouselUrls?: string[] | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type OrderPreview = {
|
||||||
|
product: PreviewProduct;
|
||||||
|
quantity: number;
|
||||||
|
deliveryType: string;
|
||||||
|
productAmount: number;
|
||||||
|
payAmount: number;
|
||||||
|
benefitAmount: number;
|
||||||
|
quantityOk?: boolean;
|
||||||
|
quantityMessage?: string | null;
|
||||||
|
minQty?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function OrderConfirmPickupPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const productId = router.params.productId ?? '';
|
||||||
|
const [quantity, setQuantity] = useState(Math.max(2, Number(router.params.qty || 2)));
|
||||||
|
const [preview, setPreview] = useState<OrderPreview | null>(null);
|
||||||
|
const [previewLoading, setPreviewLoading] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [msg, setMsg] = useState('');
|
||||||
|
const phonePromptSkipped = useRef(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!productId) return;
|
||||||
|
let cancelled = false;
|
||||||
|
setPreviewLoading(true);
|
||||||
|
request<OrderPreview>('/trade/orders/preview', {
|
||||||
|
method: 'POST',
|
||||||
|
data: { productId, quantity, onSitePickup: true },
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
if (!cancelled) {
|
||||||
|
setPreview(data);
|
||||||
|
setMsg(data.quantityOk === false ? data.quantityMessage || '' : '');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
if (!cancelled) {
|
||||||
|
setPreview(null);
|
||||||
|
setMsg(e instanceof Error ? e.message : '加载失败');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
if (!cancelled) setPreviewLoading(false);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [productId, quantity]);
|
||||||
|
|
||||||
|
const minQty = preview?.minQty ?? 2;
|
||||||
|
const quantityOk = preview ? preview.quantityOk !== false && quantity >= minQty : false;
|
||||||
|
const canSubmit = !!preview && quantityOk && !loading && !previewLoading;
|
||||||
|
|
||||||
|
function updateQuantity(next: number) {
|
||||||
|
if (next < minQty) return;
|
||||||
|
setQuantity(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function doSubmit() {
|
||||||
|
const order = await request<{ id: string }>('/trade/orders', {
|
||||||
|
method: 'POST',
|
||||||
|
data: { productId, quantity, onSitePickup: true },
|
||||||
|
});
|
||||||
|
Taro.redirectTo({
|
||||||
|
url: buildPayUrl({
|
||||||
|
orderId: order.id,
|
||||||
|
productId,
|
||||||
|
qty: String(quantity),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
if (!canSubmit) {
|
||||||
|
if (!quantityOk) setMsg(`现场提货至少购买 ${minQty} 瓶`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const returnPath = `/pages/order-confirm-pickup/index?productId=${productId}&qty=${quantity}`;
|
||||||
|
|
||||||
|
if (!phonePromptSkipped.current) {
|
||||||
|
try {
|
||||||
|
const profile = await fetchUserProfile();
|
||||||
|
const phoneBound =
|
||||||
|
!!profile.phoneVerified ||
|
||||||
|
(!!profile.phone && /^1[3-9]\d{9}$/.test(String(profile.phone)));
|
||||||
|
if (!phoneBound) {
|
||||||
|
const { confirm, cancel } = await Taro.showModal({
|
||||||
|
title: '建议绑定手机号',
|
||||||
|
content: '绑定后便于订单通知与售后联系;也可跳过,不绑定也能继续下单。',
|
||||||
|
confirmText: '去绑定',
|
||||||
|
cancelText: '暂不绑定',
|
||||||
|
});
|
||||||
|
if (confirm) {
|
||||||
|
goLogin(returnPath, { needPhone: '1' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cancel) {
|
||||||
|
phonePromptSkipped.current = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
/* 拉取档案失败不阻塞下单 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ready = await ensurePayReady(returnPath);
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
setMsg('');
|
||||||
|
try {
|
||||||
|
await doSubmit();
|
||||||
|
} catch (e) {
|
||||||
|
setMsg(e instanceof Error ? e.message : '下单失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const productImage = preview?.product ? getProductMainImage(preview.product) : '';
|
||||||
|
const submitLabel = loading
|
||||||
|
? '提交中…'
|
||||||
|
: !quantityOk
|
||||||
|
? `至少购买 ${minQty} 瓶`
|
||||||
|
: '提交订单';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell variant="sub" className="order-confirm-page" hasFixedFooter>
|
||||||
|
<SubPageHeader title="现场取货确认" />
|
||||||
|
<View className="sub-page-body">
|
||||||
|
<View className="order-card">
|
||||||
|
<Text className="order-card-title">取货方式</Text>
|
||||||
|
<Text className="u-muted">现场取货 · 无需填写收货地址 · 免运费</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{preview ? (
|
||||||
|
<>
|
||||||
|
<View className="order-card">
|
||||||
|
<Text className="order-card-title">商品信息</Text>
|
||||||
|
<View className="order-product-row">
|
||||||
|
<View className="order-product-thumb">
|
||||||
|
{productImage ? (
|
||||||
|
<Image
|
||||||
|
className="order-product-thumb-img"
|
||||||
|
src={productImage}
|
||||||
|
mode="aspectFill"
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
<View style={{ flex: 1 }}>
|
||||||
|
<Text className="order-product-name">{preview.product.name}</Text>
|
||||||
|
{preview.product.spec ? (
|
||||||
|
<Text className="u-muted">{preview.product.spec}</Text>
|
||||||
|
) : null}
|
||||||
|
<Text className="order-product-price">
|
||||||
|
¥{Number(preview.product.price).toFixed(2)}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
<View className="order-qty-row">
|
||||||
|
<Text>购买数量</Text>
|
||||||
|
<View className="order-qty-controls">
|
||||||
|
<View
|
||||||
|
className={`order-qty-btn${quantity <= minQty ? ' order-qty-btn--disabled' : ''}`}
|
||||||
|
onClick={() => updateQuantity(Math.max(minQty, quantity - 1))}
|
||||||
|
>
|
||||||
|
<Text>−</Text>
|
||||||
|
</View>
|
||||||
|
<Text className="order-qty-value">{quantity}</Text>
|
||||||
|
<View className="order-qty-btn" onClick={() => updateQuantity(quantity + 1)}>
|
||||||
|
<Text>+</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
{!quantityOk ? (
|
||||||
|
<Text className="order-qty-hint">
|
||||||
|
{`现场提货至少购买 ${minQty} 瓶,请调整数量`}
|
||||||
|
</Text>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View className="order-card">
|
||||||
|
<Text className="order-card-title">费用明细</Text>
|
||||||
|
<View className="order-row">
|
||||||
|
<Text className="order-row-label">商品金额</Text>
|
||||||
|
<Text className="order-row-value">¥{Number(preview.productAmount).toFixed(2)}</Text>
|
||||||
|
</View>
|
||||||
|
<View className="order-row">
|
||||||
|
<Text className="order-row-label">好客权益</Text>
|
||||||
|
<Text className="order-row-value--price">¥{Number(preview.benefitAmount).toFixed(2)}</Text>
|
||||||
|
</View>
|
||||||
|
<View className="order-row">
|
||||||
|
<Text className="order-row-label">运费</Text>
|
||||||
|
<Text className="order-row-value">免运费</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</>
|
||||||
|
) : previewLoading ? (
|
||||||
|
<View className="u-empty">加载订单信息…</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{msg ? (
|
||||||
|
<Text className="u-muted" style={{ display: 'block', marginTop: 8, textAlign: 'center' }}>
|
||||||
|
{msg}
|
||||||
|
</Text>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
<View className="order-confirm-bar">
|
||||||
|
<View className="order-confirm-total">
|
||||||
|
<Text className="order-confirm-total-label">应付合计</Text>
|
||||||
|
<Text className="order-confirm-total-value">
|
||||||
|
¥{preview ? Number(preview.payAmount).toFixed(2) : '—'}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
<View
|
||||||
|
className={`order-confirm-submit${canSubmit ? '' : ' order-confirm-submit--disabled'}`}
|
||||||
|
onClick={() => {
|
||||||
|
if (!canSubmit) return;
|
||||||
|
void submit();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text>{submitLabel}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -333,7 +333,11 @@ export default function OrderConfirmPage() {
|
|||||||
{!previewLoading && !preview && productId ? (
|
{!previewLoading && !preview && productId ? (
|
||||||
<View className="u-empty">无法加载商品信息</View>
|
<View className="u-empty">无法加载商品信息</View>
|
||||||
) : null}
|
) : null}
|
||||||
{msg ? <Text className="u-muted" style={{ display: 'block', marginTop: 8 }}>{msg}</Text> : null}
|
{msg ? (
|
||||||
|
<Text className="u-muted" style={{ display: 'block', marginTop: 8, textAlign: 'center' }}>
|
||||||
|
{msg}
|
||||||
|
</Text>
|
||||||
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View className="order-confirm-bar">
|
<View className="order-confirm-bar">
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ type OrderDetail = {
|
|||||||
receiverAddress?: string;
|
receiverAddress?: string;
|
||||||
createdAt?: string;
|
createdAt?: string;
|
||||||
originOrderId?: string | null;
|
originOrderId?: string | null;
|
||||||
|
orderType?: string;
|
||||||
|
isProxyOrder?: boolean;
|
||||||
|
proxyPartnerName?: string | null;
|
||||||
items?: OrderItem[];
|
items?: OrderItem[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,7 +50,9 @@ const STATUS_LABELS: Record<string, string> = {
|
|||||||
PENDING_SHIP: '待发货',
|
PENDING_SHIP: '待发货',
|
||||||
OUT_WAREHOUSE: '出库中',
|
OUT_WAREHOUSE: '出库中',
|
||||||
SHIPPING: '配送中',
|
SHIPPING: '配送中',
|
||||||
|
SHIPPED: '配送中',
|
||||||
PENDING_RECEIVE: '待签收',
|
PENDING_RECEIVE: '待签收',
|
||||||
|
DELIVERED: '待签收',
|
||||||
COMPLETED: '已完成',
|
COMPLETED: '已完成',
|
||||||
CANCELLED: '已取消',
|
CANCELLED: '已取消',
|
||||||
REFUNDING: '退款中',
|
REFUNDING: '退款中',
|
||||||
@@ -68,6 +73,7 @@ export default function OrderDetailPage() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const orderId = router.params.id ?? '';
|
const orderId = router.params.id ?? '';
|
||||||
const [order, setOrder] = useState<OrderDetail | null>(null);
|
const [order, setOrder] = useState<OrderDetail | null>(null);
|
||||||
|
const [confirming, setConfirming] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!orderId) return;
|
if (!orderId) return;
|
||||||
@@ -76,7 +82,12 @@ export default function OrderDetailPage() {
|
|||||||
.catch((e) => toast(e instanceof Error ? e.message : '加载失败'));
|
.catch((e) => toast(e instanceof Error ? e.message : '加载失败'));
|
||||||
}, [orderId]);
|
}, [orderId]);
|
||||||
|
|
||||||
const canPay = !!order && order.status === 'PENDING_PAY' && !order.originOrderId;
|
const isReship = !!order?.originOrderId;
|
||||||
|
const isProxy = !!order && (order.isProxyOrder || order.orderType === 'PROXY');
|
||||||
|
const canPay = !!order && order.status === 'PENDING_PAY' && !isReship;
|
||||||
|
const canConfirmReceive =
|
||||||
|
!!order && !isReship && !isProxy && ['PENDING_RECEIVE', 'DELIVERED'].includes(order.status || '');
|
||||||
|
|
||||||
const item = order?.items?.[0];
|
const item = order?.items?.[0];
|
||||||
const productName = item?.productName || order?.productName || '杜康商品';
|
const productName = item?.productName || order?.productName || '杜康商品';
|
||||||
const quantity = item?.quantity ?? order?.quantity ?? order?.qty ?? 1;
|
const quantity = item?.quantity ?? order?.quantity ?? order?.qty ?? 1;
|
||||||
@@ -111,10 +122,36 @@ export default function OrderDetailPage() {
|
|||||||
Taro.navigateTo({ url: '/pages/customer-service/index' });
|
Taro.navigateTo({ url: '/pages/customer-service/index' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function confirmReceive() {
|
||||||
|
if (!order || !canConfirmReceive || confirming) return;
|
||||||
|
|
||||||
|
const { confirm } = await Taro.showModal({
|
||||||
|
title: '确认收货?',
|
||||||
|
content: '请确认已收到商品。确认后订单将完成,好客权益可正常使用。',
|
||||||
|
confirmText: '确认收货',
|
||||||
|
cancelText: '再想想',
|
||||||
|
});
|
||||||
|
if (!confirm) return;
|
||||||
|
|
||||||
|
setConfirming(true);
|
||||||
|
try {
|
||||||
|
const updated = await request<OrderDetail>(`/trade/orders/${order.id}/confirm-receive`, {
|
||||||
|
method: 'POST',
|
||||||
|
data: {},
|
||||||
|
});
|
||||||
|
setOrder(updated);
|
||||||
|
toast('已确认收货');
|
||||||
|
} catch (e) {
|
||||||
|
toast(e instanceof Error ? e.message : '确认收货失败');
|
||||||
|
} finally {
|
||||||
|
setConfirming(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const pageClass = [
|
const pageClass = [
|
||||||
'order-detail-page',
|
'order-detail-page',
|
||||||
order ? 'order-detail-page--with-actions' : '',
|
order ? 'order-detail-page--with-actions' : '',
|
||||||
canPay ? 'order-detail-page--with-pay' : '',
|
canPay || canConfirmReceive ? 'order-detail-page--with-pay' : '',
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(' ');
|
.join(' ');
|
||||||
@@ -133,9 +170,15 @@ export default function OrderDetailPage() {
|
|||||||
<>
|
<>
|
||||||
<View className="order-card">
|
<View className="order-card">
|
||||||
<Text className="order-card-title">订单状态</Text>
|
<Text className="order-card-title">订单状态</Text>
|
||||||
<Text className="order-list-status">
|
<View className="order-status-row">
|
||||||
{STATUS_LABELS[order.status || ''] || order.status || '处理中'}
|
<Text className="order-list-status">
|
||||||
</Text>
|
{STATUS_LABELS[order.status || ''] || order.status || '处理中'}
|
||||||
|
</Text>
|
||||||
|
{isProxy ? <Text className="order-proxy-badge">代下单</Text> : null}
|
||||||
|
</View>
|
||||||
|
{isProxy && order.proxyPartnerName ? (
|
||||||
|
<Text className="order-proxy-hint">由合伙人 {order.proxyPartnerName} 代下</Text>
|
||||||
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
<View className="order-card">
|
<View className="order-card">
|
||||||
<Text className="order-card-title">商品信息</Text>
|
<Text className="order-card-title">商品信息</Text>
|
||||||
@@ -189,7 +232,11 @@ export default function OrderDetailPage() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
{order ? (
|
{order ? (
|
||||||
<View className={`order-detail-actionbar${canPay ? ' order-detail-actionbar--with-pay' : ''}`}>
|
<View
|
||||||
|
className={`order-detail-actionbar${
|
||||||
|
canPay || canConfirmReceive ? ' order-detail-actionbar--with-pay' : ''
|
||||||
|
}`}
|
||||||
|
>
|
||||||
{isWeapp ? (
|
{isWeapp ? (
|
||||||
<ContactCsButton
|
<ContactCsButton
|
||||||
className="order-detail-cs-btn"
|
className="order-detail-cs-btn"
|
||||||
@@ -219,6 +266,14 @@ export default function OrderDetailPage() {
|
|||||||
</View>
|
</View>
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
|
{canConfirmReceive ? (
|
||||||
|
<View
|
||||||
|
className={`order-confirm-submit${confirming ? ' order-confirm-submit--disabled' : ''}`}
|
||||||
|
onClick={confirming ? undefined : () => void confirmReceive()}
|
||||||
|
>
|
||||||
|
{confirming ? '提交中…' : '确认收货'}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
</PageShell>
|
</PageShell>
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import SubPageHeader from '../../components/SubPageHeader';
|
|||||||
import { request, toast } from '../../lib/api';
|
import { request, toast } from '../../lib/api';
|
||||||
import { buildPayUrl } from '../../lib/checkout-nav';
|
import { buildPayUrl } from '../../lib/checkout-nav';
|
||||||
|
|
||||||
|
import { ORDER_STATUS_LABELS } from '@dukang/shared-types';
|
||||||
|
|
||||||
const TABS = [
|
const TABS = [
|
||||||
{ key: 'all', label: '全部订单' },
|
{ key: 'all', label: '全部订单' },
|
||||||
{ key: 'pending_pay', label: '待付款' },
|
{ key: 'pending_pay', label: '待付款' },
|
||||||
@@ -13,22 +15,12 @@ const TABS = [
|
|||||||
{ key: 'completed', label: '已完成' },
|
{ key: 'completed', label: '已完成' },
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
const STATUS_LABELS: Record<string, string> = {
|
|
||||||
PENDING_PAY: '待付款',
|
|
||||||
PENDING_SHIP: '已付款',
|
|
||||||
OUT_WAREHOUSE: '已付款',
|
|
||||||
SHIPPED: '已付款',
|
|
||||||
DELIVERED: '已付款',
|
|
||||||
COMPLETED: '已完成',
|
|
||||||
CANCELLED: '已取消',
|
|
||||||
};
|
|
||||||
|
|
||||||
function orderStatusLabel(tab: string, status?: string): string {
|
function orderStatusLabel(tab: string, status?: string): string {
|
||||||
if (tab !== 'all') {
|
if (tab !== 'all') {
|
||||||
return TABS.find((t) => t.key === tab)?.label || status || '';
|
return TABS.find((t) => t.key === tab)?.label || status || '';
|
||||||
}
|
}
|
||||||
if (!status) return '';
|
if (!status) return '';
|
||||||
return STATUS_LABELS[status] || status;
|
return ORDER_STATUS_LABELS[status] || status;
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderItem = {
|
type OrderItem = {
|
||||||
@@ -47,6 +39,9 @@ type OrderRow = {
|
|||||||
qty?: number;
|
qty?: number;
|
||||||
quantity?: number;
|
quantity?: number;
|
||||||
originOrderId?: string | null;
|
originOrderId?: string | null;
|
||||||
|
orderType?: string;
|
||||||
|
isProxyOrder?: boolean;
|
||||||
|
proxyPartnerName?: string | null;
|
||||||
items?: OrderItem[];
|
items?: OrderItem[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,6 +105,7 @@ export default function OrdersPage() {
|
|||||||
const qty = item?.quantity ?? o.quantity ?? o.qty ?? 1;
|
const qty = item?.quantity ?? o.quantity ?? o.qty ?? 1;
|
||||||
const unitPrice = Number(item?.unitPrice ?? 0);
|
const unitPrice = Number(item?.unitPrice ?? 0);
|
||||||
const canPay = o.status === 'PENDING_PAY' && !o.originOrderId;
|
const canPay = o.status === 'PENDING_PAY' && !o.originOrderId;
|
||||||
|
const isProxy = o.isProxyOrder || o.orderType === 'PROXY';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
@@ -118,11 +114,17 @@ export default function OrdersPage() {
|
|||||||
onClick={() => Taro.navigateTo({ url: `/pages/order-detail/index?id=${o.id}` })}
|
onClick={() => Taro.navigateTo({ url: `/pages/order-detail/index?id=${o.id}` })}
|
||||||
>
|
>
|
||||||
<View className="order-list-head">
|
<View className="order-list-head">
|
||||||
<Text className="order-list-no">{o.orderNo || o.id}</Text>
|
<View className="order-list-head-left">
|
||||||
|
<Text className="order-list-no">{o.orderNo || o.id}</Text>
|
||||||
|
{isProxy ? <Text className="order-proxy-badge">代下单</Text> : null}
|
||||||
|
</View>
|
||||||
<Text className="order-list-status">
|
<Text className="order-list-status">
|
||||||
{orderStatusLabel(tab, o.status)}
|
{orderStatusLabel(tab, o.status)}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
{isProxy && o.proxyPartnerName ? (
|
||||||
|
<Text className="order-proxy-hint">由合伙人 {o.proxyPartnerName} 代下</Text>
|
||||||
|
) : null}
|
||||||
<View className="order-list-body">
|
<View className="order-list-body">
|
||||||
<View className="order-list-thumb">
|
<View className="order-list-thumb">
|
||||||
{productImage ? (
|
{productImage ? (
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export default function PayPage() {
|
|||||||
const [msg, setMsg] = useState('');
|
const [msg, setMsg] = useState('');
|
||||||
const [orderNo, setOrderNo] = useState('');
|
const [orderNo, setOrderNo] = useState('');
|
||||||
const [payAmount, setPayAmount] = useState('—');
|
const [payAmount, setPayAmount] = useState('—');
|
||||||
|
const [deliveryType, setDeliveryType] = useState('');
|
||||||
|
|
||||||
const returnPath = orderId
|
const returnPath = orderId
|
||||||
? `/pages/pay/index?orderId=${orderId}`
|
? `/pages/pay/index?orderId=${orderId}`
|
||||||
@@ -62,11 +63,15 @@ export default function PayPage() {
|
|||||||
setPayAmount('—');
|
setPayAmount('—');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
request<{ orderNo?: string; payAmount?: number | string; totalAmount?: number | string }>(
|
request<{
|
||||||
`/trade/orders/${orderId}`,
|
orderNo?: string;
|
||||||
)
|
payAmount?: number | string;
|
||||||
|
totalAmount?: number | string;
|
||||||
|
deliveryType?: string;
|
||||||
|
}>(`/trade/orders/${orderId}`)
|
||||||
.then((order) => {
|
.then((order) => {
|
||||||
setOrderNo(order.orderNo || '');
|
setOrderNo(order.orderNo || '');
|
||||||
|
setDeliveryType(order.deliveryType || '');
|
||||||
const amount = Number(order.payAmount ?? order.totalAmount ?? 0);
|
const amount = Number(order.payAmount ?? order.totalAmount ?? 0);
|
||||||
if (Number.isFinite(amount) && amount > 0) {
|
if (Number.isFinite(amount) && amount > 0) {
|
||||||
setPayAmount(amount.toFixed(2));
|
setPayAmount(amount.toFixed(2));
|
||||||
@@ -74,6 +79,7 @@ export default function PayPage() {
|
|||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
setOrderNo('');
|
setOrderNo('');
|
||||||
|
setDeliveryType('');
|
||||||
toast(e instanceof Error ? e.message : '加载订单失败');
|
toast(e instanceof Error ? e.message : '加载订单失败');
|
||||||
});
|
});
|
||||||
}, [orderId]);
|
}, [orderId]);
|
||||||
@@ -137,7 +143,11 @@ export default function PayPage() {
|
|||||||
} else {
|
} else {
|
||||||
toast('支付成功', 'success');
|
toast('支付成功', 'success');
|
||||||
}
|
}
|
||||||
Taro.redirectTo({ url: '/pages/orders/index?tab=paid' });
|
if (deliveryType === 'ON_SITE_PICKUP') {
|
||||||
|
Taro.redirectTo({ url: `/pages/pickup-receive/index?id=${orderId}` });
|
||||||
|
} else {
|
||||||
|
Taro.redirectTo({ url: '/pages/orders/index?tab=paid' });
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isWechatAuthRequiredError(e)) {
|
if (isWechatAuthRequiredError(e)) {
|
||||||
setNeedsWechatAuth(true);
|
setNeedsWechatAuth(true);
|
||||||
@@ -200,7 +210,7 @@ export default function PayPage() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{msg ? (
|
{msg ? (
|
||||||
<Text className="pay-wechat-auth-msg" style={{ display: 'block', marginTop: 12 }}>
|
<Text className="pay-wechat-auth-msg" style={{ marginTop: 12 }}>
|
||||||
{msg}
|
{msg}
|
||||||
</Text>
|
</Text>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export default definePageConfig({
|
||||||
|
navigationStyle: 'custom',
|
||||||
|
navigationBarTitleText: '确认收货',
|
||||||
|
});
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
import { useCallback, useState } from 'react';
|
||||||
|
import { View, Text, Image } from '@tarojs/components';
|
||||||
|
import Taro, { useDidShow, useRouter } from '@tarojs/taro';
|
||||||
|
import PageShell from '../../components/PageShell';
|
||||||
|
import SubPageHeader from '../../components/SubPageHeader';
|
||||||
|
import { request, toast } from '../../lib/api';
|
||||||
|
import { getProductMainImage } from '../../lib/product-images';
|
||||||
|
|
||||||
|
type OrderDetail = {
|
||||||
|
id: string;
|
||||||
|
orderNo?: string;
|
||||||
|
status?: string;
|
||||||
|
payAmount?: number | string;
|
||||||
|
productName?: string;
|
||||||
|
productSpec?: string;
|
||||||
|
quantity?: number;
|
||||||
|
product?: {
|
||||||
|
name?: string;
|
||||||
|
spec?: string;
|
||||||
|
mainImageUrl?: string | null;
|
||||||
|
carouselUrls?: string[] | null;
|
||||||
|
};
|
||||||
|
imageUrl?: string | null;
|
||||||
|
mainImageUrl?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function PickupReceivePage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const orderId = router.params.id ?? router.params.orderId ?? '';
|
||||||
|
const [order, setOrder] = useState<OrderDetail | null>(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
|
const load = useCallback(() => {
|
||||||
|
if (!orderId) return;
|
||||||
|
setLoading(true);
|
||||||
|
request<OrderDetail>(`/trade/orders/${orderId}`)
|
||||||
|
.then((data) => setOrder(data))
|
||||||
|
.catch((e) => toast(e instanceof Error ? e.message : '加载失败'))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, [orderId]);
|
||||||
|
|
||||||
|
useDidShow(() => {
|
||||||
|
load();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function confirmReceive() {
|
||||||
|
if (!orderId || submitting) return;
|
||||||
|
setSubmitting(true);
|
||||||
|
try {
|
||||||
|
await request(`/trade/orders/${orderId}/confirm-receive`, {
|
||||||
|
method: 'POST',
|
||||||
|
data: {},
|
||||||
|
});
|
||||||
|
toast('确认收货成功', 'success');
|
||||||
|
setTimeout(() => {
|
||||||
|
Taro.redirectTo({ url: '/pages/orders/index?tab=done' });
|
||||||
|
}, 500);
|
||||||
|
} catch (e) {
|
||||||
|
toast(e instanceof Error ? e.message : '确认失败');
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = order?.productName || order?.product?.name || '商品';
|
||||||
|
const spec = order?.productSpec || order?.product?.spec;
|
||||||
|
const image =
|
||||||
|
order?.mainImageUrl ||
|
||||||
|
order?.imageUrl ||
|
||||||
|
(order?.product ? getProductMainImage(order.product) : '') ||
|
||||||
|
'';
|
||||||
|
const amount = Number(order?.payAmount ?? 0);
|
||||||
|
const canConfirm = order?.status === 'PENDING_RECEIVE' || order?.status === 'DELIVERED';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageShell variant="sub" className="order-confirm-page" hasFixedFooter>
|
||||||
|
<SubPageHeader title="确认收货" />
|
||||||
|
<View className="sub-page-body">
|
||||||
|
<View className="order-card">
|
||||||
|
<Text className="order-card-title">现场取货</Text>
|
||||||
|
<Text className="u-muted">请确认已在现场拿到商品后再点击确认收货</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{loading && !order ? (
|
||||||
|
<View className="order-card">
|
||||||
|
<Text className="u-muted">加载中…</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{order ? (
|
||||||
|
<>
|
||||||
|
<View className="order-card">
|
||||||
|
<View className="order-row">
|
||||||
|
<Text className="order-row-label">订单号</Text>
|
||||||
|
<Text className="order-row-value">{order.orderNo || '—'}</Text>
|
||||||
|
</View>
|
||||||
|
<View className="order-product-row" style={{ marginTop: 12 }}>
|
||||||
|
<View className="order-product-thumb">
|
||||||
|
{image ? (
|
||||||
|
<Image className="order-product-thumb-img" src={image} mode="aspectFill" />
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
<View style={{ flex: 1 }}>
|
||||||
|
<Text className="order-product-name">{name}</Text>
|
||||||
|
{spec ? <Text className="u-muted">{spec}</Text> : null}
|
||||||
|
<Text className="u-muted">×{order.quantity ?? 1}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View className="order-card">
|
||||||
|
<View className="order-row">
|
||||||
|
<Text className="order-row-label">实付金额</Text>
|
||||||
|
<Text className="order-row-value order-pay-amount">
|
||||||
|
¥{Number.isFinite(amount) ? amount.toFixed(2) : '—'}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
<View className="pay-bar">
|
||||||
|
<View
|
||||||
|
className="order-confirm-submit"
|
||||||
|
style={{ flex: 1, opacity: canConfirm && !submitting ? 1 : 0.6 }}
|
||||||
|
onClick={() => {
|
||||||
|
if (!canConfirm || submitting) return;
|
||||||
|
void confirmReceive();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text>{submitting ? '提交中…' : canConfirm ? '确认收货' : '订单状态不可确认'}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</PageShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -11,17 +11,51 @@ type BenefitSummary = {
|
|||||||
maxRedeemAmount: number;
|
maxRedeemAmount: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MIN_REDEEM_AMOUNT = 0.01;
|
||||||
|
|
||||||
function formatMoney(amount: number) {
|
function formatMoney(amount: number) {
|
||||||
return amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
return amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核销金额输入清洗:
|
||||||
|
* - 只保留数字与一个小数点
|
||||||
|
* - 小数最多 2 位(再输入会被截断)
|
||||||
|
* - 去掉多余前导 0
|
||||||
|
*/
|
||||||
|
function sanitizeRedeemAmountInput(raw: string): string {
|
||||||
|
let next = String(raw ?? '').replace(/[^\d.]/g, '');
|
||||||
|
if (!next) return '';
|
||||||
|
|
||||||
|
const firstDot = next.indexOf('.');
|
||||||
|
if (firstDot >= 0) {
|
||||||
|
const intRaw = next.slice(0, firstDot).replace(/\D/g, '');
|
||||||
|
const decRaw = next
|
||||||
|
.slice(firstDot + 1)
|
||||||
|
.replace(/\D/g, '')
|
||||||
|
.slice(0, 2);
|
||||||
|
const intPart = intRaw.replace(/^0+(?=\d)/, '') || '0';
|
||||||
|
if (next.endsWith('.') && decRaw.length === 0) {
|
||||||
|
return `${intPart}.`;
|
||||||
|
}
|
||||||
|
if (decRaw.length > 0) {
|
||||||
|
return `${intPart}.${decRaw}`;
|
||||||
|
}
|
||||||
|
return intPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
return next.replace(/^0+(?=\d)/, '');
|
||||||
|
}
|
||||||
|
|
||||||
export default function RedeemPage() {
|
export default function RedeemPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const couponId = router.params.couponId;
|
const couponId = router.params.couponId;
|
||||||
const initialAmount = router.params.amount ?? '';
|
const initialAmount = router.params.amount ?? '';
|
||||||
const [balance, setBalance] = useState(0);
|
const [balance, setBalance] = useState(0);
|
||||||
const [couponBalance, setCouponBalance] = useState<number | null>(null);
|
const [couponBalance, setCouponBalance] = useState<number | null>(null);
|
||||||
const [amount, setAmount] = useState(initialAmount);
|
const [amount, setAmount] = useState(() => sanitizeRedeemAmountInput(initialAmount));
|
||||||
|
/** 原生 input 在截断小数后偶发不同步,强制 remount 对齐受控值 */
|
||||||
|
const [inputKey, setInputKey] = useState(0);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const redeemableMax = couponId ? (couponBalance ?? 0) : balance;
|
const redeemableMax = couponId ? (couponBalance ?? 0) : balance;
|
||||||
@@ -50,14 +84,24 @@ export default function RedeemPage() {
|
|||||||
}, [couponId]);
|
}, [couponId]);
|
||||||
|
|
||||||
function fillMaxAmount() {
|
function fillMaxAmount() {
|
||||||
if (redeemableMax <= 0) return;
|
if (redeemableMax < MIN_REDEEM_AMOUNT) return;
|
||||||
setAmount(String(redeemableMax));
|
setAmount(sanitizeRedeemAmountInput(redeemableMax.toFixed(2)));
|
||||||
|
setInputKey((k) => k + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onAmountChange(raw: string) {
|
||||||
|
const next = sanitizeRedeemAmountInput(raw);
|
||||||
|
setAmount(next);
|
||||||
|
// 用户试图输入超过两位小数 / 非法字符时,强制刷新原生框显示
|
||||||
|
if (next !== raw) {
|
||||||
|
setInputKey((k) => k + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
const value = Math.round(Number(amount) * 100) / 100;
|
const value = Math.round(Number(amount) * 100) / 100;
|
||||||
if (!(value > 0)) {
|
if (!Number.isFinite(value) || value < MIN_REDEEM_AMOUNT) {
|
||||||
toast('请输入核销金额');
|
toast(`核销金额不能低于 ${MIN_REDEEM_AMOUNT.toFixed(2)} 元`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (value > redeemableMax) {
|
if (value > redeemableMax) {
|
||||||
@@ -98,12 +142,15 @@ export default function RedeemPage() {
|
|||||||
</View>
|
</View>
|
||||||
<View className="redeem-input-wrap">
|
<View className="redeem-input-wrap">
|
||||||
<Input
|
<Input
|
||||||
|
key={inputKey}
|
||||||
className="redeem-input"
|
className="redeem-input"
|
||||||
type="digit"
|
type="digit"
|
||||||
placeholder="输入核销金额"
|
placeholder="输入核销金额"
|
||||||
placeholderClass="redeem-input-placeholder"
|
placeholderClass="redeem-input-placeholder"
|
||||||
value={amount}
|
value={amount}
|
||||||
onInput={(e) => setAmount(e.detail.value)}
|
maxlength={12}
|
||||||
|
onInput={(e) => onAmountChange(e.detail.value)}
|
||||||
|
onBlur={(e) => onAmountChange(e.detail.value)}
|
||||||
style={{ textAlign: 'center' }}
|
style={{ textAlign: 'center' }}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
@@ -115,12 +162,14 @@ export default function RedeemPage() {
|
|||||||
全部核销
|
全部核销
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text className="redeem-tips">
|
<View className="redeem-tips">
|
||||||
直接核销:金额须大于 0 且不超过全部可用权益余额。核销码有效期 3 分钟,请到店出示。
|
<Text className="redeem-tips-text">
|
||||||
</Text>
|
核销金额最低 0.01 元,小数最多两位。不超过可用权益余额。核销码有效期 3 分钟,请到店出示给收银员扫码。
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
<View
|
<View
|
||||||
className={`redeem-submit${loading || redeemableMax <= 0 ? ' redeem-submit--disabled' : ''}`}
|
className={`redeem-submit${loading || redeemableMax < MIN_REDEEM_AMOUNT ? ' redeem-submit--disabled' : ''}`}
|
||||||
onClick={loading || redeemableMax <= 0 ? undefined : submit}
|
onClick={loading || redeemableMax < MIN_REDEEM_AMOUNT ? undefined : submit}
|
||||||
>
|
>
|
||||||
<Text>{loading ? '生成中...' : '生成核销码'}</Text>
|
<Text>{loading ? '生成中...' : '生成核销码'}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { View, Text } from '@tarojs/components';
|
import { View, Text, Image } from '@tarojs/components';
|
||||||
import Taro, { usePageScroll, useRouter, useShareAppMessage, useShareTimeline } from '@tarojs/taro';
|
import Taro, { usePageScroll, useRouter, useShareAppMessage, useShareTimeline } from '@tarojs/taro';
|
||||||
import PageShell from '../../components/PageShell';
|
import PageShell from '../../components/PageShell';
|
||||||
import PageNavBar from '../../components/PageNavBar';
|
import PageNavBar from '../../components/PageNavBar';
|
||||||
@@ -13,19 +13,61 @@ import {
|
|||||||
toWeappShareMessage,
|
toWeappShareMessage,
|
||||||
} from '../../lib/wechat-share';
|
} from '../../lib/wechat-share';
|
||||||
|
|
||||||
|
type StoreMedia = {
|
||||||
|
url?: string | null;
|
||||||
|
bizType?: string | null;
|
||||||
|
mediaType?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
type Store = {
|
type Store = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
address?: string;
|
address?: string;
|
||||||
|
province?: string;
|
||||||
|
cityName?: string;
|
||||||
|
city?: string;
|
||||||
district?: string;
|
district?: string;
|
||||||
phone?: string;
|
phone?: string;
|
||||||
|
intro?: string | null;
|
||||||
|
benefitUsageRule?: string | null;
|
||||||
coverUrl?: string | null;
|
coverUrl?: string | null;
|
||||||
carouselUrls?: string[] | null;
|
carouselUrls?: string[] | null;
|
||||||
|
media?: StoreMedia[] | null;
|
||||||
openTime?: string | null;
|
openTime?: string | null;
|
||||||
closeTime?: string | null;
|
closeTime?: string | null;
|
||||||
|
openTime2?: string | null;
|
||||||
|
closeTime2?: string | null;
|
||||||
|
avgPrice?: number | null;
|
||||||
|
latitude?: number | string | null;
|
||||||
|
longitude?: number | string | null;
|
||||||
category?: { name: string } | null;
|
category?: { name: string } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function uniqueUrls(urls: Array<string | null | undefined>) {
|
||||||
|
const seen = new Set<string>();
|
||||||
|
const out: string[] = [];
|
||||||
|
for (const raw of urls) {
|
||||||
|
const url = String(raw || '').trim();
|
||||||
|
if (!url || seen.has(url)) continue;
|
||||||
|
seen.add(url);
|
||||||
|
out.push(url);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function envPhotoUrls(store: Store) {
|
||||||
|
return uniqueUrls(
|
||||||
|
(store.media || [])
|
||||||
|
.filter((m) => !m.bizType || m.bizType === 'ENV')
|
||||||
|
.map((m) => m.url),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fullAddress(store: Store) {
|
||||||
|
const city = store.cityName || store.city || '';
|
||||||
|
return `${store.province || ''}${city}${store.district || ''}${store.address || ''}`.trim();
|
||||||
|
}
|
||||||
|
|
||||||
export default function StoreDetailPage() {
|
export default function StoreDetailPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const storeId = router.params.id ?? '';
|
const storeId = router.params.id ?? '';
|
||||||
@@ -52,12 +94,15 @@ export default function StoreDetailPage() {
|
|||||||
}, [storeId]);
|
}, [storeId]);
|
||||||
|
|
||||||
const sharePayload = useMemo(
|
const sharePayload = useMemo(
|
||||||
() => ({
|
() => {
|
||||||
title: store?.name || DEFAULT_SHARE_TITLE,
|
const envFirst = store ? envPhotoUrls(store)[0] : undefined;
|
||||||
desc: store?.address || DEFAULT_SHARE_DESC,
|
return {
|
||||||
path: `/pages/store-detail/index?id=${storeId}`,
|
title: store?.name || DEFAULT_SHARE_TITLE,
|
||||||
imgUrl: store?.coverUrl || store?.carouselUrls?.[0] || undefined,
|
desc: store?.intro?.trim() || store?.address || DEFAULT_SHARE_DESC,
|
||||||
}),
|
path: `/pages/store-detail/index?id=${storeId}`,
|
||||||
|
imgUrl: store?.coverUrl || envFirst || store?.carouselUrls?.[0] || undefined,
|
||||||
|
};
|
||||||
|
},
|
||||||
[store, storeId],
|
[store, storeId],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -74,6 +119,44 @@ export default function StoreDetailPage() {
|
|||||||
else Taro.switchTab({ url: '/pages/stores/index' });
|
else Taro.switchTab({ url: '/pages/stores/index' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function callStore() {
|
||||||
|
if (!store?.phone) {
|
||||||
|
toast('暂无门店电话');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Taro.makePhoneCall({ phoneNumber: store.phone }).catch(() => toast('无法拨打电话'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function openMap() {
|
||||||
|
if (!store) return;
|
||||||
|
const lat = store.latitude != null ? Number(store.latitude) : NaN;
|
||||||
|
const lng = store.longitude != null ? Number(store.longitude) : NaN;
|
||||||
|
const address = fullAddress(store) || store.address || store.name;
|
||||||
|
|
||||||
|
if (Number.isFinite(lat) && Number.isFinite(lng)) {
|
||||||
|
Taro.openLocation({
|
||||||
|
latitude: lat,
|
||||||
|
longitude: lng,
|
||||||
|
name: store.name,
|
||||||
|
address,
|
||||||
|
scale: 16,
|
||||||
|
}).catch(() => {
|
||||||
|
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
|
||||||
|
window.location.href = `https://uri.amap.com/marker?position=${lng},${lat}&name=${encodeURIComponent(store.name)}&address=${encodeURIComponent(address)}`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toast('无法打开地图导航');
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' && address) {
|
||||||
|
window.location.href = `https://uri.amap.com/search?keyword=${encodeURIComponent(address)}&src=dukang`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toast('门店位置待完善,暂无法导航');
|
||||||
|
}
|
||||||
|
|
||||||
if (!store) {
|
if (!store) {
|
||||||
return (
|
return (
|
||||||
<PageShell variant="scroll" className="store-detail-page">
|
<PageShell variant="scroll" className="store-detail-page">
|
||||||
@@ -83,12 +166,25 @@ export default function StoreDetailPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const images =
|
const envPhotos = envPhotoUrls(store);
|
||||||
(store.carouselUrls && store.carouselUrls.length > 0
|
const images = uniqueUrls([
|
||||||
? store.carouselUrls
|
store.coverUrl,
|
||||||
: store.coverUrl
|
...(store.carouselUrls || []),
|
||||||
? [store.coverUrl]
|
...envPhotos,
|
||||||
: []) as string[];
|
]);
|
||||||
|
|
||||||
|
const intro = store.intro?.trim() || '';
|
||||||
|
const benefitRuleRaw = store.benefitUsageRule?.trim() || '';
|
||||||
|
const benefitRule =
|
||||||
|
benefitRuleRaw && !/^null$/i.test(benefitRuleRaw) ? benefitRuleRaw : '';
|
||||||
|
|
||||||
|
function previewEnv(index: number) {
|
||||||
|
if (!envPhotos.length) return;
|
||||||
|
Taro.previewImage({
|
||||||
|
current: envPhotos[index],
|
||||||
|
urls: envPhotos,
|
||||||
|
}).catch(() => toast('无法预览图片'));
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageShell variant="scroll" className="store-detail-page" hasFixedFooter>
|
<PageShell variant="scroll" className="store-detail-page" hasFixedFooter>
|
||||||
@@ -107,14 +203,39 @@ export default function StoreDetailPage() {
|
|||||||
|
|
||||||
<View className="store-detail-info-card">
|
<View className="store-detail-info-card">
|
||||||
<Text className="store-detail-name">{store.name}</Text>
|
<Text className="store-detail-name">{store.name}</Text>
|
||||||
|
|
||||||
|
<View className="store-detail-row">
|
||||||
|
<Text className="store-detail-meta store-detail-meta--flex">
|
||||||
|
{store.district ? `${store.district} · ` : ''}
|
||||||
|
{store.address || '地址待完善'}
|
||||||
|
</Text>
|
||||||
|
<Text className="store-detail-action" onClick={openMap}>
|
||||||
|
导航
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
<Text className="store-detail-meta">
|
<Text className="store-detail-meta">
|
||||||
{store.district ? `${store.district} · ` : ''}
|
营业时间:{' '}
|
||||||
{store.address || '地址待完善'}
|
{(() => {
|
||||||
|
const parts: string[] = [];
|
||||||
|
if (store.openTime && store.closeTime) parts.push(`${store.openTime}-${store.closeTime}`);
|
||||||
|
if (store.openTime2 && store.closeTime2) parts.push(`${store.openTime2}-${store.closeTime2}`);
|
||||||
|
return parts.length ? parts.join(',') : '10:00-22:00';
|
||||||
|
})()}
|
||||||
</Text>
|
</Text>
|
||||||
<Text className="store-detail-meta">
|
{store.avgPrice != null && Number(store.avgPrice) > 0 ? (
|
||||||
营业时间: {store.openTime && store.closeTime ? `${store.openTime}-${store.closeTime}` : '10:00-22:00'}
|
<Text className="store-detail-meta">人均约 ¥{Number(store.avgPrice).toFixed(0)}</Text>
|
||||||
</Text>
|
) : null}
|
||||||
{store.phone ? <Text className="store-detail-meta">电话: {store.phone}</Text> : null}
|
|
||||||
|
{store.phone ? (
|
||||||
|
<View className="store-detail-row">
|
||||||
|
<Text className="store-detail-meta store-detail-meta--flex">电话: {store.phone}</Text>
|
||||||
|
<Text className="store-detail-action" onClick={callStore}>
|
||||||
|
拨打
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<View className="store-detail-tags">
|
<View className="store-detail-tags">
|
||||||
{store.category?.name ? (
|
{store.category?.name ? (
|
||||||
<Text className="store-detail-tag">{store.category.name}</Text>
|
<Text className="store-detail-tag">{store.category.name}</Text>
|
||||||
@@ -124,8 +245,42 @@ export default function StoreDetailPage() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{intro ? (
|
||||||
|
<View className="store-detail-section">
|
||||||
|
<Text className="store-detail-section-title">门店详情</Text>
|
||||||
|
<Text className="store-detail-intro">{intro}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{benefitRule ? (
|
||||||
|
<View className="store-detail-section">
|
||||||
|
<Text className="store-detail-section-title">好客权益券使用规则</Text>
|
||||||
|
<Text className="store-detail-intro">{benefitRule}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{envPhotos.length > 0 ? (
|
||||||
|
<View className="store-detail-section">
|
||||||
|
<Text className="store-detail-section-title">店内环境</Text>
|
||||||
|
<View className="store-detail-env-grid">
|
||||||
|
{envPhotos.map((url, index) => (
|
||||||
|
<View
|
||||||
|
key={`${url}-${index}`}
|
||||||
|
className="store-detail-env-item"
|
||||||
|
onClick={() => previewEnv(index)}
|
||||||
|
>
|
||||||
|
<Image className="store-detail-env-img" src={url} mode="aspectFill" />
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<View className="store-detail-bar">
|
<View className="store-detail-bar">
|
||||||
<View className="u-btn u-btn--block" onClick={() => toast('核销请前往「好客权益」')}>
|
<View
|
||||||
|
className="u-btn u-btn--block"
|
||||||
|
onClick={() => Taro.navigateTo({ url: '/pages/redeem/index' })}
|
||||||
|
>
|
||||||
<Text>到店核销</Text>
|
<Text>到店核销</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -2,4 +2,6 @@ export default definePageConfig({
|
|||||||
navigationBarTitleText: '门店',
|
navigationBarTitleText: '门店',
|
||||||
enablePullDownRefresh: true,
|
enablePullDownRefresh: true,
|
||||||
backgroundTextStyle: 'dark',
|
backgroundTextStyle: 'dark',
|
||||||
|
enableShareAppMessage: true,
|
||||||
|
enableShareTimeline: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { View, Text, Image, Input } from '@tarojs/components';
|
import { View, Text, Image, Input } from '@tarojs/components';
|
||||||
import Taro, { useDidShow, usePullDownRefresh } from '@tarojs/taro';
|
import Taro, { useDidShow, usePullDownRefresh, useShareAppMessage, useShareTimeline } from '@tarojs/taro';
|
||||||
import PageShell from '../../components/PageShell';
|
import PageShell from '../../components/PageShell';
|
||||||
import TabMainHeader from '../../components/TabMainHeader';
|
import TabMainHeader from '../../components/TabMainHeader';
|
||||||
|
import WechatShareReady from '../../components/WechatShareReady';
|
||||||
import RegionPicker from '../../components/RegionPicker';
|
import RegionPicker from '../../components/RegionPicker';
|
||||||
|
import CategoryPicker, {
|
||||||
|
EMPTY_CATEGORY,
|
||||||
|
formatCategoryLabel,
|
||||||
|
type CategorySelection,
|
||||||
|
type StoreCategoryNode,
|
||||||
|
} from '../../components/CategoryPicker';
|
||||||
import {
|
import {
|
||||||
DEFAULT_REGION,
|
DEFAULT_REGION,
|
||||||
formatRegionLabel,
|
formatRegionLabel,
|
||||||
@@ -11,9 +18,21 @@ import {
|
|||||||
type RegionSelection,
|
type RegionSelection,
|
||||||
} from '../../lib/region-data';
|
} from '../../lib/region-data';
|
||||||
import UserTabBar, { shouldRenderPageTabBar, syncTabBarSelected } from '../../components/UserTabBar';
|
import UserTabBar, { shouldRenderPageTabBar, syncTabBarSelected } from '../../components/UserTabBar';
|
||||||
import { getCityCodeForCatalog, resolveUserCity } from '../../lib/user-location';
|
import {
|
||||||
|
getCityCodeForCatalog,
|
||||||
|
readCachedUserCoords,
|
||||||
|
resolveUserCity,
|
||||||
|
toCityWideRegion,
|
||||||
|
type UserCoords,
|
||||||
|
} from '../../lib/user-location';
|
||||||
import { FALLBACK_CITY_CODE } from '../../lib/product-images';
|
import { FALLBACK_CITY_CODE } from '../../lib/product-images';
|
||||||
|
import { formatDistanceMeters } from '../../lib/geo';
|
||||||
import { request, toast } from '../../lib/api';
|
import { request, toast } from '../../lib/api';
|
||||||
|
import {
|
||||||
|
DEFAULT_SHARE_DESC,
|
||||||
|
DEFAULT_SHARE_TITLE,
|
||||||
|
toWeappShareMessage,
|
||||||
|
} from '../../lib/wechat-share';
|
||||||
|
|
||||||
type Store = {
|
type Store = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -25,38 +44,73 @@ type Store = {
|
|||||||
coverUrl?: string | null;
|
coverUrl?: string | null;
|
||||||
openTime?: string | null;
|
openTime?: string | null;
|
||||||
closeTime?: string | null;
|
closeTime?: string | null;
|
||||||
|
openTime2?: string | null;
|
||||||
|
closeTime2?: string | null;
|
||||||
|
avgPrice?: number | null;
|
||||||
status?: string;
|
status?: string;
|
||||||
|
categoryId?: string | null;
|
||||||
|
category?: { id?: string; name?: string; parentId?: string | null } | null;
|
||||||
|
latitude?: number | string | null;
|
||||||
|
longitude?: number | string | null;
|
||||||
|
distanceMeters?: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CATEGORY_TABS = ['全部', '火锅', '地方菜', '高端餐饮', '烧烤烤肉', '西餐'] as const;
|
|
||||||
const MOCK_DISTANCES = ['800m', '1.2km', '3.5km', '1.5km', '2.0km'];
|
|
||||||
|
|
||||||
export default function StoresPage() {
|
export default function StoresPage() {
|
||||||
const [stores, setStores] = useState<Store[]>([]);
|
const [stores, setStores] = useState<Store[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [categoryTab, setCategoryTab] = useState<string>('全部');
|
const [keywordInput, setKeywordInput] = useState('');
|
||||||
const [keyword, setKeyword] = useState('');
|
const [keyword, setKeyword] = useState('');
|
||||||
const [region, setRegion] = useState<RegionSelection>(DEFAULT_REGION);
|
const [region, setRegion] = useState<RegionSelection>(DEFAULT_REGION);
|
||||||
const [regionOpen, setRegionOpen] = useState(false);
|
const [regionOpen, setRegionOpen] = useState(false);
|
||||||
|
const [category, setCategory] = useState<CategorySelection>(EMPTY_CATEGORY);
|
||||||
|
const [categoryOpen, setCategoryOpen] = useState(false);
|
||||||
|
const [categoryTree, setCategoryTree] = useState<StoreCategoryNode[]>([]);
|
||||||
const [cityCode, setCityCode] = useState<string>(FALLBACK_CITY_CODE);
|
const [cityCode, setCityCode] = useState<string>(FALLBACK_CITY_CODE);
|
||||||
|
const [userCoords, setUserCoords] = useState<UserCoords | null>(() => readCachedUserCoords());
|
||||||
const regionLabel = formatRegionLabel(region);
|
const regionLabel = formatRegionLabel(region);
|
||||||
|
const categoryLabel = formatCategoryLabel(category);
|
||||||
|
|
||||||
|
const childIdsByParent = useMemo(() => {
|
||||||
|
const map = new Map<string, string[]>();
|
||||||
|
for (const root of categoryTree) {
|
||||||
|
map.set(
|
||||||
|
root.id,
|
||||||
|
(root.children ?? []).map((c) => c.id),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, [categoryTree]);
|
||||||
|
|
||||||
useDidShow(() => {
|
useDidShow(() => {
|
||||||
syncTabBarSelected(1);
|
syncTabBarSelected(1);
|
||||||
void resolveUserCity().then((resolved) => {
|
void resolveUserCity().then((resolved) => {
|
||||||
setRegion(resolved.region);
|
setRegion(toCityWideRegion(resolved.region));
|
||||||
setCityCode(getCityCodeForCatalog(resolved));
|
setCityCode(getCityCodeForCatalog(resolved));
|
||||||
|
setUserCoords(readCachedUserCoords());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void request<StoreCategoryNode[]>('/store-categories')
|
||||||
|
.then((tree) => setCategoryTree(Array.isArray(tree) ? tree : []))
|
||||||
|
.catch(() => setCategoryTree([]));
|
||||||
|
}, []);
|
||||||
|
|
||||||
const loadStores = useCallback(() => {
|
const loadStores = useCallback(() => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const path = cityCode ? `/stores?cityCode=${encodeURIComponent(cityCode)}` : '/stores';
|
const qs = new URLSearchParams();
|
||||||
|
if (cityCode) qs.set('cityCode', cityCode);
|
||||||
|
const coords = userCoords ?? readCachedUserCoords();
|
||||||
|
if (coords) {
|
||||||
|
qs.set('lat', String(coords.latitude));
|
||||||
|
qs.set('lng', String(coords.longitude));
|
||||||
|
}
|
||||||
|
const path = qs.toString() ? `/stores?${qs}` : '/stores';
|
||||||
return request<Store[]>(path)
|
return request<Store[]>(path)
|
||||||
.then((list) => setStores(Array.isArray(list) ? list : []))
|
.then((list) => setStores(Array.isArray(list) ? list : []))
|
||||||
.catch((e) => toast(e instanceof Error ? e.message : '加载失败'))
|
.catch((e) => toast(e instanceof Error ? e.message : '加载失败'))
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [cityCode]);
|
}, [cityCode, userCoords]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void loadStores();
|
void loadStores();
|
||||||
@@ -65,12 +119,20 @@ export default function StoresPage() {
|
|||||||
usePullDownRefresh(() => {
|
usePullDownRefresh(() => {
|
||||||
void (async () => {
|
void (async () => {
|
||||||
try {
|
try {
|
||||||
const resolved = await resolveUserCity();
|
const resolved = await resolveUserCity(true);
|
||||||
setRegion(resolved.region);
|
setRegion(toCityWideRegion(resolved.region));
|
||||||
const nextCode = getCityCodeForCatalog(resolved);
|
const nextCode = getCityCodeForCatalog(resolved);
|
||||||
setCityCode(nextCode);
|
setCityCode(nextCode);
|
||||||
|
const coords = readCachedUserCoords();
|
||||||
|
setUserCoords(coords);
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const path = nextCode ? `/stores?cityCode=${encodeURIComponent(nextCode)}` : '/stores';
|
const qs = new URLSearchParams();
|
||||||
|
if (nextCode) qs.set('cityCode', nextCode);
|
||||||
|
if (coords) {
|
||||||
|
qs.set('lat', String(coords.latitude));
|
||||||
|
qs.set('lng', String(coords.longitude));
|
||||||
|
}
|
||||||
|
const path = qs.toString() ? `/stores?${qs}` : '/stores';
|
||||||
const list = await request<Store[]>(path);
|
const list = await request<Store[]>(path);
|
||||||
setStores(Array.isArray(list) ? list : []);
|
setStores(Array.isArray(list) ? list : []);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -82,53 +144,99 @@ export default function StoresPage() {
|
|||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function matchesCategory(store: Store): boolean {
|
||||||
|
if (!category.parentId) return true;
|
||||||
|
const storeCatId = String(store.categoryId || store.category?.id || '');
|
||||||
|
const storeParentId = String(store.category?.parentId || '');
|
||||||
|
if (category.childId) {
|
||||||
|
return storeCatId === category.childId;
|
||||||
|
}
|
||||||
|
if (storeParentId && storeParentId === category.parentId) return true;
|
||||||
|
const siblings = childIdsByParent.get(category.parentId) ?? [];
|
||||||
|
return siblings.includes(storeCatId);
|
||||||
|
}
|
||||||
|
|
||||||
const filtered = stores.filter((s) => {
|
const filtered = stores.filter((s) => {
|
||||||
if (!matchesRegionFilter(s, region)) return false;
|
if (!matchesRegionFilter(s, region)) return false;
|
||||||
|
if (!matchesCategory(s)) return false;
|
||||||
if (!keyword.trim()) return true;
|
if (!keyword.trim()) return true;
|
||||||
const q = keyword.trim();
|
const q = keyword.trim();
|
||||||
return s.name.includes(q) || (s.address ?? '').includes(q) || (s.district ?? '').includes(q);
|
return s.name.includes(q) || (s.address ?? '').includes(q) || (s.district ?? '').includes(q);
|
||||||
});
|
});
|
||||||
|
|
||||||
function formatHours(store: Store) {
|
function applySearch() {
|
||||||
if (store.openTime && store.closeTime) {
|
setKeyword(keywordInput.trim());
|
||||||
return `营业时间: ${store.openTime}-${store.closeTime}`;
|
|
||||||
}
|
|
||||||
return '营业时间: 10:00-22:00';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetFilters() {
|
||||||
|
setKeywordInput('');
|
||||||
|
setKeyword('');
|
||||||
|
setCategory(EMPTY_CATEGORY);
|
||||||
|
setRegion(DEFAULT_REGION);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatHours(store: Store) {
|
||||||
|
const parts: string[] = [];
|
||||||
|
if (store.openTime && store.closeTime) parts.push(`${store.openTime}-${store.closeTime}`);
|
||||||
|
if (store.openTime2 && store.closeTime2) parts.push(`${store.openTime2}-${store.closeTime2}`);
|
||||||
|
return parts.length ? `营业时间: ${parts.join(',')}` : '营业时间: 10:00-22:00';
|
||||||
|
}
|
||||||
|
|
||||||
|
const sharePayload = useMemo(
|
||||||
|
() => ({
|
||||||
|
title: '杜康好客门店',
|
||||||
|
desc: DEFAULT_SHARE_DESC,
|
||||||
|
path: '/pages/stores/index',
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
useShareAppMessage(() => toWeappShareMessage(sharePayload));
|
||||||
|
useShareTimeline(() => ({
|
||||||
|
title: sharePayload.title || DEFAULT_SHARE_TITLE,
|
||||||
|
query: '',
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageShell variant="tab" className="store-page no-tab-header">
|
<PageShell variant="tab" className="store-page no-tab-header">
|
||||||
|
<WechatShareReady payload={sharePayload} />
|
||||||
<TabMainHeader title="门店" />
|
<TabMainHeader title="门店" />
|
||||||
<View className="store-toolbar">
|
|
||||||
<View className="store-location" onClick={() => setRegionOpen(true)}>
|
|
||||||
<View className="store-location-pin" />
|
|
||||||
<Text className="store-location-text">{regionLabel} ▾</Text>
|
|
||||||
</View>
|
|
||||||
<Input
|
|
||||||
className="store-search"
|
|
||||||
placeholder="搜索门店"
|
|
||||||
value={keyword}
|
|
||||||
onInput={(e) => setKeyword(e.detail.value)}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View className="store-category-tabs">
|
<View className="store-filter">
|
||||||
{CATEGORY_TABS.map((tab) => (
|
<View className="store-search-row">
|
||||||
<Text
|
<Input
|
||||||
key={tab}
|
className="store-search-input"
|
||||||
className={`store-category-tab${categoryTab === tab ? ' store-category-tab--active' : ''}`}
|
placeholder="搜索门店名称/地址"
|
||||||
onClick={() => setCategoryTab(tab)}
|
value={keywordInput}
|
||||||
>
|
confirmType="search"
|
||||||
{tab}
|
onInput={(e) => setKeywordInput(e.detail.value)}
|
||||||
|
onConfirm={applySearch}
|
||||||
|
/>
|
||||||
|
<View className="store-search-btn" onClick={applySearch} aria-label="搜索">
|
||||||
|
<View className="store-search-icon" />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View className="store-filter-row">
|
||||||
|
<View className="store-filter-chip" onClick={() => setRegionOpen(true)}>
|
||||||
|
<Text className="store-filter-chip-text">{regionLabel}</Text>
|
||||||
|
<Text className="store-filter-chip-arrow">▾</Text>
|
||||||
|
</View>
|
||||||
|
<View className="store-filter-chip" onClick={() => setCategoryOpen(true)}>
|
||||||
|
<Text className="store-filter-chip-text">{categoryLabel}</Text>
|
||||||
|
<Text className="store-filter-chip-arrow">▾</Text>
|
||||||
|
</View>
|
||||||
|
<Text className="store-filter-reset" onClick={resetFilters}>
|
||||||
|
重置
|
||||||
</Text>
|
</Text>
|
||||||
))}
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View className="store-list">
|
<View className="store-list">
|
||||||
{loading ? <View className="u-empty">加载中…</View> : null}
|
{loading ? <View className="u-empty">加载中…</View> : null}
|
||||||
{!loading && filtered.length === 0 ? <View className="u-empty">暂无营业中门店</View> : null}
|
{!loading && filtered.length === 0 ? <View className="u-empty">暂无营业中门店</View> : null}
|
||||||
{!loading &&
|
{!loading &&
|
||||||
filtered.map((s, index) => (
|
filtered.map((s) => (
|
||||||
<View
|
<View
|
||||||
key={s.id}
|
key={s.id}
|
||||||
className="store-card"
|
className="store-card"
|
||||||
@@ -146,8 +254,13 @@ export default function StoresPage() {
|
|||||||
{s.address || '地址待完善'}
|
{s.address || '地址待完善'}
|
||||||
</Text>
|
</Text>
|
||||||
<Text className="store-card-meta">{formatHours(s)}</Text>
|
<Text className="store-card-meta">{formatHours(s)}</Text>
|
||||||
|
{s.avgPrice != null && Number(s.avgPrice) > 0 ? (
|
||||||
|
<Text className="store-card-meta">人均¥{Number(s.avgPrice).toFixed(0)}</Text>
|
||||||
|
) : null}
|
||||||
<View className="store-card-footer">
|
<View className="store-card-footer">
|
||||||
<Text className="store-card-distance">{MOCK_DISTANCES[index % MOCK_DISTANCES.length]}</Text>
|
<Text className="store-card-distance">
|
||||||
|
{formatDistanceMeters(s.distanceMeters)}
|
||||||
|
</Text>
|
||||||
<Text
|
<Text
|
||||||
className="store-card-cta"
|
className="store-card-cta"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
@@ -171,6 +284,13 @@ export default function StoresPage() {
|
|||||||
onClose={() => setRegionOpen(false)}
|
onClose={() => setRegionOpen(false)}
|
||||||
onConfirm={(next) => setRegion(next)}
|
onConfirm={(next) => setRegion(next)}
|
||||||
/>
|
/>
|
||||||
|
<CategoryPicker
|
||||||
|
open={categoryOpen}
|
||||||
|
tree={categoryTree}
|
||||||
|
value={category}
|
||||||
|
onClose={() => setCategoryOpen(false)}
|
||||||
|
onConfirm={(next) => setCategory(next)}
|
||||||
|
/>
|
||||||
</PageShell>
|
</PageShell>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,14 @@
|
|||||||
z-index: 2;
|
z-index: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.benefit-header__share .page-nav-bar__btn {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.benefit-header__share .page-nav-bar__icon {
|
||||||
|
color: var(--color-heritage-red);
|
||||||
|
}
|
||||||
|
|
||||||
.benefit-header-city-pin {
|
.benefit-header-city-pin {
|
||||||
width: 8px;
|
width: 8px;
|
||||||
height: 8px;
|
height: 8px;
|
||||||
|
|||||||
@@ -31,23 +31,45 @@
|
|||||||
background: var(--color-background);
|
background: var(--color-background);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.home-promo-banner {
|
||||||
|
margin: 12px var(--space-page) 0;
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--color-card);
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
aspect-ratio: 15 / 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.home-promo-banner-swiper {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.home-promo-banner-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
.home-aroma-nav {
|
.home-aroma-nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
padding: 8px var(--space-page);
|
margin-top: 4px;
|
||||||
background: rgba(250, 249, 247, 0.95);
|
padding: 6px var(--space-page) 4px;
|
||||||
border-bottom: 1px solid var(--color-surface-container);
|
background: transparent;
|
||||||
|
border-bottom: none;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: var(--nav-bar-height, 56px);
|
top: 0;
|
||||||
z-index: 40;
|
z-index: 40;
|
||||||
|
background: rgba(250, 249, 247, 0.96);
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-aroma-tabs {
|
.home-aroma-tabs {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
gap: 4px;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
@@ -66,11 +88,11 @@
|
|||||||
.home-aroma-tab {
|
.home-aroma-tab {
|
||||||
border: none;
|
border: none;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 6px 12px;
|
padding: 4px 10px;
|
||||||
font-family: var(--font-headline);
|
font-family: var(--font-headline);
|
||||||
font-size: 16px;
|
font-size: 14px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
line-height: 24px;
|
line-height: 22px;
|
||||||
color: var(--color-subtle-gray);
|
color: var(--color-subtle-gray);
|
||||||
border-bottom: 2px solid transparent;
|
border-bottom: 2px solid transparent;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@@ -84,68 +106,49 @@
|
|||||||
.home-product-list {
|
.home-product-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 16px;
|
gap: 10px;
|
||||||
padding: 16px var(--space-page);
|
padding: 8px var(--space-page) 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-product-card {
|
.home-product-card {
|
||||||
background: var(--color-card);
|
background: var(--color-card);
|
||||||
border-radius: var(--radius-lg);
|
border-radius: 12px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
box-shadow: var(--shadow-card);
|
box-shadow: var(--shadow-card);
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-carousel-wrap {
|
.home-product-card-inner {
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
aspect-ratio: 1;
|
|
||||||
background: var(--color-surface-container);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.home-carousel {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.home-carousel-item,
|
|
||||||
.home-carousel-image,
|
|
||||||
.home-carousel-placeholder {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.home-carousel-placeholder {
|
|
||||||
background: var(--color-surface-container);
|
|
||||||
}
|
|
||||||
|
|
||||||
.home-carousel-dots {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 12px;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
align-items: stretch;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-carousel-dot {
|
.home-product-thumb-wrap {
|
||||||
height: 4px;
|
flex-shrink: 0;
|
||||||
width: 6px;
|
width: 88px;
|
||||||
margin: 0 3px;
|
height: 88px;
|
||||||
border-radius: 999px;
|
border-radius: 8px;
|
||||||
background: rgba(153, 153, 153, 0.35);
|
overflow: hidden;
|
||||||
|
background: var(--color-surface-container);
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-carousel-dot--active {
|
.home-product-thumb {
|
||||||
width: 20px;
|
width: 100%;
|
||||||
background: var(--color-heritage-red);
|
height: 100%;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-product-body {
|
.home-product-thumb--empty {
|
||||||
padding: var(--space-gutter);
|
background: var(--color-surface-container);
|
||||||
|
}
|
||||||
|
|
||||||
|
.home-product-main {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 4px;
|
gap: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-product-row {
|
.home-product-row {
|
||||||
@@ -157,9 +160,9 @@
|
|||||||
|
|
||||||
.home-product-name {
|
.home-product-name {
|
||||||
font-family: var(--font-headline);
|
font-family: var(--font-headline);
|
||||||
font-size: 16px;
|
font-size: 14px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
line-height: 24px;
|
line-height: 20px;
|
||||||
color: var(--color-on-surface);
|
color: var(--color-on-surface);
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -168,61 +171,96 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.home-product-price {
|
.home-product-price {
|
||||||
font-size: 16px;
|
font-size: 15px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
line-height: 20px;
|
||||||
color: var(--color-heritage-red);
|
color: var(--color-heritage-red);
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-product-sub {
|
.home-product-sub {
|
||||||
font-size: 13px;
|
font-size: 11px;
|
||||||
color: var(--color-subtle-gray);
|
color: var(--color-subtle-gray);
|
||||||
line-height: 18px;
|
line-height: 16px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-product-footer {
|
.home-product-footer {
|
||||||
margin-top: 4px;
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-product-actions {
|
.home-product-actions {
|
||||||
padding: 0 var(--space-gutter) var(--space-gutter);
|
margin-top: auto;
|
||||||
|
padding-top: 4px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.home-pickup-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 4px 10px;
|
||||||
|
border-radius: var(--radius-full);
|
||||||
|
background: var(--color-aged-amber);
|
||||||
|
color: #5c4500;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 16px;
|
||||||
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-buy-btn {
|
.home-buy-btn {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 8px 16px;
|
padding: 4px 12px;
|
||||||
border-radius: var(--radius-full);
|
border-radius: var(--radius-full);
|
||||||
background: var(--color-heritage-red);
|
background: var(--color-heritage-red);
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 13px;
|
font-size: 11px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
line-height: 16px;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.home-promo-footer {
|
||||||
|
margin: 0 var(--space-page) 8px;
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--color-card);
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
aspect-ratio: 15 / 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.home-promo-footer-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: block;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
.home-empty {
|
.home-empty {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 48px 24px;
|
padding: 32px 24px;
|
||||||
color: var(--color-subtle-gray);
|
color: var(--color-subtle-gray);
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-badge {
|
.home-page .coupon-badge {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: var(--color-aged-amber);
|
background: var(--color-aged-amber);
|
||||||
color: var(--color-on-secondary-container);
|
color: var(--color-on-secondary-container);
|
||||||
padding: 4px 12px;
|
padding: 2px 8px;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
font-family: var(--font-label);
|
font-family: var(--font-label);
|
||||||
font-size: 12px;
|
font-size: 11px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
letter-spacing: 0.05em;
|
letter-spacing: 0.02em;
|
||||||
|
line-height: 16px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -498,3 +498,58 @@
|
|||||||
opacity: 0.65;
|
opacity: 0.65;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mine-qualification-mask {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 1200;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.55);
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mine-qualification-scroll {
|
||||||
|
flex: 1;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
max-width: none;
|
||||||
|
max-height: none;
|
||||||
|
border-radius: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mine-qualification-body {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
min-height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
padding: 24px 16px 56px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mine-qualification-img {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mine-qualification-hint {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: calc(12px + env(safe-area-inset-bottom, 0px));
|
||||||
|
z-index: 1;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgba(255, 255, 255, 0.9);
|
||||||
|
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
|
padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 小程序原生 tabBar 页面窗口已扣除底栏,避免滑到底多余空白 */
|
||||||
|
.page-shell--tab.page-shell--native-tabbar {
|
||||||
|
padding-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
.page-shell--scroll,
|
.page-shell--scroll,
|
||||||
.page-shell--sub,
|
.page-shell--sub,
|
||||||
.page-shell--plain {
|
.page-shell--plain {
|
||||||
|
|||||||
@@ -68,6 +68,11 @@
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.order-confirm-submit--disabled {
|
||||||
|
opacity: 0.55;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
.order-card {
|
.order-card {
|
||||||
background: var(--color-card);
|
background: var(--color-card);
|
||||||
border-radius: var(--radius-lg);
|
border-radius: var(--radius-lg);
|
||||||
@@ -164,6 +169,7 @@
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: var(--color-heritage-red);
|
color: var(--color-heritage-red);
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.order-row {
|
.order-row {
|
||||||
@@ -291,11 +297,41 @@
|
|||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.order-list-head-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.order-list-no {
|
.order-list-no {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: var(--color-subtle-gray);
|
color: var(--color-subtle-gray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.order-status-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-proxy-badge {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--color-heritage-red);
|
||||||
|
background: rgba(166, 29, 36, 0.08);
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-proxy-hint {
|
||||||
|
display: block;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--color-subtle-gray);
|
||||||
|
margin: -4px 0 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.order-list-status {
|
.order-list-status {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
@@ -433,7 +469,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.pay-wechat-auth-msg {
|
.pay-wechat-auth-msg {
|
||||||
|
display: block;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: var(--color-heritage-red, #a02d30);
|
color: var(--color-heritage-red, #a02d30);
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,12 +77,18 @@
|
|||||||
.redeem-tips {
|
.redeem-tips {
|
||||||
display: block;
|
display: block;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
width: 100%;
|
margin: 8px var(--space-page) 0;
|
||||||
margin: 0;
|
padding: 12px 16px;
|
||||||
padding: 0 var(--space-page);
|
border-radius: var(--radius-md);
|
||||||
|
background: rgba(0, 0, 0, 0.03);
|
||||||
|
}
|
||||||
|
|
||||||
|
.redeem-tips-text {
|
||||||
|
display: block;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: var(--color-subtle-gray);
|
color: var(--color-subtle-gray);
|
||||||
line-height: 1.6;
|
line-height: 1.7;
|
||||||
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
.redeem-amount-hint {
|
.redeem-amount-hint {
|
||||||
|
|||||||
@@ -79,6 +79,38 @@
|
|||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.store-detail-meta--flex {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-detail-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-detail-action {
|
||||||
|
flex-shrink: 0;
|
||||||
|
padding: 2px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: rgba(166, 29, 36, 0.08);
|
||||||
|
color: var(--color-heritage-red);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-detail-intro {
|
||||||
|
display: block;
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--color-on-surface);
|
||||||
|
line-height: 1.7;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
.store-detail-tags {
|
.store-detail-tags {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
@@ -112,6 +144,27 @@
|
|||||||
color: var(--color-on-surface);
|
color: var(--color-on-surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.store-detail-env-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-detail-env-item {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
aspect-ratio: 1;
|
||||||
|
border-radius: var(--radius-md, 8px);
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--color-surface-container);
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-detail-env-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
.store-detail-bar {
|
.store-detail-bar {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|||||||
@@ -3,56 +3,34 @@
|
|||||||
background: var(--color-background);
|
background: var(--color-background);
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-toolbar {
|
.store-filter {
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
padding: 0 var(--space-page) 12px;
|
padding: 0 var(--space-page) 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-location {
|
.store-search-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-shrink: 0;
|
gap: 8px;
|
||||||
max-width: 42%;
|
width: 100%;
|
||||||
color: var(--color-on-surface-variant);
|
box-sizing: border-box;
|
||||||
font-size: 12px;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-location-pin {
|
.store-search-input {
|
||||||
width: 8px;
|
|
||||||
height: 8px;
|
|
||||||
border-radius: 50%;
|
|
||||||
background: var(--color-heritage-red);
|
|
||||||
margin-right: 6px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.store-location-text {
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.store-search {
|
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
padding: 0 12px;
|
padding: 0 14px;
|
||||||
border-radius: var(--radius-md);
|
border-radius: var(--radius-md);
|
||||||
background: var(--color-surface-container-low);
|
background: var(--color-surface-container-low);
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
color: var(--color-on-surface);
|
color: var(--color-on-surface);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-search input,
|
.store-search-input input,
|
||||||
.store-search .taro-input,
|
.store-search-input .taro-input,
|
||||||
.store-search .weui-input {
|
.store-search-input .weui-input {
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
height: 100% !important;
|
height: 100% !important;
|
||||||
min-height: 0 !important;
|
min-height: 0 !important;
|
||||||
@@ -66,32 +44,92 @@
|
|||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-category-tabs {
|
.store-search-btn {
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
background: var(--color-heritage-red);
|
||||||
|
color: #fff;
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 12px var(--space-page);
|
align-items: center;
|
||||||
overflow-x: auto;
|
justify-content: center;
|
||||||
white-space: nowrap;
|
|
||||||
border-bottom: 1px solid rgba(226, 190, 188, 0.1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-category-tab {
|
.store-search-icon {
|
||||||
flex-shrink: 0;
|
position: relative;
|
||||||
margin-right: 24px;
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
border: 2px solid currentColor;
|
||||||
|
border-radius: 50%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-search-icon::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
right: -5px;
|
||||||
|
bottom: -4px;
|
||||||
|
width: 7px;
|
||||||
|
height: 2px;
|
||||||
|
background: currentColor;
|
||||||
|
border-radius: 1px;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
transform-origin: left center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-filter-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-filter-chip {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
height: 36px;
|
||||||
|
padding: 0 10px;
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
background: var(--color-surface-container-low);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-filter-chip-text {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: var(--color-on-surface-variant);
|
color: var(--color-on-surface);
|
||||||
padding-bottom: 6px;
|
|
||||||
border-bottom: 2px solid transparent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-category-tab--active {
|
.store-filter-chip-arrow {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--color-subtle-gray);
|
||||||
|
}
|
||||||
|
|
||||||
|
.store-filter-reset {
|
||||||
|
flex-shrink: 0;
|
||||||
|
height: 36px;
|
||||||
|
padding: 0 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
color: var(--color-heritage-red);
|
color: var(--color-heritage-red);
|
||||||
border-bottom-color: var(--color-heritage-red);
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-list {
|
.store-list {
|
||||||
padding: 16px var(--space-page);
|
padding: 4px var(--space-page) 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-card {
|
.store-card {
|
||||||
|
|||||||
@@ -42,10 +42,11 @@ if [[ -z "$DEPLOY_HOST" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
SSH_OPTS=(-o "StrictHostKeyChecking=accept-new" -p "$DEPLOY_PORT")
|
SSH_OPTS=(-o "StrictHostKeyChecking=accept-new" -p "$DEPLOY_PORT")
|
||||||
[[ -n "$DEPLOY_SSH_KEY" ]] && SSH_OPTS+=(-i "$DEPLOY_SSH_KEY")
|
SCP_OPTS=(-o "StrictHostKeyChecking=accept-new" -P "$DEPLOY_PORT")
|
||||||
|
[[ -n "$DEPLOY_SSH_KEY" ]] && SSH_OPTS+=(-i "$DEPLOY_SSH_KEY") && SCP_OPTS+=(-i "$DEPLOY_SSH_KEY")
|
||||||
REMOTE="${DEPLOY_USER}@${DEPLOY_HOST}"
|
REMOTE="${DEPLOY_USER}@${DEPLOY_HOST}"
|
||||||
|
|
||||||
echo "==> 同步 production 环境到 $REMOTE:$APP_ROOT/server/dukang-api/.env.production"
|
echo "==> 同步 production 环境到 $REMOTE:$APP_ROOT/server/dukang-api/.env.production"
|
||||||
scp "${SSH_OPTS[@]}" "$SRC_ENV" "$REMOTE:$APP_ROOT/server/dukang-api/.env.production"
|
scp "${SCP_OPTS[@]}" "$SRC_ENV" "$REMOTE:$APP_ROOT/server/dukang-api/.env.production"
|
||||||
ssh "${SSH_OPTS[@]}" "$REMOTE" "pm2 restart dukang-api && sleep 2 && curl -sf -o /dev/null -w 'api-health:%{http_code}\n' http://127.0.0.1:8090/api/v1/health"
|
ssh "${SSH_OPTS[@]}" "$REMOTE" "pm2 restart dukang-api && sleep 2 && curl -sf -o /dev/null -w 'api-health:%{http_code}\n' http://127.0.0.1:8090/api/v1/health"
|
||||||
echo "==> 完成"
|
echo "==> 完成"
|
||||||
|
|||||||
@@ -61,12 +61,28 @@ describe('validatePartnerCityBinding', () => {
|
|||||||
expect(result.ok).toBe(false);
|
expect(result.ok).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects overlapping district codes', () => {
|
it('allows overlapping district codes as labels', () => {
|
||||||
const result = validatePartnerCityBinding(
|
const result = validatePartnerCityBinding(
|
||||||
[{ id: '1', partnerAccountId: '10', scopeType: 'DISTRICT', districtCodes: ['410105'] }],
|
[
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
partnerAccountId: '10',
|
||||||
|
scopeType: 'DISTRICT',
|
||||||
|
districtCodes: ['410105'],
|
||||||
|
companyName: '甲公司',
|
||||||
|
},
|
||||||
|
],
|
||||||
{ partnerAccountId: '11', scopeType: 'DISTRICT', districtCodes: ['410105'] },
|
{ partnerAccountId: '11', scopeType: 'DISTRICT', districtCodes: ['410105'] },
|
||||||
);
|
);
|
||||||
expect(result.ok).toBe(false);
|
expect(result.ok).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows district partner without district codes', () => {
|
||||||
|
const result = validatePartnerCityBinding(
|
||||||
|
[],
|
||||||
|
{ partnerAccountId: '11', scopeType: 'DISTRICT', districtCodes: [] },
|
||||||
|
);
|
||||||
|
expect(result.ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows valid district binding', () => {
|
it('allows valid district binding', () => {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ export interface PartnerCityBindingInput {
|
|||||||
scopeType: CityPartnerScopeType;
|
scopeType: CityPartnerScopeType;
|
||||||
districtCodes?: string[] | null;
|
districtCodes?: string[] | null;
|
||||||
bindingStatus?: CityPartnerStatus;
|
bindingStatus?: CityPartnerStatus;
|
||||||
|
/** 仅用于重合报错文案 */
|
||||||
|
companyName?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PartnerCityResolveRef {
|
export interface PartnerCityResolveRef {
|
||||||
@@ -93,25 +95,7 @@ export function validatePartnerCityBinding(
|
|||||||
return { ok: true };
|
return { ok: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
const districts = normalizeDistrictCodes(input.districtCodes);
|
// 区域合伙人所选区县可为空(录入时可稍后补全)
|
||||||
if (!districts.length) {
|
|
||||||
return { ok: false, message: '区域合伙人须至少选择一个区县' };
|
|
||||||
}
|
|
||||||
|
|
||||||
const occupied = new Set<string>();
|
|
||||||
for (const row of others) {
|
|
||||||
if (row.scopeType !== 'DISTRICT') continue;
|
|
||||||
for (const code of normalizeDistrictCodes(row.districtCodes)) {
|
|
||||||
occupied.add(code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const code of districts) {
|
|
||||||
if (occupied.has(code)) {
|
|
||||||
return { ok: false, message: `区县 ${code} 已被其他区域合伙人占用` };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ import { describe, expect, it } from 'vitest';
|
|||||||
import {
|
import {
|
||||||
calcBenefitAmount,
|
calcBenefitAmount,
|
||||||
calcRedeemSettleAmount,
|
calcRedeemSettleAmount,
|
||||||
|
calcLogisticsFeeByBottles,
|
||||||
|
calcOrderBoxCount,
|
||||||
|
shouldHoldAutoCourierDispatch,
|
||||||
validateMinPurchase,
|
validateMinPurchase,
|
||||||
|
validateBusinessHours,
|
||||||
|
formatBusinessHours,
|
||||||
validateRedeemAmount,
|
validateRedeemAmount,
|
||||||
allocateBenefitCoupons,
|
allocateBenefitCoupons,
|
||||||
calcBenefitSummary,
|
calcBenefitSummary,
|
||||||
@@ -32,6 +37,50 @@ describe('validateMinPurchase', () => {
|
|||||||
expect(validateMinPurchase('CROSS_CITY', 5, 2, 6).ok).toBe(false);
|
expect(validateMinPurchase('CROSS_CITY', 5, 2, 6).ok).toBe(false);
|
||||||
expect(validateMinPurchase('CROSS_CITY', 6, 2, 6).ok).toBe(true);
|
expect(validateMinPurchase('CROSS_CITY', 6, 2, 6).ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('on-site pickup requires at least local min (2 bottles)', () => {
|
||||||
|
expect(validateMinPurchase('ON_SITE_PICKUP', 0, 2, 6).ok).toBe(false);
|
||||||
|
expect(validateMinPurchase('ON_SITE_PICKUP', 1, 2, 6).ok).toBe(false);
|
||||||
|
expect(validateMinPurchase('ON_SITE_PICKUP', 2, 2, 6).ok).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('validateBusinessHours', () => {
|
||||||
|
it('accepts one segment', () => {
|
||||||
|
expect(validateBusinessHours([{ open: '09:00', close: '22:00' }]).ok).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts two non-overlapping segments', () => {
|
||||||
|
expect(
|
||||||
|
validateBusinessHours([
|
||||||
|
{ open: '09:00', close: '14:00' },
|
||||||
|
{ open: '17:00', close: '21:00' },
|
||||||
|
]).ok,
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects overlapping second segment', () => {
|
||||||
|
expect(
|
||||||
|
validateBusinessHours([
|
||||||
|
{ open: '09:00', close: '14:00' },
|
||||||
|
{ open: '13:00', close: '21:00' },
|
||||||
|
]).ok,
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('formatBusinessHours', () => {
|
||||||
|
it('formats one or two segments', () => {
|
||||||
|
expect(formatBusinessHours({ openTime: '9:00', closeTime: '22:00' })).toBe('9:00-22:00');
|
||||||
|
expect(
|
||||||
|
formatBusinessHours({
|
||||||
|
openTime: '09:00',
|
||||||
|
closeTime: '14:00',
|
||||||
|
openTime2: '17:00',
|
||||||
|
closeTime2: '21:00',
|
||||||
|
}),
|
||||||
|
).toBe('09:00-14:00,17:00-21:00');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validateRedeemAmount', () => {
|
describe('validateRedeemAmount', () => {
|
||||||
@@ -62,6 +111,46 @@ describe('calcRedeemSettleAmount', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('calcLogisticsFeeByBottles', () => {
|
||||||
|
const xfx = {
|
||||||
|
baseBottles: 2,
|
||||||
|
baseFee: 6,
|
||||||
|
extraBottleFee: 2,
|
||||||
|
boxBottles: 6,
|
||||||
|
boxFee: 14,
|
||||||
|
};
|
||||||
|
|
||||||
|
it('charges base for 1~2 bottles', () => {
|
||||||
|
expect(calcLogisticsFeeByBottles(1, xfx)).toBe(6);
|
||||||
|
expect(calcLogisticsFeeByBottles(2, xfx)).toBe(6);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds extra bottle fee', () => {
|
||||||
|
expect(calcLogisticsFeeByBottles(3, xfx)).toBe(8);
|
||||||
|
expect(calcLogisticsFeeByBottles(5, xfx)).toBe(12);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses box fee for full boxes', () => {
|
||||||
|
expect(calcLogisticsFeeByBottles(6, xfx)).toBe(14);
|
||||||
|
expect(calcLogisticsFeeByBottles(12, xfx)).toBe(28);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('combines boxes with remainder ladder', () => {
|
||||||
|
expect(calcLogisticsFeeByBottles(7, xfx)).toBe(20);
|
||||||
|
expect(calcLogisticsFeeByBottles(8, xfx)).toBe(20);
|
||||||
|
expect(calcLogisticsFeeByBottles(9, xfx)).toBe(22);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('shouldHoldAutoCourierDispatch', () => {
|
||||||
|
it('holds at 10 full boxes (60 bottles)', () => {
|
||||||
|
expect(shouldHoldAutoCourierDispatch(59)).toBe(false);
|
||||||
|
expect(shouldHoldAutoCourierDispatch(60)).toBe(true);
|
||||||
|
expect(shouldHoldAutoCourierDispatch(66)).toBe(true);
|
||||||
|
expect(calcOrderBoxCount(60)).toBe(10);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('allocateBenefitCoupons', () => {
|
describe('allocateBenefitCoupons', () => {
|
||||||
const coupons = [
|
const coupons = [
|
||||||
{ id: '1', balance: 300, createdAt: 1 },
|
{ id: '1', balance: 300, createdAt: 1 },
|
||||||
|
|||||||
@@ -8,11 +8,18 @@ export function calcBenefitAmount(product: ProductPricing): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function validateMinPurchase(
|
export function validateMinPurchase(
|
||||||
deliveryType: 'LOCAL' | 'CROSS_CITY',
|
deliveryType: 'LOCAL' | 'CROSS_CITY' | 'ON_SITE_PICKUP',
|
||||||
quantity: number,
|
quantity: number,
|
||||||
localMinQty: number,
|
localMinQty: number,
|
||||||
crossMinQty: number,
|
crossMinQty: number,
|
||||||
): { ok: boolean; message?: string } {
|
): { ok: boolean; message?: string } {
|
||||||
|
if (deliveryType === 'ON_SITE_PICKUP') {
|
||||||
|
const min = localMinQty > 0 ? localMinQty : 2;
|
||||||
|
if (quantity < min) {
|
||||||
|
return { ok: false, message: `现场提货至少购买 ${min} 瓶` };
|
||||||
|
}
|
||||||
|
return { ok: true };
|
||||||
|
}
|
||||||
const min = deliveryType === 'LOCAL' ? localMinQty : crossMinQty;
|
const min = deliveryType === 'LOCAL' ? localMinQty : crossMinQty;
|
||||||
if (quantity < min) {
|
if (quantity < min) {
|
||||||
return {
|
return {
|
||||||
@@ -89,6 +96,120 @@ export function calcRedeemSettleAmount(amount: number, settlementRate: number):
|
|||||||
return Math.round(amount * settlementRate * 100) / 100;
|
return Math.round(amount * settlementRate * 100) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TIME_HM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
||||||
|
|
||||||
|
export type BusinessHoursSegment = { open: string; close: string };
|
||||||
|
|
||||||
|
export function timeToMinutes(hhmm: string): number {
|
||||||
|
const [h, m] = hhmm.split(':').map(Number);
|
||||||
|
return h * 60 + m;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 校验 1~2 段营业时间,例如 09:00-22:00 或 09:00-14:00 + 17:00-21:00 */
|
||||||
|
export function validateBusinessHours(
|
||||||
|
segments: BusinessHoursSegment[],
|
||||||
|
): { ok: boolean; message?: string } {
|
||||||
|
const cleaned = segments
|
||||||
|
.map((s) => ({ open: String(s.open || '').trim(), close: String(s.close || '').trim() }))
|
||||||
|
.filter((s) => s.open || s.close);
|
||||||
|
if (cleaned.length < 1) return { ok: false, message: '请设置营业时间' };
|
||||||
|
if (cleaned.length > 2) return { ok: false, message: '营业时间最多支持 2 段' };
|
||||||
|
for (let i = 0; i < cleaned.length; i++) {
|
||||||
|
const s = cleaned[i];
|
||||||
|
if (!TIME_HM_RE.test(s.open) || !TIME_HM_RE.test(s.close)) {
|
||||||
|
return { ok: false, message: `第 ${i + 1} 段时间格式须为 HH:MM` };
|
||||||
|
}
|
||||||
|
if (timeToMinutes(s.open) >= timeToMinutes(s.close)) {
|
||||||
|
return { ok: false, message: `第 ${i + 1} 段结束时间须晚于开始时间` };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cleaned.length === 2 && timeToMinutes(cleaned[0].close) >= timeToMinutes(cleaned[1].open)) {
|
||||||
|
return { ok: false, message: '第二段开始时间须晚于第一段结束时间' };
|
||||||
|
}
|
||||||
|
return { ok: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatBusinessHours(store: {
|
||||||
|
openTime?: string | null;
|
||||||
|
closeTime?: string | null;
|
||||||
|
openTime2?: string | null;
|
||||||
|
closeTime2?: string | null;
|
||||||
|
}): string {
|
||||||
|
const parts: string[] = [];
|
||||||
|
if (store.openTime && store.closeTime) {
|
||||||
|
parts.push(`${store.openTime}-${store.closeTime}`);
|
||||||
|
}
|
||||||
|
if (store.openTime2 && store.closeTime2) {
|
||||||
|
parts.push(`${store.openTime2}-${store.closeTime2}`);
|
||||||
|
}
|
||||||
|
return parts.length ? parts.join(',') : '10:00-22:00';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 物流(快递)按瓶计价规则,如小飞侠:2瓶6元、加一瓶+2元、6瓶一箱14元 */
|
||||||
|
export const BOTTLES_PER_BOX = 6;
|
||||||
|
|
||||||
|
/** 小飞侠自动推单上限箱数:达到该箱数起拦截,需总部确认后推单或自配送 */
|
||||||
|
export const XFX_AUTO_DISPATCH_MAX_BOXES = 10;
|
||||||
|
|
||||||
|
/** 按箱规向上取整得到箱数 */
|
||||||
|
export function calcOrderBoxCount(quantity: number, bottlesPerBox = BOTTLES_PER_BOX): number {
|
||||||
|
const qty = Math.floor(Number(quantity) || 0);
|
||||||
|
if (qty <= 0 || !(bottlesPerBox > 0)) return 0;
|
||||||
|
return Math.ceil(qty / bottlesPerBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 是否因大单拦截自动推承运商(默认 ≥10 箱 = 60 瓶) */
|
||||||
|
export function shouldHoldAutoCourierDispatch(
|
||||||
|
quantity: number,
|
||||||
|
options?: { bottlesPerBox?: number; maxBoxes?: number },
|
||||||
|
): boolean {
|
||||||
|
const bottlesPerBox = options?.bottlesPerBox ?? BOTTLES_PER_BOX;
|
||||||
|
const maxBoxes = options?.maxBoxes ?? XFX_AUTO_DISPATCH_MAX_BOXES;
|
||||||
|
const qty = Math.floor(Number(quantity) || 0);
|
||||||
|
return qty >= bottlesPerBox * maxBoxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 物流(快递)按瓶计价规则,如小飞侠:2瓶6元、加一瓶+2元、6瓶一箱14元 */
|
||||||
|
export type LogisticsPricingRule = {
|
||||||
|
baseBottles: number;
|
||||||
|
baseFee: number;
|
||||||
|
extraBottleFee: number;
|
||||||
|
boxBottles?: number;
|
||||||
|
boxFee?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
function roundMoney(n: number): number {
|
||||||
|
return Math.round(n * 100) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcLogisticsBottleLadder(quantity: number, rule: LogisticsPricingRule): number {
|
||||||
|
const qty = Math.floor(quantity);
|
||||||
|
if (qty <= 0) return 0;
|
||||||
|
if (qty <= rule.baseBottles) return rule.baseFee;
|
||||||
|
return rule.baseFee + (qty - rule.baseBottles) * rule.extraBottleFee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按承运商计价标准计算单票物流费。
|
||||||
|
* 配置了箱规时:整箱按 boxFee,余瓶按「起送瓶数/加瓶」阶梯。
|
||||||
|
*/
|
||||||
|
export function calcLogisticsFeeByBottles(quantity: number, rule: LogisticsPricingRule): number {
|
||||||
|
const qty = Math.floor(Number(quantity) || 0);
|
||||||
|
if (qty <= 0) return 0;
|
||||||
|
if (!(rule.baseBottles > 0) || !(rule.baseFee >= 0) || !(rule.extraBottleFee >= 0)) {
|
||||||
|
throw new Error('计价标准不完整');
|
||||||
|
}
|
||||||
|
|
||||||
|
const boxBottles = rule.boxBottles && rule.boxBottles > 0 ? rule.boxBottles : 0;
|
||||||
|
const boxFee = rule.boxFee != null && rule.boxFee >= 0 ? rule.boxFee : null;
|
||||||
|
if (boxBottles > 0 && boxFee != null) {
|
||||||
|
const boxes = Math.floor(qty / boxBottles);
|
||||||
|
const rem = qty % boxBottles;
|
||||||
|
return roundMoney(boxes * boxFee + calcLogisticsBottleLadder(rem, rule));
|
||||||
|
}
|
||||||
|
return roundMoney(calcLogisticsBottleLadder(qty, rule));
|
||||||
|
}
|
||||||
|
|
||||||
export function generateUserNo(): string {
|
export function generateUserNo(): string {
|
||||||
const suffix = Math.floor(10000000 + Math.random() * 90000000);
|
const suffix = Math.floor(10000000 + Math.random() * 90000000);
|
||||||
return `DK${suffix}`;
|
return `DK${suffix}`;
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ export interface ProductDto {
|
|||||||
/** 详情长图(bizType=DETAIL 或 detailContent JSON) */
|
/** 详情长图(bizType=DETAIL 或 detailContent JSON) */
|
||||||
detailImageUrls?: string[];
|
detailImageUrls?: string[];
|
||||||
detailContent?: ProductDetailContentDto | null;
|
detailContent?: ProductDetailContentDto | null;
|
||||||
|
/** 是否允许现场取货下单 */
|
||||||
|
allowOnSitePickup?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProductDetailFeatureDto {
|
export interface ProductDetailFeatureDto {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user