import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {SelectPersonComponent} from '../../../modal/select-person/select-person.component';
import {WorkService} from '../../work.service';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
  selector: 'smart-transfor',
  templateUrl: './transfor.component.html',
  styles: []
})
export class TransforComponent implements OnInit {
  @ViewChild('smartSelectPerson') smartSelectPerson:SelectPersonComponent;
  @Output() done = new EventEmitter<any>();

    title;
    transforId;
    isVisiable;
    transforList;
  constructor(private workSer:WorkService,private message:NzMessageService) { }

  ngOnInit() {
  }

    //事件转派--start
    showTransforModal(title,id){
        this.transforId = id;
        this.title = title;
        this.isVisiable = true;
    }

    //选择处理人弹窗
    selectPerson(){
        this.smartSelectPerson.showModal("选择转派人",null);
    }

    //选择转派人done
    getUser(e){
        const arr = [];
        e.forEach(res => {
            const data = {
                username: res.name,
                userId: res.id
            };
            arr.push(data);
        });
        this.transforList = arr;
    }

    //取消
    handleCancel(){
        this.isVisiable = false;
        this.transforList = [];
    }

    deletePerson(i){
        this.transforList.splice(i,1);
    }

    //确定
    handleOk(){
        const data = {
            id:this.transforId,
            operators:this.transforList
        };
        this.workSer.transfer(data).subscribe(
            (res)=>{
                if(res.errCode == 10000){
                    this.message.success("事件转派成功");
                    this.isVisiable = false;
                    this.transforList = [];
                   this.done.emit();
                }else{
                    this.message.error(res.errMsg);
                }
            }
        )
    }

}
