index.js 12.2 KB
Newer Older
陈卓 Joechan Chen's avatar
陈卓 Joechan Chen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
/**
 * 首次绑定
 */
import React, {
    Component
} from 'react';
import ReactDOM from 'react-dom';
import {
    NavBar,
    Icon,
    Button,
    Toast,
    Modal,
    Picker,
    Accordion,
    List,
} from 'antd-mobile';
import './index.less';
import pdaApi from '../../common/api/pdauser'
import SingleItem,{SingleInput} from '../../common/commonview/singleitem';
import NewSteps from '../../common/commonview/newsteps'
import AccardionSteps from '../../common/accardionsteps'
import back from '../../assets/back.png';
import clear from '../../assets/delete.png';


class AdminTranckingQuery extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            id:'',
            boxnum:'',
            partid:'',
            shunfengid:'',
            onthewayinfoshow:false,
            onthewayinfoshowtype:2,
            data:[],
            isshunfeng:false,
            userInfo:''
        }
        this.handleInputChange = this.handleInputChange.bind(this)
        this.goVagueaQuery = this.goVagueaQuery.bind(this)
    }
    handleInputChange(event){
        const target = event.target
        const value = target.type === 'checkbox' ? target.checked : target.value
        const name = target.name
        this.setState({
            [name]: value
        })
        if(name=="shunfengid"){
            localStorage.setItem("shunfengid",value);
        }else{
            localStorage.setItem("partid",value);
        }
    }
    goVagueaQuery(){
        window.location.href='/adminTrackingVagueQuery.html'
    }
    goVagueaQuerybox(){
        window.location.href='/adminTrackingBoxNumVagueQuery.html'
    }
    query(){
        if(!this.state.id && !this.state.boxnum  && !this.state.shunfengid){
            Toast.info("请输入查询条件")
            this.setState({
                data:[]
            })
        }else{
            if(this.state.shunfengid){
                //根据顺丰单号查询
                var orderid=this.state.shunfengid
                pdaApi.getquerybyid({orderid}).then(res=>{
                    console.log('在途查询--顺丰单号',res);
                    if(res.code==1&&res.result.length!=0){
                        this.setState({
                            data:res.result,
                            onthewayinfoshow:true,
                            onthewayinfoshowtype:1,
                            isshunfeng:true
                        })
                    }else{
                        Toast.info('没有查询到在途信息')
                        this.setState({
                            data:[]
                        })
                    }
                })
                return
            }
            if(this.state.boxnum){
                //根据箱号查询
                var box_number=this.state.boxnum
                var code=this.state.userInfo.code || ""//站点
                pdaApi.getqueryinfo({box_number,code}).then(res=>{
                    console.log('在途查询--箱号',res);
                    if(res.code==1&&res.result.length!=0){
                        this.setState({
                            data:res.result,
                            onthewayinfoshow:true,
                            onthewayinfoshowtype:1
                        })
                    }else{
                        Toast.info('没有查询到在途信息')
                        this.setState({
                            data:[]
                        })
                    }
                })
                return
            }
            if(this.state.id){
                //根据注册号查询
                var pacid=this.state.partid ||''
                var regid=this.state.id
                var code=this.state.userInfo.code || ""//站点
                pdaApi.getqueryinfo({regid,pacid,code}).then(res=>{
                    console.log('在途查询--注册号',res);
                    if(res.code==1&&res.result.length!=0){
                        this.setState({
                            data:res.result,
                            onthewayinfoshow:true,
                            onthewayinfoshowtype:2
                        })
                    }else{
                        Toast.info('没有查询到在途信息')
                        this.setState({
                            data:[]
                        })
                    }
                })
            }
        }

    }
    render() {
        var containner={
            marginTop:'0.5rem',
            width:'100%',
            display:'flex',
            flexDirection: 'column',
            alignItems: 'center',
            backgroundColor:'#ffffff'
        }
        var SeachButtonwrap={
            width:'80%',
            height:'0.75rem',
            marginTop:'0.3rem',
            backgroundColor:'#80b3f2',
            borderTopColor:'#80b3f2',
            borderRadius:100,
            display:'flex',
            justifyContent:'center',
            alignItems:'center',
            fontSize:'0.34rem',
            color:'#fefefe',
            textAlign:'center'
        }
        var OnthewayButtonwrap={
            width:'100%',
            height:'0.8rem',
            marginTop:'0.5rem',
            backgroundColor:'#fefefe',
            borderTopColor:'#fefefe',
            borderRadius:0,
            boxShadow:'0 0.02rem 0.08rem 0 rgba(112,115,118,0.30)',
            display:'flex',
            justifyContent:'flex-start',
            alignItems:'center',
            fontSize:'0.34rem',
            color:'#505050',
            paddingLeft:'0.4rem'
        }
        var infowrap={
            width:'100%',
            padding:'0.2rem',
            display:'none'
        }
        var infowrapshown={
            width:'100%',
            padding:'0.2rem',
        }
        var loc = this.state.data.length>0 ? this.state.data[0].item[0].dealercode:''
        //var loc = '我是经销商'
        console.log('loc 是',loc);
        return (
            <div>
                <NavBar 
                    leftContent={<div style={{ 'display': 'flex', 'alignItems': 'center' }}>
                                    < img style={{ 'width': '.25rem' }} src={back} /> 
                                    <span style={{ 'marginLeft': '.12rem' }}>返回</span>
                                </div>
                                }
                    iconName={false}
                    onLeftClick={() => {
                        // window.history.back(-1);
                        window.location.href='/adminIndex.html'
                    }}>
                    跟踪查询
                </NavBar>
                <div style={containner}>
                    <SingleItem 
                        name="注册号"
                        >
                        <SingleInput 
                        name="id" 
                        onChange={this.handleInputChange} 
                        onFocus={this.goVagueaQuery} 
                        value={this.state.id}
                        onIconClick={()=>{this.clear('id')}}
                        iconStyle={{marginTop:'.2rem'}}
                        icon={clear}/>/>
                    </SingleItem>
                    <SingleItem
                            name="箱号"
                        >
                        <SingleInput 
                        name="boxnum" 
                        onChange={this.handleInputChange} 
                        onFocus={this.goVagueaQuerybox}
                        value={this.state.boxnum}
                        onIconClick={()=>{this.clear('boxnum')}}
                        iconStyle={{marginTop:'.2rem'}}
                        icon={clear}/>/>
                    </SingleItem>
                    <SingleItem 
                        name="零件号"
                        >
                        <SingleInput name="partid" onChange={this.handleInputChange}  value={this.state.partid}/>
                    </SingleItem>
                    <SingleItem 
                        name="顺丰单号"
                        >
                        <SingleInput name="shunfengid" onChange={this.handleInputChange}/>
                    </SingleItem>
                    <Button style={SeachButtonwrap} 
                        loading={this.state.loading}
                        onClick={()=>{this.query()}}>
                        查询
                    </Button>
                    <Button style={OnthewayButtonwrap} 
                        loading={this.state.loading}
                        >
                        在途信息{loc?'-经销商代码:'+loc:''}
                    </Button>
                    {this.state.onthewayinfoshowtype==1?
                        <div style={this.state.onthewayinfoshow==true?infowrapshown:infowrap}>
                            {this.state.data.map((item,index)=>{
                                var tempdata=[]
                                item.item.map((m,n)=>{
                                    if(this.state.isshunfeng){
                                        //var tempitem={itemtext:m.description,date:m.date_time} //LEO
                                        var tempitem={itemtext:m.scg_description+" "+m.location_id_value,date:m.eventdate}
                                    }else{
                                        //var tempitem={itemtext:m.description,date:m.eventdate}
                                        var tempitem={itemtext:m.scg_description+" "+m.location_id_value,date:m.eventdate}
                                    }
                                    tempdata.push(tempitem)
                                })
                                return<NewSteps
                                    data={tempdata}
                                />
                            })}
                        </div>:
                        <div style={this.state.onthewayinfoshow==true?infowrapshown:infowrap}>
                            {this.state.data.map((item,index)=>{
                                if(item.item){
                                    var tempdata=[]
                                    item.item.map((m,n)=>{
                                        //var tempitem={itemtext:m.description,date:m.eventdate}
                                        var tempitem={itemtext:m.scg_description+" "+m.location_id_value,date:m.eventdate}
                                        tempdata.push(tempitem)
                                    })
                                }else{
                                    var tempdata=[{itemtext:'暂无信息',date:''}]
                                }
                                return<AccardionSteps
                                    data={tempdata} boxnum={item.box_number}
                                />
                            })}
                        </div>
                    }
                </div>    
        </div>
        );
    }
    componentDidMount(){
        // 获取用户信息
        let userInfo=JSON.parse(localStorage.getItem("userInfo")) || ''
        if(userInfo!=''){
            console.log('用户信息',userInfo);
            this.setState({
                userInfo:userInfo
            })
        }else{
            window.location.href = "/binduser.html";
        }
        var partid=localStorage.getItem("partid")||''
        if(partid!=''){
            this.setState({
                partid:partid,
            })
        }
        var shunfengid=localStorage.getItem("shunfengid")||''
        if(shunfengid!=''){
            this.setState({
                shunfengid:shunfengid,
            })
        }
        var id=localStorage.getItem("id")||''
        if(id!=''){
            this.setState({
                id:id,
            })
        }
        var boxnum=localStorage.getItem("boxnum")||''
        if(boxnum!=''){
            this.setState({
                boxnum:boxnum,
            })
        }
    }
    clear(type){
        if(type=="id"){
            this.setState({
                id:''
            })
            localStorage.removeItem("id");
        }else{
            this.setState({
                boxnum:''
            })
            localStorage.removeItem("boxnum");
        }
    }
}


const render = () => {
    ReactDOM.render(
        <AdminTranckingQuery></AdminTranckingQuery>, document.getElementById('root'));
}
render();