<template>
  <div class="page-body">
    <div class="head-box">
      <div class="head-box-top">
        <div class="top-call" />
        <div class="top-call"><img src="@/assets/home_images/cisnet_logo_b.png"></div>
        <div class="top-call"><title-menus ref="titleMenus" menu-index="99" style="padding-top: 15px" /></div>
        <div class="top-call"><user-login ref="userLogin" /></div>
        <div class="top-call"><language-setting ref="languageSetting" /></div>
      </div>
    </div>
    <div class="content-box">
      <div style="width: 88%;padding-left: 9%;">
        <el-row :gutter="20" style="padding-top: 10px">
          <el-col :span="3">
            <user-menus menu-index="4" />
          </el-col>
          <el-col :span="21" style="padding: 0 20px">
            <div style="width: 100%;height: 66vh;margin-top: 5px;overflow: auto">
              <!--供应商展柜-->
              <div v-for="(item,index) in tableData" :key="'s_'+index" class="showcase-line">
                <div class="supplier_card" style="position: relative;">
                  <div class="sup_btn touch" style="position: absolute;top: 15px;right: 30px" @click="goToDetails(item, '/supplier/details')">查看产品</div>
                  <div class="sup_btn touch" style="position: absolute;top: 60px;right: 30px;background: transparent;color: #FB7B09" @click="inquiry(item, 'supplier')">留言咨询</div>
                  <div class="sup_title">
                    <span class="touch" @click="goToDetails(item, '/supplier/details')">{{ item.name }}</span>
                  </div>
                  <div class="sup_area">
                    <img src="@/assets/home_images/locate.png">
                    <span :title="item.area">{{ item.area }}</span>
                    <img v-if="item.isStore" class="touch" src="@/assets/home_images/to_like_h.png" title="点击取消收藏" style="position: absolute;top: 58px;right: 220px" @click="storeShowcase(item, 'supplier')">
                    <img v-else class="touch" src="@/assets/home_images/to_like.png" title="点击收藏" style="position: absolute;top: 58px;right: 220px" @click="storeShowcase(item, 'supplier')">
                  </div>
                  <div style="margin: 25px 40px">
                    <div class="block-c">
                      <div>成立时间</div>
                      <div>{{ item.createTime }}</div>
                    </div>
                    <div class="block-c">
                      <div>可购品类数</div>
                      <div style="color: #EF1F1F">{{ item.classSum }}</div>
                    </div>
                    <div class="block-c">
                      <div>产品价格区间</div>
                      <div style="color: #EF1F1F">{{ item.price }}</div>
                    </div>
                  </div>
                  <el-row style="margin-top: 38px">
                    <el-col :span="3">
                      <div class="block-b">主营品类:</div>
                    </el-col>
                    <el-col :span="21">
                      <div class="block-b ellipsis">{{ item.mainProduct }}</div>
                    </el-col>
                  </el-row>
                </div>
                <div v-if="item.products[0]" class="product_card">
                  <el-image :src="item.products[0].imgSrc?imgSrcStart+'/productPic/'+item.products[0].imgSrc:defaultImgProduct" style="width:240px;height: 220px;border-radius: 10px;" />
                  <div class="product_title touch ellipsis" :title="item.products[0].name" @click="goToDetails(item.products[0], '/product/details')">{{ item.products[0].name }}</div>
                </div>
                <div v-else style="width:240px;height:278px;" />
                <div v-if="item.products[1]" class="product_card">
                  <el-image :src="item.products[1].imgSrc?imgSrcStart+'/productPic/'+item.products[1].imgSrc:defaultImgProduct" style="width:240px;height: 220px;border-radius: 10px;" />
                  <div class="product_title touch ellipsis" :title="item.products[1].name" @click="goToDetails(item.products[1], '/product/details')">{{ item.products[1].name }}</div>
                </div>
                <div v-else style="width:240px;height:278px;" />
              </div>
            </div>
            <!--分页组件-->
            <el-pagination :total="total" :current-page="page" :page-size="pageSize" style="margin-top: 8px;" layout="total, prev, pager, next, sizes" @size-change="sizeChange" @current-change="pageChange" />
          </el-col>
        </el-row>
      </div>
    </div>
    <home-footer ref="homeFooter" />
    <inquiry-view ref="inquiryView" />
    <el-backtop />
  </div>
</template>
<script>
import default_product from '@/assets/home_images/default_product.png'

import titleMenus from '../components/titleMenusV2'
import userLogin from '../components/userLoginV2'
import languageSetting from '../components/languageSettingV2'
import homeFooter from '../components/homeFooter'
import inquiryView from '../components/inquiryView'
import userMenus from '../components/userMenus'
import { HttpReq } from '@/api/common'

