<?php

namespace App\Web\Components\Blog;

use App\Exceptions\ApiException;
use App\Web\Facades\BlogRenderFacade;
use App\Web\Facades\WebFacade;
use App\Web\Models\BlogPlateModel;
use App\Web\Services\WebService;
use Illuminate\View\Component;

class Partners extends Component
{
    protected $page; //这是参数
    protected $pageSize;
    protected $viewFile; //视图地址
    protected $typeId;
    protected $plateId;
    protected $router_path;


    /**
     * @throws ApiException
     */
    public function __construct($viewFile = '', $params = [], $typeId = 0, $page = 1, $pageSize = 10,$routerPath='')
    {

        if (empty($viewFile)) {
            throw new ApiException('common.page_none', '您访问的地址不存在~');
        }
        $this->page = $params['page'] ?? $page;
        $this->pageSize = $params['page_size'] ?? $pageSize;
        $this->typeId = $params['type_id'] ?? $typeId;
        $this->plateId = BlogPlateModel::PARTNERS;
        $this->router_path = $params['router_path'] ?? $routerPath;
        $this->viewFile = $viewFile;
    }


    /**
     * 合作伙伴列表组件
     */
    public function render()
    {
        $retData['partners'] = BlogRenderFacade::getPublishBlogList(
            $this->plateId,
            '',
            $this->page,
            $this->pageSize,
            [],
            (int)$this->typeId,
            0,
            'a.id,a.title,a.image_url,a.image_alt'
        );
        $retData['areas'] = BlogRenderFacade::getPublishedTypeList($this->plateId);
        if (!empty($this->router_path)) {
            $pageContent = WebFacade::getStaticPageInfo(['route_path' => $this->router_path]);
            $retData['page_content'] = $pageContent['page_content'];
        }
        $retData['menu_data']=WebFacade::getWebMenu();
        //dd($retData);
        return view($this->viewFile, $retData);
    }

}
