<!--
   * @Descrip: 主页
 * @Author: your name
 * @Date: 2019-10-10 14:25:15
 * @LastEditTime: 2019-11-14 09:56:22
 * @LastEditors: Please set LastEditors
   -->
<template>
  <h-view id="homePage" class="public-style" title="演示demo">
    <h-header :proportion="[3,6,1]" :hasBorder="false">
      <div slot="left" class="h-header-btn">
        <h2>煤科广场</h2>
      </div>
      <div slot="center" class="search">
        <i class="icon ion-ios-search-strong"/>
        <input placeholder="请输入搜索关键词">
      </div>
    </h-header>
    <h-content class="has-footer">
      <!--      <div class="top-wrap"/>
      <div class="top-wrap-white"/>
      <swipe :interval="5000" class="hls-swipe">
        <swipe-item class="hls-swipe">
          <img src="@/assets/homePage/banner6.jpg" alt="">
        </swipe-item>
        <swipe-item class="hls-swipe">
          <img src="@/assets/homePage/banner7.jpg" alt="">
        </swipe-item>
        <swipe-item class="hls-swipe">
          <img src="@/assets/homePage/banner8.jpg" alt="">
        </swipe-item>
      </swipe>-->
      <div class="card">
        <div class="card-body">
          <h4>Hi，今日为你推荐</h4>
          <div class="time">
            <h2>
              {{ new Date().getDate() }}
            </h2>
            <div class="line"/>
            <div class="date">
              <span>{{ getMonth }}</span>
              <span>{{ new Date().getFullYear() }}</span>
            </div>
          </div>
          <h2>
            学习贯彻习近平新时代中国特色社会主义思想教育主题
          </h2>
        </div>

      </div>
      <div class="news">
        <div class="news-top">
          <div class="news-top-title">
            集团新闻
          </div>
          <div class="news-top-more" @click="gotoNews()">
            更多 》
          </div>
        </div>
        <div class="news-items vue-1px-b">
          <div v-for="(item,index) in newsList" v-if="index<5" :key="item.index" class="news-item">
            <div class="news-item-num">{{ '0'+Number(index+1) }}</div>
            <div class="news-item-title">{{ item.new_title }}</div>
          </div>
        </div>
      </div>

      <div class="news-cards">
        <div class="news-card" v-for="item in newCard" key="item.index">
          <div class="news-card-left">
            <div class="news-card-left-title">
              <div class="news-card-left-title-tip">{{item.tip}}</div>
              <div class="news-card-left-title-title">{{item.title}}</div>
            </div>
            <div class="news-card-left-content">
              <div class="company">{{item.company}}</div>
              <div class="line"></div>
              <div class="company">{{item.time}}</div>
            </div>
          </div>
          <div class="news-card-right">
            <img :src="item.imgUrl">
          </div>
        </div>
      </div>

    </h-content>
  </h-view>
</template>
<script>

