<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/gemho_logo_b.png"></div>
        <div class="top-call"><title-menus ref="titleMenus" menu-index="2" 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%;">
        <breadcrumb />
        <!--查询面板-->
        <div class="search-box">
          <div class="search-tools">
            <el-row :gutter="18">
              <el-col :span="21">
                <el-input v-model="query.keyword" clearable placeholder="请输入关键字" />
              </el-col>
              <el-col :span="3">
                <el-button icon="el-icon-search" class="btn" @click="search">搜索</el-button>
              </el-col>
            </el-row>
          </div>
          <div class="search-keyword">
            <span v-for="(item, index) in keywords" :key="index" class="label" @click="keywordClick(item, 'keyword')">{{ item.name }}</span>
          </div>
          <el-row style="padding-top: 16px">
            <el-col :span="2"><div class="area-title">地区选择</div></el-col>
            <el-col :span="22" style="border: 1px solid rgba(0,0,0,0.12);">
              <div v-for="(item,index) in areaOpts" :key="'a_'+index" class="area_item touch" :class="query.area===item.value?'active':''" @click="query.area=item.value">{{ item.label }}</div>
            </el-col>
          </el-row>
          <el-row style="padding-top: 10px">
            <el-col :span="2">
              <div class="search-item" :class="query.type===undefined?'active':''">
                <span class="touch label" @click="setQuertType()">默认排序</span>
                <span v-if="query.type===undefined">
                  <i v-if="query.sort" class="el-icon-sort-up touch" />
                  <i v-else class="el-icon-sort-down touch" />
                </span>
              </div>
            </el-col>
            <el-col :span="2">
              <div class="search-item" :class="query.type==='hot'?'active':''">
                <span class="touch label" @click="setQuertType('hot')">人气排序</span>
                <span v-if="query.type==='hot'">
                  <i v-if="query.sort" class="el-icon-sort-up touch" />
                  <i v-else class="el-icon-sort-down touch" />
                </span>
              </div>
            </el-col>
            <el-col :span="2">
              <div class="search-item" :class="query.type==='time'?'active':''">
                <span class="touch label" @click="setQuertType('time')">上架时间</span>
                <span v-if="query.type==='time'">
                  <i v-if="query.sort" class="el-icon-sort-up touch" />
                  <i v-else class="el-icon-sort-down touch" />
                </span>
              </div>
            </el-col>
            <el-col :span="18">
              <div class="search-item">
                <span>产品价格区间</span>
                <div style="position: absolute;top: 15px;left: 35%;">
                  <el-input v-model="query.minPrice" placeholder="请输入价格（元）" clearable style="width: 140px" />
                  ~
                  <el-input v-model="query.maxPrice" placeholder="请输入价格（元）" clearable style="width: 140px" />
                  <div class="btn touch" @click="search">确 定</div>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
        <!--供应商展柜-->
        <div v-for="(item,index) in supplierList" :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>
              <img v-if="item.isGood" src="@/assets/home_images/diamond.png" title="推荐" style="position:relative;top:4px;">
            </div>
            <div class="sup_area">
              <img src="@/assets/home_images/locate.png">
              <span>{{ item.area }}</span>
              <img v-if="item.isStore" class="touch" src="@/assets/home_images/to_like_h.png" title="点击取消收藏" style="right:-12px;top:7px" @click="storeShowcase(item, 'supplier')">
              <img v-else class="touch" src="@/assets/home_images/to_like.png" title="点击收藏" style="right:-12px;top:7px" @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-for="(p,i) in item.products" :key="'p_'+index+'_'+i" class="product_card">
            <el-image :src="p.imgSrc?imgSrcStart+'/img'+p.imgSrc:defaultImgProduct" style="width:240px;height: 220px;border-radius: 10px;" />
            <div class="product_title touch ellipsis" :title="p.name" @click="goToDetails(p, '/product/details')">{{ p.name }}</div>
          </div>
        </div>
        <div class="pagination">
          <!--          <span style="font-size: 14px; color: #666; margin-right: 8px">共 {{ total }} 条记录</span>-->
          <el-pagination
            :hide-on-single-page="true"
            :background="true"
            :current-page.sync="page"
            :page-size="pageSize"
            :total="total"
            layout=" prev, pager, next"
            @current-change="pageChange"
          />
        </div>
      </div>
    </div>
    <home-footer ref="homeFooter" />
    <inquiry-view ref="inquiryView" />
    <el-backtop />
    <float-btn ref="floatBtn" />
  </div>
