<!--
 * @Author: changjun
 * @FilePath: /yuan-qingdao-zld-browser/src/views/monitoring/overview/components/IndicatorMap.vue
 * @Date: 2022-08-27 10:39:57
 * @Description: 
 * @LastEditTime: 2023-08-31 13:34:23
 * @LastEditors: 曹文丽
-->
<script setup lang="ts">
import { ref, defineProps, watch } from 'vue'
import ProvincesMap from "../../../../components/chart/map/ProvincesMap.vue";
import CommonCard from "../../../../components/CommonCard/CommonCard.vue";
import { bigNumberTransform } from "../../../../utils/utils";
import {
  queryCityDistribution,
  queryMapCityDistribution,
} from "../../../../api/monitoring/InternetStiff/totalSituations";
import { ElScrollbar } from "element-plus";
import { getThemeColor } from "../../../../components/chart/options/theme";
import { mapMapping } from "../../../../assets/map/provinceData";
const mapData = mapMapping();
const chartData = ref([]);
const tooltipFormatter = function (params) {
  const _data = params.data || {
    value: 0,
    valueTwo: 0,
  };
  return `<div class="light-map-tip-box">
      <div class="light-map-tip-box-name">${params.name}</div>
      <div class="light-map-tip-box-content">
        <div class="light-map-tip-box-item">
          <div class="light-map-tip-box-label">访问量</div>
          <div class="light-map-tip-box-value">${_data.value || 0}</div>
        </div>
      </div>
      
    </div>`;
};

const resetData = (e) => {
  let arr = [];
  let city = e.city.split(",");
  let num = e.num.split(",");
  let proportion = e.proportion.split(",");
  return city.map((item, i) => {
    return {
      city: city[i],
      num: num[i],
      proportion: proportion[i],
    };
  });
};

const list = ref([]);
const controlList = ref([]);
const props = defineProps({
  LIST: Array,
});
watch(
  () => props.LIST,
  (val, preVal) => {
    controlList.value = val.map((item, index) => {
      return {
        city: item.city,
        num: item.visitCount,
        proportion: item.percentage,
      };
    });
    chartData.value = val.map((item, index) => {
      return {
        name: item.city,
        value: bigNumberTransform(item.visitCount),
        percentage: item.percentage,
      };
    });
  }
);
</script>

<template>
  <CommonCard title="各地市网站被访问量TOP5" unit="次">
    <div class="yaMap">
      <div class="ya-indic-map">
        <div class="ya-box-echart" :class="mapData?.en">
          <img v-if="mapData?.en !== 'shandong'" class="ya-indic-map-bg"
            :src="'./resource/images/map/bg_' + mapData?.en + '.png'" alt="" />
          <ProvincesMap style="width: 70%" makePoint autotip :colorPoint="(getThemeColor().colorList && getThemeColor().colorList[0]) ||
            '#8D92FF'
            " showMakeOne :chartData="chartData" :tooltipFormatter="tooltipFormatter" />
        </div>

        <div class="ya-indic-map-item">
          <div class="adress-center">
            <div class="adress ya-border-color ya-bg-color">
              <ElScrollbar>
                <div class="title ya-fill-color ya-primary-text">
                  <div>地市</div>
                  <div>访问量</div>
                </div>
                <div class="ya-bg-color" v-if="controlList.length > 0">
                  <div class="adress-flex" v-for="item in controlList">
                    <div class="ya-regular-text adress-flex-name" :class="mapData?.en">
                      {{ item.city }}
                    </div>
                    <div class="adress-flex-item">
                      <div class="adress-line">
                        <div class="adress-line-item newbg" :style="{
                          width: item.proportion,
                          background:
                            (getThemeColor().colorList &&
                              getThemeColor().colorList[0]) ||
                            '#8d92ff',
                        }"></div>
                      </div>
                      <div class="ya-regular-text">
                        {{ bigNumberTransform(item.num) }}
                      </div>
                    </div>
                  </div>
                </div>
                <div class="no-data ya-bg-color" v-else>
                  <img class="img1" src="../../../../assets/image/no-d.png" alt="" />
                  <div class="no-data-text">暂无数据</div>
                </div>
              </ElScrollbar>
            </div>
          </div>
        </div>
      </div>
    </div>
  </CommonCard>
</template>

<style scope lang="scss">
.yaMap {
  width: 100%;
  height: 100%;
  display: flex;

  .ya-indic-map {
    width: 100%;
    height: 100%;
    position: relative;
    // anhui需要价
    // padding-left: 100px;
    box-sizing: border-box;

    .ya-box-echart {
      position: absolute;
      // demo暂时注释
      width: 700px;
      height: 700px;
      // left: 3vw;
      // top: -14vh;
      transform: rotateX(45deg);

      .ya-echart-map {}

      .ya-indic-map-bg {
        position: absolute;
      }

      &.shandong {
        transform: rotateX(30deg);
        width: 100%;
        height: 100%;
      }

      &.anhui {
        top: -125px;
        left: 40px;

        .ya-indic-map-bg {
          width: 1067px;
          height: 1095px;
          top: -136px;
          left: -373px;
        }
      }

      &.hubei {
        transform: rotateX(0deg);

        .ya-indic-map-bg {
          top: -135px;
          left: -20px;
          width: 755px;
        }

        .chart {
          width: 81.4% !important;
          left: 38px;
          top: -131px;
        }
      }
    }
  }

  .ya-indic-map-item {
    position: absolute;
    right: -10px;
    bottom: 0px;
    z-index: 1;

    .adress-center {
      display: flex;
      justify-content: space-between;
      width: 100%;
      height: 200px;

      .adress {
        width: 300px;
        border-radius: 8px;
        border: 1px solid rgba(0, 0, 0, 0.2);
        font-size: 14px;

        .title {
          font-weight: 400;
          color: rgba(0, 0, 0, 0.65);
          height: 31px;
          line-height: 31px;
          border-radius: 7px 7px 0px 0px;
          background: #f4f4f4;
          display: flex;
          justify-content: space-between;
          padding-left: 24px;
          padding-right: 16px;
        }

        .adress-flex {
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding-left: 24px;
          padding-right: 16px;
          height: 32px;
          line-height: 32px;
          color: rgba(0, 0, 0, 0.65);

          .adress-flex-name {
            min-width: 47px;

            &.anhui {
              min-width: 60px;
            }
          }

          .adress-flex-item {
            display: flex;
            align-items: center;
            color: rgba(0, 0, 0, 0.4);
            flex: 1;
          }

          .adress-line {
            height: 4px;
            min-width: 100px;
            max-width: 180px;
            margin-right: 5px;
            position: relative;
            flex: 1;

            .adress-line-item {
              height: 100%;
              background: #f18301;
              position: absolute;
              border-radius: 4px;
              left: 0;
            }

            .newbg {
              background: #8d92ff;
            }
          }
        }
      }
    }
  }
}

.light-map-tip-box {
  position: relative;
  top: 20px;
  background-color: rgba(9, 103, 138, 0.8);
}

.no-data {
  .img1 {
    width: 130px;
    height: 100px;
  }

  margin: 20px auto;
  text-align: center;
  color: #96a2b5;
  font-size: 14px;
}
</style>
