<template>
  <div class="visitor">
    <div class="left_visitor">
      <HeadlineTag value="访客列表"></HeadlineTag>
      <div class="box_arch_point">
        <div class="point_box" style="margin-top: 10px;">
          <el-input v-model="input" placeholder="按访客名称搜索" />
        </div>
        <div style="height: calc(100% - 160px);">
          <Empty></Empty>
        </div>
        <div class="center_in">
          <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
            layout="total, prev, pager, next" @pagination="getList" />
        </div>
      </div>
    </div>
    <div class="right_visitor">
      <div class="garden_box">
        <HeadlineTag type="right" value="园区基本信息"></HeadlineTag>
        <div class="card_visitor_star">
          <div class="item_visitor_top">
            <div class="circle_itor center_in">
              <svg class="visitor_star" aria-hidden="true">
                <defs>
                  <linearGradient id="myGradient" x1="0%" y1="100%" x2="0%" y2="0%">
                    <stop offset="0%" stop-color="rgb(20, 188, 244)" />
                    <stop offset="100%" stop-color="#ffffff" />
                  </linearGradient>
                </defs>
                <use xlink:href="#icon-user" fill="url('#myGradient')" />
              </svg>
            </div>
            <div class="title_box_itor">
              <div class="title_itor_13">总规划建筑面积</div>
              <div class="title_itor_18">142万</div>
            </div>
          </div>
          <div class="item_visitor_top">
            <div class="circle_itor center_in">
              <svg class="visitor_star" aria-hidden="true">
                <defs>
                  <linearGradient id="myGradient" x1="0%" y1="100%" x2="0%" y2="0%">
                    <stop offset="0%" stop-color="rgb(20, 188, 244)" />
                    <stop offset="100%" stop-color="#ffffff" />
                  </linearGradient>
                </defs>
                <use xlink:href="#icon-user" fill="url('#myGradient')" />
              </svg>
            </div>
            <div class="title_box_itor">
              <div class="title_itor_13">总规划建筑面积</div>
              <div class="title_itor_18">142万</div>
            </div>
          </div>
          <div class="item_visitor_top">
            <div class="circle_itor center_in">
              <svg class="visitor_star" aria-hidden="true">
                <defs>
                  <linearGradient id="myGradient" x1="0%" y1="100%" x2="0%" y2="0%">
                    <stop offset="0%" stop-color="rgb(20, 188, 244)" />
                    <stop offset="100%" stop-color="#ffffff" />
                  </linearGradient>
                </defs>
                <use xlink:href="#icon-user" fill="url('#myGradient')" />
              </svg>
            </div>
            <div class="title_box_itor">
              <div class="title_itor_13">总规划建筑面积</div>
              <div class="title_itor_18">142万</div>
            </div>
          </div>
          <div class="item_visitor_top">
            <div class="circle_itor center_in">
              <svg class="visitor_star" aria-hidden="true">
                <defs>
                  <linearGradient id="myGradient" x1="0%" y1="100%" x2="0%" y2="0%">
                    <stop offset="0%" stop-color="rgb(20, 188, 244)" />
                    <stop offset="100%" stop-color="#ffffff" />
                  </linearGradient>
                </defs>
                <use xlink:href="#icon-user" fill="url('#myGradient')" />
              </svg>
            </div>
            <div class="title_box_itor">
              <div class="title_itor_13">总规划建筑面积</div>
              <div class="title_itor_18">142万</div>
            </div>
          </div>
        </div>
      </div>
      <div class="flex_spection">
        <HeadlineTag type="right" value="访客统计"></HeadlineTag>
        <div class="box_arch">
          <starView></starView>
        </div>
      </div>
      <div class="flex_spection">
        <HeadlineTag type="right" value="外地人员分配"></HeadlineTag>
        <div class="box_arch">
          <div ref="chartDom" style="width: 100%;height: 100%;" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import HeadlineTag from '@/components/HeadlineTag'
import Empty from '@/components/Empty'
import starView from './starView'
import * as echarts from 'echarts'
const total = ref(0);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
});
const input = ref('')
/** 查询列表 */
function getList() {
};