export default {
  components: { titleMenus, userLogin, languageSetting, homeFooter, inquiryView, userMenus },
  data() {
    return {
      defaultImgProduct: default_product,
      imgSrcStart: process.env.VUE_APP_BASE_API,
      page: 1,
      pageSize: 8,
      total: 0,
      tableData: [],
      throttle: null, // 节流器
      throttleTime: 300
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.loadData()
    })
  },
  methods: {
    setQuertType(type) {
      if (type === this.query.type) {
        this.query.sort = !this.query.sort
      } else {
        this.query.type = type
        this.query.sort = false
      }
    },
    loadData() {
      HttpReq.webClientApi.collectSupplier({
        page: this.page - 1,
        pageSize: this.pageSize,
        productNumber: 2
      }).then((res) => {
        this.tableData = res.data.data
        this.total = res.data.total
      })
    },
    // 点击询价
    inquiry(item, type) {
      this.$refs.inquiryView.initView(null, item.customerId, type, '9')
    },
    // 点击收藏
    storeShowcase(item, type) {
      HttpReq.webClientApi.collectProductOrSupplier({
        id: item.id,
        collect: !item.isStore,
        type: type
      }).then((res) => {
        item.isStore = !item.isStore
        this.$message.warning({
          message: res.msg
        })
      })
    },
    // 跳转到详情
    goToDetails(item, path) {
      if (item) {
        this.$router.push({ path: `${path}/${item.id || 123}` })
      } else {
        this.$router.push({ path: `${path}` })
      }
    },
    pageChange(e) {
      this.page = e
      this.loadData()
    },
    sizeChange(e) {
      this.page = 1
      this.pageSize = e
      this.loadData()
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.touch {
  cursor:pointer;
}
.clear {
  clear: both
}
.inline-block {
  display: inline-block;
}
.ellipsis {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  -webkit-line-clamp: 2;
  text-overflow: ellipsis;
}
.head-box {
  width: 100vw;
  top: 0;
  position: fixed;
  background: none repeat scroll 0 0 white;
  z-index: 999;
  box-shadow: 0px 3px 7px 0px rgba(0,0,0,0.2);
  .head-box-top {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    .top-call {
      height: 80px;
      padding-top: 15px;
    }
  }
}
.content-box {
  min-height: 70vh;
  margin-top: 94px;
  font-family: Source Han Sans CN;
  user-select: none;
  .showcase-line {
    margin: 16px 0 28px;
    display: flex;
    justify-content: space-between;
    font-family: Source Han Sans CN;
    font-weight: 400;
  }
  .supplier_card {
    padding: 10px 20px;
    width: 742px;
    height: 278px;
    background: #F3F4F5;
    border: 1px solid rgba(25,97,197,0.12);
    box-shadow: 1px 2px 8px 0 rgba(0,0,0,0.12);
    border-radius: 10px;
    .sup_btn {
      width: 124px;
      height: 36px;
      padding: 6px;
      background: #FB7B09 ;
      border: 1px solid #FB7B09 ;
      border-radius: 10px;
      font-size: 20px;
      color: #FFFFFF;
      text-align: center;
    }
    .sup_btn:hover {
      font-weight: bold;
    }
    .sup_title {
      max-width: 540px;
      color: #1961C5;
      font-size: 26px;
      line-height: 34px;
      span:hover {
        font-weight: bolder;
      }
    }
    .sup_area {
      width: 460px;
      padding: 10px 0;
      color: #666666;
      font-size: 18px;
      overflow:hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      -o-text-overflow:ellipsis;
      img {
        position:relative;
        top:4px;
      }
    }
    .block-c {
      display: inline-block;
      width: 180px;
      font-size: 20px;
      line-height: 26px;
      font-weight: 600;
      color: #333333;
      text-align: center;
      opacity: 0.9;
    }
    .block-b {
      height: 50px;
      font-size: 18px;
      color: #666666;
      line-height: 25px;
      opacity: 0.9;
    }
  }
  .product_card {
    width: 240px;
    height: 278px;
    background: #FFFFFF;
    border: 1px solid rgba(0,0,0,0.12);
    box-shadow: 1px 2px 8px 0 rgba(0,0,0,0.12);
    border-radius: 10px;
    .product_title {
      padding: 0 10px;
      width: 100%;
      height: 40px;
      line-height: 20px;
      text-align: center;
    }
    .product_title:hover {
      font-weight: bolder;
    }
  }
}
.line-btn {
  display: flex;
  justify-content: center;
  font-family: Source Han Sans CN;
  font-weight: 400;
  .btn-o {
    margin: 0 25px;
    width: 360px;
    padding: 6px 10px;
    background: #F7601A;
    box-shadow: 0 3px 6px 0 rgba(0,0,0,0.2);
    text-align: center;
    border: 1px solid transparent;
    font-size: 22px;
    color: #FFFFFF;
    cursor:pointer;
    user-select: none;
  }
  .btn-o:hover {
    border: 1px solid rgba(30, 144, 255, 0.8);
    color: #1482f0;
  }
  .btn-l {
    margin: 0 25px;
    width: 360px;
    padding: 10px;
    background: #1961C5;
    box-shadow: 0 3px 6px 0 rgba(0,0,0,0.2);
    text-align: center;
    border: 1px solid transparent;
    font-size: 22px;
    color: #FFFFFF;
    cursor:pointer;
    user-select: none;
  }
  .btn-l:hover {
    border: 1px solid rgba(0,0,0,0.3);
    color: #F7601A;
  }
  .btn-b {
    margin: 0 10px;
    width: 168px;
    padding: 6px;
    background: #EFF6FF;
    border: 1px solid transparent;
    box-shadow: 0 1px 2px 0 rgba(0,0,0,0.2);
    text-align: center;
    font-size: 20px;
    color: #1961C5;
    cursor:pointer;
    user-select: none;
  }
  .btn-b:hover {
    border: 1px solid rgba(30, 144, 255, 0.9);
  }
  .active {
    color: #FFFFFF;
    font-weight: 400;
    background: #1961C5;
  }
}
</style>
