import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { BsModalService } from 'ngx-bootstrap/modal';
import { CookieService } from 'ngx-cookie-service';
import { MsgService } from 'src/app/core/service/msg.service';
import { FramePageComponent } from 'src/app/routes/frame/core/page/frame.page';

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

  subjectArr = [];
  agent:any;

  constructor(private router: Router, private cookies: CookieService, private modalService: BsModalService) { 
    super(modalService);
    // 获取缓存中的微信编号
    const agent_id = this.cookies.get('CurrentAgentId');
    if (agent_id !== undefined && agent_id.length > 0) {
      // 去获取
      this.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(): void {
    this.listSubject();
  }

  listSubject() {
    this.AjaxService.requestArray('ly/topic/subject/list.htm',{agent_id: this.agent.agent_id}, (array)=> {
      this.subjectArr = array;
    });
  }

  uploadCallback(ajax) {
    MsgService.successAlert('导入成功!');
  }
}
