<template>
  <div class="responsibility-implementation">
    <div class="title">
      <span class="line"></span>
      <span class="text">安全责任落实</span>
    </div>
    <div class="responsibility-implementation__content">
      <div class="content-title">责任书签订情况</div>
      <div class="signing-rate">
        <span>签订率</span>
        <span class="signing-rate-value">
          <span class="signing-rate-value-bar" :style="{ width: `${signingRate}%` }"></span>
        </span>
        <span class="signing-rate-unit">{{ signingRate }}%</span>
      </div>
      <div class="signing-nums">
        <div class="signing-nums__item" v-for="item in signingList" :key="item.name">
          <span class="name">{{ item.name }}</span>
          <span class="num">{{ item.num }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { onMounted, ref } from 'vue';
  import { getResponsibilityImplementation } from '@/api/institute-safety';

  interface SigningList {
    name: string;
    num: number;
  }

  const signingRate = ref<number>(0);
  const signingList = ref<SigningList[]>([]);

  onMounted(() => {
    getResponsibilityImplementation().then((res) => {
      signingRate.value = Number(res.rate.replace('%', ''));
      signingList.value = [
        { name: '所/中心/职能部门', num: res.firstDeptSign },
        { name: '科室', num: res.unitSign },
        { name: '员工', num: res.employeeSign },
        { name: '所/中心级部门', num: res.secondDeptSign },
        { name: '常驻供应商', num: res.supplierSign },
      ];
    });
  });
</script>

<style scoped lang="scss">
  .title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;

    .line {
      width: 3px;
      height: 16px;
      background: #1777ff;
    }

    .text {
      font-weight: 500;
      font-size: 16px;
      color: #000000;
      line-height: 22px;
    }
  }

  .responsibility-implementation__content {
    width: 310px;
    height: 212px;
    margin: 0 10px;
    background: linear-gradient(90deg, #ebf3ff 0%, #fafcff 100%);
    border-radius: 4px;
    padding-top: 14px;

    .content-title {
      margin: 0 16px;
      font-weight: 500;
      font-size: 16px;
      color: #333333;
      line-height: 22px;
    }

    .signing-rate {
      margin: 16px 16px 20px 16px;
      font-weight: 400;
      font-size: 14px;
      color: #333333;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .signing-rate-value {
        width: 180px;
        height: 6px;
        background: #d8d8d8;
        border-radius: 4px;
        position: relative;

        .signing-rate-value-bar {
          width: 0;
          height: 100%;
          background: #1777ff;
          border-radius: 4px;
          position: absolute;
          left: 0;
          top: 0;
        }
      }

      .signing-rate-unit {
        font-weight: 600;
        font-family: DINAlternate;
      }
    }

    .signing-nums {
      display: grid;
      grid-template-columns: 120px 70px 70px;
      grid-auto-flow: row;
      grid-gap: 9px 12px;
      margin: 0 16px;

      .signing-nums__item {
        display: flex;
        flex-direction: column;

        .name {
          font-weight: 400;
          font-size: 14px;
          color: #666666;
          line-height: 20px;
        }

        .num {
          font-family: DINAlternate;
          font-weight: 600;
          font-size: 22px;
          color: #333333;
          line-height: 26px;
        }
      }
    }
  }
</style>
