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

@Component({
  selector: 'app-weixin-processor-page',
  templateUrl: './weixin-processor-page.component.html',
  styleUrls: ['./weixin-processor-page.component.scss']
})
export class WeixinProcessorPageComponent extends FramePageComponent implements OnInit {

  wxDefine: any;
  constructor(private router: Router, private cookies: CookieService,  modalService: BsModalService) {
    super(modalService);
    // 获取缓存中的微信编号
    const wx_id = this.cookies.get('CurrentWxId');
    if (wx_id !== undefined && wx_id.length > 0 ) {
      // 去获取
      AjaxService.requestEntity('weixin/define/find.htm', {wx_id: wx_id}, (entity) => {
        this.wxDefine = entity;
        setTimeout( () => {
          if (this.pager) {
            this.pager.reload({wx_id: this.wxDefine.wx_id});
          }
        }, 1);
      });
    } else {
      this.router.navigate(['/weixin/define/page']) ;
    }
    this.modalComponent = WeixinProcessorDetailComponent;
  }

  ngOnInit() {
  }

}
