<template>
  <div class="card-box card-box-list">
    <div class="card-box-title">通话申请</div>
    <ul class="card-box-list-content">
      <li
        class="card-box card-box-list-item"
        v-for="(item, i) in viewList"
        :key="item.id"
      >
        <span class="icon icon-call-full"></span>
        <span class="ellipsis card-box-list-item-user">
          {{ item.examStudentName }}
        </span>
        <span class="call-time">{{ item.durationTime }}</span>
        <span class="ellipsis early-warning-reason">
          <span
            v-if="item.callStatus === 'CANCEL'"
            class="operation"
            @click="onCancel(item, i)"
          >
            忽略
          </span>
          <span class="operation" @click="$emit('backCall', item)">
            {{ item.callStatus === "CANCEL" ? "回拨" : "接听" }}
          </span>
        </span>
      </li>
    </ul>
  </div>
</template>

<script>
import { communicationOver } from "@/api/invigilation";
export default {
  name: "RequestCallList",
  props: {
    list: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      removed: [],
    };
  },
  computed: {
    viewList() {
      return this.list.filter((item) => !this.removed.includes(item.id));
    },
  },
  methods: {
    async onCancel(item) {
      this.removed.push(item.id);
      // await communicationCalling({
      //   recordId: item.examRecordId,
      //   source: item.source,
      // });
      await communicationOver({
        recordId: item.examRecordId,
        source: item.source,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.ellipsis {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.card-box-list {
  padding: 0 10px 10px;
  list-style: none;
  .card-box-title {
    font-size: 14px;
    font-weight: bold;
    color: #ffffff;
    line-height: 1;
    padding: 20px 0;
  }
  .card-box-list-content {
    margin: 0;
    padding: 0;
    padding-right: 10px;
    height: 300px; // 6
    overflow-y: auto;
    .card-box-list-item {
      width: unset;
      background-color: #3f444d;
      padding: 10px;
      line-height: 1;
      display: flex;
      align-items: center;
      color: #fff;
      font-size: 12px;
      &:not(:last-child) {
        margin-bottom: 6px;
      }
      .icon {
        width: 24px;
        height: 24px;
      }
      .card-box-list-item-user {
        font-weight: bold;
        margin: 0 10px;
        width: 48px;
      }
      .call-time {
        color: #a1a8b3;
      }
      .early-warning-reason {
        color: #a1a8b3;
        margin-left: auto;
        flex: 1;
        text-align: right;
        .operation {
          margin-left: 10px;
          cursor: pointer;
          &:hover {
            filter: brightness(1.2);
          }
        }
      }
    }
  }
}
</style>
