import React from 'react';
import 'antd-mobile/dist/antd-mobile.css';
import { ListView, Checkbox,List, Icon, Button, WhiteSpace, WingBlank, Flex, Radio,Accordion} from 'antd-mobile';
import { Http } from '../../Utils/help';
import './less/list.less';
import { Z_FIXED } from 'zlib';

const Item = List.Item;
const Brief = Item.Brief;
const typelist=[{'id':4,'name':'待确认'},{'id':1,'name':'处理中'},{'id':2,'name':'处理完成'}]
export default class repairs extends React.Component {
    constructor(props) {
        super(props);
        this.NUM_SECTIONS = 1;
        this.NUM_ROWS_PER_SECTION = 50;
        // const { func } = this.props.location.state?{func:{}};
        this.genData = this.genData.bind(this);
        this.onEndReached = this.onEndReached.bind(this);
        this.getNowFormatDate = this.getNowFormatDate.bind(this)
        this.onRepairstypeChange=this.onRepairstypeChange.bind(this)
        this.getNowFormatDate = this.getNowFormatDate.bind(this)   
        this.diffTime=this.diffTime.bind(this)
        this.formatDate=this.formatDate.bind(this)
        this.issame=this.issame.bind(this)
        this.getBillKey=this.getBillKey.bind(this)
        this.isEmpty = this.isEmpty.bind(this)
        this.onSuccess = this.onSuccess.bind(this)
        const getSectionData = (dataBlob, sectionID) => dataBlob[sectionID];
        const getRowData = (dataBlob, sectionID, rowID) => dataBlob[rowID];
        const repairstypelist = [{"id":1,"name":"已接单"}, {"id":0,"name":"待接单"}, {"id":2,"name":"处理完成"}]
        const dataSource = new ListView.DataSource({
            getRowData,
            getSectionHeaderData: getSectionData,
            rowHasChanged: (row1, row2) => row1 !== row2,
            sectionHeaderHasChanged: (s1, s2) => s1 !== s2,
        });
        // localStorage.removeItem("newData")
        // localStorage.removeItem("datalength")
        this.state = {
            typelist:typelist,
            dataSource: dataSource,
            // func: func,
            nodata: true,
            data: {},
            page:1,
            pageSize:10,
            height: document.documentElement.clientHeight * 1/2,
            radioval: 1,//存储点击时按钮的id
            my:false,
           // userid:localStorage['loginemployee'],
            repairstypelist:repairstypelist,
            billkey:1,//1报修单2维修单3保养单4点检单
            repstatus: new Map(),
            impactdegreeid: new Map(),
            login:{},
            //条件保存
            ifin:false,//是否已保存过一次
            i:{},//若有，保存的对象，取出进行条件刷新
        };
    }
    //获取billkey
    getBillKey=(key)=>{
        //保存条件S
        console.log(this.state.ifin)
        if(this.state.ifin){
            this.state.i['value']['billkey']=key
            this.state.i['value']['buttonkey']=this.state.radioval
            this.state.i['value']['loginid']=this.state.login.Employeeid
        }
        if(!this.state.ifin){
            window.conditionarr.push({key:'myallbills',value:{billkey:key,buttonkey:this.state.radioval,loginid:this.state.login.Employeeid}})
            window.conditionarr.map((data=>{
            if(data['key']==='myallbills'){
                this.state.ifin=true
                this.state.i=data
                this.setState({ifin:true,i:data})
                return
            }
            }))
        }
        //保存条件E
        console.log(key)
        this.state.billkey=key
        console.log(this.state.radioval)
        console.log(this.state.repstatus.get('1'))
        if(this.state.billkey==='1'){
            if(this.state.radioval===1)
                this.dataAjax = Http.getJSON2("repairs/getanywhere", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})    
            if(this.state.radioval===2)
                this.dataAjax = Http.getJSON2("repairs/gethalfyear", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})    
            if(this.state.radioval===4)
                this.dataAjax = Http.getJSON2("repairs", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})   //有限定登录人
                //this.dataAjax = Http.getJSON2("repairs", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"page":1, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})    //放宽条件

            }
        else if(this.state.billkey==='2'){
            if(this.state.radioval===1)
                this.dataAjax = Http.getJSON2("maintain", {"stacon":this.state.radioval===1?2:1, "userid": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===2)
                this.dataAjax = Http.getJSON2("maintain/gethalfyear", {"stacon":this.state.radioval===1?2:1, "userid": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===4)
                this.dataAjax = Http.getJSON2("maintain", {"stacon":this.state.radioval+1, "userid": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            }
        else if(this.state.billkey==='3'){
            if(this.state.radioval===1)
                this.dataAjax = Http.getJSON2("maintenance", {"isdone":this.state.radioval===1?0:1,"maintenancer": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===2)
                this.dataAjax = Http.getJSON2("maintenance/gethalfyear", {"isdone":this.state.radioval===1?0:1,"maintenancer": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===4)
                this.dataAjax = Http.getJSON2("maintenance", {"isdone":this.state.radioval,"maintenancer": 0,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            } 
        else if(this.state.billkey==='4'){
            if(this.state.radioval===1)
                this.dataAjax = Http.getJSON2("machealthchecklog", {"isdone":this.state.radioval===1?0:1,"checker": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===2)
                this.dataAjax = Http.getJSON2("machealthchecklog/gethalfyear", {"isdone":this.state.radioval===1?0:1,"checker": this.state.login.Employeeid,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===4)
                this.dataAjax = Http.getJSON2("machealthchecklog", {"isdone":this.state.radioval,"checker":0,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            }         
        this.dataAjax.done((data) => {
            console.log(data.data)
                try {
                    this.genData(data.data);
                    console.log(data.data, this.state)
                    this.setState({
                    dataSource: this.state.dataSource.cloneWithRowsAndSections(this.dataBlobs, this.sectionIDs, this.rowIDs),
                    hight:document.documentElement.clientHeight * 1/2,
                    data:data.data,
                    nodata:!data||data.length==0,
                    });
                    console.log("this.state", this.state)
                } catch (err) {
                    console.error(err.message);
                    console.error(err.stack);
                    }
                });
        
    }
    //获取当前时间
    getNowFormatDate = () =>{
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1<10? "0"+(date.getMonth() + 1):date.getMonth() + 1;
        var strDate = date.getDate()<10? "0" + date.getDate():date.getDate();
        var currentdate = date.getFullYear() + seperator1  + month  + seperator1  + strDate
                + " "  + date.getHours()  + seperator2  + date.getMinutes()
                + seperator2 + date.getSeconds();
        return currentdate;
    }
    //翻页
    onEndReached(event){
        // load new data
        // hasMore: from backend data, indicates whether it is the last page, here is false
        if (this.state.isLoading && !this.state.hasMore) {
          return;
        }
        console.log('reach end', event);
        //this.setState({ isLoading: true });
        let that = this;
        if(this.state.billkey==='1'){
            if(this.state.radioval===1)
                this.dataAjax = Http.getJSON2("repairs/getanywhere", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.login.Employeeid ,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})
            if(this.state.radioval===2)
                this.dataAjax = Http.getJSON2("repairs/gethalfyear", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.login.Employeeid ,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})
            if(this.state.radioval===4)
                this.dataAjax = Http.getJSON2("repairs", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.login.Employeeid ,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})
                //this.dataAjax = Http.getJSON2("repairs", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})
            }
        else if(this.state.billkey==='2'){
            if(this.state.radioval===2)
                this.dataAjax = Http.getJSON2("maintain/gethalfyear", {"stacon":this.state.radioval===1?2:1,"userid":this.state.login.Employeeid,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===1)
                this.dataAjax = Http.getJSON2("maintain", {"stacon":this.state.radioval===1?2:1,"userid": this.state.login.Employeeid,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===4)
                this.dataAjax = Http.getJSON2("maintain", {"stacon":this.state.radioval+1,"userid": this.state.login.Employeeid,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            }
        else if(this.state.billkey==='3'){
            if(this.state.radioval===1)
                this.dataAjax = Http.getJSON2("maintenance", {"isdone":this.state.radioval===1?0:1,"maintenancer": this.state.login.Employeeid,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===2)
                this.dataAjax = Http.getJSON2("maintenance/gethalfyear", {"isdone":this.state.radioval===1?0:1,"maintenancer": this.state.login.Employeeid,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            if(this.state.radioval===4)
                this.dataAjax = Http.getJSON2("maintenance", {"isdone":this.state.radioval,"maintenancer": 0,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            }
        else if(this.state.billkey==='4'){
                if(this.state.radioval===1)
                    this.dataAjax = Http.getJSON2("machealthchecklog", {"isdone":this.state.radioval===1?0:1,"checker": this.state.login.Employeeid,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                if(this.state.radioval===2)
                    this.dataAjax = Http.getJSON2("machealthchecklog/gethalfyear", {"isdone":this.state.radioval===1?0:1,"checker": this.state.login.Employeeid,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                if(this.state.radioval===4)
                    this.dataAjax = Http.getJSON2("machealthchecklog", {"isdone":this.state.radioval,"checker": 0,"page":++this.state.page, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
            }
        this.dataAjax.done((data) => {
                console.log("onEndReached:", data.data)
                if(data.data && data.data.length>0){
                    try {
                        //var c=data.data.concat(that.state.data);
                        var c = that.state.data.concat(data.data)
                        that.genData(c);
                        console.log(data, that.state)
                        that.setState({
                        dataSource: that.state.dataSource.cloneWithRowsAndSections(that.dataBlobs, that.sectionIDs, that.rowIDs),
                        data:c,
                        page:data.Page,
                        nodata:!data||data.length==0,
                        isLoading:false,
                        });
                    } catch (err) {
                        console.error(err.message);
                        console.error(err.stack);
                    }
                }
            });
      }
      formatDate = (date_str) =>{//时间格式处理
        if(this.isEmpty(date_str)){
            return date_str
        }
        var date = new Date(Date.parse(date_str.replace(/-/g, "/")));
        var seperator1 = "-";
        var seperator2 = ":";
        var year=date.getFullYear();
        var month = date.getMonth() + 1<10? "0"+(date.getMonth() + 1):date.getMonth() + 1;
        var strDate = date.getDate()<10? "0" + date.getDate():date.getDate();
        var hour=  date.getHours() <10?"0"+ date.getHours() : date.getHours() 
        var minute=date.getMinutes() <10?"0"+date.getMinutes() :date.getMinutes() 
        // var currentdate = month  + seperator1  + strDate
        //         + " "  + hour  + seperator2  + minute     
        var currentdate = year+seperator1+month  + seperator1  + strDate    
        return currentdate;
    }
    componentWillMount(){
        if(typeof(window.conditionarr)=="undefined"){window.conditionarr=[]}//保存条件
        console.log("条件数组",window.conditionarr)
        //判断是否存过一次S
        window.conditionarr.map((data=>{
            if(data['key']==='myallbills'){
                this.state.ifin=true
                this.state.i=data
                this.setState({
                    billkey:this.state.i['value']['billkey'],
                    radioval:this.state.i['value']['buttonkey']

                })
                return
            }
        }))
        //判断是否存过一次E
        console.log('rowData: ', this.state.rowData)
        Http.postJSON2("employee/getlogin", {},data=>{
            console.log(data)
            this.setState({login:data[0]})
        }).done(data=>{
            console.log(this.state)
        })
        console.log("componentWillMount")
        //console.log(localStorage['loginid'])
       // console.log(localStorage['usercode'])
        //拿到影响程度类别数据
        Http.getJSON2("basetype/items", { parentid:'2019130036900000111'}, (data) => {
            const map = new Map()
            data.data.map((item) => { map.set(item.id, item.name) })
            this.setState({ impactdegreeid: map })
        })
        //拿到报修状态类别数据repstatus
        Http.getJSON2("basetype/items", { parentid:'2019130037600000511'}, (data) => {
            const map = new Map()
            data.data.map((item) => { map.set(item.code, item.id)})
            this.setState({ repstatus: map },()=>{
                        //按照存储的条件请求S
        window.conditionarr.map((data=>{
            // keys.push()
            if(data['key']==='myallbills'){
                this.state.ifin=true
                this.state.i=data
                this.setState({ifin:true,i:data},()=>{
                    if(this.state.ifin){
                    this.setState({page:1}, () =>{
                        if(this.state.billkey==='1'){
                            if(this.state.radioval===1)
                                this.dataAjax = Http.getJSON2("repairs/getanywhere", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})    
                            if(this.state.radioval===2)
                                this.dataAjax = Http.getJSON2("repairs/gethalfyear", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})    
                            if(this.state.radioval===4)
                                this.dataAjax = Http.getJSON2("repairs", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})   //有限定登录人
                                //this.dataAjax = Http.getJSON2("repairs", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"page":1, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'})    //放宽条件               
                            }
                        else if(this.state.billkey==='2'){
                            if(this.state.radioval===1)
                                this.dataAjax = Http.getJSON2("maintain", {"stacon":this.state.radioval===1?2:1, "userid": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                            if(this.state.radioval===2)
                                this.dataAjax = Http.getJSON2("maintain/gethalfyear", {"stacon":this.state.radioval===1?2:1, "userid": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                            if(this.state.radioval===4)
                                this.dataAjax = Http.getJSON2("maintain", {"stacon":this.state.radioval+1, "userid": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                            }
                        else if(this.state.billkey==='3'){
                            if(this.state.radioval===1)
                                this.dataAjax = Http.getJSON2("maintenance", {"isdone":this.state.radioval===1?0:1,"maintenancer": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                            if(this.state.radioval===2)
                                this.dataAjax = Http.getJSON2("maintenance/gethalfyear", {"isdone":this.state.radioval===1?0:1,"maintenancer": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                            if(this.state.radioval===4)
                                this.dataAjax = Http.getJSON2("maintenance", {"isdone":this.state.radioval,"maintenancer": 0,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                            } 
                        else if(this.state.billkey==='4'){
                            if(this.state.radioval===1)
                                this.dataAjax = Http.getJSON2("machealthchecklog", {"isdone":this.state.radioval===1?0:1,"checker": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                            if(this.state.radioval===2)
                                this.dataAjax = Http.getJSON2("machealthchecklog/gethalfyear", {"isdone":this.state.radioval===1?0:1,"checker": this.state.i['value']['loginid'],"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                            if(this.state.radioval===4)
                                this.dataAjax = Http.getJSON2("machealthchecklog", {"isdone":this.state.radioval,"checker": 0,"page":1, "pageSize":this.state.pageSize,  "orderby":'createtime desc'})
                            } 
                        this.dataAjax.done((data) => {
                            console.log(data.data)
                                try {
                                    this.genData(data.data);
                                    console.log(data.data, this.state)
                                    this.setState({
                                    dataSource: this.state.dataSource.cloneWithRowsAndSections(this.dataBlobs, this.sectionIDs, this.rowIDs),
                                    hight:document.documentElement.clientHeight * 1/2,
                                    data:data.data,
                                    nodata:!data||data.length==0,
                                    });
                                    console.log("this.state", this.state)
                                } catch (err) {
                                    console.error(err.message);
                                    console.error(err.stack);
                                    }
                                });
                    }) 
                }               
                })
                
            }
            }))
         //按照存储的条件请求E
            })
        })

    }
    
    
    componentDidUpdate() {
    }
    componentDidMount() {
        console.log("componentDidMount")
        const creator = localStorage['loginid']
        this.setState({creator})
        // this.dataAjax = Http.getJSON2("repairs", {"repstatus":this.state.radioval,"creator": this.state.creator,"orderby":'impactdegreeid asc,createtime desc'})
        // .done((data) => {
        //     console.log(data.data)
        //     try {
        //         this.genData(data.data);
        //         console.log(data.data, this.state)
        //         this.setState({
        //         dataSource: this.state.dataSource.cloneWithRowsAndSections(this.dataBlobs, this.sectionIDs, this.rowIDs),
        //         data:data.data,
        //         nodata:!data||data.length==0,
        //         });
        //         console.log("this.state", this.state)
        //     } catch (err) {
        //         console.error(err.message);
        //         console.error(err.stack);
        //     }
        // });
    }
    isEmpty = (obj) =>{
        if (typeof obj === 'undefined' || obj == null || obj === '') { 
            return true; 
            } else {
             return false; 
            } 
        }
    //计算两个日期之间的时间间隔，以小时为单位
    diffTime=(createtime)=>{
        createtime= new Date(createtime);
        var endDate = new Date(this.getNowFormatDate());
        var diff=endDate.getTime() - createtime.getTime();//时间差的毫秒数 
        var days=Math.floor(diff/(24*3600*1000));          //计算出相差天数 
        //计算出小时数 
        var leave1=diff%(24*3600*1000);    //计算天数后剩余的毫秒数 
        var hours=Math.floor(leave1/(3600*1000)); 
        var hours_count=days*24+hours;//
        var returnStr=hours_count+"小时"
        return returnStr; 
    }  
    


    //头部按钮处理中和处理完成两种状态切换时绑定的事件
    onRepairstypeChange=(id)=>{
        //保存条件S
        console.log(this.state.ifin)
        if(this.state.ifin){
            this.state.i['value']['buttonkey']=id
            this.state.i['value']['loginid']=this.state.login.Employeeid
        }
        if(!this.state.ifin){
            window.conditionarr.push({key:'myallbills',value:{buttonkey:id,logid:this.state.login.Employeeid}})
            //保存条件S
            window.conditionarr.map((data=>{
            if(data['key']==='myallbills'){
                this.state.ifin=true
                this.state.i=data
                this.setState({ifin:true,i:data})
                return
            }
            }))
        }
        //保存条件E
        this.setState({radioval:id})
        if(this.state.billkey==='1'){
            console.log(this.state.repstatus)
            console.log(this.state.repstatus.get(this.state.radioval))
            if(id === 1)
                this.setState({radioval:id, page:1},()=>{                   
                    this.dataAjax= Http.getJSON2("repairs/getanywhere", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'}, (data)=>this.onSuccess(data)) 
                } )
            if(id===2)
                this.setState({radioval:id, page:1},()=>{
                    this.dataAjax = Http.getJSON2("repairs/gethalfyear", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'}, (data)=>this.onSuccess(data)) 
            } )
            if(id === 4)
            this.setState({radioval:id, page:1},()=>{                   
                this.dataAjax= Http.getJSON2("repairs", {"repstatus":this.state.repstatus.get(this.state.radioval.toString()),"repairser": this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize,  "orderby":'impactdegreeid asc,createtime desc'}, (data)=>this.onSuccess(data)) 
            } )
          }   
        else if(this.state.billkey==='2'){
            if(id === 1)
                this.setState({radioval:id, page:1},()=>{
                    this.dataAjax = Http.getJSON2("maintain", {"stacon":this.state.radioval===1?2:1, "userid":  this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize, "orderby":'createtime desc'},(data)=>this.onSuccess(data))
                })
            if(id ===2)
                this.setState({radioval:id, page:1},()=>{
                    this.dataAjax = Http.getJSON2("maintain/gethalfyear", {"stacon":this.state.radioval===1?2:1, "userid":this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize, "orderby":'createtime desc'},(data)=>this.onSuccess(data))
                })
            if(id ===4)
                this.setState({radioval:id, page:1},()=>{
                    this.dataAjax = Http.getJSON2("maintain", {"stacon":this.state.radioval+1, "userid":  this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize, "orderby":'createtime desc'},(data)=>this.onSuccess(data))
            })   
        }
        else if(this.state.billkey==='3'){
            if(id === 1)
                this.setState({radioval:id, page:1},()=>{
                    this.dataAjax = Http.getJSON2("maintenance", {"isdone":this.state.radioval===1?0:1, "maintenancer": this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize, "orderby":'createtime desc'},(data)=>this.onSuccess(data))
                })
            if(id===2)
            this.setState({radioval:id, page:1},()=>{
                this.dataAjax = Http.getJSON2("maintenance/gethalfyear", {"isdone":this.state.radioval===1?0:1, "maintenancer": this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize, "orderby":'createtime desc'},(data)=>this.onSuccess(data))
            })
            if(id===4)
            this.setState({radioval:id, page:1},()=>{
                this.dataAjax = Http.getJSON2("maintenance", {"isdone":this.state.radioval, "maintenancer": 0,"page":this.state.page, "pageSize":this.state.pageSize, "orderby":'createtime desc'},(data)=>this.onSuccess(data))
            })
        }
        else if(this.state.billkey==='4'){
            if(id === 1)
                this.setState({radioval:id, page:1},()=>{
                    this.dataAjax = Http.getJSON2("machealthchecklog", {"isdone":this.state.radioval===1?0:1, "checker": this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize, "orderby":'createtime desc'},(data)=>this.onSuccess(data))
                })
            if(id===2)
            this.setState({radioval:id, page:1},()=>{
                this.dataAjax = Http.getJSON2("machealthchecklog/gethalfyear", {"isdone":this.state.radioval===1?0:1, "checker": this.state.login.Employeeid,"page":this.state.page, "pageSize":this.state.pageSize, "orderby":'createtime desc'},(data)=>this.onSuccess(data))
            })
            if(id===4)
            this.setState({radioval:id, page:1},()=>{
                this.dataAjax = Http.getJSON2("machealthchecklog", {"isdone":this.state.radioval, "checker": 0,"page":this.state.page, "pageSize":this.state.pageSize, "orderby":'createtime desc'},(data)=>this.onSuccess(data))
            })
        }

    }
    onSuccess = (data) =>{
        this.genData(data.data);
        console.log(data.data, this.state)
        this.setState({
        dataSource: this.state.dataSource.cloneWithRowsAndSections(this.dataBlobs, this.sectionIDs, this.rowIDs),
        data:data.data,
        nodata:!data||data.length==0,
        }, this.lv.scrollTo(0,0));
        console.log("this.state", this.state)           
    }
    issame=(id)=>{
        var type
        if(this.state.radioval === id)
            type='primary'
        else
            type='dafault'
        return  type
            

    }
    getNowFormatDate = () =>{//获取当前时间
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1<10? "0"+(date.getMonth() + 1):date.getMonth() + 1;
        var strDate = date.getDate()<10? "0" + date.getDate():date.getDate();
        var currentdate = date.getFullYear() + seperator1  + month  + seperator1  + strDate
                + " "  + date.getHours()  + seperator2  + date.getMinutes()
                + seperator2 + date.getSeconds();
        return currentdate;
    }

    genData = (datas) => {
        this.dataBlobs = {};
        this.sectionIDs = [];
        this.rowIDs = [];
        if (!datas)
            return;

        let pIndex = 0;
        this.NUM_ROWS_PER_SECTION = datas.length;
        for (let i = 0; i < this.NUM_SECTIONS; i++) {
            const ii = (pIndex * this.NUM_SECTIONS) + i;
            const sectionName = `Section ${ii}`;
            this.sectionIDs.push(sectionName);
            this.dataBlobs[sectionName] = sectionName;
            this.rowIDs[ii] = [];

            for (let jj = 0; jj < this.NUM_ROWS_PER_SECTION; jj++) {
                const rowName = `S${ii}, R${jj}`;
                this.rowIDs[ii].push(rowName);
                this.dataBlobs[rowName] = datas[jj];
            }
        }
        this.sectionIDs = [...this.sectionIDs];
        this.rowIDs = [...this.rowIDs];
    }

    render() {
        const separator = (sectionID, rowID) => (
            <div
                key={`${sectionID}-${rowID}`}
                style={{
                    backgroundColor: '#F5F5F9',
                    height: 4,
                    borderTop: '1px solid #ECECED',
                    borderBottom: '1px solid #ECECED',
                }}
            />
        );
        //维修单
        const row1= (rowData, sectionID, rowID) => {
            return (
                <div key={rowID} >
                <List className="am-list-content">
                <Item multipleLine onClick={() => { 
                    console.log("rowData", rowData)
                    if (null != rowID && '' != rowID) {
                        const { history } = this.props;
                        history.push({
                            pathname: '/maintaindetail',
                            state: {
                                func: this.state.func,//没有这段代码，页面不能跳转
                                rowData: rowData,
                            }
                        });
                    }
                }} 
                // extra={rowData.ExtraDatas.staconname}
                >
                <Flex>
                    <Flex.Item>机台:{rowData.ExtraDatas.devcode}</Flex.Item>
                </Flex>
                {/* <div style={{overflow:'hidden', textOverflow:'ellipsis' }}>维修单号:{rowData.billno}</div>
                机台:{rowData.ExtraDatas.devcode} */}
                <Flex>
                    <Flex.Item><Brief>单据日期:{this.formatDate(rowData.createtime)}</Brief></Flex.Item>
                    <Flex.Item><Brief>维修状态:{rowData.ExtraDatas.staconname }</Brief></Flex.Item>
                </Flex>
                    {/* <Brief>问题描述:{rowData.trouble}</Brief> */}
                <Flex>
                    <Flex.Item>
                        <Brief><Item wrap style={{paddingLeft:0}}><div style = {{color:"#8E8E8E",fontSize:'15px'}}>问题描述:{rowData.trouble}</div></Item></Brief>
                    </Flex.Item>
                </Flex> 
                
                </Item>
                </List>
                </div>
            );
        };
        //保养单
        const row2 = (rowData, sectionID, rowID) => {
            return (
                <div key={rowID} >
                <List className="am-list-content">
                <Item multipleLine onClick={() => { 
                    console.log("rowData", rowData)
                    if (null != rowID && '' != rowID) {
                        const { history } = this.props;
                        history.push({
                            pathname: '/maintenancedetail',
                            state: {
                                func: this.state.func,//没有这段代码，页面不能跳转
                                rowData: rowData,
                            }
                        });
                    }
                }} 
                extra={ rowData.ExtraDatas.staconname}>
                <Flex>
                    <Flex.Item>机台:{rowData.ExtraDatas.devicecode}</Flex.Item>
                </Flex>
                {/* <div style={{overflow:'hidden', textOverflow:'ellipsis' }}>维修单号:{rowData.billno}</div>
                机台:{rowData.ExtraDatas.devcode} */}
                <Flex>
                    <Flex.Item><Brief>单据日期:{this.formatDate(rowData.CreateTime)}</Brief></Flex.Item>     
                    <Flex.Item><Brief>保养状态:{rowData.isdone === 'True'? "保养完成":"未完成"}</Brief></Flex.Item>
                </Flex>
                </Item>
                </List>
                </div>
            );
        };
        //点检单
        const spotcheckrow = (rowData, sectionID, rowID) => {
            return (
                <div key={rowID} >
                <List className="am-list-content">
                <Item multipleLine onClick={() => { 
                    console.log("rowData", rowData)
                    if (null != rowID && '' != rowID) {
                        const { history } = this.props;
                        history.push({
                            pathname: '/spotcheckdetail',
                            state: {
                                func: this.state.func,//没有这段代码，页面不能跳转
                                rowData: rowData,
                            }
                        });
                    }
                }} 
                // extra={ rowData.ExtraDatas.devicecode}
                >
                <Flex>
                    <Flex.Item>机台:{rowData.ExtraDatas.devicecode}</Flex.Item>
                </Flex>
                {/* <div style={{overflow:'hidden', textOverflow:'ellipsis' }}>维修单号:{rowData.billno}</div>
                机台:{rowData.ExtraDatas.devcode} */}
                <Flex>
                    <Flex.Item><Brief>单据日期:{this.formatDate(rowData.CreateTime)}</Brief></Flex.Item>     
                    <Flex.Item><Brief>保养状态:{rowData.isdone === 'True'? "保养完成":"未完成"}</Brief></Flex.Item>
                </Flex>
                </Item>
                </List>
                </div>
            );
        };
        //报修单
        const row = (rowData, sectionID, rowID) => {
            return (
                <div key={rowID} >
                <List className="am-list-content">
                <Item multipleLine onClick={() => { 
                    console.log("rowData", rowData)
                    if (null != rowID && '' != rowID) {
                        const { history } = this.props;
                        history.push({
                            pathname: '/myrepairsdetail',
                            state: {
                                func: this.state.func,//没有这段代码，页面不能跳转
                                rowData: rowData,
                            }
                        });
                    }
                }} 
                //修改对应的一个字段名 
                extra={ rowData.ExtraDatas.staconname}>
                <Flex>
                    <Flex.Item style={{ flex: '0.4' }}>机台:{rowData.ExtraDatas.devicecode}</Flex.Item>
                    <Flex.Item style={{ flex: '0.6' }}>
                        <Brief><Item wrap style={{paddingLeft:0}}><div style = {{color:"#8E8E8E",fontSize:'14px'}}>影响程度:{this.state.impactdegreeid.get(rowData.impactdegreeid)}</div></Item></Brief>                        
                        {/* <Brief>影响程度:{this.state.impactdegreeid.get(rowData.impactdegreeid)}</Brief> */}
                    </Flex.Item>
                   
                </Flex>
                {console.log(rowData)}
                <Flex>
                    <Flex.Item style={{ flex: '0.4' }}>
                        <Brief><Item wrap style={{paddingLeft:0}}><div style = {{color:"#8E8E8E",fontSize:'14px'}}>报修日期:{this.formatDate(rowData.createtime)}</div></Item></Brief>                        
                        {/* <Brief>报修日期:{this.formatDate(rowData.createtime)}</Brief> */}
                    </Flex.Item>
                    <Flex.Item style={{ flex: '0.6' }}>
                        <Brief><Item wrap style={{paddingLeft:0}}><div style = {{color:"#8E8E8E",fontSize:'14px'}}>报修状态:{rowData.ExtraDatas.repstatusname}</div></Item></Brief>                        
                    {/* <Brief>报修状态:{rowData.ExtraDatas.repstatusname}</Brief> */}
                    </Flex.Item>
                </Flex>
                {/* <Brief>问题描述:{rowData.trouble}</Brief> */}
                <Flex>
                    <Flex.Item>
                        <Brief><Item wrap style={{paddingLeft:0}}><div style = {{color:"#8E8E8E",fontSize:'15px'}}>问题描述:{rowData.trouble}</div></Item></Brief>
                    </Flex.Item>
                </Flex>             
                </Item>
                </List>
                </div>
            );
        };
        return (
            <div>
                <div style={{backgroundColor:'#FFFFFF'}}>                    
                    <WingBlank>
                        {console.log(this.state.repairstypelist)}
                        <WhiteSpace size="sm" />
                        <Flex style={{width:'100%'}}>
                        {
                            this.state.typelist.map(i=>(
                                <Flex.Item key={i.id}  onClick={() => this.onRepairstypeChange(i.id)}>
                                        <Button type={this.issame(i.id)}> {i.name} 
                                       </Button>
                                </Flex.Item>
                                ))
                            }
                        </Flex>
                        <WhiteSpace size="sm" />
                    </WingBlank>
                </div>

                <div >
                    <Accordion accordion openAnimation={{}} onChange={this.getBillKey} defaultActiveKey={this.state.ifin?this.state.i['value']['billkey']:''}>
                        <Accordion.Panel key='1' header="报修单" >
                            <List>
                                <ListView className= "am-list-header"
                                ref={el => this.lv = el}
                                dataSource={this.state.dataSource}
                                //renderHeader={() => <span><h3>品质警报</h3><div >信息总数：{this.state.datalength} 未读信息数：{this.state.arraylength}</div></span>}
                                renderRow={row}
                                renderSeparator={separator}
                                className="am-list"
                                initialListSize={40}
                                // useBodyScroll
                                onScroll={() => { console.log('scroll'); }}
                                scrollRenderAheadDistance={500}
                                onEndReached={this.onEndReached}
                                onEndReachedThreshold={10}
                                style={{
                                    height: this.state.height,
                                    overflow: 'auto',
                                }}
                                />
                            </List>
                    </Accordion.Panel>
                    <Accordion.Panel key='2' header="维修单" >
                    <List>
                                <ListView className= "am-list-header"
                                ref={el => this.lv = el}
                                dataSource={this.state.dataSource}
                                //renderHeader={() => <span><h3>品质警报</h3><div >信息总数：{this.state.datalength} 未读信息数：{this.state.arraylength}</div></span>}
                                renderRow={row1}
                                renderSeparator={separator}
                                className="am-list"
                                initialListSize={40}
                                // useBodyScroll
                                onScroll={() => { console.log('scroll'); }}
                                scrollRenderAheadDistance={500}
                                onEndReached={this.onEndReached}
                                onEndReachedThreshold={10}
                                style={{
                                    height: this.state.height,
                                    overflow: 'auto',
                                }}
                                />
                            </List>
                    </Accordion.Panel>
                    <Accordion.Panel key='3' header="保养单" >
                        <List>
                                <ListView className= "am-list-header"
                                ref={el => this.lv = el}
                                dataSource={this.state.dataSource}
                                //renderHeader={() => <span><h3>品质警报</h3><div >信息总数：{this.state.datalength} 未读信息数：{this.state.arraylength}</div></span>}
                                renderRow={row2}
                                renderSeparator={separator}
                                className="am-list"
                                initialListSize={40}
                                // useBodyScroll
                                onScroll={() => { console.log('scroll'); }}
                                scrollRenderAheadDistance={500}
                                onEndReached={this.onEndReached}
                                onEndReachedThreshold={10}
                                style={{
                                    height: this.state.height,
                                    overflow: 'auto',
                                }}
                                />
                            </List>
                    </Accordion.Panel>
                    <Accordion.Panel key='4' header="点检单" >
                        <List>
                                <ListView className= "am-list-header"
                                ref={el => this.lv = el}
                                dataSource={this.state.dataSource}
                                //renderHeader={() => <span><h3>品质警报</h3><div >信息总数：{this.state.datalength} 未读信息数：{this.state.arraylength}</div></span>}
                                renderRow={spotcheckrow}
                                renderSeparator={separator}
                                className="am-list"
                                initialListSize={40}
                                // useBodyScroll
                                onScroll={() => { console.log('scroll'); }}
                                scrollRenderAheadDistance={500}
                                onEndReached={this.onEndReached}
                                onEndReachedThreshold={10}
                                style={{
                                    height: this.state.height,
                                    overflow: 'auto',
                                }}
                                />
                            </List>
                    </Accordion.Panel>
            </Accordion>
            </div>

            </div>
        );
    }
}