import { action, observable } from 'mobx'
import Api from '../service/api'
import Storage from '../utils/Storage'

class UserContext{
    @observable
    userId = null
    @observable
    menu = null
    @observable
    token = null
	
	@observable
	bchnam= "..."
	
	@observable
    usrnam= "..."
    
    @observable
    bchsta_loginsta = "未知"    //机构登陆状态

    @observable
    bchsta_online="未知"        //线上清算开关

    @observable
    syssta_sysdat="未知"        //当前系统日期

    @observable
    syssta_syssta="未知"        //当前系统状态

    async login(args)
    {
       Storage.setUser(args.username)
       let rtnmsg = await Api.post('login',{data:args})
       if(rtnmsg.retcod == SUCCESS)
       {
            const {data} = rtnmsg
            this.menu = data.menu
            this.token = data.token
            this.userId = args.username
            Storage.setUser(this.userId)
            Storage.setToken(this.token)
            Storage.setMenu(this.menu)
       }     
       return rtnmsg
    }
    logout()
    {
        this.menu = null
        this.token = null
        this.userId = null
        Storage.clearItems()

    }



}

export default new UserContext()