<template>
  <view>
    <u-sticky bgColor="#fff" customNavHeight="0" offsetTop="0">
      <u-search placeholder="搜索感兴趣的内容" v-model="keyword" :show-action="false" margin="30rpx 34rpx 15rpx 34rpx"
        borderColor="rgb(230, 230, 230)" height="74rpx" bgColor="#F5F6FA" @search="search"></u-search>
      <u-tabs :list="tabList" :activeStyle="{'color': '#cf000d','font-weight':'bold'}" lineWidth="30rpx"
        lineHeight="4rpx" lineColor="#cf000d" @click="tabChange"></u-tabs>
    </u-sticky>
    <u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" v-if="NewsList.length <= 0"></u-empty>
    <newsList v-for="(item,index) in NewsList" :key="index" :newItem="item" v-else></newsList>
  </view>
</template>

<script>
  import newsList from '@/components/news-list/news-list.vue'
  import {
    getInfoMarketInformationlist
  } from '@/api/infoMarketInformation.js'
  import {
    listSimpleDictDatas
  } from '@/api/dict.js'
  import keyboard from '../../uni_modules/uview-ui/libs/config/props/keyboard'
  export default {
    components: {
      newsList
    },
    props: {

    },
    data() {
      return {
        keyword: "",
        current: 0,
        tabList: [{
          name: "全部",
          key: -1
        }, {
          name: "宏观经济",
          key: 0
        }, {
          name: "产业政策",
          key: 1
        }, {
          name: "行业动态",
          key: 2
        }, {
          name: "友商动态",
          key: 3
        }, {
          name: "用户资讯",
          key: 4
        }, {
          name: "国际能源",
          key: 5
        }],
        NewsList: [],
        queryParameter: {
          keyword: "",
          plate_name: ""
        }
      }
    },
    computed: {

    },
    onLoad() {
      this.initData()
    },
    methods: {
      initData() {
        // this.updateList()
        getInfoMarketInformationlist().then(res => {
          console.log(res);
          if (res.code === 200) {
            this.NewsList = res.rows
            console.log(this.NewsList);
          }
        })
      },
      search() {
        console.log("搜索");
        if (this.keyword) {
          this.updateList({
            keyword: this.keyword
          })
        }
      },
      updateList() {
        let Params
        if (this.keyword && this.current !== -1) {
          Params = {keyword: this.keyword,plateName: this.current}
        } else if (this.keyword) {
          Params = {keyword: this.keyword,}
        } else if (this.current !== -1) {
          Params = {plateName: this.current}
        }
        getInfoMarketInformationlist(Params).then(res => {
          console.log(res);
          if (res.code === 200) {
            this.NewsList = res.rows
            console.log(this.NewsList);
          }
        })
      },
      tabChange(e) {
        console.log(e);
        this.current = e.key
        this.updateList()
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>