import { Injectable } from '@angular/core' ; import { LoadingController , AlertController , ModalController , ToastController } from 'ionic-angular' ; /**
 *  遮罩层服务
 *
 */ @ Injectable ( ) export class PopSerProvider { private load : any ; constructor ( public loadingCtrl , public alertCtrl , public toastCtrl , public modalCtrl ) { console . log ( 'PopSerProvider Provider' ) ; } /**
     * alert弹窗
     * http://ionicframework.com/docs/api/components/alert/AlertController/
     */ alert ( content , callback = ( ) => { } ) { let alert = this . alertCtrl . create ( { title : '<span>提示</span>' , message : '<div>' + content + '</div>' , enableBackdropDismiss : false , cssClass : '' , buttons : [ { text : "好的" , cssClass : 'pop_btn' , handler : ( ) => { if ( callback != undefined && callback != null && typeof callback == 'function' ) { callback ( ) ; } } } ] } ) ; alert . present ( ) ; } /**
     * 自定义alert弹窗-
     */ alertDIY ( obj , ok_callback = ( ) => { } ) { let confirm_diy = this . alertCtrl . create ( { title : obj . title || '<div class="content_img">提示</div>' , subTitle : obj . subTitle , message : obj . content , cssClass : obj . cssClass , enableBackdropDismiss : false , buttons : [ { text : obj . okText || '确定' , cssClass : 'pop_btn' , handler : ( ) => { if ( ok_callback != undefined && ok_callback != null && typeof ok_callback == 'function' ) { ok_callback ( ) ; } } } ] } ) ; confirm_diy . present ( ) ; } /**
     * confirm确认框
     */ confirm ( content , ok_callback = ( ) => { } ) { let alert = this . alertCtrl . create ( { title : '<div class="content_img">提示</div>' , subTitle : '' , message : content , cssClass : '' , enableBackdropDismiss : false , buttons : [ { text : '取消' , role : 'cancel' , } , { text : '确定' , cssClass : 'pop_btn' , handler : ( ) => { if ( ok_callback != undefined && ok_callback != null && typeof ok_callback == 'function' ) { ok_callback ( ) ; } } } ] } ) ; alert . present ( ) ; } /**
     * 自定义confirm确认框
     */ confirmDIY ( obj , esc_callback = ( ) => { } , ok_callback = ( ) => { } ) { let confirm_diy = this . alertCtrl . create ( { title : obj . title || '<div class="content_img"><img  src="assets/img/use_over.png" class="img"/></div>' , subTitle : obj . subTitle || '' , cssClass : obj . cssClass || '' , message : '<div>' + obj . content + '</div>' , enableBackdropDismiss : false , buttons : [ { text : obj . escText || '取消' , handler : ( ) => { if ( esc_callback != undefined && esc_callback != null && typeof esc_callback == 'function' ) { esc_callback ( ) ; } } } , { text : obj . okText || '确定' , cssClass : 'pop_btn' , handler : ( ) => { if ( ok_callback != undefined && ok_callback != null && typeof ok_callback == 'function' ) { ok_callback ( ) ; } } } ] } ) ; confirm_diy . present ( ) ; } param { string } content param { string } position param { string } cssClass param { number } duration toast ( content , position = 'bottom' , cssClass = '' , duration = 3000 ) { let toast = this . toastCtrl . create ( { message : content , duration : 3000 , position : position , cssClass : cssClass , showCloseButton : false , closeButtonText : "关闭" , dismissOnPageChange : false , } ) ; toast . onDidDismiss ( ( ) => { console . log ( 'Dismissed toast' ) ; } ) ; toast . present ( ) ; } /**
     * 拨打号码弹窗
     */ callPop ( obj , esc_callback = ( ) => { } , ok_callback = ( ) => { } ) { setTimeout ( ( ) => { let test = document . getElementsByClassName ( "pop_btn" ) [ 0 ] ; test . innerHTML = "<a href='tel:" + obj . tel + "'> 继续呼叫 </a>" ; } , 3 ) ; let confirm_diy = this . alertCtrl . create ( { title : obj . title || '<div class="content_img"><img  src="assets/img/use_over.png" class="img"/></div>' , subTitle : obj . subTitle , cssClass : "call" , message : '<div>' + obj . content + '</div>' , enableBackdropDismiss : false , buttons : [ { text : obj . escText || '取消' , handler : ( ) => { if ( esc_callback != undefined && esc_callback != null && typeof esc_callback == 'function' ) { esc_callback ( ) ; } } } , { text : obj . okText || '确定' , cssClass : 'pop_btn' , handler : ( ) => { if ( ok_callback != undefined && ok_callback != null && typeof ok_callback == 'function' ) { ok_callback ( ) ; } } } ] } ) ; confirm_diy . present ( ) ; } param { string } op param { string } content param { string } spinner param { string } css param { boolean } showBackdrop loading ( op , content = '' , spinner = 'ios-small' , css = '' , showBackdrop = true ) { if ( op == 'hide' ) { if ( this . load ) { this . load . dismiss ( ) ; } } else { this . load = this . loadingCtrl . create ( { spinner : spinner , content : content , cssClass : css , showBackdrop : showBackdrop , enableBackdropDismiss : false , dismissOnPageChange : false , } ) ; this . load . present ( ) ; setTimeout ( ( ) => { this . load . dismiss ( ) ; } , 10000 ) ; } this . load . onDidDismiss ( ( ) => { console . log ( 'Dismissed loading' ) ; } ) ; } }