From 266c01538e0228a5791f4629eeb377bf17578f75 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Tue, 3 Nov 2026 03:29:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=20=E8=AE=A2=E5=8D=95=E4=B8=8E?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E5=95=86=E5=93=81=E4=BA=A4=E4=BA=92=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 待审核订单增加「含未绑定」开关(默认只显示已绑定),列表与导出条件保持一致 - 店铺商品增加「只看有订单未绑定」筛选与「待处理订单」列;绑定弹窗改为左侧页签 + 右侧可搜索分页列表 - 订单切换仓库改为弹窗选择,新增通用 RecordPickerDialog 组件 - 订单与店铺商品表格改为表体内部滚动,筛选栏与分页固定 - 手工建单必须选择非平台店铺;平台订单编辑时店铺不可修改 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- frontend/src/api/externalPrintAccount.ts | 145 ++++ frontend/src/api/orderStatus.ts | 12 +- frontend/src/api/shop.ts | 28 + frontend/src/api/shopProduct.ts | 31 +- .../src/components/RecordPickerDialog.vue | 148 ++++ .../src/views/ExternalPrintPlatform/Index.vue | 171 +++- frontend/src/views/Order/Index.vue | 5 +- frontend/src/views/Order/OrderFormDialog.vue | 39 +- frontend/src/views/Order/StatusPanel.vue | 149 ++-- frontend/src/views/Shop/Index.vue | 223 +++++- frontend/src/views/ShopProduct/Index.vue | 740 +++++++++++++----- 11 files changed, 1377 insertions(+), 314 deletions(-) create mode 100644 frontend/src/components/RecordPickerDialog.vue diff --git a/frontend/src/api/externalPrintAccount.ts b/frontend/src/api/externalPrintAccount.ts index 5d9c931..0ebe6a1 100644 --- a/frontend/src/api/externalPrintAccount.ts +++ b/frontend/src/api/externalPrintAccount.ts @@ -74,3 +74,148 @@ export function loginExternalPrintAccount(id: number) { { timeout: 60000 }, ) } + +/** 平台侧店铺(商家)列表项:统一结构,不直接依赖具体平台字段 */ +export interface ExternalPrintMerchantItem { + external_id: string + name: string + contact_name?: string + contact_phone?: string + /** 1 正常 0 停用 */ + status: number + remark?: string + /** 是否已创建到 OMS 店铺 */ + added?: boolean + /** 平台返回的原始结构,创建店铺时原样保存 */ + raw?: unknown +} + +/** 拉取账号在外部打单平台的店铺(商家)列表(后端按平台分发,不直连平台) */ +export function getExternalPrintMerchants(id: number, params?: object) { + return get<{ list: ExternalPrintMerchantItem[]; total: number; page: number; pageSize: number }>( + `/external-print-accounts/${id}/merchants`, + params, + ) +} + +/** 商品同步时单个分区的拉取明细(同一域名下可能有多套库,如「新系统区」) */ +export interface ExternalPrintShopProductSyncArea { + dbname: string + name: string + total: number + unique: number + pages: number + verified: boolean +} + +/** 商品同步时单个域名的拉取明细 */ +export interface ExternalPrintShopProductSyncHost { + host: string + total: number + unique: number + pages: number + verified: boolean + areas?: ExternalPrintShopProductSyncArea[] +} + +/** 商家店铺商品同步结果 */ +export interface ExternalPrintShopProductSyncResult { + total: number + unique: number + created: number + updated: number + /** 平台已不存在、且未绑定未被订单引用 → 已删除的行数 */ + removed: number + /** 平台已不存在、但已绑定或被订单引用 → 保留并标为下架的行数 */ + offline: number + verified: boolean + hosts: ExternalPrintShopProductSyncHost[] +} + +/** 同步外部打单平台商家的店铺商品(后端按商家分区逐域名拉取全量快照) */ +export function syncExternalPrintShopProducts(accountId: number, shopId: number) { + return post( + `/external-print-accounts/${accountId}/shops/${shopId}/sync-products`, + undefined, + { timeout: 120000 }, + ) +} + +/** 待补拉的商品(订单明细里的平台商品ID/规格ID) */ +export interface PullShopProductItem { + outer_item_id: string + outer_sku_id?: string +} + +/** 单品补拉结果里写入的店铺商品 */ +export interface PulledShopProductRow { + id: number + shop_id: number + outer_item_id: string + outer_sku_id: string | null + title: string | null + spec: string | null + platform_type: string | null + status: number + bind_type: number + product_id: number | null + combo_product_id: number | null +} + +/** 单品补拉结果(未命中的商品带原因返回) */ +export interface PullShopProductsResult { + requested: number + matched: number + created: number + updated: number + hosts: string[] + missing: Array<{ outer_item_id: string; outer_sku_id: string; reason: string }> + products: PulledShopProductRow[] +} + +/** 按平台商品ID单独补拉店铺商品(订单明细匹配不到店铺商品时使用) */ +export function pullExternalPrintShopProducts( + accountId: number, + shopId: number, + items: PullShopProductItem[], +) { + return post( + `/external-print-accounts/${accountId}/shops/${shopId}/pull-products`, + { items }, + { timeout: 120000 }, + ) +} + +/** 拉取订单结果(手动与定时共用同一后端逻辑) */ +export interface SyncShopOrdersResult { + start_time: string + end_time: string + orders: number + created: number + updated: number + items: number + items_bound: number + items_unbound: number + hosts: string[] +} + +/** 手动拉取外部打单平台商家订单(按天数或时间窗) */ +export function syncExternalPrintShopOrders( + accountId: number, + shopId: number, + params: { days?: number; start_time?: string; end_time?: string } = {}, +) { + return post( + `/external-print-accounts/${accountId}/shops/${shopId}/sync-orders`, + params, + { timeout: 300000 }, + ) +} + +/** 把选中的平台店铺(商家)创建到 OMS 店铺 */export function createShopsFromMerchants(id: number, merchants: ExternalPrintMerchantItem[]) { + return post<{ created: number; skipped: number; shops: Array<{ id: number; code: string; name: string }> }>( + `/external-print-accounts/${id}/shops`, + { merchants }, + { timeout: 60000 }, + ) +} diff --git a/frontend/src/api/orderStatus.ts b/frontend/src/api/orderStatus.ts index 5442c67..8eeaa37 100644 --- a/frontend/src/api/orderStatus.ts +++ b/frontend/src/api/orderStatus.ts @@ -95,6 +95,8 @@ export interface OrderStatusItem { address: string | null status: OrderStage status_label?: string + /** 是否外部打单平台拉取的订单(店铺由平台决定,不可修改) */ + is_external?: boolean remark: string | null /** —— 老发货单口径字段(为容纳老表而扩展) —— */ order_type?: string | null @@ -175,7 +177,7 @@ export interface OrderStatusFilters { archive_months: number /** 订单索引表名 */ index_table?: string - shops: { id: number; name: string }[] + shops: { id: number; code?: string; name: string; type?: number }[] warehouses: { id: number; code: string; name: string }[] } @@ -386,11 +388,3 @@ export function changeOrdersWarehouse(ids: number[], warehouseId: number) { { ids, warehouse_id: warehouseId }, ) } - -/** 批量设置所属店铺(同步刷新 shop_nick 快照) */ -export function changeOrdersShop(ids: number[], shopId: number) { - return post<{ updated: number; target: { id: number; name: string } }>('/order-status/change-shop', { - ids, - shop_id: shopId, - }) -} diff --git a/frontend/src/api/shop.ts b/frontend/src/api/shop.ts index 95a8404..20ccc8b 100644 --- a/frontend/src/api/shop.ts +++ b/frontend/src/api/shop.ts @@ -9,6 +9,30 @@ export interface ShopItem { contact_name: string | null contact_phone: string | null status: number + /** 店铺类型:1 平台店铺 2 外部打单平台商家 3 数据库模式(预留) */ + type?: number + /** 来源外部打单账号ID(type=2 时有值) */ + external_print_account_id?: number | null + /** 外部打单平台返回的商家原始结构 */ + external_data?: unknown | null + /** 数据库地址(type=3 数据库模式店铺使用,预留) */ + db_host?: string | null + /** 数据库端口(type=3 数据库模式店铺使用,预留) */ + db_port?: number | null + /** 数据库名(type=3 数据库模式店铺使用,预留) */ + db_name?: string | null + /** 数据库账号(type=3 数据库模式店铺使用,预留) */ + db_username?: string | null + /** 是否已配置数据库密码(密码不回显) */ + has_db_password?: boolean + /** 是否自动拉取订单:1 是 0 否 */ + auto_fetch_order: number + /** 自动拉取订单间隔(分钟,最小 3) */ + auto_fetch_interval: number + /** 最近一次拉取订单时间(手动/自动) */ + last_order_sync_at?: string | null + /** 最近一次拉取订单结果/失败原因 */ + last_order_sync_msg?: string | null extra: unknown | null remark: string | null created_at?: string @@ -23,6 +47,10 @@ export interface ShopPayload { contact_name?: string contact_phone?: string status?: number + /** 是否自动拉取订单:1 是 0 否 */ + auto_fetch_order?: number + /** 自动拉取订单间隔(分钟,最小 3) */ + auto_fetch_interval?: number remark?: string } diff --git a/frontend/src/api/shopProduct.ts b/frontend/src/api/shopProduct.ts index 4a51db6..0875101 100644 --- a/frontend/src/api/shopProduct.ts +++ b/frontend/src/api/shopProduct.ts @@ -1,4 +1,4 @@ -import { get, post, put, del } from '@/utils/request' +import { get, post } from '@/utils/request' /** 绑定类型:0未绑定 1系统商品 2组合商品 */ export const BIND_TYPES = { none: 0, product: 1, combo: 2 } as const @@ -16,6 +16,12 @@ export interface ShopProductItem { price: number | string | null stock: number status: number + /** 外部平台类型:TouTiao/Taobao/Pinduoduo 等(外部平台采集时有值) */ + platform_type?: string | null + /** 外部平台的店铺ID(如店管家 ShopId) */ + external_shop_id?: string | null + /** 引用该商品但未绑定系统商品的订单数(列表接口回填) */ + unbound_order_count?: number bind_type: number product_id: number | null combo_product_id: number | null @@ -27,19 +33,6 @@ export interface ShopProductItem { comboProduct?: { id: number; code: string; name: string } | null } -export interface ShopProductPayload { - shop_id: number - outer_item_id: string - outer_sku_id?: string - title?: string - outer_code?: string - spec?: string - image?: string - price?: number - stock?: number - status?: number -} - export interface BindPayload { bind_type: number product_id?: number | null @@ -54,17 +47,7 @@ export function getShopProducts(params?: object) { ) } -/** 更新店铺商品采集信息 */ -export function updateShopProduct(id: number, data: Partial) { - return put<{ id: number }>(`/shop-products/${id}`, data) -} - /** 绑定系统商品 / 组合商品,bind_type=0 为解绑 */ export function bindShopProduct(id: number, data: BindPayload) { return post<{ id: number }>(`/shop-products/${id}/bind`, data) } - -/** 删除店铺商品 */ -export function deleteShopProduct(id: number) { - return del<{ id: number }>(`/shop-products/${id}`) -} diff --git a/frontend/src/components/RecordPickerDialog.vue b/frontend/src/components/RecordPickerDialog.vue new file mode 100644 index 0000000..425d4da --- /dev/null +++ b/frontend/src/components/RecordPickerDialog.vue @@ -0,0 +1,148 @@ + + + + + diff --git a/frontend/src/views/ExternalPrintPlatform/Index.vue b/frontend/src/views/ExternalPrintPlatform/Index.vue index 474e568..517f497 100644 --- a/frontend/src/views/ExternalPrintPlatform/Index.vue +++ b/frontend/src/views/ExternalPrintPlatform/Index.vue @@ -1,5 +1,5 @@ @@ -348,4 +504,15 @@ onMounted(async () => { .search-bar { margin-bottom: 12px; } +.merchant-search { + margin-bottom: 8px; +} +.merchant-table { + width: 100%; +} +.merchant-selected { + margin-right: 12px; + font-size: 12px; + color: var(--el-text-color-secondary); +} diff --git a/frontend/src/views/Order/Index.vue b/frontend/src/views/Order/Index.vue index fa49167..d8ea486 100644 --- a/frontend/src/views/Order/Index.vue +++ b/frontend/src/views/Order/Index.vue @@ -942,7 +942,7 @@ onMounted(async () => { { min-height: 0; overflow: hidden; } -.fill-table { - height: 100%; -} diff --git a/frontend/src/views/Order/OrderFormDialog.vue b/frontend/src/views/Order/OrderFormDialog.vue index ecbe66f..6473bce 100644 --- a/frontend/src/views/Order/OrderFormDialog.vue +++ b/frontend/src/views/Order/OrderFormDialog.vue @@ -127,13 +127,19 @@ function defaultWarehouseId(): number | null { return list.length ? list[0].id : null } -/** 默认店铺:优先父级入口指定的店铺,否则取店铺列表第一个 */ +/** 手工建单可选店铺:排除外部打单平台店铺(type=2,其订单只能由平台拉取) */ +const selectableShops = computed(() => (props.filters.shops || []).filter(shop => Number(shop.type ?? 1) !== 2)) + +/** 默认店铺:优先父级入口指定的店铺,否则取可选店铺列表第一个 */ function defaultShopIdOf(): number | null { if (props.defaultShopId) return props.defaultShopId - const list = props.filters.shops || [] + const list = selectableShops.value return list.length ? list[0].id : null } +/** 当前编辑的单据是否由外部打单平台拉取(店铺不可修改) */ +const isExternal = ref(false) + function reset() { Object.assign(form, { parent_order_no: '', @@ -175,6 +181,8 @@ async function loadDetail(id: number) { loading.value = true try { const { order, items } = await getOrderStatusDetail(id) + // 外部打单平台拉取的订单,店铺由平台决定,编辑时不允许修改 + isExternal.value = !!(order as { is_external?: boolean }).is_external Object.assign(form, { parent_order_no: order.parent_order_no || '', order_no: order.order_no, @@ -543,9 +551,25 @@ async function submit() { - - + + +
平台拉取的订单,店铺由平台决定,不可修改
+
+ 当前主体下没有可用的平台店铺(外部打单平台店铺不可用于手工建单) +
@@ -870,6 +894,13 @@ async function submit() { line-height: 16px; color: var(--el-text-color-secondary); } +.form-tip { + display: block; + margin-top: 2px; + font-size: 12px; + line-height: 16px; + color: var(--el-text-color-secondary); +} :deep(.el-descriptions__label) { width: 110px; } diff --git a/frontend/src/views/Order/StatusPanel.vue b/frontend/src/views/Order/StatusPanel.vue index d4f1660..c4182fd 100644 --- a/frontend/src/views/Order/StatusPanel.vue +++ b/frontend/src/views/Order/StatusPanel.vue @@ -4,6 +4,7 @@ import { ElMessage, ElMessageBox } from 'element-plus' import DataTable from '@/components/DataTable.vue' import ExportButton from '@/components/ExportButton.vue' import ListPager from '@/components/ListPager.vue' +import RecordPickerDialog from '@/components/RecordPickerDialog.vue' import OrderFormDialog from './OrderFormDialog.vue' import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage' import { formatDateTime } from '@/utils/datetime' @@ -12,7 +13,6 @@ import { archiveOrders, auditOrders, cancelOrders, - changeOrdersShop, changeOrdersWarehouse, getOrderStatusDetail, getOrderStatusFilters, @@ -66,6 +66,14 @@ const query = reactive({ archivedRange: [] as string[], }) +/** 「含未绑定商品订单」开关(默认关闭:不显示含未绑定商品的订单) */ +const showUnboundOrders = ref(false) + +function onUnboundSwitchChange() { + query.page = 1 + search() +} + const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({ query, @@ -89,6 +97,8 @@ const { loading, list, total, elapsed, fetchList, search, handlePageChange, hand params.archived_from = query.archivedRange[0] params.archived_to = query.archivedRange[1] } + // 待审核默认只看「商品都已绑定」的订单,开关打开才包含未绑定商品的订单 + if (props.status === 'pending' && !showUnboundOrders.value) params.exclude_unbound = 1 return getOrderStatusList(params as never) }, }) @@ -119,6 +129,7 @@ const exportFilters = computed(() => ({ created_to: query.createdRange[1], archived_from: query.archivedRange[0], archived_to: query.archivedRange[1], + exclude_unbound: props.status === 'pending' && !showUnboundOrders.value ? 1 : '', })) /* -------------------- 筛选项数据源(状态枚举 / 店铺 / 归档阈值) -------------------- */ @@ -155,14 +166,12 @@ type BatchKey = | 'void' | 'restore' | 'change_warehouse' - | 'change_shop' -/** 批量操作按场景分布在各视图 */ +/** 批量操作按场景分布在各视图(店铺在创建时确定,不再提供批量设置店铺) */ const BATCH_ACTIONS: Record = { pending: [ { key: 'audit', label: '批量审核(→ 待推送)', type: 'primary' }, { key: 'change_warehouse', label: '切换仓库', type: 'default' }, - { key: 'change_shop', label: '设置店铺', type: 'default' }, { key: 'cancel', label: '取消', type: 'warning' }, { key: 'void', label: '作废', type: 'danger' }, ], @@ -170,7 +179,6 @@ const BATCH_ACTIONS: Record { - const list = filters.value.warehouses || [] - if (!list.length) { +/** 切换仓库使用的目标选择弹窗(列表选择,而非手输名称) */ +const picker = reactive({ + visible: false, + title: '', +}) + +const pickerOptions = computed>>(() => + (filters.value.warehouses || []).map(item => ({ ...item })), +) + +const pickerColumns = [ + { prop: 'code', label: '仓库编码', width: 180 }, + { prop: 'name', label: '仓库名称', minWidth: 200 }, +] + +/** 弹窗确认后的回调(由打开方注入) */ +let pickerResolve: ((row: Record | null) => void) | null = null + +/** + * 打开仓库选择弹窗并等待结果 + * @return 选中的仓库行,取消返回 null + */ +function openPicker() { + if (!(filters.value.warehouses || []).length) { ElMessage.warning('当前主体下没有仓库,请先到「仓库管理」创建') - return null + return Promise.resolve(null) } - try { - const { value } = await ElMessageBox.prompt('请输入目标仓库名称或编码关键词后选择', '切换仓库', { - confirmButtonText: '确定', - cancelButtonText: '取消', - inputPlaceholder: `可选:${list.map(w => `${w.name}(${w.code})`).join(' / ')}`, - inputValidator: (text: string) => { - const keyword = String(text || '').trim() - return list.some(w => w.name.includes(keyword) || w.code.includes(keyword)) - ? true - : '请输入列表中的仓库名称或编码' - }, - }) - const keyword = String(value).trim() - const hit = list.find(w => w.name.includes(keyword) || w.code.includes(keyword)) - return hit ? hit.id : (current ?? null) - } catch { - return null + picker.title = '切换仓库' + picker.visible = true + return new Promise | null>((resolve) => { + pickerResolve = resolve + }) +} + +function onPickerConfirm(row: Record) { + if (pickerResolve) pickerResolve(row) + pickerResolve = null +} + +function onPickerClose(visible: boolean) { + picker.visible = visible + if (!visible && pickerResolve) { + pickerResolve(null) + pickerResolve = null } } -async function pickShop(): Promise { - const list = filters.value.shops || [] - if (!list.length) { - ElMessage.warning('当前主体下没有店铺,请先到「店铺管理」创建') - return null - } - try { - const { value } = await ElMessageBox.prompt('请输入目标店铺名称关键词', '设置所属店铺', { - confirmButtonText: '确定', - cancelButtonText: '取消', - inputPlaceholder: `可选:${list.map(s => s.name).join(' / ')}`, - inputValidator: (text: string) => { - const keyword = String(text || '').trim() - return list.some(s => s.name.includes(keyword)) ? true : '请输入列表中的店铺名称' - }, - }) - const keyword = String(value).trim() - const hit = list.find(s => s.name.includes(keyword)) - return hit ? hit.id : null - } catch { - return null - } +async function pickWarehouse(): Promise { + const row = await openPicker() + return row ? Number(row.id) : null } /** 批量操作入口 */ @@ -282,15 +288,6 @@ async function handleBatch(key: BatchKey) { await fetchList() return } - if (key === 'change_shop') { - const shopId = await pickShop() - if (!shopId) return - const result = await changeOrdersShop(ids, shopId) - ElMessage.success(`已设置店铺:${result.target.name}`) - selectedIds.value = [] - await fetchList() - return - } let tip = '' if (key === 'push_failed') { @@ -598,6 +595,16 @@ onMounted(async () => { 已选 {{ selectedIds.length }} 条
+ 新建订单(发货单) @@ -668,13 +675,13 @@ onMounted(async () => { - +
@@ -853,6 +860,19 @@ onMounted(async () => { :filters="filters" @saved="handleFormSaved" /> + + +
@@ -877,6 +897,9 @@ onMounted(async () => { gap: 8px; flex-wrap: wrap; } +.unbound-switch { + margin-right: 4px; +} .toolbar-right { display: flex; align-items: center; diff --git a/frontend/src/views/Shop/Index.vue b/frontend/src/views/Shop/Index.vue index 3167f96..d8ad86d 100644 --- a/frontend/src/views/Shop/Index.vue +++ b/frontend/src/views/Shop/Index.vue @@ -10,6 +10,7 @@ import { type ShopItem, type ShopDetail, } from '@/api/shop' +import { syncExternalPrintShopProducts, syncExternalPrintShopOrders } from '@/api/externalPrintAccount' import SplitLayout from '@/components/SplitLayout.vue' import ExportButton from '@/components/ExportButton.vue' import DataTable from '@/components/DataTable.vue' @@ -27,6 +28,9 @@ const PLATFORMS = [ const STATUS_LABELS: Record = { 1: '启用', 0: '禁用' } +/** 店铺类型:1 平台店铺 2 外部打单平台商家 3 数据库模式(预留) */ +const TYPE_LABELS: Record = { 1: '平台店铺', 2: '外部打单平台', 3: '数据库模式' } + function platformLabel(value?: string | null) { return PLATFORMS.find((p) => p.value === value)?.label || value || '-' } @@ -97,12 +101,27 @@ const form = reactive({ contact_name: '', contact_phone: '', status: 1, + auto_fetch_order: 0, + auto_fetch_interval: 3, remark: '', }) // 新增时无需填编码(由后端生成 OMS 前缀编码),故 code 不做必填校验 const rules: FormRules = { name: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }], status: [{ required: true, message: '请选择状态', trigger: 'change' }], + auto_fetch_interval: [ + { + validator: (_rule: unknown, value: unknown, callback: (e?: string | Error) => void) => { + const interval = Number(value) + if (!Number.isInteger(interval) || interval < 3) { + callback(new Error('拉取间隔必须是不小于 3 的整数(分钟)')) + } else { + callback() + } + }, + trigger: 'change', + }, + ], } function openCreate() { @@ -113,6 +132,8 @@ function openCreate() { form.contact_name = '' form.contact_phone = '' form.status = 1 + form.auto_fetch_order = 0 + form.auto_fetch_interval = 3 form.remark = '' dialogVisible.value = true } @@ -125,6 +146,8 @@ function openEdit(row: ShopItem) { form.contact_name = row.contact_name || '' form.contact_phone = row.contact_phone || '' form.status = row.status + form.auto_fetch_order = Number(row.auto_fetch_order) === 1 ? 1 : 0 + form.auto_fetch_interval = Number(row.auto_fetch_interval) || 3 form.remark = row.remark || '' dialogVisible.value = true } @@ -157,6 +180,82 @@ async function submitForm() { }) } +/** 正在拉取订单的店铺ID(防止重复点击) */ +const fetchingOrderId = ref(null) +/** 拉取订单弹窗 */ +const fetchOrderVisible = ref(false) +const fetchOrderSubmitting = ref(false) +const fetchOrderShop = ref(null) +const fetchOrderForm = reactive({ days: 1 }) + +const FETCH_ORDER_DAYS = [ + { label: '最近 1 天', value: 1 }, + { label: '最近 3 天', value: 3 }, + { label: '最近 7 天', value: 7 }, + { label: '最近 30 天', value: 30 }, +] + +/** 打开手动拉单弹窗(外部打单平台店铺) */ +function openFetchOrder(row: ShopItem) { + if (!row.external_print_account_id) { + ElMessage.warning('该店铺未关联外部打单账号,无法拉取订单') + return + } + fetchOrderShop.value = row + fetchOrderForm.days = 1 + fetchOrderVisible.value = true +} + +/** 手动拉取订单:后端按店铺所属商家逐平台分区拉取并写入订单/明细 */ +async function submitFetchOrder() { + const shop = fetchOrderShop.value + if (!shop || !shop.external_print_account_id) return + fetchOrderSubmitting.value = true + fetchingOrderId.value = shop.id + try { + const res = await syncExternalPrintShopOrders(shop.external_print_account_id, shop.id, { + days: fetchOrderForm.days, + }) + ElMessage.success( + `拉取完成:${res.orders} 单(新增 ${res.created},更新 ${res.updated}),明细 ${res.items} 条`, + ) + fetchOrderVisible.value = false + await fetchList() + if (currentShop.value && currentShop.value.id === shop.id) await fetchDetail(shop.id) + } catch { + // 拦截器已提示 + } finally { + fetchOrderSubmitting.value = false + fetchingOrderId.value = null + } +} + +/** 正在同步商品的店铺ID(防止重复点击) */ +const syncingId = ref(null) + +/** 同步外部打单平台商家的店铺商品(后端按商家分区逐域名拉取全量快照) */ +async function handleSyncProducts(row: ShopItem) { + const accountId = row.external_print_account_id + if (!accountId) { + ElMessage.warning('该店铺未关联外部打单账号,无法同步商品') + return + } + syncingId.value = row.id + try { + const res = await syncExternalPrintShopProducts(accountId, row.id) + const parts = [ `新增 ${res.created}`, `更新 ${res.updated}` ] + if (res.removed) parts.push(`移除 ${res.removed}`) + if (res.offline) parts.push(`下架 ${res.offline}(已绑定或被订单引用,已保留)`) + const suffix = res.verified ? '' : '(平台数据在拉取过程中有变动,本次未处理下架,建议重试)' + ElMessage.success(`同步完成:${parts.join(',')},共 ${res.unique} 条${suffix}`) + if (currentShop.value && currentShop.value.id === row.id) await fetchDetail(row.id) + } catch { + // 拦截器已提示 + } finally { + syncingId.value = null + } +} + async function handleDelete(row: ShopItem) { try { await ElMessageBox.confirm(`确认删除店铺「${row.name}」?`, '删除确认', { @@ -225,7 +324,7 @@ onMounted(fetchList) :loading="loading" :data="list" highlight-current-row - class="fill-table" + height="100%" @row-click="handleRowClick" > @@ -233,6 +332,24 @@ onMounted(fetchList) + + + + + + @@ -242,9 +359,27 @@ onMounted(fetchList) - + @@ -274,6 +409,22 @@ onMounted(fetchList) 编辑 + + 拉取订单 + + + 同步商品 +
@@ -282,6 +433,16 @@ onMounted(fetchList) {{ platformLabel(currentShop.platform) }} + + {{ currentShop.auto_fetch_order === 1 ? `是(每 ${currentShop.auto_fetch_interval} 分钟)` : '否' }} + + + + {{ formatDateTime(currentShop.last_order_sync_at) }} + {{ currentShop.last_order_sync_msg || '' }} + + - + {{ currentShop.contact_name || '-' }} @@ -361,6 +522,19 @@ onMounted(fetchList) + + + 开启后按间隔自动拉取该店铺订单 + + + + 分钟(不小于 3 分钟,开启自动拉取后生效) + @@ -370,6 +544,30 @@ onMounted(fetchList) 保存 + + + + + + {{ fetchOrderShop?.name || '-' }} + + + + + + + + + @@ -394,6 +592,19 @@ onMounted(fetchList) justify-content: space-between; font-weight: 600; } +.last-sync { + margin-top: 2px; + font-size: 11px; + color: var(--el-text-color-secondary); + cursor: default; +} +.fetch-order-tip { + margin-bottom: 14px; +} +.sync-msg { + margin-left: 6px; + color: var(--el-text-color-secondary); +} .search-bar { margin-bottom: 12px; } @@ -402,12 +613,14 @@ onMounted(fetchList) min-height: 0; overflow: hidden; } -.fill-table { - height: 100%; -} .code-tip { margin-bottom: 14px; } +.form-tip { + margin-left: 8px; + font-size: 12px; + color: var(--el-text-color-secondary); +} .detail-tabs { flex: 1; min-height: 0; diff --git a/frontend/src/views/ShopProduct/Index.vue b/frontend/src/views/ShopProduct/Index.vue index d70d120..036fad8 100644 --- a/frontend/src/views/ShopProduct/Index.vue +++ b/frontend/src/views/ShopProduct/Index.vue @@ -1,14 +1,14 @@