<template>
  <div class="homepage" >
    <div class="content ">
      <div class="banner">
        <!-- <el-carousel trigger="click" height="4.21rem" width="100%" class="car">
          <el-carousel-item v-for="(item,index) in picArr" :key="index">
              <img :src="item.picUrl" alt="" class="src-img">
          </el-carousel-item>
        </el-carousel> -->
        <img src="~/assets/images/back.png" style="height:5.3rem;width:100%">
      </div>
        <div class="loginbox">
          <div class="login"  >
            <div class="author" >
              <img src="~/assets/css/user.png">
            </div>
          <div class="login-title">{{userName}}</div>
          <div class="login-button t10" @click="loginuser" v-show="showDefault">用户登录</div>
          <div class="login-button t11" @click="Merchant" v-show="showDefault" >商家入驻</div>
          <div class="login-button" v-show="!showDefault" @click="pushH">管理后台</div>
          <div class="flex" style="margin-top:20px">
            <span v-show="showDefault">还没有账号?</span>
            <span class="font" @click="reg" v-show="showDefault"> 我要注册</span>
          </div>
        </div>
      </div>
    </div>
    <div class=" message">
      <div v-for="(item,index) in messageList" :key="index" class="message-item">
        <div class=" t12">{{item.head}}</div>
        <div >
          <img style="border-top:2px solid #D8D8D8" :src="item.src" alt="" >
          <div style="margin-top:30px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{''+item.title}}</div>
        </div>
      </div>
    </div>
   <div class="message flex-between">
      <div  class="dynamic-item">
        <div class="flex-between col">
          <div class="t3 " @click="latformDynamics">平台动态</div>
          <div class="more t1 list-con" @click="latformDynamics">更多></div>
        </div>
        <ul>
          <li v-for="(item,index) in dynamic1" :key="index" v-show="index<5" class="flex-between list-con" >
            <div @click="linkTo2(item.id)" class="newsSty">{{item.title}}</div>
            <div class="time">{{item.createTime.slice(0,10)}}</div>
          </li>
        </ul>
      </div>
      <div  class="dynamic-item">
        <div class="flex-between col">
          <div class="t3" @click="lawsRegulations">法律法规</div>
          <div class="more t1 list-con" @click="lawsRegulations">更多></div>
        </div>
        <ul>
          <li v-for="(item,index) in dynamic2" :key="index" v-show="index<5" class="flex-between list-con" >
            <div @click="linkTo1(item.id)" class="newsSty">{{item.title}}</div>
            <div class="time">{{item.createTime.slice(0,10)}}</div>
          </li>
        </ul>
      </div>
      <div  class="dynamic-item">
        <div class="flex-between col">
          <div class="t3" @click="newsInfo">新闻资讯</div>
          <div class="more t1 list-con" @click="newsInfo">更多></div>
        </div>
        <ul>
          <li v-for="(item,index) in dynamic3" :key="index" v-show="index<5" class="flex-between list-con" >
            <div @click="linkTo(item.id)" class="newsSty">{{item.title}}</div>
            <div class="time">{{item.createTime.slice(0,10)}}</div>
          </li>
        </ul>
      </div>
    </div> 
    
   <!-- <div class="content cooperation">
      <div class="cooperation-title t3">合作平台</div>
      <div class="flex-between">
        <div class="cooperation-item" v-for="item in 5">

        </div>
      </div>
    </div> -->
  </div>
</template>

