<template>
  <div class="bg-F5">
    <div class="container">
      <el-row class="mt2rem" :gutter="20">
        <el-col :span="4">
          <category @change="e => $router.push({ path: `/mall`, query: e })" />
        </el-col>
        <el-col :span="14">
          <el-carousel class="bannerD marquee">
            <el-carousel-item v-for="x in 3" :key="`banner${x}`">
              <img class="banner" :src="require(`@assets/lunbo${x}.png`)" />
            </el-carousel-item>
          </el-carousel>
        </el-col>
        <el-col :span="6">
          <user-info />
          <div class="noticeDiv">
            <div class="noticeTitle">
              通知公告
              <router-link to="/news">
                <span class="more"
                  >more<i class="el-icon-d-arrow-right"></i
                ></span>
              </router-link>
            </div>
            <div class="notice" v-for="item in notices[0]" :key="item.noticeId">
              <router-link :to="`/newsDetail/${item.noticeId}`">
                {{ item.noticeTitle }}
              </router-link>
            </div>
          </div>
        </el-col>
      </el-row>
      <div class="partTitle"><span class="orangeLine"></span>服务能力</div>
      <div class="fwnl">
        <div
          class="fwnlItem"
          v-for="({ text, img, num }, index) in fwList"
          :key="`fwList${index}`"
        >
          <div class="numDiv">
            <img :src="require(`@assets/${img}.png`)" alt />
            <span>{{ num }}</span>
          </div>
          <div class="titleDiv">
            <span>{{ num }}</span>
            {{ text }}
          </div>
          <div class="line" v-if="index < fwList.length - 1"></div>
        </div>
      </div>
      <!-- 广告位 -->
      <div class="mt2rem">
        <img src="@assets/home_ggw1.png" alt />
      </div>
      <div class="partTitle">
        <span class="orangeLine"></span>热门商品
        <router-link to="/mall">
          <span class="more">more<i class="el-icon-d-arrow-right"></i></span>
        </router-link>
      </div>
      <div class="rmspList">
        <router-link
          :to="`/shop/${item.companyId}/${item.id}`"
          class="product"
          v-for="item in products"
          :key="item.id"
        >
          <div class="imgDiv">
            <img :src="`${$basePath}${item.cover}`" />
          </div>
          <a :title="item.name" class="name">{{ item.name }}</a>
          <div class="money">
            ¥
            <span>{{ item.price }}</span>
          </div>
          <div class="company ">{{ item.companyName }}</div>
        </router-link>
      </div>
      <div class="partTitle ppsj">
        <span class="orangeLine"></span>品牌商家
        <router-link to="/shops" class="more"
          >more<i class="el-icon-d-arrow-right"></i
        ></router-link>
      </div>
      <div class="ppsjList">
        <div class="plist" :style="`animation-duration:${shops.length * 3}s`">
          <router-link
            class="item"
            v-for="({ defaultImgUrl, primaryBusiness, companyName, id },
            index) in [...shops, ...shops]"
            :key="`ppsjList${index}`"
            :to="`/shop/${id}`"
          >
            <div class="imgDiv2">
              <img :src="`${$basePath}${defaultImgUrl}`" alt />
            </div>
            <div class="name">{{ companyName }}</div>
            <div class="company">主营商品:{{ primaryBusiness }}</div>
          </router-link>
        </div>
      </div>
      <div class="partTitle"><span class="orangeLine"></span>需求供应</div>
      <div class="xqgy">
        <template v-for="(info, index) in infos">
          <div :key="`info${index}`" class="xqDiv">
            <div class="xqTitle">
              <img
                :src="
                  require(`@assets/${index ? 'gongyingshang' : 'xuqiu'}.png`)
                "
                alt
              />{{ index ? "供应商" : "需求" }}
              <router-link :to="`/info/${index}`">
                <span class="more"
                  >more<i class="el-icon-d-arrow-right"></i
                ></span>
              </router-link>
            </div>

            <router-link
              :to="`/info/${index ? 'sell' : 'buy'}/${item.id}`"
              v-for="item in info"
              :key="item.id"
            >
              <div class="xq">
                <div class="con">
                  【{{ index ? "供应" : "求购" }}】{{
                    index ? item.supplyTitle : item.purchaseTitle
                  }}
                </div>
                <div class="date">
                  {{ `${item.releaseTime}`.split(" ")[0] }}
                </div>
              </div>
            </router-link>
          </div>
          <div class="t" :key="`info-t${index}`" v-if="index === 0"></div>
        </template>
      </div>
      <!-- 广告位 -->
      <div class=" mt2rem">
        <img src="@assets/home_ggw2.png" alt />
      </div>
      <el-row :gutter="20">
        <el-col
          :span="12"
          v-for="([item, ...items], index) in notices.slice(1)"
          :key="`notices${index}`"
        >
          <div class="partTitle">
            <span class="orangeLine"></span
            >{{ index ? "家具保养" : "行业资讯" }}
            <router-link :to="`/news/${index + 1}`">
              <span class="more"
                >more<i class="el-icon-d-arrow-right"></i
              ></span>
            </router-link>
          </div>
          <div class="hyzxDiv" v-if="item">
            <router-link
              :to="`/newsDetail/${item.noticeId}`"
              class="noticeDetails"
            >
              <div class="img">
                <img :src="`${$basePath}${item.fmzFileUrl}`" alt />
              </div>
              <div class="content">
                <div class="tit">{{ item.noticeTitle }}</div>
                <div class="desc">
                  {{ item.noticeOutline }}
                </div>
                <div class="date">{{ `${item.createTime}`.split(" ")[0] }}</div>
              </div>
            </router-link>
            <ul class="bottomUl">
              <li v-for="item in items" :key="item.noticeId">
                <router-link :to="`/newsDetail/${item.noticeId}`">
                  {{ item.noticeTitle }}
                </router-link>
              </li>
            </ul>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script lang="ts">
