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:'',  //用户组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);
        const data = {}
        this.appService.ObserverHttpPost('/wisdomgroup/modules/question/create',this.desrc)
            .subscribe(
                (res)=>{
                    toast.setMessage('创建成功');
                    toast.present();
                    setTimeout((res) => {
                        this.navCtrl.pop();
                    }, 2000);
                }
            )
    }

    selectPerson(){
        let modal = this.modalCtrl.create(PersonPage);
        modal.onDidDismiss(data=>{
            console.log(data);
            this.desrc.usergroup = data.id;
            this.groupName = data.groupName;
        })
        modal.present();
    }

}