export default {
  name: 'HomePage',
  data () {
    return {
      user_bp_status: '',
      user_bp_class: '',
      bp_id: '',
      isVisitor: false,
      newsList: [],
      newCard: [
        {tip: '专题', title: '喜迎二十大·煤科建新功', time: '2023-12-23', company: '中国煤炭科工集团', imgUrl: 'https://manager.ccteg.cn/uploads/images/42bdfb3b46502ccf34990387666b9f55.png'},
        {tip: '媒体聚焦', title: '突破世界级难题、创造世界记录', time: '2023-11-02', company: '中国煤炭科工集团', imgUrl: 'https://manager.ccteg.cn/uploads/images/9928278f516b0a82aecd3d7bc72002a4.png'},
        {tip: '煤科硬核', title: '喜迎二十大·煤科建新功', time: '2023-12-12', company: '中国煤炭科工集团', imgUrl: 'https://manager.ccteg.cn/uploads/images/214a37b186e9cdf9a66c9a35fcbef2ab.png'}],
    }
  },
  computed: {
    getMonth () {
      const month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Spt', 'Oct', 'Nov', 'Dec']
      return month[new Date().getMonth()].toUpperCase()
    },
  },
  watch: {},
  created () {
    // this.getLocation()
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      // if (from.name === 'Login') {
      if (window.localStorage.getItem('user_phone')) {
        vm.userQuery()
      }
      // vm.guessingQuery() // 猜你喜欢查询
      vm.isVisitor = !window.localStorage.getItem('password')
      // vm.guessingQuery() // 猜你喜欢查询
      vm.getNews()
      //  }
    })
  },
  methods: {
    // 新闻资讯
    getNews () {
      let url = $config.basePath + 'news_entrance_list'
      let param = {}
      this.$post(url, param).then((res) => {
        this.hlsPopup.hideLoading()
        if (res.result === 'S') {
          this.newsList = res.lists
        } else {
          hlsPopup.showLongCenter(res.message)
        }
      })
    },
    goModuleFunction (data) {
      let vm = this
      if (this.isVisitor && data.moduleState !== 'FinancingTrial') {
        hlsPopup.showConfirm({
          title: '提示',
          content: `请先登录！`,
          onConfirm: data => {
            if (data) {
              vm.$router.push('/login')
            } else {
            }
          },
        })
      } else {
        this.$router.push({
          name: data.moduleState,
        })
      }
    },
    gotoNews () {
      this.$router.push({
        name: 'NewsList',
      })
    },
    // 用户信息查询
    userQuery () {
      // let vm = this
      // let url = $config.basePath + 'user_query'
      // let param = {
      //   'bp_id': window.localStorage.getItem('user_phone'),
      // }
      // vm.hlsPopup.showLoading('数据加载中')
      // vm.$post(url, param).then(function (res) {
      //   vm.hlsPopup.hideLoading()
      //   if (res.result === 'S') {
      //     window.localStorage.setItem('bp_type', res.info.user_bp_type)
      //     // window.localStorage.setItem('user_phone', res.info.user_phone)
      //     vm.user_bp_status = res.info.user_bp_status
      //     vm.user_bp_class = res.info.user_bp_class
      //     vm.bp_id = res.info.user_bp_id
      //   } else {
      //     hlsPopup.showLongCenter(res.message)
      //   }
      // })

      this.user_bp_status = JSON.parse(window.localStorage.getItem('now_user_bp_bind_id')).bp_status
      this.user_bp_class = JSON.parse(window.localStorage.getItem('now_user_bp_bind_id')).bp_class
      this.bp_id = JSON.parse(window.localStorage.getItem('now_user_bp_bind_id')).bp_id
    },

    // 进入产品明细
    goProductDetail (list) {
      let vm = this
      if (!window.localStorage.getItem('password')) {
        hlsPopup.showConfirm({
          title: '提示',
          content: `请先登录！`,
          onConfirm: data => {
            if (data) {
              vm.$router.push('/login')
            } else {
            }
          },
        })
      } else {
        this.$router.push({
          name: 'ProDetailed',
          params: {
            product_id: list.product_id,
            bp_id: list.bp_id,
          },
        })
      }
    },
  },
}
</script>
<style lang='less'>
  @import "../../styles/vue-1px";

  #homePage {
    .content {
      background-image: linear-gradient(180deg, #FFFFFF 0%, #F9F9F9 68%);
      padding: 0 6px;

      .card {
        background: url("../../assets/homePage/home-card@2x.png") no-repeat;
        background-size: 100% 100%;
        height: 160px;

        &-body {
          width: 60%;
          float: right;
          padding: 20px 10px;

          h4 {
            font-size: 12px;
            color: rgba(255, 255, 255, 0.80);
            // text-align: center;
            font-weight: 400;
            margin-bottom: 0;
          }

          h2 {
            font-size: 14px;
            color: #FFFFFF;
            font-weight: 700;
            margin-bottom: 0;
          }

          .time {
            color: #FFFFFF;
            // text-align: center;
            display: flex;
            align-items: center;
            height: 30px;
            margin: 10px 0 16px 0;

            h2 {
              font-size: 27px;
              font-weight: 700;
              color: #FFFFFF;
              margin-bottom: 0;
              margin-right: 5px;
            }

            .line {
              border-left: 1px solid #fff;
              height: 25px
            }

            .date {
              margin-left: 5px;
              display: flex;
              flex-direction: column;
              font-size: 12px;
            }
          }
        }
      }
    }

    .h-header .h-header-left .h-header-btn h2 {
      font-size: 18px;
      color: #000000;
      text-align: center;
      font-weight: 700;
      margin-bottom: 0;
    }

    .h-header .h-header-left .h-header-btn:first-of-type {
      padding-left: 0.2rem;
    }

    .h-header .h-header-center {
      height: 32px;
      background: #F0F1F3;
      border-radius: 16px;

      .search {
        width: 100%;
        height: 32px;
        line-height: 32px;
        font-size: 14px;
        display: flex;
        justify-content: space-between;
        padding: 0 15px;

        .icon {
          font-size: 18px;
        }

        input {
          background-color: transparent;
          margin-left: 10px;
          width: 100%;
        }
      }
    }

    .news {
      height: auto;
      width: 100%;
      margin: 0 auto 10px;
      border-radius: 10px;
      padding: 10px;

      &-top {
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: space-between;

        &-title {
          font-size: 16px;
          color: #000000;
          font-weight: 600;
        }

        &-more {
          font-size: 12px;
          color: #C9CACC;
          font-weight: 500;
        }
      }

      &-items {
        padding-bottom: 10px;
      }

      &-item {
        height: 30px;
        line-height: 30px;
        display: flex;
        margin: 10px 0;
        width: 100%;

        &-num {
          font-size: 18px;
          font-weight: 700;
          color: #F6B358;
          margin-right: 10px;
        }

        &-title {
          font-size: 14px;
          color: #000000;
          letter-spacing: 0.4px;
          font-weight: 400;
          width: 100%;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }

    }

    .news-cards{
      .news-card{
        display: flex;
        align-items: center;
        background: #FFFFFF;
        box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.05);
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 12px;
        &-left{
          width: 70%;
          height: 80px;
          display: flex;
          flex-direction: column;
          justify-content: space-between;

          &-title {
            display: flex;
            height: 20px;
            line-height: 20px;
            font-size: 14px;
            color: #000000;
            font-weight: 500;
            &-tip{
              font-size: 12px;
              font-weight: bold;
              color: #F6B358;
              border: 2px solid #F6B358;
              padding: 2px;
              border-radius: 4px;
              line-height: 14px;
              margin-right: 4px;
              max-width: 60px;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
            }
            &-title{
              width: 70%;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
            }
          }
          &-content{
            display: flex;
            font-size: 12px;
            align-items: center;
            color: #C9CACC;
            font-weight: 500;
            height: 17px;

            .company{
              margin-right: 4px;
            }
            .line{
              height: 15px;
              border-left: 1px solid #C9CACC;
              margin-right: 4px;
            }
          }
        }

        &-right{
          width: 30%;
          img {
            height: 80px;
            width: 100%;
            border-radius: 4px;
          }
        }
      }
    }
  }
</style>
