import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {AppGlobal, AppService} from "../../../service/appHttpService";
import {message} from "../../../app/main";
import {Response} from "@angular/http";


@IonicPage()
@Component({
  selector: 'page-activity-search',
  templateUrl: 'activity-search.html',
})
export class ActivitySearchPage {

    searchValue = '';
    items;
    id;
    picture: string = AppGlobal.picture;
  constructor(public navCtrl: NavController, public navParams: NavParams,
              public appService: AppService) {
  }

  ionViewDidLoad() {
    this.id = this.navParams.get('id');
    this.searchUser();
  }

    clearValue() {
        this.searchValue = "";
    }

    //代报名
    goSignUp(item) {
        this.navCtrl.push('ReplaceApplyPage', {id: this.id, personInfo: item})
    }

    confirmSayNo(item){
        this.appService.alert('确定设置该用户不参加？',(res)=>{
            this.sayNo(item);
        })
    }

    //不参加
    sayNo(item) {
        const data = {
            'userId': item.id,
            'userName': item.name
        };
        this.appService.ObserverHttpForm("/wisdomgroup/modules/activityNon/", this.id, data)
            .subscribe((res: Response) => {
                   this.appService.popToastView('已保存该用户不参加','middle',1500);
                   this.searchUser();
                }, error => {
                }
            );
    }

    searchUser() {
        const data = {
            name: this.searchValue,
        };
        this.appService.ObserverHttpForm('/wisdomgroup/modules/activity/signAllByName/', this.id, data).subscribe((res) => {
            this.items = res.json();
        })
    }

    //取消报名
    cancelSignUp(item){
        this.appService.alert('确定取消该活动报名',(res)=>{
            const data = {
                'userid':item.id,
                'id':item.orderId
            }
            this.appService.ObserverHttpGetOption("/wisdomgroup/modules/order/deleteOrder", data).
            subscribe((res)=>{
                this.appService.popToastView('取消报名成功!','middle',1500);
                this.searchUser();
            })
        })
    }

}
