publish-confirm.component.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { Component, Input, OnInit } from '@angular/core';
  2. import { NzMessageService } from 'ng-zorro-antd/message';
  3. import { firstValueFrom } from 'rxjs';
  4. import { EpgService } from '../epg/epg.service';
  5. import { ArtService } from './art.service';
  6. @Component({
  7. selector: 'app-publish-confirm',
  8. template: `
  9. <nz-spin [nzSpinning]="isLoading">
  10. <div i18n>确认测试通过?</div>
  11. <ng-container *ngIf="!isLoading && unshelfList && unshelfList.length > 0">
  12. <div style="margin-top: 10px" i18n>提测后是否自动上架到以下epg? 请勾选确认:</div>
  13. <nz-table #unshelfTable nzSize="small" [nzFrontPagination]="false" [nzShowPagination]="false" [nzData]="unshelfList"
  14. [nzTemplateMode]="true" class="table table-hover table-sm table-edit">
  15. <thead>
  16. <tr>
  17. <th [nzChecked]="checked" [nzIndeterminate]="indeterminate" (nzCheckedChange)="onAllChecked($event)"></th>
  18. <th i18n>发布路径</th>
  19. </tr>
  20. </thead>
  21. <tbody *ngIf="unshelfTable.data && unshelfTable.data.length > 0">
  22. <tr *ngFor="let data of unshelfTable.data; let i = index" class="editable-row">
  23. <td [nzChecked]="checkDataSet.has(data)" (nzCheckedChange)="onItemChecked(data, $event)"></td>
  24. <td> {{data.path}} </td>
  25. </tr>
  26. </tbody>
  27. </nz-table>
  28. </ng-container>
  29. </nz-spin>
  30. `,
  31. styles: [
  32. ]
  33. })
  34. export class PublishConfirmComponent implements OnInit {
  35. @Input() art: any;
  36. onshelfList: any[] = []; // 已上架列表
  37. pubList: any[] = []; // 根据tag与绑定epgs规则生成的可上架的列表
  38. unshelfList: any[] = []; // pubList 减去 onshelfList 后剩下的最终建议可上架的列表
  39. epgs: any[] = []; // epg 列表
  40. constructor(
  41. private message: NzMessageService,
  42. private artService: ArtService,
  43. private epgService: EpgService,
  44. ) {
  45. }
  46. ngOnInit(): void {
  47. this.loadData();
  48. }
  49. isLoading: boolean = false;
  50. loadData() {
  51. this.isLoading = true;
  52. firstValueFrom(this.artService.getShelfInfo(this.art._id)).then((resp: any) => {
  53. this.onshelfList = resp as any[];
  54. firstValueFrom(this.epgService.epgAll()).then((ret: any) => {
  55. this.epgs = ret.data || [];
  56. this.generatePubList()
  57. this.isLoading = false;
  58. })
  59. })
  60. }
  61. generatePubList() {
  62. let tags = this.art.tags;
  63. let epgs = this.art.epgs;
  64. let pubList = [];
  65. epgs.forEach(epgId => {
  66. let epg = this.epgs.find(e => e.epgId == epgId);
  67. if (epg) {
  68. epg.columns.forEach(col => {
  69. if (tags.includes(col.id)) {
  70. pubList.push({
  71. epg: epg.epgId,
  72. column: col.id,
  73. path: `${epg.epgId} -> ${col.zh}(${col.id})`
  74. });
  75. }
  76. })
  77. }
  78. })
  79. this.pubList = pubList;
  80. this.unshelfList = this.pubList.filter(item => {
  81. if (this.onshelfList.find(e => e.epg == item.epg && e.column == item.column)) return false; // 找到,说明已经上架过了,忽略
  82. else return true;
  83. })
  84. }
  85. //////////////////////////////// table checked ////////////////////////
  86. checkDataSet = new Set<any>();
  87. checked = false;
  88. indeterminate = false;
  89. onItemChecked(data: any, checked: boolean): void {
  90. this.updateCheckedSet(data, checked);
  91. this.refreshCheckedStatus();
  92. }
  93. updateCheckedSet(data: any, checked: boolean): void {
  94. if (checked) {
  95. this.checkDataSet.add(data);
  96. } else {
  97. this.checkDataSet.delete(data);
  98. }
  99. }
  100. refreshCheckedStatus(): void {
  101. this.checked = this.unshelfList.every(item => this.checkDataSet.has(item));
  102. this.indeterminate = this.unshelfList.some(item => this.checkDataSet.has(item)) && !this.checked;
  103. }
  104. onAllChecked(checked: boolean): void {
  105. this.unshelfList.forEach(item => this.updateCheckedSet(item, checked));
  106. this.refreshCheckedStatus();
  107. }
  108. cleanAllChecked() {
  109. this.checkDataSet.clear();
  110. this.checked = false;
  111. this.indeterminate = false;
  112. }
  113. }