<?php

namespace App\Web\Components\Meeting;

use App\Exceptions\ApiException;
use App\Web\Facades\MeetingFacade;
use App\Web\Facades\WebFacade;
use App\Web\Services\MeetingService;
use Illuminate\View\Component;

class MeetingGlobalList extends Component
{
    protected $page; //这是参数
    protected $pageSize;
    protected $viewFile; //视图地址
    protected $typeIds;
    protected $tagIds;
    protected $keyword;
    protected $country;
    protected $expo_date;
    protected $router_path;


    public function __construct($viewFile = "", $params = [], $page = 1, $pageSize = 10,$routerPath = '', $typeIds = [], $tagIds = [], $keyword = '', $country = '', $expo_date = '')
    {
        if (empty($viewFile)) {
            throw new ApiException("common.page_none", '您访问的地址不存在~');
        }
        $this->page = isset($params['page']) ? $params['page'] : $page;
        $this->pageSize = isset($params['page_size']) ? $params['page_size'] : $pageSize;
        $this->typeIds = isset($params['type_ids']) ? $params['type_ids'] : $typeIds;
        $this->tagIds = isset($params['tag_ids']) ? $params['tag_ids'] : $tagIds;
        $this->keyword = isset($params['keyword']) ? $params['keyword'] : $keyword;
        $this->country = isset($params['country']) ? $params['country'] : $country;
        $this->expo_date = isset($params['expo_date']) ? $params['expo_date'] : $expo_date;
        $this->router_path = isset($params['router_path']) ? $params['router_path'] : $routerPath;
        $this->viewFile = $viewFile;
    }


    /**
     * 资讯列表组件
     */
    public function render()
    {
        $params = [
            "page" => $this->page,
            "page_size" => $this->pageSize,
            "type_ids" => $this->typeIds,
            "tag_ids" => $this->tagIds,
            "keyword" => $this->keyword,
            "country" => $this->country,
            "expo_date" => $this->expo_date,
        ];
        $params['status'] = 0;
        $params['sort']['start_date'] = 1;
        $params['is_paginate'] = 1;
        $retData = MeetingFacade::getPublishMeetingList($params);
        if (!empty($this->router_path)) {
            $pageContent = WebFacade::getStaticPageInfo(['route_path' => $this->router_path]);
            $retData['page_content'] = $pageContent['page_content'];
            $retData['router_path'] = $this->router_path;
        }
        $retData['global_data_list'] = MeetingFacade::getGlobalFilter(1,0);
        $retData['global_data_list_s'] = MeetingFacade::getGlobalFilter(1,1);
        //dd($retData);
        $retData['menu_data']=WebFacade::getWebMenu();
//        dd($retData);
        return view($this->viewFile, $retData);
    }

}
