import { observable, action, toJS } from 'mobx';
import {message} from 'antd';
import isFunction from 'lodash/isFunction';
import { WeaForm } from 'comsMobx';
import {WeaLocaleProvider, WeaTools} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import {
	i18n
} from '../../public/i18n';

export default class OutSignAppSetting {

    @observable photo = '';//拍照
    @observable remark = ''; // 备注
    @observable nearly = ''; //附近位置
    @observable visible = false;
    @observable loading = false;
    onCancle = null;
    scope = '';

    @action init = (scope,onCancle) => {
        this.scope = scope;
        this.onCancle = onCancle;
        this.visible = true;
        this.loading = true;
        WeaTools.callApi('/api/hrm/kq/attendanceButton/getOutSignSetting','GET',{}).then(resp => {
            this.loading = false;
            if(resp.status == '1'){
                this.photo = resp.photo;
                this.remark = resp.remark;
                this.nearly = resp.nearly;
            }
        })
    }

    @action
    cancel = () => {
      this.visible = false;
      isFunction(this.onCancle) && this.onCancle();
    }

    @action
    onChange = (value, c) => {
            if(c == 'remark'){
                this.remark = value;
            }else if(c == 'photo'){
                this.photo = value;
            }else {
                this.nearly = value;
            }
    }

    @action
    doSave = () => {
        const params ={
            photo: this.photo,
            remark: this.remark,
            nearly: this.nearly
        } 
        WeaTools.callApi('/api/hrm/kq/attendanceButton/saveOutSignSetting','POST',params).then(resp => {
            if(resp.status == '1'){
                message.success(i18n.message.saveSuccess());
                this.cancel();
            }else{
                message.error(i18n.message.saveFailed());
                this.cancel();
            }
        })
    }

    }