Skip to content
home.ts 9.81 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import { Component, ViewChild } from '@angular/core';
import { NavController, IonicPage, Slides } from 'ionic-angular';
wangqinghua's avatar
wangqinghua committed
import { ActivityListPage } from '../../activity/activityList/activityList';
wangqinghua's avatar
wangqinghua committed
import { Http, Response } from '@angular/http';
wangqinghua's avatar
wangqinghua committed
import { ActivityStatisticService } from '../../../service/activityStatisticService';
import { MyActivityListPage } from '../../myActivityList/myActivityList';
import { AppService, AppGlobal } from '../../../service/appHttpService';
import { Calendar } from '@ionic-native/calendar';
wangqinghua's avatar
wangqinghua committed
import { ActivityApplyPage } from '../../activity/activityApply/activityApply'
wangqinghua's avatar
wangqinghua committed
import { ActivityConfirmPage } from '../../activity/activityConfirm/activityConfirm';
wangqinghua's avatar
wangqinghua committed
import { OutGoingReportPage } from '../../report/outGoingReport/outGoingReport';
wangqinghua's avatar
wangqinghua committed
import { OperationListPage } from '../../operation-list/operation-list';
import { AnnouncementPage } from '../../announcement/announcement';
import { Storage } from '@ionic/storage';
wangqinghua's avatar
wangqinghua committed
import { OutGoingReportEditPage } from '../../report/outGoingReportEdit/outGoingReportEdit';
wangqinghua's avatar
wangqinghua committed
import { AnnouncementViewPage } from '../../announcementView/announcementView';
wangqinghua's avatar
wangqinghua committed
import {MoreAppPage} from "../../home/more-app/more-app";
wangqinghua's avatar
wangqinghua committed
import {ReportTrackPage} from "../../report/reportTrack/reportTrack";
wangqinghua's avatar
wangqinghua committed
import { CalendarComponentOptions } from "ion2-calendar";
wangqinghua's avatar
wangqinghua committed
import {NoticePage} from "../notice/notice";
wangqinghua's avatar
wangqinghua committed
import {monthCh, weekDay} from "../../../app/main";
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
declare var Swiper;
wangqinghua's avatar
wangqinghua committed
@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {
  @ViewChild(Slides) slides: Slides;

  hasNewActivity:number = 0;
  hasNewNotice:number = 0;
  hasNewPremanager:number = 0;

wangqinghua's avatar
wangqinghua committed
  //日历
    date: string;
    type: 'string';

    optionsMulti: CalendarComponentOptions = {
        pickMode: 'multi',
        monthFormat: 'YYYY 年 MM 月 ',
wangqinghua's avatar
wangqinghua committed
        weekdays: weekDay,
        monthPickerFormat:monthCh,
wangqinghua's avatar
wangqinghua committed
        weekStart: 1,
    };

wangqinghua's avatar
wangqinghua committed
  //待出行
  waitgoCount = '0';
  //待确认
  waitsureCount = '0';
  //未读通知
  NoticeNotreadCount = '0';
  //尚未报备
  PremanagerNotdoCount = '0';
  //是否显示正在开发中
  isWait: boolean = false;

wangqinghua's avatar
wangqinghua committed
  slidersItems = [];
  noticeList = [];
wangqinghua's avatar
wangqinghua committed

  picture: string = AppGlobal.picture;

  operations: Array<string>;

  //当前年份
  year;
  //当前月份
  month;
  //当前第几周
  weekNo;

wangqinghua's avatar
wangqinghua committed


wangqinghua's avatar
wangqinghua committed
  //当前周日历展示
  week: Week[] = [{
    id: 0,
    title: '',
    date: null,
    isToday: false
  }, {
    id: 1,
    title: '',
    date: null,
    isToday: false
  }, {
    id: 2,
    title: '',
    date: null,
    isToday: false
  }, {
    id: 3,
    title: '',
    date: null,
    isToday: false
  }, {
    id: 4,
    title: '',
    date: null,
    isToday: false
  }, {
    id: 5,
    title: '',
    date: null,
    isToday: false
  }, {
    id: 6,
    title: '',
    date: null,
    isToday: false
  }]

  constructor(public navCtrl: NavController, public activityStatisticService: ActivityStatisticService,
    public appService: AppService, public http: Http, private calendar: Calendar, public storage: Storage) {
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
  }


  goActivity() {
    this.navCtrl.push('ActivityListPage', {

    });
  }

  goAnnouncement() {
    this.navCtrl.push("AnnouncementPage");
  }

wangqinghua's avatar
wangqinghua committed
  ngOnInit(): void {
wangqinghua's avatar
wangqinghua committed
    this.appService.ObserverHttpGet("/wisdomgroup/modules/common/file/getBanner", {}).subscribe((res: Response) => {
          this.slidersItems = res.json();
          console.log(res.json());
        }, error => {
          this.appService.alert('系统错误!');
        });

        this.appService.ObserverHttpGet("/wisdomgroup/modules/message/findAllActivityForAppWithXQ", null).subscribe((res: Response) => {
wangqinghua's avatar
wangqinghua committed
          this.noticeList = res.json().slice(0,2);
          console.log(this.noticeList);
        }, error => {
          this.appService.alert('系统错误!');
        })

  }
wangqinghua's avatar
wangqinghua committed

  ionViewDidEnter() {
    setTimeout(() => {
      if (this.slidersItems.length > 0) {
wangqinghua's avatar
wangqinghua committed
        // this.slides.freeMode = true;
        // this.slides.autoplay = 2000;
        // this.slides.speed = 500;
        // this.slides.loop = true;
        // this.slides.autoplayDisableOnInteraction=false;
        // this.slides.startAutoplay();
wangqinghua's avatar
wangqinghua committed
      }
    }, 1000)
  }

  ionViewWillEnter() {
    //初始化日期
    this.getHasNewActivity();
    this.getHasNewNotice();
    this.getHasNewPremanager();
    //统计待进行和待确认活动数目
    this.activityStatisticService.myActivityOrderCount((data) => {
      this.waitgoCount = data.waitgoOrder;
      this.waitsureCount = data.waitSureOrder;
    });

    this.appService.ObserverHttpGet("/wisdomgroup/modules/common/file/getBanner", {}).subscribe((res: Response) => {
      this.slidersItems = res.json();
    }, error => {
      this.appService.alert('网络异常!');
    })

    //初始化统计未读通知
    this.activityStatisticService.myNoticeNotreadCount((data) => {
      this.NoticeNotreadCount = data;
    });
    //初始化统计尚未报备
    this.activityStatisticService.myNotdoPremanagerCount((data) => {
      this.PremanagerNotdoCount = data;
    });

    //初始化操作记录
  }

  goMyActivity() {
    this.navCtrl.push("MyActivityListPage");
  }
  goMyNotice() {
    this.navCtrl.push("AnnouncementPage");
  }

wangqinghua's avatar
wangqinghua committed
  //活动跟踪
    goActivityTrack(){
        this.navCtrl.push("ActivityTrackPage");
    }

wangqinghua's avatar
wangqinghua committed
    //报备跟踪
    goReportTrack(){
        this.navCtrl.push("ReportTrackPage");
    }

wangqinghua's avatar
wangqinghua committed
  wait() {
    this.isWait = true;
  }

  cancleWait() {
    this.isWait = false;
  }

wangqinghua's avatar
wangqinghua committed
    onChange(e){
      console.log(e);
    }
wangqinghua's avatar
wangqinghua committed

  go(item) {
    if (item.type == 1) {
      this.getActivity(item.id);
    } else if (item.type == 2) {
      this.getPremanager(item.id);
    } else if (item.type == 3) {
      this.navCtrl.push("AnnouncementViewPage", {
        id: item.id
      });
    }
  }

  //获取活动ById
  getActivity(id) {
    this.appService.ObserverHttpPost("/wisdomgroup/modules/activity/appFindById", { id: id })
      .toPromise()
      .then(res => {
        let activity = res.json();
        if (activity.orderList.length == 0) {
          this.goApply(activity);
        } else {
          this.goDetail(activity);
        }
      })
      .catch(error => {
      });
  }


  //获取报备
  getPremanager(id) {
    this.appService.ObserverHttpPost("/wisdomgroup/modules/premanager/findById", { id: id })
      .toPromise()
      .then(res => {
        let premanager = res.json();
        this.storage.set("premanager", premanager);
        this.navCtrl.push("OutGoingReportEditPage");
      })
      .catch(error => {
      });
  }

  //查看详情
  goDetail(item) {
    let orderid = item.orderList[0]["orderid"];
    this.findMyOrderByOrderId(orderid, result => {
      let order = result;
      this.navCtrl.push("ActivityConfirmPage", { lookOrderDetails: order });
    });
  }

  //报名按钮
  goApply(item) {   //活动状态:1:待发布(不可报名),2:发布中(可报名)3:已完成(报名截止)
    if (item.activityState == 2) {
      let flag = false;
      this.isExitOrderWithActivity(item, result => {
        flag = result;
        if (flag) {
          this.appService.toast("您已经报名该活动,请在我的活动中查看!");
        } else {
          this.navCtrl.push("ActivityApplyPage", { item: item });
        }
      });

    } else {
      if (item.activityState == 1) {
        this.appService.toast("报名暂未开通!");
      } else {
        this.appService.toast("活动已完成!");
      }
    }
  }

  findMyOrderByOrderId(orderid, callback?) {
    let order = this.appService.ObserverHttpPost("/wisdomgroup/modules/order/findMyOrderByOrderId", { "orderid": orderid })
      .subscribe((res: Response) => {
        let data = res.json();
        callback(data == null ? "[]" : data);
      }, error => {
        this.appService.alert('网络异常!');
      }
      );
  }

  isExitOrderWithActivity(activity, callback?): any {
    this.appService.ObserverHttpPost("/wisdomgroup/modules/order/isExitOrderWithActivity", activity)
      .toPromise()
      .then(res => {
        var data = res.json();
        callback(data == null ? "[]" : data);
      })
      .catch(error => {
      });
  }




wangqinghua's avatar
wangqinghua committed
  //消息通知
    gotoNotice(){
        this.navCtrl.setRoot(NoticePage);
        this.navCtrl.parent.select(2);
    }

wangqinghua's avatar
wangqinghua committed
  goOperationListPage() {
    this.navCtrl.push("OperationListPage");
  }

  //外出报备跳转
  goOutGoingReportAboutAll() {
    this.navCtrl.push("OutGoingReportPage", {
      type: 1
    });
  }

wangqinghua's avatar
wangqinghua committed
    goDuty(){
      this.navCtrl.push("DutyPage");
    }

wangqinghua's avatar
wangqinghua committed
  //更多应用
    gotoMore(){
      this.navCtrl.push('MoreAppPage')
    }

wangqinghua's avatar
wangqinghua committed
  //尚未报备跳转
  goOutGoingReportAboutNot() {
    this.navCtrl.push("OutGoingReportPage", {
      type: 2
    });
  }

  //获取是否有新的活动
  getHasNewActivity(){
    this.appService.ObserverHttpGet("/wisdomgroup/modules/activity/hasNewActivity", null)
      .subscribe((res: Response) => {
        let data = res.json();
        console.log(data);
        this.hasNewActivity = data;
      }, error => {
        this.appService.alert('网络异常!');
      }
      );
  }

  //获取是否有新的公告
  getHasNewNotice(){
    this.appService.ObserverHttpGet("/wisdomgroup/modules/notice/hasNewNotice", null)
    .subscribe((res: Response) => {
      let data = res.json();
      console.log(data);
      this.hasNewNotice = data;
    }, error => {
      this.appService.alert('网络异常!');
    }
    );
  }

  //获取是否有新的报备
  getHasNewPremanager(){
    this.appService.ObserverHttpGet("/wisdomgroup/modules/premanager/hasNewPremanager", null)
    .subscribe((res: Response) => {
      let data = res.json();
      console.log(data);
      this.hasNewPremanager = data;
    }, error => {
      this.appService.alert('网络异常!');
    }
    );
  }

}
//定义星期实体
export class Week {
  id: number;
  title: string;
  date: number;
  isToday: boolean = false;
}