<?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 SolutionList extends Component
{
    protected $page; //这是参数
    protected $pageSize;
    protected $viewFile; //视图地址
    protected $typeId;
    protected $tagId;
    protected $plateId;
    protected $keyword;
    protected $router_path;


    /**
     * @throws ApiException
     */
    public function __construct($viewFile = '', $params = [], $keyword = '', $typeId = 0, $tagId = 0,$routerPath='', $page = 1, $pageSize = 10)
    {
        if (empty($viewFile)) {
            throw new ApiException('common.page_none', '您访问的地址不存在~');
        }
        $this->keyword = $params['keyword'] ?? $keyword;
        $this->page = $params['page'] ?? $page;
        $this->pageSize = $params['page_size'] ?? $pageSize;
        $this->typeId = $params['type_id'] ?? $typeId;
        $this->tagId = $params['tag_id'] ?? $tagId;
        $this->router_path = $params['router_path'] ?? $routerPath;
        $this->plateId = BlogPlateModel::SOLUTION;
        $this->viewFile = $viewFile;
    }

    /**
     * 资讯列表组件
     */
    public function render()
    {
        $retData = BlogRenderFacade::getPublishBlogList(
            $this->plateId,
            $this->keyword,
            $this->page,
            $this->pageSize,
            ['pub_date'],
            (int)$this->typeId,
            (int)$this->tagId
        );
        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);
    }
}
