import { Component, OnInit } from '@angular/core';
import {CookieService} from 'ngx-cookie-service';
import {Router} from '@angular/router';
import {LayoutMaterialAppointmentDetailComponent} from '../layout-material-appointment-detail/layout-material-appointment-detail.component';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { BsModalService } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../../core/service/ajax.service';

@Component({
  selector: 'app-layout-material-appointment',
  templateUrl: './layout-material-appointment.component.html',
  styleUrls: ['./layout-material-appointment.component.scss']
})
export class LayoutMaterialAppointmentComponent  extends FramePageComponent implements OnInit {
  agent: any;
  order_field = 'arrange_country_total';

  constructor(private router: Router, private cookies: CookieService, modalService: BsModalService) {
    super(modalService);
    this.modalComponent = LayoutMaterialAppointmentDetailComponent;
    // 获取缓存中的微信编号
    const agent_id = this.cookies.get('CurrentAgentId');
    this.agent = {};
    if (agent_id !== undefined && agent_id.length > 0) {
      // 去获取
      AjaxService.requestEntity('layout/agent/find.htm', {ly_agent_id: agent_id}, (entity) => {
        this.agent = entity;
        setTimeout(() => {
          if (this.ajax) {
            this.ajax.reload();
          }
        }, 1);
      });
    } else {
      this.router.navigate(['/art/layout/agent/page']);
    }
  }


  ngOnInit() {
  }

  //取消预约
  cancelAppointment() {
    this.MsgService.confirmAlert('确定要取消预约吗？请谨慎操作！', () => {
      this.AjaxService.request('layout/group/appointment/cancel.htm', {ly_agent_id: this.agent.ly_agent_id}, () => {
        this.MsgService.successAlert('取消成功！');
        this.ajax.reload();
      }, {RequestWithLoading: true});
    });
  }

  downloadByTime() {
    this.FuncService.ajaxDownload('rpt/layout/interview/arrage/time.htm' ,{ly_agent_id: this.agent.ly_agent_id});
  }

}
