import { SysDataService } from "../../../service/sys-data.service";
import { Component, OnInit } from "@angular/core";
import { PageData } from "../../../data/PageData";
import { Router } from "@angular/router";
import swal from "sweetalert2";

@Component({
  selector: "app-sys005-create-page",
  templateUrl: "./sys005-create-page.component.html"
})
export class Sys005CreatePageComponent implements OnInit {
  pageData: PageData;
  errorMessage: string;
  data: any;
  constructor(private sysDataService: SysDataService, private router: Router) {}
  ngOnInit() {
    this.pageData = new PageData();
  }

  postPageDataList() {
    this.sysDataService.postPageListData(this.pageData).subscribe(res => {
      const result = res.json();
      if (result.Success === true) {
        swal({
          type: "success",
          title: "新增成功",
          text: "轉跳回檢視頁面...",
          showConfirmButton: false,
          timer: 1000,
          onOpen: () => {
            swal.showLoading();
          },
          onClose: () => {
            this.router.navigate(["sys/sys005"]);
          }
        });
      } else {
        swal({
          type: "error",
          title: "新增失敗",
          text: "請檢查您輸入的資訊...",
          showConfirmButton: true
        });
      }
    });
  }

  backPreviousPage() {
    this.router.navigateByUrl("/sys/sys005");
  }
}