import { Component, Vue, Watch, Prop } from "vue-property-decorator";
@Component
export default class extends Vue {
  private notices: IAny[] = [];
  private infos: IAny[] = [];
  private products: IAny[] = [];
  private shops: IAny[] = [];
  private fwList: Array<{
    img: string;
    num: number;
    text: string;
  }> = [
    {
      img: "qiyeruzhu",
      num: 0,
      text: "家钢制家具生产企业入驻"
    },
    {
      img: "chanpin",
      num: 0,
      text: "个钢制家具产品入驻"
    },
    {
      img: "huiyuan",
      num: 0,
      text: "位平台会员注册"
    },
    {
      img: "yingyee",
      num: 0,
      text: "万在线电商营业额"
    }
  ];
  async created() {
    const arr = `/goods/info/hotlist,
      /demand/info/getDemandInfoTenList,
      /supply/info/getSupplyInfoTenLsit,
      /company/hotlist,
      /company/countCompanyInfo`
      .split(",")
      .map(url => this.$post(url.trim()));
    const [
      { list: p },
      { demandList: d },
      { supplyList: s },
      { list: shops },
      { companyNum, goodsNum, memberNum },

      ...n
    ] = await Promise.all([
      ...arr,
      ...[...Array(3)].map((x, index) =>
        this.$post("/interface/notice/getNoticeListTop5", {
          noticeType: index + 1
        })
      )
    ]).then(x => x.map(([, data]) => data));
    this.products = p;
    this.infos = [d, s];
    this.shops = shops;
    [companyNum, goodsNum, memberNum].forEach(
      (x: number, index) => (this.fwList[index].num = x)
    );
    this.notices = n.map(({ list }) => list);
  }
}
</script>

<style lang="scss" scoped>
.bannerD {
  height: 39rem;
  .banner {
    width: 100%;
    height: 100%;
  }
}
.noticeDiv {
  margin-top: 1rem;
  height: 22rem;
  background: #fff;
  border-radius: 0.4rem;
  padding: 2rem;
  box-sizing: border-box;
  .noticeTitle {
    height: 3rem;
    line-height: 3rem;
    font-size: 1.6rem;
    color: #333;
    .more {
      line-height: 3rem;
      font-size: 1.4rem;
      color: #999;
      float: right;
    }
  }
  .notice {
    height: 3rem;
    line-height: 3rem;
    overflow: hidden;
    font-size: 1.4rem;
    color: #666;
    a {
      color: #666;
    }
  }
}
.partTitle {
  padding: 3rem 0 2rem 0;
  font-size: 1.8rem;
  color: #333;
  &.ppsj {
    padding-top: 2rem;
  }
  .orangeLine {
    display: inline-block;
    height: 1.8rem;
    width: 0.3rem;
    background: #fd5522;
    vertical-align: middle;
    border-radius: 0.15rem;
    margin-right: 1rem;
  }
  .more {
    line-height: 3rem;
    font-size: 1.4rem;
    color: #999;
    float: right;
  }
}
.fwnl {
  width: 100%;
  height: 17rem;
  display: table;
  background: #fff;
  text-align: center;
  .fwnlItem {
    width: 25%;
    display: table-cell;
    vertical-align: middle;
    position: relative;
    .numDiv {
      margin-bottom: 1rem;
      img {
        height: 3.6rem;
        vertical-align: bottom;
      }
      span {
        font-size: 1.8rem;
        color: #fd5522;
        font-weight: bold;
        vertical-align: bottom;
        margin-left: 1rem;
      }
    }
    .titleDiv {
      font-size: 1.6rem;
      color: #333;
    }
    .line {
      width: 0.1rem;
      height: 4rem;
      background: #e5e5e5;
      position: absolute;
      top: 50%;
      right: 0;
      margin-top: -2rem;
    }
  }
}

