<template>
  <div>
    <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" @click="gotoHome" style="cursor: pointer">
            <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="">
              <el-tabs v-model="searchType" type="card">
                <el-tab-pane v-for="item in tabArr" :label="item.label" :name="item.name" :key="item.label"></el-tab-pane>
              </el-tabs>
              <div class="search-input">
                <el-input placeholder="请输入内容" v-model="searchVal" class="input-with-select">
                  <el-button class="search-button" slot="append"  type="primary" @click="handleSearchData">搜索</el-button>
                </el-input>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="6">
          <el-button type="primary pull-right" class="releaseBtn" @click="checkLogin()">免费发布众测需求</el-button>
        </el-col>
      </el-row>
      <div>
      </div>
    </div>
    <div class="mine-body" style="text-align: center;">
      <el-tabs value="myProject" v-loading="loading" style="width: 90%;margin-left: 5%">
        <el-tab-pane name="myProject" v-if="currTab == 'project'">
          <span v-if="projectList == null || projectList.length == 0"> 暂无项目 </span>
          <el-row v-if="projectList != null && projectList.length != 0" type="flex" align="middle" justify="center"
                  style="font-size: 14px;">
            <el-col :span="6" type="flex" align="middle" justify="center">项目图片</el-col>
            <el-col :span="6" type="flex" align="middle" justify="center">项目名称</el-col>
            <el-col :span="3" type="flex" align="middle" justify="center">应用类型</el-col>
            <el-col :span="3" type="flex" align="middle" justify="center">项目预算</el-col>
            <el-col :span="3" type="flex" align="middle" justify="center">参与人数</el-col>
            <el-col :span="4" type="flex" align="middle" justify="center">操作</el-col>
          </el-row>
          <project-item v-if="(projectList != null || projectList.length > 0 )"
                                    v-for="(item,index) in projectList" :key="index" :projectItem="item"/>
        </el-tab-pane>
      </el-tabs>
    </div>

    <div class="container">
      <el-row>
        <el-col :span="18" class="project-task">
          <el-pagination
            v-if="currTab!=='squareHome'&&projectList&&projectList.length"
            :page-size="10"
            layout="prev, pager, next"
            :total="totalElements"
            :current-page = "activePage"
            @current-change="handlePageChange"
            class="pull-right"
          >
          </el-pagination>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
    import Http from '@/js/http.js'
    import Apis from '@/js/api.js'
    import SearchBar from '../../components/commons/SearchBar'
    import {notify} from "../../constants"
    import ProjectItem from '../../components/commons/ProjectItem'
    import {defaultValue, storageGet} from '@/js/index'
    export default {
        name: 'CrowdDetail',
        comments: {ProjectItem},
        data(){
            return {
                loading: false,
                isLogin: false,
                searchType:'project',
                searchVal: '',
                currTab:'project',
                tabArr : [
                    {label:"众测项目",name:"project"},
                ],
                projectList:[],
                activePage:1,
                totalElements:0,
                code: ''
            }
        },
        components: {
            ProjectItem,
            SearchBar,
        },
        computed:{
        },
        methods:{
            loadData(){
                this.showLoading();
                if (storageGet('user') != null) {
                    this.isLogin = true;
                }
                this.code = this.$route.params.code;
                this.getCrowdProject();
                this.hideLoading();
            },
            getCrowdProject(){
                let params = {
                    "keyword": this.searchVal,//搜索关键字
                    "activePage": this.activePage,//指定页面
                    "columnFilters":[]
                };
                Http.post(Apis.PROJECT.CROWD_PROJECT.replace('{code}', this.code), params).then((res) => {
                    this.projectList = res.data.content;
                    this.totalElements = res.data.totalElements;
                    console.log(this.projectList)
                })
            },
            gotoHome(){
                this.$router.push('/home');
            },
            checkLogin(){
                if(!this.isLogin){
                    console.log("请登录后访问");
                    notify('warning','请登录后访问');
                }else{
                    console.log("已登录");
                    this.$router.push('/project/create');
                }
            },
            handleSearchData(){
                this.getCrowdProject();
            },
            handlePageChange(index){
                this.activePage = index;
                this.getCrowdProject();
            },
            showLoading () {
                this.loading = true
            },
            hideLoading () {
                this.loading = false
            },
        },
        mounted() {
            this.loadData();
        }
    }
</script>

<style lang="less">
  @import "../../style/search-nav";
  .project-task {
    padding: 15px 0;
    .el-card {
      border: none;
    }
  }

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


  .mine-container {
    padding: 0 80px 40px 80px;
  }

  .mine-top-wrapper {
    height: 350px;
    background-color: #fff;
  }

  [class*="el-col-"] {
    height: 100%;
  }

  .advertise-imgs {
    height: 100%;
  }

  .advertise-imgs img {
    width: 100%;
    height: 100%;
  }

  .user-banner {
    text-align: center;
    display: inline-table;
    height: 100%;
    width: 100%;
    margin-top: 40px;
  }

</style>
