import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { AjaxService } from 'src/app/core/service/ajax.service';
import { MsgService } from 'src/app/core/service/msg.service';
import { FrameDetailComponent } from '../../../frame/core/detail/frame.detail';

@Component({
  selector: 'app-wish-plan-group',
  templateUrl: './wish-plan-group.component.html',
  styleUrls: ['./wish-plan-group.component.scss']
})
export class WishPlanGroupComponent extends FrameDetailComponent implements OnInit {

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) { 
    super(bsModalRef);
    this.detailForm = fb.group({
      'wish_group': [null, Validators.compose([Validators.required])]
    });
  }

  ngOnInit(): void {
  }

  savePlanGroup() {
    let wish_ids = [];
    for(const r of this.ResponseArray) {
      wish_ids.push(r.wish_id);
    }
    AjaxService.request('wish/plan/merge.htm', {
      wish_ids : wish_ids,
      wish_group: this.currentEntity.wish_group
    }, () => {
      MsgService.successToastr('合并分组成功');
      this.closeWindow();
    });
  }
}