</template>
<script>
import default_product from '@/assets/home_images/default_product.png'
import default_project from '@/assets/home_images/default_project.png'
import default_system from '@/assets/home_images/default_system.png'
import titleMenus from '../components/titleMenusV2'
import userLogin from '../components/userLoginV2'
import languageSetting from '../components/languageSettingV2'
import breadcrumb from '../components/breadcrumb'
import homeFooter from '../components/homeFooter'
import inquiryView from '../components/inquiryView'
import floatBtn from '../components/floatBtn'
import { HttpReq } from '@/api/common'

export default {
  components: { titleMenus, userLogin, languageSetting, breadcrumb, homeFooter, inquiryView, floatBtn },
  dicts: ['product_type', 'area_province'],
  data() {
    return {
      defaultImgProduct: default_product,
      defaultImgProject: default_project,
      defaultImgSystem: default_system,
      imgSrcStart: process.env.VUE_APP_BASE_API,
      page: 1,
      pageSize: 10,
      total: 0,
      query: {
        keyword: '',
        area: undefined,
        type: undefined,
        sort: false
      },
      areaOpts: [],
      keywords: [],
      supplierList: [
        {
          isGood: true,
          isStore: true,
          name: '佛山英沃传感器科技有限公司',
          area: '江苏省淮安市',
          createTime: '2023 01-01 ',
          classSum: '18',
          price: '15 -300元',
          mainProduct: '温度传感器 热电偶传感器 流量计 报做仪 pt100热电阳 压力变送器 气体检测仪 氟化氢检测仪',
          products: [
            { name: '3GDN M30百流三线防 爆电感式接近传感爆电感式接近传感爆电感式接近传感爆电感式接近传感', imgSrc: '' },
            { name: '3GDN M30百流三线防 爆电感式接近传感', imgSrc: '' },
            { name: '3GDN M30百流三线防 爆电感式接近传感', imgSrc: '' }
          ]
        }, {
          isGood: false,
          isStore: false,
          name: '佛山英沃传感器科技有限公司',
          area: '江苏省淮安市',
          createTime: '2023 01-01 ',
          classSum: '18',
          price: '15 -300元',
          mainProduct: '温度传感器 热电偶传感器 流量计 报做仪 pt100热电阳 压力变送器 气体检测仪 氟化氢检测仪',
          products: [
            { name: '3GDN M30百流三线防 爆电感式接近传感爆电感式接近传感爆电感式接近传感爆电感式接近传感', imgSrc: '' },
            { name: '3GDN M30百流三线防 爆电感式接近传感', imgSrc: '' },
            { name: '3GDN M30百流三线防 爆电感式接近传感', imgSrc: '' }
          ]
        }, {
          isGood: true,
          isStore: false,
          name: '佛山英沃传感器科技有限公司',
          area: '江苏省淮安市',
          createTime: '2023 01-01 ',
          classSum: '18',
          price: '15 -300元',
          mainProduct: '温度传感器 热电偶传感器 流量计 报做仪 pt100热电阳 压力变送器 气体检测仪 氟化氢检测仪',
          products: [
            { name: '3GDN M30百流三线防 爆电感式接近传感爆电感式接近传感爆电感式接近传感爆电感式接近传感', imgSrc: '' },
            { name: '3GDN M30百流三线防 爆电感式接近传感', imgSrc: '' },
            { name: '3GDN M30百流三线防 爆电感式接近传感', imgSrc: '' }
          ]
        }
      ],
      throttle: null, // 节流器
      throttleTime: 300
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.query = Object.assign(this.query, this.$route.params)
      HttpReq.webClientApi.homePageGetSearch({
        preview: false
      }).then((res) => {
        this.keywords = res.data.suppliers
      })
    })
  },
  methods: {
    onDictReady(dict) {
      this.areaOpts = [{ value: undefined, label: '全部' }, ...dict.area_province]
    },
    search() {
      HttpReq.webClientApi.productGetHardwareList({
        page: this.page - 1,
        pageSize: this.pageSize,
        ...this.query
      }).then((res) => {
        this.hardwareList = res.data.hardwareList.data
        this.total = res.data.hardwareList.total
      })
    },
    keywordClick(item, type) {
      this.query.keyword = item.name
      this.search()
    },
    setQuertType(type) {
      if (type === this.query.type) {
        this.query.sort = !this.query.sort
      } else {
        this.query.type = type
        this.query.sort = false
      }
    },
    // 点击询价
    inquiry(item, type) {
      console.log(item, type)
      this.$refs.inquiryView.initView(item.id, type)
    },
    // 跳转到详情
    goToDetails(item, path) {
      if (item) {
        this.$router.push({ path: `${path}/${item.id || 123}` })
      } else {
        this.$router.push({ path: `${path}` })
      }
    },
    // 点击收藏
    storeShowcase(item, type) {
      item.isStore = !item.isStore
      this.$message.warning({
        message: `您${item.isStore ? '' : '已取消'}收藏了该产品！`
      })
      console.log(item, type)
    },
    pageChange(e) {
      this.page = e
      this.loadData()
    },
    loadData() {

    },
    goTop() {
      document.body.scrollTop = 0
      document.documentElement.scrollTop = 0
    }
  }
}
</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;
}
//  分页 前文字+分页
.pagination {
  margin-top: 23px;
  text-align: center;
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  >>>.el-pagination.is-background .el-pager li {
    font-style: normal;
    font-weight: 400;
    font-size: 14px;
    text-align: center;
    background-color: #fff;
    color: #000000;
    border: 1px solid #e5e5ea;
  }
  /* 激活后的样式 */
  >>>.el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #ffffff;
    color: #0366ed;
    border: 1px solid #0366ed;
    text-align: center;
  }
  /* 修改左右箭头样式 */
  >>>.el-pagination .btn-next .el-icon, >>>.el-pagination .btn-prev .el-icon {
    font-style: normal;
    font-weight: 400;
    font-size: 14px;
    text-align: center;
    background-color: #fff;
    color: #e5e5ea;
    border: 1px solid #e5e5ea;
  }
  >>>.el-pager {
    height: 35.5px !important;
  }
  >>>.number, >>>.el-icon {
    height: 35.5px !important;
    line-height: 35.5px !important;
  }
}
.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;
  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 {
      padding: 10px 0;
      color: #666666;
      font-size: 18px;
      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;
    }
  }
}
.search-box {
  padding-top: 12px;
  width: 100%;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
  user-select: none;
  .search-item {
    width: 100%;
    height: 38px;
    display: inline-block;
    padding: 8px 20px;
    background: #F7F7F7;
    border: 1px solid rgba(0,0,0,0.12);
    overflow:hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    -o-text-overflow:ellipsis;
    .label:hover {
      font-weight: 600;
    }
    .btn {
      width: 74px;
      padding: 3px;
      margin-left: 12px;
      display: inline-block;
      background: #1961C5;
      border-radius: 6px;
      color: white;
      text-align: center;
      opacity: 0.7;
    }
    .btn:hover {
      opacity: 1;
    }
  }
  .area-title {
    height: 62px;
    background: #F7F7F7;
    border: 1px solid rgba(0,0,0,0.12);
    text-align: center;
    line-height: 60px;
  }
  .area_item {
    height: 30px;
    padding: 6px 12px;
    display: inline-block;
  }
  .area_item:hover {
    font-weight: 600;
  }
  .active {
    color: #1961C5;
  }
  .search-tools {
    width: 100%;
    .btn{
      width: 76%;
      height: 38px;
      border: 2px solid #1961C5;
      border-radius: 8px;
      background: #1961C5;
      font-family: Source Han Sans CN;
      font-weight: 400;
      font-size: 21px;
      color: #ffffff;
      opacity: 0.7;
    }
    .btn:hover {
      opacity: 1;
    }
    >>>.el-input__inner {
      height: 38px;
      border: 2px solid #1961C5;
      border-radius: 8px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      font-size: 18px;
      color: #333333;
      opacity: 0.7;
    }
    >>>.el-input__inner:hover {
      opacity: 1;
    }
  }
  .search-keyword {
    padding: 5px 0;
    font-family: Source Han Sans CN;
    font-weight: 400;
    font-size: 14px;
    text-align: left;
    .label {
      padding: 1px 15px 1px;
      color: #333333;
      cursor:pointer;
      user-select: none;
    }
    .label:hover {
      color: #1961C5;
    }
  }
}
.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>
