import { observable, action } from 'mobx';
import {message} from 'antd';
import {WeaForm} from 'comsMobx';
import * as API from '../apis/trainrecord';
import * as Util from '../util/index';
import {WeaTableNew} from 'comsMobx';
import {i18n} from '../public/i18n';
const {TableStore} = WeaTableNew;

export class HrmTrainRecord {
  title = i18n.module.trainRecord;
  tabDatas = [
    {title:'培训记录',key:"1"},
    {title:'培训安排',key:"2"}
  ];
  @observable id = "";
  @observable form = new WeaForm();
  @observable table = new TableStore();
  @observable condition=[];
  @observable showSearchAd=false;
  @observable searchParamsAd={};
  @observable tabkey = '1';

  @action
  getData = (params = {}) => {
    this.getSearchCondition();
    this.getSearchList();
  }

  getSearchCondition = (params = {}) => {
    if (this.tabkey) params.tabkey = this.tabkey;
    API.getSearchCondition(params).then((data) => {
        this.condition = data.condition;
        this.form.initFormFields(data.condition);
    });
  }

  doSearch = () => {
    const formParams = this.form.getFormParams();
    formParams.search="search";
    this.getSearchList(formParams);
  }

  getSearchList = (params = {}) => {
    if (this.tabkey) params.tabkey = this.tabkey;
    params.resourceid = this.id;
    API.getSearchList(params).then((data) => {
      if(data.status == null || data.status == '1')
        this.table.getDatas(data.sessionkey,1);
      else
        message.error(data.message);
    });
  }

  changeTab = (key) => {
    this.tabkey = key;
    this.form = new WeaForm();
    this.setShowSearchAd(false);
    this.getData();
  }
  
  setShowSearchAd = (bool) => {
    this.showSearchAd = bool;
  }

  getFormParams = () => {
    return this.form.getFormParams();
  }
  @action changeId = (id) => {
    this.id = id;
  }
}