import {Component, OnInit, ViewChild} from '@angular/core';
import {WorkService} from '../work.service';
import {NzMessageService} from 'ng-zorro-antd';
import {ParamsTypeComponent} from '../modal/params-type/params-type.component';
import {CommonService} from '../../shared/common/common.service';

@Component({
  selector: 'smart-pararms',
  templateUrl: './pararms.component.html',
  styles: [
      `
          :host ::ng-deep .content-params .ant-row,
          .handle{
              margin: 10px 0;
          }
      `
  ]
})
export class PararmsComponent implements OnInit {
  @ViewChild('smartParamstype') smartParamstype:ParamsTypeComponent;

    eventList;
    planList;
    value;
    isDisabled = true;
  constructor(private workSer:WorkService,private message:NzMessageService,
              private commomSer:CommonService) { }

  ngOnInit() {
    this.getList();
  }

  //获取分类列表
  getList(){
    const data = {
        type:0
    };
    this.workSer.findParamsByType(data).subscribe(
        (res)=>{
          this.eventList = res.data;
        }
    );
      data.type = 1;
      this.workSer.findParamsByType(data).subscribe(
          (res)=>{
              this.planList = res.data;
          }
      )
  }

  //0=事件分类, 1=计划分类
  showAddModal(title,type){
    this.smartParamstype.showAddModal(title,type);
  }

    showEditModal(title,type,item){
        this.smartParamstype.showEditModal(title,type,item.id,item);
    }

    //删除分类
  deleteItem(item){
    this.commomSer.deleteThing("确定删除该分类?",()=>{
      const data = {
          ids:[]
      };
      data.ids.push(item.id);
      this.workSer.deleteTypeByparams(data).subscribe(
          (res)=>{
            if(res.errCode == 10000){
              this.message.success("删除成功");
              this.getList()
            }else{
              this.message.error(res.errMsg);
            }
          }
      )
    })
  }

    editType(){
      this.isDisabled = false;
    }

    saveType(){
      this.isDisabled = true;
    }

}
