import {
  registerRoutes,
} from 'mutants-microfx';
import {User,tApi,registerLogoutMiddleWare,serverLog,UIConfirm} from './src';
import _filter from 'lodash/filter';
import { Modal} from 'antd-mobile';
const { alert } = Modal;
import * as React from 'react';
registerRoutes([{
  path: '/',
  component: () => {
    const login = async ()=>{
      registerLogoutMiddleWare('loginOut',()=>{
        console.log('注销后...');
      });
      UIConfirm.registerImpl((message:string,postEvent:()=>{})=>{
        alert('温馨提示',message,[
          { text: '否', onPress: () => console.log('点击否') },
          { text: '是', onPress: () => 
            {
              console.log('点击是')
              postEvent && postEvent();
            }
          },,
        ]);
      });
      //用户认证 获取企业列表
      const user:User = await User.authentication('13161351900','111111');
      console.log('user=========',user);

      //过滤企业
      let tcOrgs:Array<any> = _filter(user.orgList,org=>org.orgFullName=='线上新建标准版0415');
      if(tcOrgs.length > 0){
       const tcOrgId:string = tcOrgs[0].orgId;
       //初始化通道
       await user.initChannel(tcOrgId);
       //登录T+
       await user.loginTplus({});
       console.log('user.logined======',user);
       const response = await tApi({},'chanjet.MB.TxBusCommon.GetSysInfoForGZQ',false,false);
       console.log('GetSysInfoForGZQ.response======',response);
       //用户注销
       User.logout();
       try{
        const response1 = await tApi({},'chanjet.MB.TxBusCommon.GetSysInfoForGZQ',false,false);
        console.log('logout.GetSysInfoForGZQ.response======',response1);
       }catch(e){
        serverLog('workreport',{eventId:'api_error',...e});
        // UIConfirm.showConfirm(e.message,()=>{
        //   //将API错误日志进行上报
          
        //   console.log('上报错误日志=========',e);
        // });
       }
      }
    };
    login();
    return (
       <div>hello world!!</div>
    )
  }
}])

