import { Component } from '@angular/core';
import {IonicPage, ModalController, NavController, NavParams, ToastController} from 'ionic-angular';
import {EditPage} from "../edit/edit";
import {PersonPage} from "../../modal/person/person";
import { AppService } from "../../../../service/appHttpService";
import {message} from "../../../../app/main";


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

  desrc = {
      title:'',   //问卷标题
      explai:'',   //问卷说明
      usergroup:null,  //用户组id
      isopen:0,  //是否公开
      isans:1,   //是否匿名
      state:1   //状态
  };
    groupName = '全体用户';

  constructor(public navCtrl: NavController, public navParams: NavParams,
              public modalCtrl: ModalController,public appService: AppService,
              public toastCtrl: ToastController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad DesicrPage');
  }

    submitOrder(){
        const toast = this.toastCtrl.create(message);
        if(this.desrc.usergroup == null){
            this.desrc.usergroup = 'all';
        }
        this.appService.ObserverHttpPost('/wisdomgroup/modules/question/create',this.desrc)
            .subscribe(
                (res)=>{
                    toast.setMessage('创建成功');
                    toast.present();
                    this.navCtrl.pop();
                }
            )
    }

    selectPerson(){
        let modal = this.modalCtrl.create(PersonPage);
        modal.onDidDismiss(data=>{
            if( data ){
                this.desrc.usergroup = data.id;
                this.groupName = data.groupName;
            }else{
                this.desrc.usergroup = 'all';
                this.groupName = '全体用户';
            }

        });
        modal.present();
    }

}