<script>
import {getLoopPic} from '@/common/list.js'
import {getSecond,getListSite,getListSite1,getListSite2} from '@/common/list.js'
import Cookies from "js-cookie"
  export default {
    mounted(){
      this.getSecond()
      this.getLoopPic()
      this.getListSite()
      this.getListSite1()
      this.getListSite2()
    },
    async asyncData({ params, route, error }){
      let mes = {
        status:1
      }
      const {data} = await getLoopPic(mes)
      return{
        picArr:data,
      }
    },
    methods:{
      //注册
      reg(){
        this.$router.push("/login/examine")
      },
      //新闻
      linkTo(cateId){
        Cookies.set("detailsType",1)
        Cookies.set("detailsId",cateId)
        let url = "/message/news?id=123"
        Cookies.set("linktoUrl",url)
        this.$router.push(url)
        console.log(cateId+'-------------++++++++++++')
      },
      //法律
      linkTo1(cateId){
        Cookies.set("detailsType",1)
        Cookies.set("detailsId",cateId)
        let url = "/message/news?id=125"
        Cookies.set("linktoUrl",url)
        this.$router.push(url)
        console.log(cateId+'-------------++++++++++++')
      },
      //平台
      linkTo2(cateId){
        Cookies.set("detailsType",1)
        Cookies.set("detailsId",cateId)
        let url = "/message/news?id=124"
        Cookies.set("linktoUrl",url)
        this.$router.push(url)
      },
      latformDynamics(){
        this.$router.push("/message/news?id=124")
      },
      lawsRegulations(){
        this.$router.push("/message/news?id=125")
      },
      newsInfo(){
        this.$router.push("/message/news?id=123")
      },
      //平台动态跳转
      Merchant(){
        this.$router.push('/login/examine')
      },
      async getListSite(){
        let me = {}
        me.cateId = 124
        const {data,id} = await getListSite(me)
        this.dynamic1 = data
      },
      async getListSite1(){
        let mes = {}
        mes.cateId = 125
        const {data} = await getListSite1(mes)
        this.dynamic2 = data
      },
      async getListSite2(){
        let mess = {}
        mess.cateId = 123
        const {data} = await getListSite2(mess)
        this.dynamic3 = data
      },
      //添加验证方法
      async getSecond(){
        let tokenStr = Cookies.get('token')
        if(tokenStr){
          this.showDefault = false
          const {data} = await getSecond()
          Cookies.set("companyName",data.companyName)
          Cookies.set("isSupplier",data.type)
          this.userName = Cookies.get("companyName")
          /* let type=1
          sessionStorage.setItem("companyNameType",type) */
          let url = Cookies.get("Id")
              let Status = Cookies.get("status")
              if(Status =="1"){
                this.$router.push("/notice/enquirydetails?id="+url)
                Cookies.remove("status")
              }
          }
          let BIDID = Cookies.get("bidId")
          let SIGN = Cookies.get("sign")
          if(SIGN=="1"){
            this.$router.push("/notice/biddingdetails?id="+BIDID)
            Cookies.remove("sign")
          }
      },
      loginuser(){
        this.$router.push("/login/user")
      },
      async getLoopPic(){
        let message = {}
        message.status =1
        const {data} = await getLoopPic(message)
        this.picArr = data
      },
      //添加退出按钮 清空token
      checkout(){
        Cookies.remove("token")
        this.$router.push("/login/user")
      },
      pushH(){
        let token=Cookies.get("token")
        if(token){
          window.location.href=`http://60.205.251.80:8082/#/purchaser/Home?token=${token}`
        }
      }
    },
    data() {
      return {
        id:123,
        dataList:[],
        dynamic1:[],
        dynamic2:[],
        dynamic3:[],
        showDefault:true,
        userName:'Hi~欢迎来到捷安采',
        userHeader: '',
        picList:[],
        picArr:[],
        messageList: [{
            head: "基地直供专区",
            src: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1601376244670&di=5f449198437dbff6319c2c907fdf25b6&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20171026%2F35d7c15621094837aeed7a92c30503de.jpeg",
            title: "脱贫攻坚是一场直接关系到夺取决胜全面建成小康社会的硬仗和大仗，需要全国各行各业和全社会的高度关注和大力支持，更需要各地因地制宜、创新方式，开展卓有成效的扶贫帮困活动。在我国，许多贫困村地处偏远，农产品销售渠道不畅通，农产品滞销严重影响贫困户脱贫增收。北京学校基地直供平台开设“工会采购专区”旨在为贫困地区农产品拓展销售渠道，将当地优秀的农副产品由田间地头搬到学生餐桌的同时，也将它展示给在校老师。基地直供平台依托自身互联网优势，开设工会采购专区能更好的让贫困地区农产品流通在线化、数据化，提高了流通和交易效率"
          },
          {
            head: "扶贫专区",
            src:"http://photocdn.sohu.com/20111209/Img328459051.jpg",
            title: "中国交建与怒江的联系可以追溯到上世纪90年代，2002年起，按照国务院扶贫开发领导小组的统一部署开始对怒江州进行定点帮扶。自2013年以来，中交集团更是与云南省政府相继签订系列投资协议，分别在交通基础设施、城市综合体开发、轨道交通及其他相关领域建立了全面的战略合作关系，投资并实施了黄牛、生猪、山地鸡养殖，雪桃、重楼、秦艽、草果、白芨、火龙果种植，以及饲料加工等一系列产业扶贫项目，由“输血式”扶贫变为造血式扶贫，中交集团在怒江州的产业扶贫“造血运动”逐渐步入正轨。"
          },
          {
            head: "溯源食品专区",
            src: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1601376572620&di=5e9d369c751fee18a0f574bd755eb33a&imgtype=0&src=http%3A%2F%2Fimgeconomy.gmw.cn%2Fattachement%2Fjpg%2Fsite2%2F20171120%2Ff44d3075899d1b7c9c4245.jpg",
            title: "基原材料供应商在向食品厂家提供原材料时候进行批次管理，将原材料的原始生产数据制造日期、食用期限、原产地、生产者、遗传基因组合的有无使用的药剂等信息录入到二维码中并打印带有二维码的标签，粘贴在包装箱上后交与食品厂家。在食品厂家原材料入库时，使用数据采集器读取二维码，取得到货原材料的原始生产数据。从该数据就可以马上确认交货的产品是否符合厂家的采购标准。然后将原材料入库。"
          }
        ],
        dynamicList: [{
          title: "新闻资讯",
          list: ["国内建筑新动向", "国内建筑新动向", "国内建筑新动向", "国内建筑新动向", "国内建筑新动向"]
        }, {
          title: "法律法规",
          list: ["国内建筑新动向", "国内建筑新动向", "国内建筑新动向", "国内建筑新动向", "国内建筑新动向"]
        }, {
          title: "平台动态",
          list: ["国内建筑新动向", "国内建筑新动向", "国内建筑新动向", "国内建筑新动向", "国内建筑新动向"]
        }]
      }
    }
  }
