import React,{Component} from 'react'

import BusinessRouter from '../Business'
import { inject, observer } from 'mobx-react'
import {Spin} from 'antd'
import Api from '@/service/api'


const host = "/data/dsp/"

@inject('i18n')
@observer
export default class Display extends Component{

    state={loading:-1}
    constructor(props)
    {
        super(props)
        window.DISPLAY_MODE= true
    }
    async componentWillMount(){
        let {trninr,trnnam} =  this.props.match.params
        //加载模型

        console.log({trninr,trnnam})
        let folder = trninr.substring(0,trninr.length - 4)
        const rtnmsg = await Api.get(host + folder+"/" + trninr +".dsp",{});
        console.log(rtnmsg)
        if(rtnmsg && rtnmsg.model && rtnmsg.changes )
        {
            this.setState({loading:0,...rtnmsg})
        }
        else
        {
            this.setState({loading:1})
        }
    }

    render(){
        const prefix = this.props.i18n.prefix+"display/"

        return  <React.Fragment>
            {
            this.state.loading ==-1? 
            <div style={{textAlign:'center'}}>
            <Spin size="large" style={{marginTop:'8em'}} />
            </div>
            :
            this.state.loading == 0? 
            <BusinessRouter prefix={prefix} model = {this.state.model} changes={this.state.changes}/>
            :
            <p>快照加载失败</p>
            }
        </React.Fragment>
    }
}