import {Component, OnInit} from '@angular/core';
import {FormBuilder, Validators} 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-conf-fee-detail',
  templateUrl: './conf-fee-detail.component.html',
  styleUrls: ['./conf-fee-detail.component.scss']
})
export class ConfFeeDetailComponent extends FrameDetailComponent implements OnInit {

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'fee_id': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(999999)])],
      'fee_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(128)])],
      'fee_range': [null, Validators.required],
      'fee_type': [null, Validators.required]
    });
  }

  ngOnInit() {
  }

  initDefautEntity() {
    if (this.detailMode === 'add') {
      this.currentEntity.fee_range = 'Private';
      this.currentEntity.fee_type = 'Aspect';
      this.currentEntity.province_flag = 'InActive';
    } else {
      // 把分转换为元
      // this.currentEntity.amount_1 = this.currentEntity.amount_1 / 100;
      // if (this.currentEntity.amount_2 !== undefined)
      //   this.currentEntity.amount_2 = this.currentEntity.amount_2 / 100;
      // if (this.currentEntity.amount_3 !== undefined)
      //   this.currentEntity.amount_3 = this.currentEntity.amount_3 / 100;
      if (this.currentEntity.out_amount_1 === undefined) {
        this.currentEntity.province_flag = 'InActive';
      } else {
        this.currentEntity.province_flag = 'Active';
      }

      // if (this.currentEntity.out_amount_1 !== undefined)
      //   this.currentEntity.out_amount_1 = this.currentEntity.out_amount_1 / 100;
      //
      // if (this.currentEntity.out_amount_2 !== undefined)
      //   this.currentEntity.out_amount_2 = this.currentEntity.out_amount_2 / 100;
      //
      // if (this.currentEntity.out_amount_3 !== undefined)
      //   this.currentEntity.out_amount_3 = this.currentEntity.out_amount_3 / 100;
    }
  }

  removeFee(batch) {
      AjaxService.requestEntity('conf/fee/batch/remove.htm', {fee_id: this.currentEntity.fee_id, batch_id: batch}, (entity) => {
        this.currentEntity = entity;
        MsgService.successToastr('操作完成！');
      });
  }

}
