- 更新环境变量配置方式,使用 dotenv 库 - 重构员工登录和权限相关代码,提高可维护性 - 优化测试数据结构,增加类型注解 - 删除冗余代码,提高代码可读性
136 lines
4.4 KiB
TypeScript
136 lines
4.4 KiB
TypeScript
import { Page } from '@playwright/test';
|
||
import { reportData } from './reportPage';
|
||
|
||
export class SalesCostSummaryReportPage {
|
||
page: Page;
|
||
_reportData: reportData[];
|
||
/**
|
||
* 销售消耗汇总表
|
||
*/
|
||
constructor(page: Page) {
|
||
this.page = page;
|
||
this._reportData = [
|
||
{
|
||
name: '护理',
|
||
content: [
|
||
{
|
||
name: '现金业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
{
|
||
name: '划卡业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
{
|
||
name: '消耗业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
],
|
||
},
|
||
{
|
||
name: '面部',
|
||
content: [
|
||
{
|
||
name: '现金业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
{
|
||
name: '划卡业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
{
|
||
name: '消耗业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
],
|
||
},
|
||
{
|
||
name: '身体',
|
||
content: [
|
||
{
|
||
name: '现金业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
{
|
||
name: '划卡业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
{
|
||
name: '消耗业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
],
|
||
},
|
||
{
|
||
name: '组合项目',
|
||
content: [
|
||
{
|
||
name: '现金业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
{
|
||
name: '划卡业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
{
|
||
name: '消耗业绩', index: -1,
|
||
value: 0,
|
||
lastValue: 0,
|
||
},
|
||
],
|
||
},
|
||
];
|
||
}
|
||
|
||
get reportData() {
|
||
return this._reportData;
|
||
}
|
||
|
||
updateReportDataIndex = async () => {
|
||
const thLocator = this.page.locator('.m-table__header-wrapper tr').first().locator('th[colspan="3"]');
|
||
await thLocator.first().waitFor();
|
||
const headers = await thLocator.allInnerTexts();
|
||
|
||
for (let i = 0; i < headers.length; i++) {
|
||
const reportDataTmp = this._reportData.find(e => e.name === headers[i]);
|
||
if (!reportDataTmp || !reportDataTmp.content) {
|
||
throw new Error(`${reportDataTmp}--${reportDataTmp?.content}`);
|
||
}
|
||
for (let j = 0; j < 3; j++) {
|
||
reportDataTmp.content[j].index = i * 3 + j;
|
||
}
|
||
}
|
||
};
|
||
|
||
updateReportData = async (store: number): Promise<void> => {
|
||
// 没有总部故-1
|
||
const trLocator = this.page.locator('.main-table-body_tr').nth(store - 1);
|
||
await trLocator.first().waitFor();
|
||
const tdLocator = trLocator.locator('td');
|
||
const headers = await tdLocator.allInnerTexts();
|
||
if (headers.length === 0) {
|
||
throw new Error('没有获取到数据');
|
||
}
|
||
for (const category of this._reportData) {
|
||
for (const content of category.content!) {
|
||
// 保存上一次的数据
|
||
content.lastValue = content.value;
|
||
// 拿取当前的数据,currentIndex第一列为门店,故+1
|
||
const currentIndex = content.index! + 1;
|
||
content.value = Number(headers[currentIndex].trim() === '--' ? 0 : headers[currentIndex].trim());
|
||
}
|
||
}
|
||
};
|
||
}
|