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

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

  aspectArray;

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
  }

  initDefautEntity() {
    this.aspectArray = [];
    for (const s of this.ResponseArray) {
      this.aspectArray.push(s);
    }
  }

  ngOnInit() {
  }

  saveAspect() {
    MsgService.confirmAlert('确定要保存省编代码吗？', () => {
      AjaxService.request('wish/province/aspect/save.htm', {
        province_id: this.currentEntity.province_id,
        aspect_json: JSON.stringify(this.aspectArray)
      }, () => {
        MsgService.successAlert('省编代码已保存！');
        this.closeWindow();
      }, {RequestWithLoading: true});
    });
  }

  showOnly() {
    this.aspectArray = [];
    for (const s of this.ResponseArray) {
      if (s.province_aspect_id !== undefined && s.province_aspect_id.length > 0)
        this.aspectArray.push(s);
    }
  }
  showAll() {
    this.aspectArray = this.ResponseArray;
  }
}
