import { Component } from '@angular/core' ; import { NavController , Toast , Storage , LocalStorage , Loading , ViewController } from 'ionic-angular' ; import { OrderInfoPage } from '../about/order_info' ; import { Http , Headers , RequestOptions } from '@angular/http' ; import { Helper } from '../helper/helper' ; @ Component ( { templateUrl : 'build/pages/about/about.html' } ) export class AboutPage { public id : string ; img_src : string ; nick : string ; private selfTastUrl : string = 'http://119.29.140.85/index.php/task/list_launch' ; private lingQuRul : string = 'http://119.29.140.85/index.php/task/list_complete' ; helper : Helper ; headers : Headers ; options : RequestOptions ; local : Storage ; page : number = 1 ; page_size : number = 10 ; loading = Loading . create ( { content : '' , showBackdrop : false } ) ; pet : string = "puppies" ; items1 = [ ] ; items2 = [ ] ; constructor ( private nav , private http , private viewCtrl ) { this . local = new Storage ( LocalStorage ) ; this . helper = new Helper ( nav ) ; } doRefresh ( refresher ) { this . http . post ( this . selfTastUrl , this . helper . headleAjaxBodyParam ( { 'launch_user_id' : this . id , 'page_size' : this . page_size , 'page' : 1 } ) , this . options ) . subscribe ( ( data ) => { let response = data . json ( ) ; if ( response . status ) { this . items1 = [ ] ; for ( let i = 0 ; i < response . data . length ; i ++ ) { this . items1 [ i ] = { 'img_src' : 'http://119.29.140.85' + this . img_src , 'nick' : this . nick , 'id' : response . data [ i ] . id , 'complete_user_id' : response . data [ i ] . complete_user_id , 'complete_user_nick' : response . data [ i ] . complete_user_nick , 'complete_user_head_pic_url' : 'http://119.29.140.85' + response . data [ i ] . complete_user_head_pic_url , 'complete_user_phone' : response . data [ i ] . complete_user_phone , 'launch_time' : response . data [ i ] . launch_time , 'complete_time' : response . data [ i ] . complete_time , 'receive_express_name' : response . data [ i ] . receive_express_name , 'receive_express_phone' : response . data [ i ] . receive_express_phone , 'express_name' : response . data [ i ] . express_name , 'receive_address' : response . data [ i ] . receive_address , 'express_info' : response . data [ i ] . express_info , 'school_name' : response . data [ i ] . school_name , 'school_code' : response . data [ i ] . school_code } ; } refresher . complete ( ) ; } else { this . helper . presentToast ( '刷新失败:' + response . info ) ; refresher . complete ( ) ; } } , ( err ) => { this . helper . presentToast ( '网络错误，刷新失败,请稍后再试!' ) ; refresher . complete ( ) ; } ) ; this . http . post ( this . lingQuRul , this . helper . headleAjaxBodyParam ( { 'complete_user_id' : this . id , 'status' : 1 , 'page_size' : this . page_size , 'page' : 1 } ) , this . options ) . subscribe ( ( data ) => { let response = data . json ( ) ; if ( response . status ) { this . loading . dismiss ( ) ; this . items2 = [ ] ; for ( let i = 0 ; i < response . data . length ; i ++ ) { this . items2 [ i ] = { 'img_src' : 'http://119.29.140.85' + this . img_src , 'nick' : this . nick , 'id' : response . data [ i ] . id , 'launch_user_id' : response . data [ i ] . launch_user_id , 'launch_user_head_pic_url' : 'http://119.29.140.85' + response . data [ i ] . launch_user_head_pic_url , 'launch_user_nick' : response . data [ i ] . launch_user_nick , 'launch_user_phone' : response . data [ i ] . launch_user_phone , 'launch_time' : response . data [ i ] . launch_time , 'complete_time' : response . data [ i ] . complete_time , 'receive_express_name' : response . data [ i ] . receive_express_name , 'receive_express_phone' : response . data [ i ] . receive_express_phone , 'express_name' : response . data [ i ] . express_name , 'receive_address' : response . data [ i ] . receive_address , 'express_info' : response . data [ i ] . express_info , } ; } refresher . complete ( ) ; } else { this . loading . dismiss ( ) ; refresher . complete ( ) ; } } , ( err ) => { this . loading . dismiss ( ) ; refresher . complete ( ) ; } ) ; } presentToast ( ) { let toast = Toast . create ( { message : '已加载完成最新数据' , duration : 2000 , position : 'middle' } ) ; toast . onDismiss ( ( ) => { } ) ; this . nav . present ( toast ) ; } showOrderInfor ( event , item ) { this . nav . push ( OrderInfoPage , { 'item' : item } ) ; } ionViewLoaded ( ) { this . nav . present ( this . loading ) ; this . headers = new Headers ( { 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8' } ) ; this . options = new RequestOptions ( { headers : this . headers } ) ; let localData = JSON . stringify ( window . localStorage ) ; let localJson = eval ( "(" + localData + ")" ) ; this . id = localJson . id ; this . img_src = localJson . head_pic_url ; this . nick = localJson . nick ; this . initData ( ) ; } initData ( ) { this . http . post ( this . selfTastUrl , this . helper . headleAjaxBodyParam ( { 'launch_user_id' : this . id , 'page_size' : this . page_size , 'page' : 1 } ) , this . options ) . subscribe ( ( data ) => { let response = data . json ( ) ; if ( response . status ) { this . loading . dismiss ( ) ; this . items1 = [ ] ; for ( let i = 0 ; i < response . data . length ; i ++ ) { this . items1 [ i ] = { 'img_src' : 'http://119.29.140.85' + this . img_src , 'nick' : this . nick , 'id' : response . data [ i ] . id , 'complete_user_id' : response . data [ i ] . complete_user_id , 'complete_user_nick' : response . data [ i ] . complete_user_nick , 'complete_user_head_pic_url' : 'http://119.29.140.85' + response . data [ i ] . complete_user_head_pic_url , 'complete_user_phone' : response . data [ i ] . complete_user_phone , 'launch_time' : response . data [ i ] . launch_time , 'complete_time' : response . data [ i ] . complete_time , 'receive_express_name' : response . data [ i ] . receive_express_name , 'receive_express_phone' : response . data [ i ] . receive_express_phone , 'express_name' : response . data [ i ] . express_name , 'receive_address' : response . data [ i ] . receive_address , 'express_info' : response . data [ i ] . express_info , 'school_name' : response . data [ i ] . school_name , 'school_code' : response . data [ i ] . school_code } ; } } else { this . loading . dismiss ( ) ; } } , ( err ) => { this . loading . dismiss ( ) ; } ) ; this . http . post ( this . lingQuRul , this . helper . headleAjaxBodyParam ( { 'complete_user_id' : this . id , 'status' : 1 , 'page_size' : this . page_size , 'page' : 1 } ) , this . options ) . subscribe ( ( data ) => { let response = data . json ( ) ; if ( response . status ) { this . loading . dismiss ( ) ; this . items2 = [ ] ; for ( let i = 0 ; i < response . data . length ; i ++ ) { this . items2 [ i ] = { 'img_src' : 'http://119.29.140.85' + this . img_src , 'nick' : this . nick , 'id' : response . data [ i ] . id , 'launch_user_id' : response . data [ i ] . launch_user_id , 'launch_user_head_pic_url' : 'http://119.29.140.85' + response . data [ i ] . launch_user_head_pic_url , 'launch_user_nick' : response . data [ i ] . launch_user_nick , 'launch_user_phone' : response . data [ i ] . launch_user_phone , 'launch_time' : response . data [ i ] . launch_time , 'complete_time' : response . data [ i ] . complete_time , 'receive_express_name' : response . data [ i ] . receive_express_name , 'receive_express_phone' : response . data [ i ] . receive_express_phone , 'express_name' : response . data [ i ] . express_name , 'receive_address' : response . data [ i ] . receive_address , 'express_info' : response . data [ i ] . express_info , } ; } } else { this . loading . dismiss ( ) ; } } , ( err ) => { this . loading . dismiss ( ) ; } ) ; } doInfinite ( infiniteScroll ) { this . page ++ ; this . http . post ( this . selfTastUrl , this . helper . headleAjaxBodyParam ( { 'launch_user_id' : this . id , 'page_size' : this . page_size , 'page' : this . page } ) , this . options ) . subscribe ( ( data ) => { let response = data . json ( ) ; if ( response . data . length > 0 ) { if ( response . status ) { for ( let i = 0 ; i < response . data . length ; i ++ ) { this . items1 [ i + ( this . page - 1 ) * 10 ] = { 'img_src' : 'http://119.29.140.85' + this . img_src , 'nick' : this . nick , 'id' : response . data [ i ] . id , 'complete_user_id' : response . data [ i ] . complete_user_id , 'complete_user_nick' : response . data [ i ] . complete_user_nick , 'complete_user_head_pic_url' : 'http://119.29.140.85' + response . data [ i ] . complete_user_head_pic_url , 'complete_user_phone' : response . data [ i ] . complete_user_phone , 'launch_time' : response . data [ i ] . launch_time , 'complete_time' : response . data [ i ] . complete_time , 'receive_express_name' : response . data [ i ] . receive_express_name , 'receive_express_phone' : response . data [ i ] . receive_express_phone , 'express_name' : response . data [ i ] . express_name , 'receive_address' : response . data [ i ] . receive_address , 'express_info' : response . data [ i ] . express_info , 'school_name' : response . data [ i ] . school_name , 'school_code' : response . data [ i ] . school_code } ; } infiniteScroll . complete ( ) ; } else { this . helper . presentToast ( '数据初始化失败：' + response . info ) ; infiniteScroll . complete ( ) ; } } else { this . helper . presentToast ( '没有更多数据' ) ; infiniteScroll . enable ( false ) ; setTimeout ( ( ) => { infiniteScroll . enable ( true ) ; } , 1000 ) ; } } , ( err ) => { this . helper . presentToast ( '网络错误，数据初始化失败!' ) ; infiniteScroll . complete ( ) ; } ) ; this . http . post ( this . lingQuRul , this . helper . headleAjaxBodyParam ( { 'complete_user_id' : this . id , 'status' : 1 , 'page_size' : this . page_size , 'page' : this . page } ) , this . options ) . subscribe ( ( data ) => { let response = data . json ( ) ; if ( response . data . length > 0 ) { if ( response . status ) { for ( let i = 0 ; i < response . data . length ; i ++ ) { this . items1 [ i + ( this . page - 1 ) * 10 ] = { 'img_src' : 'http://119.29.140.85' + this . img_src , 'nick' : this . nick , 'id' : response . data [ i ] . id , 'launch_user_id' : response . data [ i ] . launch_user_id , 'launch_user_head_pic_url' : response . data [ i ] . launch_user_head_pic_url , 'launch_user_nick' : 'http://119.29.140.85' + response . data [ i ] . launch_user_nick , 'launch_user_phone' : response . data [ i ] . launch_user_phone , 'launch_time' : response . data [ i ] . launch_time , 'complete_time' : response . data [ i ] . complete_time , 'receive_express_name' : response . data [ i ] . receive_express_name , 'receive_express_phone' : response . data [ i ] . receive_express_phone , 'express_name' : response . data [ i ] . express_name , 'receive_address' : response . data [ i ] . receive_address , 'express_info' : response . data [ i ] . express_info , } ; } infiniteScroll . complete ( ) ; } else { this . helper . presentToast ( '数据初始化失败：' + response . info ) ; infiniteScroll . complete ( ) ; } } else { this . helper . presentToast ( '没有更多数据' ) ; infiniteScroll . enable ( false ) ; setTimeout ( ( ) => { infiniteScroll . enable ( true ) ; } , 1000 ) ; } } , ( err ) => { this . helper . presentToast ( '网络错误，数据初始化失败!' ) ; infiniteScroll . complete ( ) ; } ) ; } }