.ppsjList {
  width: 100%;
  overflow: hidden;
  .plist {
    animation: marquee linear infinite;
    box-sizing: border-box;
    white-space: nowrap;
    display: inline-block;
    &:hover {
      animation-play-state: paused;
    }
  }
  .item {
    width: 216px;
    height: 210px;
    display: inline-block;
    margin-right: 20px;
    background: #fff;
    border-radius: 0.4rem;
    box-sizing: border-box;
    padding-bottom: 1.6rem;

    .name {
      height: 2rem;
      line-height: 2rem;
      font-size: 1.4rem;
      color: #333;
      font-weight: bold;
      margin-top: 2rem;
      overflow: hidden;
      padding: 0 2rem;
      box-sizing: border-box;
    }
    .company {
      height: 2rem;
      line-height: 2rem;
      font-size: 1.2rem;
      color: #666;
      overflow: hidden;
      padding: 0 2rem;
      box-sizing: border-box;
    }
    .imgDiv2 {
      width: 100%;
      height: 115px;
      img {
        width: 100%;
        max-height: 100%;
      }
    }
  }
}
.rmspList {
  .product {
    display: inline-block;
    width: 216px;
    height: 340px;
    background: #fff;
    overflow: hidden;
    margin-right: 20px;
    margin-bottom: 1rem;
    border-radius: 0.4rem;
    box-sizing: border-box;
    padding: 2rem;
    &:nth-child(5n + 5) {
      margin-right: 0;
    }
    .imgDiv {
      border: 0.1rem solid #e5e5e5;
      width: 175px;
      height: 200px;
      text-align: center;
      line-height: 0;
      position: relative;
      img {
        width: 90%;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
    }
    .name {
      font-size: 1.4rem;
      color: #333;
      font-weight: bold;
      margin-top: 15px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      display: block;
    }
    .money {
      font-size: 1.2rem;
      margin-top: 5px;
      color: #fd5522;
      span {
        font-size: 1.8rem;
      }
    }
    .company {
      margin-top: 10px;
      font-size: 1.2rem;
      color: #666;
    }
  }
}
.xqgy {
  overflow: hidden;
  // height: 430px;
  background: #fff;
  position: relative;
  .t {
    position: absolute;
    top: 0;
    left: 560px;
    bottom: 0;
    width: 20px;

    background: #f5f5f5;
  }
  .xqDiv {
    float: left;
    width: 560px;
    height: 100%;
    margin-left: 20px;
    padding: 20px;
    box-sizing: border-box;
    &:first-child {
      margin-left: 0;
    }
    .xqTitle {
      height: 3rem;
      line-height: 3rem;
      font-size: 1.6rem;
      color: #fd5522;
      img {
        height: 1.6rem;
        vertical-align: middle;
        margin-right: 1rem;
      }
      .more {
        line-height: 3rem;
        font-size: 1.4rem;
        color: #999;
        float: right;
      }
    }
    .xq {
      height: 3.6rem;
      line-height: 3.6rem;
      overflow: hidden;
      .con {
        width: 65%;
        float: left;
        height: 100%;
        font-size: 1.4rem;
        color: #333;
        padding-right: 1rem;
        box-sizing: border-box;
        overflow: hidden;
      }
      .date {
        width: 35%;
        float: left;
        height: 100%;
        font-size: 1.2rem;
        color: #666;
        text-align: right;
      }
    }
  }
}
.hyzxDiv {
  background: #fff;
  border-radius: 0.4rem;
  padding: 1.6rem;
  box-sizing: border-box;
  margin-bottom: 4rem;
  .noticeDetails {
    height: 100px;
    display: inline-block;
    overflow: hidden;
    box-sizing: border-box;
    .img {
      border: 1px solid #e5e5e5;
      width: 120px;
      float: left;
      height: 100%;
      position: relative;
      box-sizing: border-box;
      img {
        width: 80%;
        max-height: 100%;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
    }
    .content {
      float: left;
      margin-left: 20px;
      width: 388px;
      .tit {
        font-size: 1.6rem;
        color: #333;
      }
      .desc {
        margin-top: 5px;
        font-size: 1.2rem;
        color: #666;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .date {
        font-size: 12px;
        color: #666;
        margin-top: 10px;
      }
    }
  }
  .bottomUl {
    list-style: none;
    padding-top: 1rem;
    li {
      height: 3rem;
      line-height: 3rem;
      font-size: 1.4rem;
      color: #333;
      overflow: hidden;
    }
  }
}
.bg-88 {
  background: #889fe9;
}
.bg-84 {
  background: #84ccc9;
}
.mt15px {
  margin-top: 1.5rem;
}
@keyframes marquee {
  from {
    transform: translateX(0px);
  }
  to {
    transform: translateX(-50%);
  }
}
</style>
