import { Locator, Page } from 'playwright'; import { waitSpecifyApiLoad } from '@/utils/utils'; export class WasteBookBusinessRecordPage { page: Page; $homePage: Locator; subPages: { name: string; url?: string[] }[]; /** * 流水模块-营业记录页面 * @param {import("@playwright/test").Page} page */ constructor(page: Page) { this.page = page; this.$homePage = this.page.locator('.top_tab .tab_item', { hasText: '营业记录', }); this.subPages = [ { name: '营业记录', url: ['/settled_flow'] }, { name: '业绩流水', url: ['/perf_flow'] }, { name: '对账流水', url: ['/payment_flow'] }, ]; } /** * 进入营业记录子页面 * @param subPageName 子页面名称 * - 营业记录 * - 业绩流水 * - 对账流水 */ gotoSubPage = async (subPageName: string) => { const subPage = this.subPages.find(item => item.name === subPageName); if (!subPage) { throw new Error(`未找到${subPageName}页面`); } const $dropDown = this.$homePage.locator('.ant-dropdown-link'); await $dropDown.click(); const $subPage = this.page.getByRole('menuitem', { name: subPageName }); await Promise.all([$subPage.click(), waitSpecifyApiLoad(this.page, subPage.url)]); }; /** * 根据billSet进行撤单操作 * 配合billSet夹具使用(baseFixture) */ revokeOrder = async (billSet: Set) => { // 撤掉在预约中开的单 if (billSet.size === 0) { return; } await this.page.getByText('已结算', { exact: true }).waitFor(); for (const bill of billSet) { await this.page.getByRole('button').click(); await this.page.getByPlaceholder('输入流水单号搜索').fill(bill); await this.page.locator('.search_btn > svg').click(); const $fixedRightTable = this.page.locator('.m-table__fixed-right'); await $fixedRightTable.locator('td').nth(1).getByText('撤单').click(); await this.page.getByPlaceholder('请输入1-100个字符备注内容').click(); await this.page.getByPlaceholder('请输入1-100个字符备注内容').fill('撤单'); await this.page.getByRole('button', { name: /确\s认/ }).click(); try { await this.page.locator('.ant-message', { hasText: '撤单成功' }).waitFor({ timeout: 3000 }); } catch (error) { console.log(`撤单失败,流水单号:${bill}`); await this.page.getByRole('button', { name: '我知道了' }).click(); } } }; }