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


@IonicPage()
@Component({
  selector: 'page-set',
  templateUrl: 'set.html',
})
export class SetPage {

    temp = {
        id:'',
        isopen:null,
        isans:null,
        title:'',
        explai:'',
        usergroup:'',
        state:''
    };
  constructor(public navCtrl: NavController, public navParams: NavParams,
              public appService: AppService) {
  }

  ionViewDidLoad() {
      this.temp = this.navParams.get('temp');
        console.log(this.temp);
  }

  save(){
     if( this.temp.isans == true || this.temp.isans == 1 ){
         this.temp.isans = 1;
     }else{
         this.temp.isans = 0;
     }
      if( this.temp.isopen == true || this.temp.isopen == 1 ){
          this.temp.isopen = 1;
      }else{
          this.temp.isopen = 0;
      }
     const data = {
          id:this.temp.id,
          title:this.temp.title,   //问卷标题
          explai:this.temp.explai,   //问卷说明
          usergroup:this.temp.usergroup,  //用户组id
          isopen:this.temp.isopen,  //是否公开
          isans: this.temp.isans,   //是否匿名
          state:this.temp.state   //状态
      };
console.log(this.temp);
        this.appService.ObserverHttpPost('/wisdomgroup/modules/question/updateOnApp', data)
            .subscribe((res)=>{
                if(res){
                    this.navCtrl.pop();
                }
            })
  }

}
