<template>
  <div class="technology-container">
    <div class="nav" stype="height:500px">
      <!--搜索框-->
      <el-row class="search-nav" style="padding: 30px 0 20px 0">
        <el-col :span="6">
          <div class="pull-left">
            <img class="logo-img" src="../../assets/img/logo-blue.png"/>
            <span class="logo-title">群智众测平台</span>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="search-nav">
            <div id="search-block " class="">
              <div class="search-input">
                <el-input placeholder="请输入内容" v-model="searchVal" class="input-with-select">
                  <el-button class="search-button" slot="append"  type="primary" @click="loadTechnologyArticles">搜索</el-button>
                </el-input>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="6">
          <el-button type="primary pull-right" class="releaseBtn">免费发布众测需求</el-button>
        </el-col>
      </el-row>
      <!--TabNav-->
      <el-tabs v-model="searchType" @tab-click="handleTabClick" class="square-tab">
        <el-tab-pane v-for="item in searchTypeArr" :name="item.value" :key="item.value">
          <span slot="label" style="font-size: 18px">{{item.name}}</span>
        </el-tab-pane>
      </el-tabs>
      <div>
      </div>
    </div>
    <div class="container" style="margin: 15px auto">
      <el-row>
        <el-col :span="18" class="project-task">
          <TechnologyCard
            :techArticleList = techArticleList.content v-if="searchType=='0'" @refreshList="loadTechnologyArticles">
          </TechnologyCard>
          <TechnologyMG :techArticleList = techArticleList.content v-if="searchType=='1'"></TechnologyMG>
          <el-pagination
            v-if="techArticleList.content&&techArticleList.content.length"
            :page-size="10"
            layout="prev, pager, next"
            :total="techArticleList.totalElements"
            @current-change="handlePageChange"
            :current-page = activePage
            class="pull-right"
          >
          </el-pagination>
        </el-col>
        <el-col :span="6"  class="popular-modules">
          <HotActicle :articleArr="articleArr"/>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
  import Http from '@/js/http.js'
  import SearchBar from '../../components/commons/SearchBar'
  import TechnologyCard from './TechnologyCard'
  import TechnologyMG from './TechnologyMG'
  import HotActicle from './HotActicle'
  import PopularProject from '../Square/PopularProject'
  import qs from 'querystring'
  import { mapActions ,mapGetters} from 'vuex';

  export default {
    name: 'Technology2.0',
    components: {
      SearchBar,
      TechnologyCard,
      TechnologyMG,
      PopularProject,
      HotActicle
    },
    data(){
      return {
        searchVal: '',
        searchType:'',
        searchTypeArr:[
          {
            "name": "技术文章",
            "value": "0"
          },
          {
            "name": "论文专著",
            "value": "1"
          }
        ],
        articleArr:[],
        keyword:"",
        activePage:1,
        techArticleList:{},
      }
    },
    methods:{
      handleTabClick(tab){
        this.searchType = tab.name
        this.activePage = 1;
        this.searchVal = '';
        this.loadTechnologyArticles();
      },
      loadHotArticles(){
        Http.get('/api/technical/ranking').then((res)=>{
          this.articleArr = res.data.technicalArticlesPage.content;
        })
      },
      loadTechnologyArticles(){
        // let url=`/api/technical/articles?searchCondition={"keyword":"${this.keyword}","activePage":${this.activePage}}`;
        // Http.get(encodeURI(url))
        let url = '/api/technical/articles';
        let params = {
          "keyword": this.searchVal,//查询条件，分页展示时就不填
          "activePage": this.activePage,//指定页数
          "columnFilters": [
            {
              "field": "type",
              "type": "enums",
              "enums": this.searchTypeArr,
              "value": this.searchType//展示技术文章value为0
            }
          ]
        }
        Http.post(url,params)
          .then(res=>{
            if(res.data.technicalArticlesPage){
              this.techArticleList = res.data.technicalArticlesPage;
              this.searchType = '0';
            }
            else if(res.data.publicationsPage){
              this.techArticleList = res.data.publicationsPage;
              this.searchType = '1';
            }
          })
      },
      handlePageChange(index){
        this.activePage = index;
        this.loadTechnologyArticles();
      }
    },
    mounted() {
      this.loadHotArticles();
      this.loadTechnologyArticles();
    }
  }
</script>

<style lang="less">
  @import "../../style/search-nav";
  .technology-container {
    /deep/ .search-input,/deep/ .releaseBtn{
      margin: 20px 0 0 0 !important;
    }

    .popular-modules {
      padding-left: 15px;
    }

  }

</style>
