import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {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;
  constructor(public navCtrl: NavController, public navParams: NavParams,
              public appService: AppService) {
  }

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

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

    //代报名
    goSignUp(item) {
        this.navCtrl.push('ReplaceApplyPage', {id: this.id, personInfo: 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 => {
                    this.appService.alert('网络异常！');
                }
            );
    }

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

}
