import {Component, OnInit} from '@angular/core';
import {BreadcrumbComponent} from "../../common/breadcrumb/breadcrumb.component";
import {NzSpinComponent, NzSpinModule} from "ng-zorro-antd/spin";
import {NzFormDirective, NzFormModule} from "ng-zorro-antd/form";
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
import {NzInputDirective} from "ng-zorro-antd/input";
import {ReactiveFormsModule} from "@angular/forms";
import {NzTabComponent, NzTabSetComponent} from "ng-zorro-antd/tabs";
import {NzBadgeComponent} from "ng-zorro-antd/badge";
import {DatePipe, NgForOf, NgIf} from "@angular/common";
import {
  NzCellFixedDirective,
  NzTableComponent, NzTableModule,
  NzTdAddOnComponent,
  NzThMeasureDirective,
  NzThSelectionComponent
} from "ng-zorro-antd/table";
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
import {NzButtonComponent} from "ng-zorro-antd/button";
import {ActivityMoneyPipe} from "../../../pipes/activity-money/activity-money.pipe";
import {ActivatedRoute, Params, RouterLink} from "@angular/router";
import {NzDividerComponent} from "ng-zorro-antd/divider";
import {environment} from "../../../../environments/environment";
import {NzModalModule, NzModalService} from "ng-zorro-antd/modal";
import {NzMessageService} from "ng-zorro-antd/message";
import {ActivityMoneyService} from "../../../services/activity-money.service";
import {NzDescriptionsComponent, NzDescriptionsItemComponent} from "ng-zorro-antd/descriptions";
import {NzBreadCrumbComponent} from "ng-zorro-antd/breadcrumb";
import {NzIconDirective} from "ng-zorro-antd/icon";
import {NzRadioComponent, NzRadioGroupComponent} from "ng-zorro-antd/radio";
import {NzDatePickerModule} from "ng-zorro-antd/date-picker";
import {NzTypographyComponent} from "ng-zorro-antd/typography";

@Component({
  selector: 'app-prize-pool-detail',
  standalone: true,
  imports: [
    BreadcrumbComponent,
    NzSpinComponent,
    NzFormDirective,
    NzRowDirective,
    NzColDirective,
    NzInputDirective,
    ReactiveFormsModule,
    NzTabSetComponent,
    NzTabComponent,
    NzBadgeComponent,
    NgForOf,
    NzTableComponent,
    DatePipe,
    NzThSelectionComponent,
    NzSelectComponent,
    NzTdAddOnComponent,
    NzOptionComponent,
    NzButtonComponent,
    NzCellFixedDirective,
    NgIf,
    ActivityMoneyPipe,
    RouterLink,
    NzDividerComponent,
    NzDescriptionsComponent,
    NzDescriptionsItemComponent,
    NzThMeasureDirective,
    NzBreadCrumbComponent,
    NzIconDirective,
    NzModalModule,
    NzTableModule,
    NzFormModule,
    NzSpinModule,
    NzRadioGroupComponent,
    NzRadioComponent,
    NzDatePickerModule,
    NzTypographyComponent
  ],
  templateUrl: './prize-pool-detail.component.html',
  styleUrl: './prize-pool-detail.component.less'
})
export class PrizePoolDetailComponent implements OnInit {
  FILE_URL = environment.imageUrl;
  selectedIndex:number = 0;

  prizePoolDetailsObject:any={};

  loadingObject = {
    spinning: false,
    msg: '加载中'
  };
  batchIdentifier="";
  constructor(
    private modal: NzModalService,
    private message: NzMessageService,
    private activityMoneyService:ActivityMoneyService,
    private activatedRoute: ActivatedRoute,
  ) { }

  ngOnInit() {
    this.activatedRoute.queryParams.subscribe((queryParams: Params) => {
      if (queryParams['batchIdentifier'] != null && queryParams['batchIdentifier'].length > 0) {
        this.batchIdentifier=queryParams['batchIdentifier'];
        this.prizePoolDetails(queryParams['batchIdentifier']);
      }
    });
  }

  /*打开奖池详情  */
  prizePoolDetails(batchIdentifier){
    let params ={
      batchIdentifier:batchIdentifier
    }
    this.activityMoneyService.queryRewardDetail(params, data => {
      if (data['return_code'] === '000000') {
        this.prizePoolDetailsObject = data['return_data'];
      } else {
        this.message.error(data['return_msg']);
      }
    });
  }

  /* 导出商户明天 */
  exportTradeOrder(batchIdentifier) {
    this.loadingObject.spinning = true;
    this.loadingObject.msg = '导出中...';
    let params ={
      batchIdentifier:batchIdentifier
    }
    this.activityMoneyService.exportRewardRoster(params, data => {
      if (data['return_code'] === '000000') {
        // window.location.href = this.FILE_URL + data['return_data'];
        window.open(data['return_data']);
      } else {
        this.message.error(data['return_msg']);
      }
      this.loadingObject.spinning = false;
    });
  }
}
