import { observable, action } from 'mobx';
import {WeaForm} from 'comsMobx';
import * as API from '../apis/rewardsrecord';
import {message} from 'antd';
import {WeaTableNew} from 'comsMobx'
const {TableStore} = WeaTableNew;
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

export class HrmRewardsRecord {
  title = () => getLabel('16065',"奖惩考核");
  tabDatas = () => [
    {title:getLabel('32740',"我的成绩"),key:"1"},
    {title:getLabel('15682',"奖惩情况"),key:"2"}
  ];
  
  qname = ''
  @observable form = new WeaForm();
  @observable table = new TableStore();
  @observable tabkey = '1';
  @observable tableinfo = [];
  @observable isshowrecord = false;

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

  doSearch = (params = {}) => {
    params.search="search";
    params.qname = this.qname;
    this.getSearchList(params);
  }

  getSearchList = (params = {}) => {
    if (this.tabkey) params.tabkey = this.tabkey;
    if(this.hrmId){
      params.resourceid=this.hrmId;
    }

    if(this.tabkey=='1'){
      API.getRewardsRecord1Tables(params).then((data)=>{
        if(data.api_status == null || data.api_status){
          this.tableinfo = data.tables;
          this.isshowrecord = data.isShowRecord;
        }else
          message.error(data.message);
      })
    }
    API.getSearchList(params).then((data) => {
      if(data.api_status == null || data.api_status){
        this.table.getDatas(data.sessionkey);
      }else{
        message.error(data.message);
      }
    });
  }

  setHrmId =(hrmId)=>{
    this.hrmId = hrmId;
  }


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

  getFormParams() {
    return this.form.getFormParams();
  }
}