import {
    observable,
    action
} from 'mobx';
import * as mobx from 'mobx';
import * as Api from '../apis/personnelResume';
import {
    WeaForm
} from 'comsMobx';
import {
    WeaTableNew
} from 'comsMobx';
import {
    Modal,
    message,
} from 'antd'
import {
    i18n
} from '../public/i18n';

const toJS = mobx.toJS;
const {
    TableStore
} = WeaTableNew;


export class PersonnelResumeStore {

    @observable topMenu = []
    @observable rightMenu = [];
    @observable condition = [];
    @observable form = new WeaForm();
    @observable loading = true;
    @observable resourceId = '';
    @observable resumeList = {};
    @observable percent = 0;
    @observable visible = false;
    @observable show = false;
    @observable params = {};
    @observable condition = [];
    @observable dialogLoading = true;


    @observable defaultShowLeft = true;
    @observable companysId = 1
    @observable hasRight = '';



    @action("获取操作按钮") getHasRight() {
        let _this = this;
        Api.getHasRight().then(res => {
            if (res.code === 200) {
                this.setHasRight(res.data.hasRight);
                res.data.rightMenu && this.setRightMenu(res.data.rightMenu);
                res.data.topMenu && this.setTopMenu(res.data.topMenu);
                setTimeout(function() {
                    res.data.hasRight && _this.getPersonnelResume();
                },1000)
            } else {
                message.warning(res.msg);
            }
        }, error => {
            message.warning(error.msg);
        })
    }

    @action("获取人员简历") getPersonnelResume() {
        this.resumeList = {};
        this.percent = 0;
        this.visible = false;
        this.interval = setInterval(() => this.getImportProcess(), 200);
        let params = {
            id:this.resourceId
        }
        Api.getPersonnelResume(params).then(res => {
            if (res.code === 200) {
                this.percent = 100;
                this.visible = true;
                this.resumeList = res.data;
            } else {
                clearInterval(this.interval);
                message.warning(`${i18n.message.checkResume()}`);
            }
        }, error => {
            message.warning(error.msg);
        })

    }

    @action("头部加载进度条") getImportProcess() {
        if(this.visible) {
            clearInterval(this.interval);
          }else {
            let max = 95;
            let min = this.percent;
            if(this.percent < max) {
              this.percent = Math.floor(Math.random() * (max - min)) + min;
            }
          }
    }

    @action("人员筛选表单") getSearchCondition() {
        this.dialogLoading = true;
        Api.getAdvanceSearchCondition().then(res => {
            if (res.code === 200) {
                this.dialogLoading = false;
                res.data.conditions && this.setCondition(res.data.conditions);
                res.data.conditions && this.form.initFormFields(res.data.conditions);
            } else {
                message.warning(res.msg);
            }
        }, error => {
            message.warning(error.msg);
        })
    }

    @action("合并导出和全部导出") downloadPerResume(type) {
        Api.downloadPerResume(type);
    }


    setCondition(condition) {
        this.condition = condition;
    }

    setTopMenu(topMenu) {
        this.topMenu = topMenu;
    }

    setRightMenu(rightMenu) {
        this.rightMenu = rightMenu;
    }

    setHasRight(bool) {
        this.hasRight = bool;
    }

}