<template>
  <div class="search-box">
    <div class="search-btn">
      <el-input v-model="query.keyword" clearable placeholder="请输入关键字" style="width: 600px" />
      <el-select v-model="query.productType" placeholder="全部产品" style="width: 160px">
        <el-option v-for="item in [{value:'',label:'全部产品'}, ...dict.product_type]" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-select v-model="query.area" placeholder="区域" style="width: 100px">
        <el-option v-for="item in [{value:'',label:'全地区'}, ...dict.area_province]" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-button icon="el-icon-search" class="btn" @click="search">搜索</el-button>
    </div>
    <div class="search-keyword">
      <span v-for="(item, index) in keywords" :key="index" class="label" @click="keywordClick(item, 'keyword')">{{ item.name }}</span>
    </div>
    <div class="search-keyword-title">
      <div class="title-s">品牌</div>
    </div>
    <div class="search-keyword-label">
      <span v-for="(item, index) in brands" :key="index" class="label" @click="keywordClick(item, 'brand')">{{ item.name }}</span>
    </div>
    <div class="search-keyword-title">
      <div class="title-s">供应商</div>
    </div>
    <div class="search-keyword-label">
      <span v-for="(item, index) in suppliers" :key="index" class="label" @click="keywordClick(item, 'supplier')">{{ item.name }}</span>
    </div>
  </div>
</template>
<script>
import { HttpReq } from '@/api/common'

export default {
  dicts: ['product_type', 'area_province'],
  data() {
    return {
      query: {
        keyword: '',
        productType: '',
        area: ''
      },
      keywords: ['曲线记录仪', '液位控制器', '双金属温度计', '位移传感器'],
      brands: ['高领传感', '施克', '蓝之宇', '高领传感', '施克', '蓝之宇'],
      suppliers: ['上海成渝智能科技发展有限公司', '山东盛茂科技有限公司', '山东天润科技有限公司']
    }
  },
  mounted() {
    this.$nextTick(() => {
      HttpReq.webClientApi.homePageGetSearch({
        preview: false
      }).then((res) => {
        this.keywords = res.data.keywords
        this.brands = res.data.brands
        this.suppliers = res.data.suppliers
      })
    })
  },
  methods: {
    search() {
      this.$router.push({
        name: 'product',
        params: this.query
      })
    },
    keywordClick(item, type) {
      if (item.url) {
        this.$router.push({ path: item.url })
      } else {
        this.query.keyword = item.name
      }
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.search-box {
  width: 100%;
  text-align: center;
  //user-select: none;
  .btn{
    width: 100px;
    height: 47px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    background: rgba(101,103,113,0.35);
    color: #FFFFFF;
    opacity: 0.7;
  }
  .btn:hover {
    opacity: 1;
  }
  >>>.el-input__inner {
    height: 47px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    background: rgba(101,103,113,0.35);
    color: #FFFFFF;
    opacity: 0.7;
  }
  >>>.el-input__inner:hover {
    opacity: 1;
  }
  .search-keyword {
    margin-top: 2px;
    text-align: left;
    padding-left: 25vw;
    .label {
      padding: 1px 15px 1px;
      font-size: 16px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #FFFFFF;
      line-height: 35px;
      cursor:pointer;
      //user-select: none;
    }
    .label:hover {
      color: wheat;
    }
  }
  .search-keyword-title {
    display: flex;
    justify-content: center;
    margin-top: 40px;
    font-size: 20px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #FFFFFF;
    .title-s {
      width: 126px;
      padding: 7px;
      border: 1px solid rgba(255, 255, 255, 0.2);
      border-radius: 20px;
      color: #FFFFFF;
    }
  }
  .search-keyword-label {
    margin-top: 20px;
    .label {
      padding: 3px 25px 3px;
      font-size: 20px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #FFFFFF;
      line-height: 35px;
      cursor:pointer;
      //user-select: none;
    }
    .label:hover {
      color: wheat;
    }
  }
}
</style>
