import { observable, action } from 'mobx';
import { WeaForm } from 'comsMobx';
import { message, Button } from 'antd';
import { WeaTools, WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
import * as mobx from 'mobx';
import cloneDeep from 'lodash/cloneDeep';

const toJS = mobx.toJS;

export default class WeaCloudstoreSetting {
  @observable condition = [];
  @observable form = new WeaForm();

  @action
  getButtons() {
    let btns = [];
    btns.push(<Button type="primary" onClick={() => this.onSaveSetting()}>{getLabel(30986, '保存')}</Button>);
    return btns;
  }
  @action
  getRightMenu() {
    let btns = [];
    btns.push({
      icon: <i className="icon-coms-Preservation" />,
      content: getLabel(30986, '保存'),
    });
    return btns;
  }
  @action
  onRightMenuClick(key) {
    switch (key) {
      case '0':
        this.onSaveSetting();
        break;
    }
  }
  @action
  getSetting() {
    WeaTools.callApi('/api/systeminfo/hrmusersetting/getForm', 'GET', {}).then((result) => {
       this.condition = result.conditions;
       this.form.initFormFields(result.conditions);
    });
  }
  @action
  onSaveSetting() {
    WeaTools.callApi('/api/systeminfo/hrmusersetting/update', 'POST', this.form.getFormParams())
    .then((result) => {
      if (result.status == '2') {
          message.error(getLabel(84544, '保存失败！'));
      } else {
          message.success(getLabel(83551, '保存成功！'));
      }
    });
  }
}
