<template>
    <!--查询组件2开始-->
<div class="common_infoquery_pc_2">
   <div class="container">
      <div class="row">
         <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="search-part">
               <span class="search-part-body">
                  <input type="text" v-model="title" placeholder="" class="search-part-inp">
                  <input type="button" @click="isearch" value="全站检索" class="search-part-btn">
               </span>
            </div>
         </div>
      </div>
      <div class="row">
         <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="search-result-hd">
               <ul>
                  <li class="active" @click="project('',$event)" ><a href="javascript:void(0)">全部</a></li>
                  <li @click="project('资讯',$event)"><a href="javascript:void(0)">资讯</a></li>
                  <li @click="project('课程',$event)"><a href="javascript:void(0)">课程</a></li>
                  <li @click="project('活动',$event)"><a href="javascript:void(0)">活动</a></li>
                  <li @click="project('班级',$event)"><a href="javascript:void(0)">班级报名</a></li>
                  <li @click="project('直播',$event)"><a href="javascript:void(0)">直播</a></li>
               </ul>
            </div>
            <div class="search-result-bd">
               <ul class="search-result-listul">
                  <li class="clearfix" v-for="(list,i) in resArr" :key="i"><i>{{list.type}}</i>
                    <a v-if="list.type=='资讯'" :href="'/infodetail?id='+list.id">{{list.title}}</a>
                    <a v-if="list.type=='课程'" :href="'/coursedetail?id='+list.id">{{list.title}}</a>
                    <a v-if="list.type=='活动'" :href="'/activedetail?id='+list.id">{{list.title}}</a>
                    <a v-if="list.type=='直播'" :href="'/livedetail?id='+list.id">{{list.title}}</a>
                    <a v-if="list.type=='班级'" :href="'/classregdetail?id='+list.id">{{list.title}}</a>
                  <span>{{list.pubDate | $toDate}}</span></li>

               </ul>
            </div>
         </div>
      </div>
      <div style="margin-top:30px;">
        <el-pagination
         background
         layout="total, sizes, prev, pager, next, jumper"
         :page-sizes="[10, 20, 50, 100]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :total="totalCount">
        </el-pagination>
      </div>

   </div>
</div>
<!--查询组件2结束-->
</template>

<script>
import formMixin from "../../../src/mixins/formMixin";
import lenye_base from "lenye_base";
import $ from "fy-kit";
import msg from "../../message";
import pagination from "../../pagination";

export default {
  name: "ElSearch1",
  mixins: [formMixin],
  props: {
    placeholder: {
      type: String,
      default: "总访问量a"
    }
  },
  components: {
    msg,
    pagination
  },
  filters:{
      $toDate(){

      }
  },
  computed: {
    defaultAttrs() {
      return {
        placeholder: this.t("ele-form.input") + this.desc._label
      };
    }
  },
  data() {
    return {
         currentPage4: 1,
         title:'',
         resArr:[],
         totalCount:0,
         rows:10,
         page:1
    };
  },

  mounted() {
      this.title = $.util.urlParams("isearch") || '';
    this.init();
  },
  methods: {
    handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.rows = val;
         this.isearch();
    },
    handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.page = val;
        this.isearch();
    },
    init() {
     this.isearch()
    },
    isearch(){
        var title = {
             type:this.name,
             siteId:lenye_base.user_data.getuserData().siteId
        };
        if (this.title){
            title['title'] = this.title;
        }
         $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/lucene-service/common/pageQuery.do",
          lenye_base.base_data.getformatting({
            indexName: 'site',
            queryType: 1,
            rows: this.rows,
            page:this.page,
            sorts: '',
            queryParams: JSON.stringify(title)
          })
        )
        .then(res => {
          if (res.success == "1") {

              this.resArr = res.data;
              this.totalCount = res.totalCount;
          } else {
            msg.error(res.message);
          }
        });
    },
    project(name,ev){
        this.name = name;
        this.resArr = [];
        var ele = $._.default(ev.target);
         ele.parent('li').addClass('active').siblings('li').removeClass('active');
        this.isearch();
    }
  }
};
</script>
