import React, { Component } from 'react'
import {
	observable,
	action,
    computed,
    toJS
} from 'mobx';
import { message , Button} from 'antd';
import * as Api from '../apis/avatarSetting'
import {WeaForm} from 'comsMobx';

import {
	WeaLocaleProvider
} from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

 export  class HrmAvatarSetting{
    @observable avatarStyleCondition = [];
    @observable avatarSettingForm = new WeaForm();
    @observable display='none';
    
    testParams = {
        fheadbackcolor: "#EF8BBA",
        fheadfontcolor: "#FFFFFF",
        mheadbackcolor: "#55B1F9",
        mheadfontcolor: "#FFFFFF",
    }

    // 获取头像样式设置表单
    @action getForm = () => {
        Api.getAvatarSettingForm().then(resp => {
            this.avatarStyleCondition = resp.condition;
            this.avatarSettingForm = new WeaForm();
            this.avatarSettingForm.initFormFields(toJS(this.avatarStyleCondition));
        })
    }

    // 保存操作
    @action doSave = () => {
        const formParams = this.avatarSettingForm.getFormParams();
        Api.saveForm(formParams).then(resp => {
            if(resp.status == '1'){
                message.success(getLabel(83551, '保存成功！'));   
                this.getDialogInfo().props.callback();
                this.getDialogInfo().close();
            }else{
                message.error(getLabel(84544, '保存失败！'));
            }
        })
    }

    // 上传图片时获取上传头像的头像ID
    @action onChange = (value,key) => {
        this.avatarSettingForm.updateFields({
            [key]:{value}
        });
    }

    // 颜色重置
    @action resetColor = (key) => {
        this.avatarSettingForm.updateFields({
            [key]: {value: this.testParams[key]}
        })
    }

    @action getDialogInfo = () => {
        return top.window.getParentDialog()
    }

    @action getBtns = () => {
        let  btns = [<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@9ef1wd`} type='primary' onClick={this.doSave}>{getLabel(30986, '保存')}</Button>,
                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@bsiggz`} onClick={() => this.getDialogInfo().close()}>{getLabel(32694, '取消')}</Button>]
        return btns;
    }
}
