<template>
  <div class="container">
    <!-- 遮罩层区域 -->
    <div class="mask" @click="handleClose"></div>
    <!-- 弹窗内容区域 -->
    <div class="radio">
      <!-- 标题区域 -->
      <div class="title" :title="currentRadio">{{ currentRadio }}</div>

      <!-- 主体内容区域 -->
      <div class="info">
        <!-- 广播列表区域 -->
        <div class="info_list">
          <!-- 每一个广播区域 -->
          <div class="info_item" v-for="(item, index) in listData" :key="index">
            <div>{{ item }}</div>
            <!-- <img src="@/assets/images/right.png" /> -->
          </div>
        </div>

        <!-- 分页器区域 -->
        <div class="info_pagination">
          <div class="pagination_box">
            <el-pagination
              v-model:current-page="currentPage"
              v-model:page-size="pageSize"
              background
              :pager-count="5"
              hide-on-single-page
              layout="total, prev, pager, next"
              :total="total"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </div>

      <!-- 关闭按钮区域 -->
      <div class="close" @click="handleClose"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
// 引入广播点位数据
import { radioData } from "@/components/map/radioData";

const porps = defineProps(["currentRadio"]);

const $emit = defineEmits(["closeDialog"]);

// 当前页
const currentPage = ref(1);
// 每页多少条
const pageSize = ref(10);
// 总条数
const total = ref(1000);

// 广播列表数据
const listData = ref();

onMounted(() => {
  // 获取广播列表数据
  getListData();
});

// 获取广播列表数据
const getListData = () => {
  // 找出数组中符合条件的对象
  const Obj = radioData.find((ele) => ele.title === porps.currentRadio);
  // 列表总条数
  total.value = Obj?.list.length as number;

  // 深拷贝数据  不影响原始数据
  let temList = [...(Obj?.list as Array<string>)];

  listData.value = (temList as Array<string>).splice(
    (currentPage.value - 1) * 10,
    currentPage.value * 10
  );
};

// 改变分页器当前页数时的回调
const handleCurrentChange = (v: number) => {
  currentPage.value = v;
  getListData();
};

// 点击关闭按钮回调
const handleClose = () => {
  $emit("closeDialog", false);
};
</script>

<style lang="scss" scoped>
.container {
  z-index: 9999;
  position: absolute;
  top: -151px;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 7072px;
  height: 1872px;
  background-color: rgba($color: #000000, $alpha: 0.4);

  .mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 7072px;
    height: 1872px;
  }

  .radio {
    position: relative;
    width: 749px;
    height: 952px;
    background-image: url(@/assets/images/86.png);
    background-size: 100% 100%;

    .title {
      padding: 0 20px;
      margin-left: 230px;
      width: 305px;
      height: 46px;
      line-height: 46px;
      text-align: center;
      font-size: 35px;
      color: #ccffe6;
      font-family: "庞门正道标题体";
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .info {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      margin-top: 15px;
      width: 655px;
      height: 765px;

      .info_list {
        padding: 0 25px;
        height: 690px;
        overflow-y: auto;

        .info_item {
          display: flex;
          justify-content: space-between;
          align-items: center;
          height: 63px;
          line-height: 63px;
          font-size: 24px;
          border-bottom: 1px solid #fff;

          img {
            width: 24px;
            height: 24px;
            cursor: pointer;
          }
        }
      }

      .info_pagination {
        padding-right: 20px;
        height: 75px;

        .pagination_box {
          display: flex;
          justify-content: flex-end;
          align-items: center;
          margin-left: auto;
          width: 450px;
          height: 100%;
        }
      }
    }

    .close {
      position: absolute;
      top: 10px;
      right: 6px;
      width: 42px;
      height: 42px;
      cursor: pointer;
      background-image: url(@/assets/images/12.png);
      background-size: 100% 100%;
    }
  }
}

::v-deep(.el-pagination.is-background .el-pager li),
::v-deep(.el-pagination.is-background .btn-next),
::v-deep(.el-pagination.is-background .btn-prev) {
  color: #000;
  background-color: #cccccc;
}

::v-deep(.el-pagination.is-background .el-pager li.is-active) {
  color: #fff;
  background-color: #0aadda;
}

::v-deep(.el-pagination__total) {
  color: #fff;
}
</style>
