import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {Response} from "@angular/http";
import {AppService} from "../../../service/appHttpService";
import {DomSanitizer} from "@angular/platform-browser";


@IonicPage()
@Component({
    selector: 'page-order-detail',
    templateUrl: 'order-detail.html',
})
export class OrderDetailPage {
    order = {
        orderstate: '',
        orderpjlevel: '',
        orderid:''
    };  //订单信息
    activity = {
        activityName: '',
        activityIntro: ''
    };    //活动
    batch = {
        batchNotice:<any>''
    };    //批次

    isCover = false;
    isIntroduce = false;

    constructor(public navCtrl: NavController, public navParams: NavParams,
                public appService: AppService ,public sanitizer: DomSanitizer) {
    }

    ionViewDidEnter() {
        this.order = this.navParams.get('item');
        this.activity = this.navParams.get('item').activity;
        this.batch = this.navParams.get('item').batch;
        let con = this.batch.batchNotice.replace(/\r?\n/g, "<br />");
        this.batch.batchNotice = this.sanitizer.bypassSecurityTrustHtml(con);
        console.log(this.order);
    }

    //取消报名（订单）
    sureCancelOrder(): void {
        this.appService.alert('确定取消报名么？', res => {
            this.cancelOrder();
        });
    }

    cancelOrder(): void {
        this.appService.ObserverHttpGetOption("/wisdomgroup/modules/order/deleteOrder", { "id": this.order.orderid })
            .subscribe((res: Response) => {
                    this.appService.alert('报名已取消！');
                    this.navCtrl.pop();
                }, error => {
                }
            );

    }

    //订单确认
    orderConform(){
        this.navCtrl.push('ActivityConfirmPage',{activity:this.activity,order:this.order});
    }

    hidden() {
        this.isCover = false;
        this.isIntroduce = false;
    }

    show() {
        this.isCover = true;
        this.isIntroduce = true;
    }

}