</script>

<style scoped>
.src-img{
  cursor: pointer;
}
  .banner {
    width:100%;
    height: 4.21rem;
  }

  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 150px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }

  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }

  .login {
    width: 260px;
    height: 328px;
    border: .01rem solid rgba(220, 220, 220, 1);
    padding-bottom: .2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: absolute;
    /* left:1040px;
    top:214px; */
    top:-310px;
    right:0;
    background: #FFFFFF;
    z-index:9999
  }

  .login>.login-button {
    width:191px;
    height: 34px;
    line-height: .36rem;
    text-align: center;
    background-color: #FF5203;
    border-radius: 0.03rem;
    margin-bottom: 0.2rem;
    /* border: 1px solid rgba(4, 134, 254, 1); */
    font-size: .16rem;
    font-weight: 300;
    color: #FFFFFF;
    cursor: pointer;
  }

  .login>.author>img{
    /* margin-top: 0.6rem; */
    width: .60rem;
    height: .60rem;
    background: rgba(216, 216, 216, 1);
    border-radius: 50%;
  }

  .login>.author{
    margin-top: 0.2rem;
    width: .60rem;
    height: .60rem;
    border-radius: 50%;
    
  }
  .login>.login-title {
    font-size: .16rem;
    font-weight: 300;
    color: rgba(0, 0, 0, 1);
    margin: .3rem 0 .53rem 0
  }

  .message {
    padding-top: 1rem;
    width:12rem;
    margin:0 auto
  }

  .message-item {
    margin-bottom: 0.2rem;
  }

  .message-item>div>img {
    width:/*  8.80rem; */12rem;
    height: /* 5.40rem; */5.2rem;
    /* margin:0 auto */
  }

  .message-item>div>div {
    width: 12rem;
    height: .76rem;
    border: 1px solid rgba(220, 220, 220, 1);
  }

  .dynamic-item {
    width: 3.88rem;
    height: 2.78rem;
    border: 1px solid rgba(151, 152, 153, 1);
    box-sizing: border-box;
    /* padding: 0.2rem; */
    margin-top:40px
  }
  .dynamic-item .col{
      background: linear-gradient(180deg, #FFFFFF 0%, #DFDFDF 100%);
  }
  .dynamic-item>div {
    padding-bottom: 0.12rem;
    border-bottom: 1px solid rgba(228, 231, 237, 1);
    padding:0.2rem
  }

  .dynamic-item .more {
    color: rgba(153, 153, 153, 1);
  }

  .dynamic-item>ul {
    margin-top: 0.12rem;
    padding:0.2rem;
    padding-top:0.05rem
  }

  .dynamic-item>ul>li {
    margin-bottom: 0.2rem;
  }

  .dynamic-item>ul>li>div {
    color: #343434
  }

  .dynamic-item>ul>li>.time {
    color: #A3A3A3
  }

  .cooperation-item {
    width: 2.31rem;
    height: 1.24rem;
    background: rgba(216, 216, 216, 1);
  }

  .cooperation-title {
    margin: 0.2rem 0 0.18rem 0
  }
  .cooperation{
    margin-bottom:1.21rem;
  }
  .list-con,.t3{
    cursor: pointer;
  }
  .newsSty{
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
    width:200px
  }
  .time{
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
    width:68px;
    height:16px
  }
  .homepage{
    width:100%;
  }
  .content{
    width:100%;
  }
  .font{
    color:#FF5203;
    cursor:pointer
  }
  .login .t10{
    width: 191px;
    height: 34px;
    background-color: #FF5203;;
    border-radius: 3px;
   /*  border: 1px solid #0486FE; */
    color:white
  }
  .login .t11{
    width: 191px;
    height: 34px;
    background-color: #FF5203;
    border-radius: 3px;
    opacity: 0.31;
    color: #FFFFFF;
  }
  .contentList{
    width:100%;
    margin:0 auto
  }
  .t12{
     margin-top:50px;
     padding-left:20px;
     border-left:4px solid  #FF5203;
     margin-bottom: 20px;
    width: 111px;
    height: 24px;
    font-size: 18px;
    font-family: MicrosoftYaHei;
    color: #FF5203;
    line-height: 24px;
        
  }
  .loginbox{
    width:12rem;
    margin:0 auto;
    position: relative;
    z-index:99999
  }
</style>
