<template>
  <div class="bg-F5">
    <div class="container">
      <el-row class="mt2rem" :gutter="20">
        <el-col :span="4">
          <category @change="id => $router.push(`/mall/-${id}`)" />
        </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">
              {{ $t("page.views.home.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> {{ $t("page.views.home.fwTitle") }}
      </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>
            {{ $t(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>{{ $t("page.views.home.productTitle") }}
        <router-link to="/mall">
          <span class="more">more<i class="el-icon-d-arrow-right"></i></span>
        </router-link>
      </div>
      <div class="categoryList">
        <el-row class="dalei">
          <el-col :span="2">
            <div class="slide left">
              <img src="@assets/slideLeft.png" @click="prev" />
            </div>
          </el-col>

          <el-col :span="20">
            <el-carousel
              :autoplay="false"
              arrow="never"
              indicator-position="none"
              ref="carousel"
              class="marquee"
            >
              <el-carousel-item
                v-for="(arr, index) in categoryList"
                :key="`carousel-list-${index}`"
              >
                <el-row class="items">
                  <el-col
                    :span="4"
                    class="item"
                    :class="{ curr: cIndex === index * 6 + i }"
                    @click.native="cIndex = index * 6 + i"
                    v-for="({ title, remake }, i) in arr"
                    :key="`carousel-list-item-${i}`"
                  >
                    <div>
                      <img :src="`${$basePath}${remake}`" alt />

                      <div>{{ title }}</div>
                    </div>
                  </el-col>
                </el-row>
              </el-carousel-item>
            </el-carousel>
          </el-col>
          <el-col :span="2">
            <div class="slide right">
              <img src="@assets/slideRight.png" @click="next" />
            </div>
          </el-col>
        </el-row>
        <div class="xiaolei">
          <div
            class="item"
            v-for="({ title, remake, id }, index) in currCategorySub"
            :key="`categoryList-xiaolei-${index}`"
            @click="() => $router.push(`/mall/-${id}`)"
          >
            <div class="img">
              <img :src="`${$basePath}${remake}`" alt />
            </div>
            <div class="tit">{{ title }}</div>
          </div>
        </div>
        <div
          class="categoryMore"
          v-if="categorySub.length > 10 && !categoryMore"
          @click="categoryMore = true"
        >
          <span>更多分类</span>
          <img src="@assets/more.png" alt />
        </div>
      </div>

      <el-row :gutter="20">
        <el-col
          :span="12"
          v-for="(items, index) in products"
          :key="`products${index}`"
          class="products"
        >
          <div class="partTitle">
            <span class="orangeLine"></span
            >{{
              $t(`page.views.home.${index ? "hotProducts" : "newsProducts"}`)
            }}
          </div>

          <router-link
            v-for="({ id, name, companyId, price, cover, companyName },
            index) in items"
            :key="`products-item-${index}`"
            :to="`/shop/${companyId}/${id}`"
            class="product"
          >
            <div class="imgDiv">
              <img :src="`${$basePath}${cover}`" />
            </div>
            <a :title="name" class="name">{{ name }}</a>
            <div class="money">
              ¥
              <span>{{ price }}</span>
            </div>
            <div class="company ">{{ companyName }}</div>
          </router-link>
        </el-col>
      </el-row>
      <div class="partTitle ppsj">
        <span class="orangeLine"></span>{{ $t("page.views.home.ppTitle") }}
        <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">
              {{ $t("page.views.home.primaryBusiness") }}:{{ primaryBusiness }}
            </div>
          </router-link>
        </div>
      </div>
      <div class="partTitle">
        <span class="orangeLine"></span>{{ $t("page.views.home.xqTitle") }}
      </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
              />{{ $t(`page.views.home.${index ? "gys" : "xq"}`) }}
              <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">
                  【{{ $t(`page.views.home.${index ? "gy" : "qg"}`) }}】{{
                    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
            >{{ $t(`page.views.home.${index ? "furniture" : "industry"}`) }}
            <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";
import menu from "@/store/modules/menu";
import { chunk } from "lodash";
import i18n from "@/lang";
import { ElCarousel } from "element-ui/types/carousel";
@Component
export default class extends Vue {
  private params = {
    typeId: 0
  };
  private cIndex = 0;
  private categoryMore = false;
  private products: IAny[][] = [];
  private notices: IAny[] = [];
  private infos: IAny[] = [];
  private shops: IAny[] = [];
  private fwList = "qiyeruzhu,chanpin,huiyuan,yingyee"
    .split(",")
    .map((img, index) => ({
      img,
      num: 0,
      text: `page.views.home.fwListText${++index}`
    }));
  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 [
      { newList, hotlist },
      { 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 = [newList, hotlist];
    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);
  }
  get categoryList() {
    return chunk(menu.pList, 6);
  }
  get categorySub() {
    if (!menu.pList.length) return [];
    return menu.subList(menu.pList[this.cIndex].id);
  }
  get currCategorySub() {
    return this.categoryMore ? this.categorySub : this.categorySub.slice(0, 10);
  }

  prev() {
    (this.$refs.carousel as ElCarousel).prev();
  }
  next() {
    (this.$refs.carousel as ElCarousel).next();
  }
}
</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;
    }
  }
}
.categoryList {
  overflow: hidden;
  margin-bottom: 30px;
  background: #fff;
  .dalei {
    height: 108px;
    border-bottom: 1px solid #f5f5f5;
    > div {
      height: 100%;
    }
    .items {
      height: 100%;
      .item {
        height: 100%;
        position: relative;
        cursor: pointer;
        &.curr {
          border-bottom: 2px solid #ff3800;
        }
        > div {
          text-align: center;
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          img {
            width: 38px;
            height: 38px;
          }
        }
      }
    }
    .slide {
      margin-top: 29px;
      position: relative;
      height: 50px;
      &.left {
        border-right: 1px solid #f5f5f5;
      }
      &.right {
        border-left: 1px solid #f5f5f5;
      }
      img {
        text-align: center;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        cursor: pointer;
      }
    }
  }
  .xiaolei {
    overflow: hidden;
    padding: 30px;
    padding-bottom: 10px;
    .item {
      height: 250px;
      width: 202px;
      cursor: pointer;
      float: left;
      border: 1px solid #e5e5e5;
      margin-right: 20px;
      border-radius: 6px;
      margin-bottom: 20px;
      &:nth-child(5n + 5) {
        margin-right: 0;
      }
      &:hover {
        border: 1px solid #ff3700;
        color: #ff3700;
        .tit {
          background: #ffdbd0;
        }
      }
      .img {
        height: 200px;
        position: relative;
        img {
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          max-width: 80%;
          max-height: 80%;
        }
      }
      .tit {
        height: 50px;
        line-height: 50px;
        background: #f5f5f5;
        text-align: center;
      }
    }
  }
  .categoryMore {
    color: #999999;
    text-align: center;
    margin-bottom: 20px;
    font-size: 12px;
    cursor: pointer;
  }
}
.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;
      overflow: hidden;
      width: 100%;
      text-overflow: ellipsis;
    }
    .imgDiv2 {
      width: 100%;
      height: 115px;
      img {
        width: 100%;
        max-height: 100%;
      }
    }
  }
}
.products {
  .product {
    width: 275px;
    &:nth-child(2n + 1) {
      margin-right: 0;
    }
  }
}
.productList {
  .product {
    width: 216px;
    &:nth-child(5n + 5) {
      margin-right: 0;
    }
  }
}
.product {
  display: inline-block;

  height: 340px;
  background: #fff;
  overflow: hidden;
  margin-right: 20px;
  margin-bottom: 1rem;
  border-radius: 0.4rem;
  box-sizing: border-box;
  padding: 2rem;

  .imgDiv {
    border: 0.1rem solid #e5e5e5;
    width: 100%;
    height: 60%;
    text-align: center;
    line-height: 0;
    position: relative;
    img {
      max-width: 90%;
      max-height: 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>
