<template>
  <div style="position: relative;" v-if="!isShow">
    <div class="toolbox isFixed">
      <div v-for="(item,index) in items" :key="index">
        <div :class="actIndex==index?'itembox act':'itembox'" @click="onClick(item,index)">
          <div v-if="index==0&&dataList.length>0">
            <el-popover
              popper-class="monitor-yt-popover"
              placement="left-start"
              width="150"
              trigger="click"
            >
              <div class="tip"
                   :style="{width:temSize.w,height:temSize.h,left:temSize.l}">
                <div class="showModel_body" v-for="item in dataList">
                  <div class="tip-trangle-right"></div>
                  <div class="name_bg name show_lime">{{item.serviceName}}&nbsp&nbsp</div>
                  <p><span class="qq_number">手机：{{item.serviceMobile}}</span></p>
                  <p class="qq_number" :style="{visibility:item.serviceQQ?'':'hidden'}">Q&nbspQ：{{item.serviceQQ}}</p>
                  <img class="code_img"
                       :src="item.serviceQRCode">
                  <p style="text-align: center;color: #adadad" class="qq_number">微信扫码咨询</p>
                </div>
              </div>
              <div slot="reference" style="font-size: 12px">
                <p style="text-align: center"><i :class="item.icon" style="font-size: 25px"></i></p>
                <p>{{item.name}}</p>
              </div>
            </el-popover>
          </div>
          <div style="font-size: 12px" v-else @click="pushUrl(index)">
            <p style="text-align: center"><i :class="item.icon" style="font-size: 25px"></i></p>
            <p>{{item.name}}</p>
          </div>
        </div>

        <el-divider></el-divider>
      </div>

    </div>
  </div>
</template>

<script>
  import { _getStorage } from "@/utils/utils";
  import { _href } from "@/utils/utils";

  export default {
    data() {
      return {
        dataList: [],
        actIndex: -1,
        isShow:false,
      };
    },
    props: {
      items: {
        type: Array,
        default: () => {
          return [];
        },
      },
    },
    mounted() {
      this.isShow=this.$route.meta.isShow
      this.getDataList();
    },
    watch: {
      '$route' (to) {
        if(to.meta.isShow){
          this.isShow=true
        }
      },
    },
    computed: {
      temSize() {
        let params = {
          w: "",
          h: "",
          l: "",
        };
        let length = this.dataList.length;
        switch (length) {
          case 0:
            params.w = "193px";
            params.h = "237px";
            params.l = "-48px";
            break;
          case 1:
            params.w = "193px";
            params.h = "237px";
            params.l = "-48px";
            break;
          case 2:
            params.w = "388px";
            params.h = "237px";
            params.l = "-242px";
            break;
          case 3:
            params.w = "582px";
            params.h = "237px";
            params.l = "-436px";
            break;
          case 4:
            params.w = "582px";
            params.h = "470px";
            params.l = "-436px";
            break;
          case 5:
            params.w = "582px";
            params.h = "470px";
            params.l = "-436px";
            break;
          case 6:
            params.w = "582px";
            params.h = "470px";
            params.l = "-436px";
            break;
          default :
            params.w = "582px";
            params.h = "470px";
            params.l = "-436px";
            break;
        }
        return params;
      },
      brandName() {
        let {brandName} = _getStorage("info");
        return brandName ? brandName : "";
      },
    },
    methods: {
      getDataList() {
        this.$axios.get("/channel/list", {
          params: {
            brandName: this.brandName,
          },
        }).then(res => {
          let { code,data } = res.data;
          if (code == 200) {
             this.dataList=data
          }
        });
      },
      pushUrl(index) {
        if(index==0){
          this.$message.warning('暂无数据')
        }else {
          this.$router.push({
            path: "/help/feedback",
          });
        }
      },
      onClick(item, index) {
        this.actIndex = index;
      },
    },
  };
</script>

<style lang="scss" scoped>
  .show_lime{
    width: 116px;
    overflow: hidden;      /*溢出隐藏*/
    white-space: nowrap;	/*规定文本不进行换行*/
    text-overflow: ellipsis;	/*当对象内文本溢出时显示省略标记（...）*/
  }
  .name_bg {
    background: url("../assets/img/icons/ico_kefumingcheng.png") no-repeat;
    background-position: 0px -1px;
  }

  .showModel_body {
    display: inline-block;
    border-radius: 3px;
    padding: 16px 38px;
    line-height: 20px;
    background: #fff;
    margin: 1px;
    .name {
      font-weight: bold;
      font-size: 15px;
      margin-left: -26px;
      padding-left: 26px;
    }
    .qq_number {
      font-size: 12px;
    }
    .code_img {
      border: 1px solid rgba(238, 238, 238, 1);
      border-radius: 3px;
      width: 114px;
      height: 114px;
      margin-top: 2px;
    }
  }

  .toolbox {
    z-index: 999;
    position: absolute;
    top: 108px;
    left: 50%;
    margin-left: 636px;
    border: 1px solid #f4f4f4;
    background: #fff;
    .itembox {
      cursor: pointer;
      padding: 10px 8px;
      width: 60px;
      text-align: center;
      line-height: 18px;

      &.act {
        color: #f60;
      }
      &:hover {
        background: #f60;
        color: #fff;
      }
    }
    .el-divider {
      margin: 0 auto;
      width: 100%;
      background-color: #EFEFEF;
    }
    &.isFixed {
      position: fixed;
      top: 40%;
    }
  }

  @media screen and (max-width: 1400px) {
    .toolbox {
      left: 48%;
    }
  }

  /*提示框容器*/
  .tip {
    position: absolute;
    top: -127px;
    overflow-x: hidden;
    overflow-y: auto;
    box-sizing: border-box;
    /*设置圆角*/
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    box-shadow: 4px 2px 6px 6px #e1e1e1;
    background: #f1f1f1;
  }

  .tip::-webkit-scrollbar {
    display: none;
  }

  /*提示框-右三角*/
  .tip-trangle-right {
    position: fixed;
    top: 2px;
    right: -10px;
    width: 0;
    height: 0;
    border-top: 15px solid transparent;
    border-bottom: 15px solid transparent;
    border-left: 15px solid #fff;
    z-index: 9999;
  }
</style>
<style>
  .monitor-yt-popover {
    transform: translateX(-10px);
  }
</style>
