import { Page } from '@playwright/test'; import { type reportData } from './reportPage'; export class PerformanceSummaryReportPage { page: Page; private readonly _reportData: reportData[]; /** * 业绩汇总表 */ constructor(page: Page) { this.page = page; this._reportData = [ { name: '营收明细', content: [ { name: '现金类总额', value: 0, lastValue: 0, index: 0 }, { name: '现金', value: 0, lastValue: 0, index: 0 }, { name: '划卡', value: 0, lastValue: 0, index: 0 }, { name: '划赠金', value: 0, lastValue: 0, index: 0 }, ], }, { name: '开支明细', content: [{ name: '支出总额', value: 0, lastValue: 0, index: 0 }], }, { name: '现金业绩', content: [ { name: '项目合计', value: 0, lastValue: 0, index: 0 }, { name: '卖品业绩', value: 0, lastValue: 0, index: 0 }, { name: '开充卡业绩', value: 0, lastValue: 0, index: 0 }, { name: '开卡业绩', value: 0, lastValue: 0, index: 0 }, { name: '充值业绩', value: 0, lastValue: 0, index: 0 }, { name: '总现金业绩', value: 0, lastValue: 0, index: 0 }, ], }, { name: '划卡业绩', content: [{ name: '项目合计', value: 0, lastValue: 0, index: 0 }], }, { name: '消耗业绩', content: [ { name: '总消耗业绩', value: 0, lastValue: 0, index: 0 }, { name: '项目总数', value: 0, lastValue: 0, index: 0 }, ], }, { name: '客流', content: [ { name: '客数', value: 0, lastValue: 0, index: 0 }, { name: '客次', value: 0, lastValue: 0, index: 0 }, ], }, { name: '套餐销售', content: [ { name: '总数量', value: 0, lastValue: 0, index: 0 }, { name: '普通数量', value: 0, lastValue: 0, index: 0 }, { name: '总金额', value: 0, lastValue: 0, index: 0 }, { name: '总业绩', value: 0, lastValue: 0, index: 0 }, ], }, { name: '卖品销售', content: [ { name: '总数量', value: 0, lastValue: 0, index: 0 }, { name: '普通数量', value: 0, lastValue: 0, index: 0 }, { name: '总金额', value: 0, lastValue: 0, index: 0 }, { name: '总业绩', value: 0, lastValue: 0, index: 0 }, ], }, { name: '其他指标', content: [ { name: '客单价', value: 0, lastValue: 0, index: 0 }, { name: '总耗业绩', value: 0, lastValue: 0, index: 0 }, ], }, ]; } get reportData() { return this._reportData; } /** * 更新业绩汇总表数据索引 */ updateReportDataIndex = async () => { const thLocator = this.page.locator('.m-table__header-wrapper tr').last().locator('th'); await thLocator.first().waitFor(); const headers = await thLocator.allInnerTexts(); for (const category of this._reportData) { for (const content of category.content!) { let index: number; let occurrence = 0; index = headers.findIndex(headerText => { if (headerText === content.name) { occurrence++; // 每次找到相同的文本,计数加1 if (category.name === '卖品销售' || category.name === '划卡业绩') { // 找到第二次出现的 content.name return occurrence === 2; } else { // 找到第一次出现的 content.name return occurrence === 1; } } return false; }); if (index !== -1) { content.index = index + 1; } else { throw new Error(`没有找到${content.name}列`); } } } }; /** * 拿取业绩汇总表的汇总数据 */ updateReportDataFromTotal = async () => { // 合计行定位器 const $totalTr = this.page.locator('.m-table-footer .m-table__row'); await $totalTr.first().waitFor(); // 拿取当前的数据 const $$totalTd = $totalTr.locator('td'); const totalAllText = await $$totalTd.allInnerTexts(); if (totalAllText.length === 0) { return new Error(`${$totalTr.toString()}没有找到`); } for (const category of this._reportData) { for (const content of category.content!) { content.lastValue = content.value; content.value = Number( totalAllText[content.index].trim() === '--' ? 0 : totalAllText[content.index].trim(), ); } } }; }