const chartDom = ref(null);
let chartInstance = null;
// 初始化图表
const initChart = () => {
  var colorList = [{
    type: 'linear',
    x: 0,
    y: 0,
    x2: 1,
    y2: 1,
    colorStops: [{
      offset: 0,
      color: 'rgba(51,192,205,0.01)' // 0% 处的颜色
    },
    {
      offset: 1,
      color: 'rgba(51,192,205,0.57)' // 100% 处的颜色
    }
    ],
    globalCoord: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 1,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [{
      offset: 0,
      color: 'rgba(115,172,255,0.02)' // 0% 处的颜色
    },
    {
      offset: 1,
      color: 'rgba(115,172,255,0.67)' // 100% 处的颜色
    }
    ],
    globalCoord: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 1,
    y: 0,
    x2: 0,
    y2: 0,
    colorStops: [{
      offset: 0,
      color: 'rgba(158,135,255,0.02)' // 0% 处的颜色
    },
    {
      offset: 1,
      color: 'rgba(158,135,255,0.57)' // 100% 处的颜色
    }
    ],
    globalCoord: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 0,
    y: 1,
    x2: 0,
    y2: 0,
    colorStops: [{
      offset: 0,
      color: 'rgba(252,75,75,0.01)' // 0% 处的颜色
    },
    {
      offset: 1,
      color: 'rgba(252,75,75,0.57)' // 100% 处的颜色
    }
    ],
    globalCoord: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 1,
    y: 1,
    x2: 1,
    y2: 0,
    colorStops: [{
      offset: 0,
      color: 'rgba(253,138,106,0.01)' // 0% 处的颜色
    },
    {
      offset: 1,
      color: '#FDB36ac2' // 100% 处的颜色
    }
    ],
    globalCoord: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 0,
    y: 0,
    x2: 1,
    y2: 0,
    colorStops: [{
      offset: 0,
      color: 'rgba(254,206,67,0.12)' // 0% 处的颜色
    },
    {
      offset: 1,
      color: '#FECE4391' // 100% 处的颜色
    }
    ],
    globalCoord: false // 缺省为 false
  }
  ]
  var colorLine = ['#33C0CD', '#73ACFF', '#9E87FF', '#FE6969', '#FDB36A', '#FECE43']

  function getRich() {
    let result = {}
    colorLine.forEach((v, i) => {
      result[`hr${i}`] = {
        backgroundColor: colorLine[i],
        borderRadius: 3,
        width: 3,
        height: 3,
        padding: [3, 3, 0, -12]
      }
      result[`a${i}`] = {
        padding: [-11, 6, -20, 6],
        color: colorLine[i],
        backgroundColor: 'transparent',
        fontSize: 12
      }
    })
    return result
  }
  let data = [{
    'name': '北京',
    'value': 25
  }, {
    'name': '上海',
    'value': 20
  }, {
    'name': '广州',
    'value': 18
  }, {
    'name': '深圳',
    'value': 15
  }, {
    'name': '未知',
    'value': 13
  }, {
    'name': '海外',
    'value': 9
  }].sort((a, b) => {
    return b.value - a.value
  })
  data.forEach((v, i) => {
    v.labelLine = {
      lineStyle: {
        width: 1,
        color: colorLine[i]
      }
    }
  })
  chartInstance = echarts.init(chartDom.value);
  chartInstance.setOption({
    series: [{
      type: 'pie',
      radius: '60%',
      center: ['50%', '50%'],
      clockwise: true,
      avoidLabelOverlap: true,
      label: {
        show: true,
        position: 'outside',
        formatter: function (params) {
          const name = params.name
          const percent = params.percent + '%'
          const index = params.dataIndex
          return [`{a${index}|${name}:${percent}}`, `{hr${index}|}`].join('\n')
        },
        rich: getRich()
      },
      itemStyle: {
        normal: {
          color: function (params) {
            return colorList[params.dataIndex]
          }
        }
      },
      data,
      roseType: 'radius'
    }]
  });
};
// 生命周期
onMounted(initChart);
// 窗口自适应
window.addEventListener('resize', () => {
  chartInstance?.resize();
});
</script>

<style scoped lang="scss">
.visitor {
  position: relative;
  width: 100%;
  padding-top: 45px;
  height: 100vh;
  overflow: hidden;
}

.left_visitor {
  position: absolute;
  left: 0;
  width: 25%;
  height: calc(100% - 45px);
  display: flex;
  flex-direction: column;
  padding-left: 10px;
}

.right_visitor {
  position: absolute;
  right: 0;
  width: 25%;
  height: calc(100% - 45px);
  display: flex;
  flex-direction: column;
}

.box_arch_point {
  height: calc(100% - 40px);
}

.operation_spection {
  height: 250px;
  color: #fff;
}

.garden_box {
  height: 300px;
}

.flex_spection {
  flex: 1;
  color: #fff;
}

.box_arch {
  display: flex;
  align-items: center;
  height: calc(100% - 40px);
}
</style>

<style lang="scss" scoped>
.point_box :deep(.el-input__wrapper) {
  background-color: transparent !important;
  box-shadow: 0 0 0 1px rgb(58, 86, 117) inset !important;
}

.point_box :deep(.el-input__wrapper.is-focus) {
  box-shadow: 0 0 0 1px #409EFF inset !important;
}

.point_box :deep(.el-input__inner) {
  color: #ffffff !important;
}

.card_visitor_star {
  height: calc(100% - 40px);
  display: flex;
  flex-direction: column;
}

.item_visitor_top {
  flex: 1;
  margin: 5px 0px;
  padding-left: 20px;
  display: flex;
  align-items: center;
  border-left: 2px solid rgb(67, 182, 235);
  background-image: linear-gradient(to right, rgba(15, 73, 138, 1) 0%, rgba(13, 65, 125, 0.5) 21%, rgba(13, 65, 125, 0.5) 52%, rgba(0, 0, 0, 0) 78%, rgba(0, 0, 0, 0) 100%);
}

.circle_itor {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid rgb(103, 168, 202);
}

.title_box_itor {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-left: 20px;
}

.title_itor_13 {
  color: #ffffff;
  font-size: 13px;
}

.title_itor_18 {
  padding-top: 5px;
  font-weight: bold;
  font-size: 18px;
  background-image: -webkit-linear-gradient(bottom, rgb(20, 127, 228), rgb(229, 232, 236));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}


.visitor_star {
  width: 30px;
  height: 30px;
}
</style>