<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="1" 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="18">
                <el-input v-model="query.keyword" clearable placeholder="请输入关键字" />
              </el-col>
              <el-col :span="3">
                <el-select v-model="query.productType" placeholder="全部产品">
                  <el-option v-for="item in [{value:'',label:'全部产品'}, ...dict.product_type]" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </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===''?'active':''">
                <span class="touch label" @click="setQuertType('')">默认排序</span>
                <span v-if="query.type===''">
                  <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-show="hardwareList.length" style="padding-top: 6px">
          <div v-for="(item,index) in hardwareList" :key="'p_'+index" class="box-card">
            <img v-if="item.isGood" src="@/assets/home_images/recommend.png" class="stamp" title="推荐" style="top: 10px;right: 8px">
            <img v-if="item.isHot" src="@/assets/home_images/hot.png" class="stamp" title="热门" style="top: 0;left: 0">
            <el-image
              class="touch"
              :src="item.imgSrc?imgSrcStart+'/productPic/'+item.imgSrc:defaultImgProduct"
              style="width:284px;height: 284px;margin: 0 32px 4px"
              @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 touch" :title="item.subTitle" @click="goToDetailsSupplier(item, '/supplier/details')">{{ item.subTitle }}</div>
              </el-col>
            </el-row>
            <el-row style="margin-top: 6px">
              <el-col :span="3" style="padding-left: 20px">
                <img src="@/assets/home_images/locate.png">
              </el-col>
              <el-col :span="13">
                <div class="area">{{ item.area }}</div>
              </el-col>
              <el-col :span="8">
                <div class="date">{{ item.date }}</div>
              </el-col>
            </el-row>
            <div class="line-btn" style="margin-top: 4px">
              <div class="btn-o" style="width: 150px;border-radius: 10px;box-shadow: 0 1px 2px 0 rgba(0,0,0,0.2);font-size:20px;" @click="inquiry(item, 'product')">询 价</div>
            </div>
          </div>
          <div style="padding: 15px 50px;text-align: center"><span v-show="page*pageSize<=total" class="more touch" title="点击查看更多..." @click="moreTo('product')">更多展开<i class="el-icon-arrow-down" /></span></div>
        </div>
        <!--解决方案展柜-->
        <div v-show="projectList.length">
          <div class="line-title"><div class="title-point" /><span class="title-text">方案概述</span></div>
          <div v-for="(item,index) in projectList" :key="'pj_'+index" class="box-block">
            <el-row :gutter="20">
              <el-col :span="12">
                <div style="display: flex">
                  <el-image :src="item.imgSrc?imgSrcStart+'/productPic/'+item.imgSrc:defaultImgProject" style="width:100%;height: 300px;margin: 1px;border-radius: 10px;" />
                </div>
              </el-col>
              <el-col :span="12">
                <div class="box-title touch" @click="goToDetails(item, '/product/details')">{{ item.title }}</div>
                <div class="content ellipsis">{{ item.productDescribe }}</div>
                <div class="line-btn" style="margin-top: 4px;justify-content: flex-end;">
                  <div class="btn-o" style="width: 140px;border-radius: 10px;box-shadow: 0 1px 2px 0 rgba(0,0,0,0.2);font-size:20px;" @click="inquiry(item, 'project')">咨 询</div>
                </div>
              </el-col>
            </el-row>
          </div>
          <div style="padding: 15px 50px;text-align: right"><span class="more touch" title="点击查看更多..." @click="moreTo('project')">更多详情>></span></div>
        </div>
        <!--系统软件-->
        <div v-show="softwareList.length">
          <div class="line-title"><div class="title-point" /><span class="title-text">系统软件</span></div>
          <div style="padding-top: 6px">
            <div v-for="(item,index) in softwareList" :key="'p_'+index" class="box-card" style="padding: 0 0 10px 0">
              <el-image
                :src="item.imgSrc?imgSrcStart+'/productPic/'+item.imgSrc:defaultImgSoftware"
                style="width:348px;height: 240px;top: -3px"
              />
              <div class="float-title touch" @click="goToDetails(item, '/product/details')">{{ item.title }}</div>
              <div class="line-btn" style="margin-top: 4px">
                <div class="btn-o" style="width: 150px;border-radius: 10px;box-shadow: 0 1px 2px 0 rgba(0,0,0,0.2);font-size:20px;" @click="inquiry(item, 'software')">免费获取方案</div>
              </div>
            </div>
            <div style="padding: 15px 50px;text-align: right"><span class="more touch" title="点击查看更多..." @click="moreTo('software')">更多详情>></span></div>
          </div>
        </div>
        <!--专业培训-->
        <div v-show="courseList.length">
          <div class="line-title"><div class="title-point" /><span class="title-text">专业培训</span></div>
          <div style="padding-top: 6px">
            <div v-for="(item,index) in courseList" :key="'p_'+index" class="box-card" style="padding: 0 0 10px 0">
              <el-image
                :src="item.imgSrc?imgSrcStart+'/productPic/'+item.imgSrc:defaultImgSoftware"
                style="width:348px;height: 240px;top: -3px"
              />
              <div class="line-text touch" @click="goToDetails(item, '/product/details')">{{ item.title }}</div>
              <div style="width: 100%;text-align: center;padding: 2px;color: #333">{{ item.subTitle }}</div>
              <div class="line-btn" style="margin-top: 14px">
                <div class="btn-o" style="width: 150px;border-radius: 10px;box-shadow: 0 1px 2px 0 rgba(0,0,0,0.2);font-size:20px;" @click="inquiry(item, 'course')">课程定制</div>
              </div>
            </div>
            <div style="margin-bottom: 20px;padding: 15px 50px;text-align: right"><span class="more touch" title="点击查看更多..." @click="moreTo('course')">更多详情>></span></div>
          </div>
        </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,
      defaultImgSoftware: default_system,
      imgSrcStart: process.env.VUE_APP_BASE_API,
      query: {
        keyword: '',
        productType: '',
        area: '',
        type: '',
        sort: false
      },
      page: 1,
      pageSize: 8,
      total: 0,
      areaOpts: [],
      keywords: [],
      hardwareList: [],
      projectList: [],
      softwareList: [],
      courseList: [],
      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.keywords
      })
    })
  },
  methods: {
    onDictReady(dict) {
      this.areaOpts = [{ value: '', label: '全部' }, ...dict.area_province]
      this.search()
    },
    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
      })
      HttpReq.webClientApi.productGetPlanSystemAndTraining({
        ...this.query
      }).then((res) => {
        this.projectList = res.data.overviewOfThePlan.data
        this.softwareList = res.data.softWareSystem.data
        this.courseList = res.data.professionalTraining.data
      })
    },
    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
      }
      this.search()
    },
    // 点击询价
    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}` })
      }
    },
    goToDetailsSupplier(item, path) {
      if (item) {
        this.$router.push({ path: `${path}/${item.customerId || 123}` })
      } else {
        this.$router.push({ path: `${path}` })
      }
    },
    // 点击更多
    moreTo(type) {
      if (type === 'product') {
        this.pageSize += 8
        this.search()
      } else if (type === 'project') {
        this.$router.push({ path: `/project` })
      } else if (type === 'software') {
        this.$router.push({ path: `/software` })
      } else if (type === 'course') {
        this.$router.push({ path: `/course` })
      }
    },
    goTop() {
      document.body.scrollTop = 0
      document.documentElement.scrollTop = 0
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.touch {
  cursor:pointer;
}
.clear {
  clear: both
}
.ellipsis {
  // 多行溢出省略号
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  -webkit-line-clamp: 6;
  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 {
  margin-top: 94px;
  user-select: none;
  .box-block {
    width: 100%;
    margin: 12px 0;
    border: 1px solid rgba(0,0,0,0.12);
    box-shadow: 1px 2px 8px 0 rgba(0,0,0,0.12);
    border-radius: 10px;
    .box-title {
      padding-top: 20px;
      padding-left: 10px;
      font-size: 22px;
      font-weight: bold;
    }
    .box-title:hover {
      color: #0457C7
    }
    .content {
      height: 200px;
      padding: 4px 30px 20px 10px;
      font-size: 16px;
      font-weight: 600;
      line-height: 32px;
      color: #666;
    }
  }
  .box-card {
    display: inline-block;
    position: relative;
    margin: 12px;
    padding: 10px 0;
    width: 350px;
    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;
    .line-text {
      width: 100%;
      height: 50px;
      text-align: center;
      padding: 5px;
      font-size: 18px;
      font-weight: bolder;
      opacity: 0.85;
    }
    .line-text:hover {
      opacity: 1;
    }
    .float-title {
      width: 344px;
      position: absolute;
      padding: 5px;
      top: 200px;
      left: 2px;
      text-align: center;
      font-weight: 600;
      color: #fff;
      background: rgba(0,0,0,0.6);
      opacity: 0.9;
    }
    .float-title:hover {
      opacity: 1;
    }
    .title {
      width: 305px;
      padding: 2px 20px;
      font-size: 18px;
      color: #333333;
      overflow:hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      -o-text-overflow:ellipsis;
    }
    .title:hover {
      font-weight: 600;
    }
    .subTitle {
      width: 260px;
      padding: 2px 20px;
      font-size: 15px;
      color: #1961C5;
      overflow:hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      -o-text-overflow:ellipsis;
    }
    .area {
      padding: 2px 0;
      font-size: 17px;
      color: #666666;
    }
    .date {
      padding: 2px 10px;
      font-size: 17px;
      color: #999999;
    }
    .stamp {
      border-style: none;
      position: absolute;
      z-index: 99;
    }
  }
  .more {
    font-size: 18px;
    font-weight: 600;
    color: #0457C7;
    opacity: 0.7;
  }
  .more:hover {
    opacity: 1;
  }
  .line-title {
    padding: 6px 0;
    position: relative;
    border-bottom: 3px solid #0457C7;
    font-size: 24px;
    color: #333333;
    .title-point {
      width: 8px;
      height: 21px;
      position: absolute;
      top: 9px;
      background: #0457c7;
    }
    .title-text {
      padding-left: 14px;
      font-weight: 600;
    }
    .title-line{
      width: 100%;
      position: absolute;
      bottom: -7px;
      border-bottom: 2px solid #1961C5;
      opacity: 0.35
    }
  }
}
.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>
