store.ts 2.41 KB
// 门店上架业务接口(PRD §5/§6,端点以实际后端为准)
// 继承 ApiClient,共享 http 与 RSA 加签/验签。
import { ApiClient } from '../core/client';
import type { PageResult } from '../core/types';

// ---------- 门店列表(PRD §5.3 已生效门店) ----------
export interface StoreListingRow {
  id: string;
  storeName: string;
  merchantNo: string;
  city?: string;
  businessScene?: string;
  status?: string;
  owner?: string;
}

export interface ListingPageParams {
  pageNum?: number;
  pageSize?: number;
  storeName?: string;
  merchantNo?: string;
  status?: string;
  businessScene?: string;
}

// ---------- 门店导入(PRD §5.1 四步:下载→校验→确认→提交审批) ----------
/** 模板下载(免签,浏览器直链 / 网关暴露,§4.3) */
export const STORE_IMPORT_TEMPLATE_URL = '/api/store/import/template';

export interface ImportSubmitPayload {
  taskId: string;
  storeName: string;
  businessScene: string;
  [key: string]: unknown;
}

// ---------- 门店审批(PRD §5.2 三页签) ----------
export type ApproveTab = 'todo' | 'done' | 'mine';

export interface ApproveRow {
  id: string;
  storeName: string;
  merchantNo: string;
  categories: string[];
  scene: string;
  cost: number | null;
  submitter: string;
  submittedAt: string;
  stayHours: number;
}

class Store extends ApiClient {
  listStores(params: ListingPageParams = {}) {
    return this.get<PageResult<StoreListingRow>>(
      '/store/listing/page',
      params as Record<string, unknown>,
    );
  }

  /** 上传模板文件做五级校验(FormData,请求体不参与签名,§3.1/§9.6) */
  uploadImport(file: File, templateVersion = 'V1.0.1') {
    const form = new FormData();
    form.append('file', file);
    form.append('templateVersion', templateVersion);
    return this.post<{ taskId: string }>('/store/import/check', form);
  }

  /** 提交导入审批(单级审批,通过后生效,§4.3) */
  submitImport(payload: ImportSubmitPayload) {
    return this.post<{ approveId: string }>('/store/import/submit', payload);
  }

  listApprovals(tab: ApproveTab, params: Record<string, unknown> = {}) {
    return this.get<PageResult<ApproveRow>>('/store/approve/page', { tab, ...params });
  }

  approve(id: string, action: 'pass' | 'reject', comment?: string) {
    return this.post<null>(`/store/approve/${id}/${action}`, { comment });
  }
}

export const store = new Store();