<template>
  <div class="w-screen pad:w-full">
    <div class="conBox container product-type">
      <p
        v-for="(item,i) in showTypes"
        :key="item.key"
        :class="`type-item ${item.key===type?'type-selected':''}`"
        @click="selectType(item.key)"
      >
        <span class="icon-box">
          <svg-icon :svgHref="item.icon"/>
        </span>
        <span class="type-name">{{lang===langType.cn?item.text:item.en_text}}</span>
      </p>
    </div>
  </div>
</template>

<script>
import langMap from "@/map/langMap";
import {pTypes} from "~/map/productMap";
import BigTitle from "~/components/public/bigTitle.vue";

export default {
  name: "showTypes",
  components: {BigTitle},
  props: {
    lang:{
      default: langMap.lang.cn
    },
    type:{
      default: 'all'
    },
    types: {
      type: Array,
      required: true
    },
    title: {
      default: '类别'
    },
    maxShow: {
      type: Number,
      default: 6,
    }
  },
  data(){
    return {
      langType: langMap.lang,
    }
  },
  computed: {
    showTypes(){
      // 移除最后几个元素
      let types = this.types.slice(0, this.maxShow);
      return types;
    }
  },

  methods:{
    getLangText(str) {
      return langMap.getText(this.lang, str);
    },
    getAbbrText(str) {
      return langMap.getAbbrText(this.lang, str);
    },
    selectType(nextType){
      console.log(nextType)
      if (this.type === nextType){
        return 0;
      }
      this.$root.$emit('changeType', nextType);
    }
  }
}
</script>

<style scoped>
.content{
  cursor: default;
}
.content .big-title{
  margin-top: 10px;
  margin-bottom: 30px;
}
.product-type{
  height: 120px;
  display: flex;
  justify-content: space-around;
}

.product-type .type-item{
  width: auto;
  height: 100%;
  cursor: pointer;
}
.product-type .type-item:hover{
  color: orangered;
}
.product-type .type-selected{
  color: #f88330;
}
.product-type .type-item .icon-box{
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 4rem;
  padding-bottom: 20px;
}
.product-type .type-selected .icon-box{
  border-bottom: 2px solid deepskyblue;
}
.product-type .type-item .type-name{
  width: 100%;
  height: 60px;
  font-size: 1.3rem;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
