<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="3" />
          </el-col>
          <el-col :span="21" style="padding: 0 20px">
            <!--查询面板-->
            <div class="search-box" style="padding:0;display:flex;font-size: 15px">
              <div class="search-item" :class="query.type==='time'?'active':''" style="width: 126px">
                <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>
              <div class="search-item" :class="query.type==='count'?'active':''" style="width: 126px">
                <span class="touch label" @click="setQuertType('count')">询价优先</span>
                <span v-if="query.type==='count'"><i v-if="query.sort" class="el-icon-sort-up touch" /><i v-else class="el-icon-sort-down touch" /></span>
              </div>
            </div>
            <div style="width: 100%;height: 62vh;margin-top: 7px;overflow: auto">
              <div v-for="(item,index) in tableData" :key="'p_'+index" class="box-card-s">
                <el-image
                  class="touch"
                  :src="item.imgSrc?imgSrcStart+'/productPic/'+item.imgSrc:defaultImgProduct"
                  style="width:200px;height: 160px;margin: 0 5px"
                  @click="goToDetails(item, '/product/details')"
                >
                  <div slot="placeholder" class="image-slot">加载中<span class="dot">...</span></div>
                </el-image>
                <el-row>
                  <el-col :span="21">
                    <div class="title touch" :title="item.title" @click="goToDetails(item, '/product/details')">{{ item.title }}</div>
                  </el-col>
                  <el-col :span="3">
                    <img v-if="item.isStore" class="touch" src="@/assets/home_images/to_like_h.png" title="点击取消收藏" @click="storeShowcase(item, 'product')">
                    <img v-else class="touch" src="@/assets/home_images/to_like.png" title="点击收藏" @click="storeShowcase(item, 'product')">
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <div class="subTitle" :title="item.subTitle">{{ item.subTitle }}</div>
                  </el-col>
                </el-row>
                <div class="line-btn" style="margin-top: 4px;padding-bottom: 4px">
                  <div class="btn-o" style="width: 120px;border-radius: 10px;box-shadow: 0 1px 2px 0 rgba(0,0,0,0.2);font-size:14px;" @click="inquiry(item, 'product')">询 价</div>
                </div>
              </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: 10,
      total: 0,
      query: {
        type: 'time'
      },
      tableData: [],
      throttle: null, // 节流器
      throttleTime: 300
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.loadData()
    })
  },
  methods: {
    setQuertType(type) {
      if (type !== this.query.type) {
        this.query.type = type
        this.loadData()
      }
    },
    loadData() {
      HttpReq.webClientApi.collectProduct({
        page: this.page - 1,
        pageSize: this.pageSize,
        ...this.query
      }).then((res) => {
        this.tableData = res.data.data
        this.total = res.data.total
      })
    },
    // 点击询价
    inquiry(item, type) {
      this.$refs.inquiryView.initView(item.id, item.customerId, type)
    },
    // 点击收藏
    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 {
  top: 0;
  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;
  .page-title {
    margin-top: 20px;
    padding: 0 20px;
    font-size: 26px;
    font-weight: bold;
    color: #333333;
  }
  .box-card-s {
    display: inline-block;
    position: relative;
    padding: 10px;
    margin: 12px;
    width: 230px;
    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;
    .title {
      width: 180px;
      padding: 2px 0;
      font-size: 15px;
      color: #333333;
      overflow:hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      -o-text-overflow:ellipsis;
    }
    .title:hover {
      font-weight: 600;
    }
    .subTitle {
      width: 200px;
      padding: 2px 0;
      font-size: 13px;
      color: #1961C5;
      overflow:hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      -o-text-overflow:ellipsis;
    }
    .date {
      padding: 2px 10px;
      font-size: 17px;
      color: #999999;
    }
    .stamp {
      border-style: none;
      position: absolute;
      z-index: 99;
    }
  }
}
.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%;
    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>
