<template>
  <el-dialog
    :visible.sync="dialogVisible"
    append-to-body
    title="今日考勤情况"
    top="0"
    width="800px"
  >
    <div class="check-in-detail">
      <div class="person-detail">
        <div class="person-portrait">
          <img :src="personData.face_img_url" alt="" />
        </div>
        <div class="person-name">
          {{ personData.name }}
          <i
            :class="['iconfont', personData.sex == 1 ? 'icon-nan' : 'icon-nv']"
          ></i>
        </div>
        <div class="person-job">{{ personData.work_types_name.join("/") }}</div>
        <div class="person-status">{{ personData.duty_status_name }}</div>
        <div class="check-status">
          <div>最近考勤：{{ personData.last_attendance_time }}</div>
          <div>考勤地点：{{ personData.last_attendance_area_name }}</div>
        </div>
        <div class="person-detail-text">
          <div>工号：{{ personData.job_number }}</div>
          <div>联系电话：{{ personData.format_mobile }}</div>
          <div>所在班组：{{ personData.team_name_arr.join(",") }}</div>
          <div>所属岗位：{{ personData.position_type_name }}</div>
          <div>单位类型：{{ personData.unit_type_name_arr.join(",") }}</div>
          <div>所属单位：{{ personData.company_name }}</div>
        </div>
      </div>
      <div class="time-detail">
        <div class="time-picker">
          <i class="iconfont icon-you-22" @click="prevDay"></i>
          <span>{{ this.getTime(this.timeStamp) }}</span>
          <i class="iconfont icon-you-2-2" @click="nextDay"></i>
        </div>
        <div class="time-line">
          <i class="iconfont icon-shijian"></i>

          <div
            class="time-line-container"
            v-for="(check, index) in checkList"
            :key="index"
          >
            <div class="list-line-container">
              <div class="mid-line">
                <div class="dot"></div>
              </div>
            </div>
            <div class="time-description">
              <div class="time-description-inner">
                <div>
                  最新考勤：{{ check.record_time
                  }}<span :style="{ color: check.type, float: 'right' }">{{
                    check.type_str
                  }}</span>
                </div>
                <div>考勤地点：{{ check.area_name }}</div>
                <div class="arrow"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { getCheckPersonData, getPersonCheckInList } from "@/api/index";
export default {
  name: "CheckInDetail",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    itemId: {
      type: [String, Number],
      default: "",
    },
  },
  data() {
    return {
      timeStamp: new Date().getTime(),
      personData: {
        work_types_name: [],
        team_name_arr: [],
        unit_type_name_arr: [],
      },
      checkList: [],
    };
  },
  methods: {
    getTime(ts) {
      let date = new Date(ts);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month > 9 ? month : "0" + month;
      day = day < 10 ? "0" + day : day;
      let today = year + "-" + month + "-" + day;
      return `${today}`;
    },
    prevDay() {
      this.timeStamp = this.timeStamp - 86400000;
      this.getPersonCheckListData();
    },
    nextDay() {
      this.timeStamp = this.timeStamp + 86400000;
      this.getPersonCheckListData();
    },
    getPersonData() {
      getCheckPersonData(this.itemId).then((res) => {
        this.personData = res.data;
      });
      this.getPersonCheckListData();
    },
    getPersonCheckListData() {
      getPersonCheckInList({
        person_id: this.itemId,
        start_time: this.getTime(this.timeStamp) + " 00:00:00",
        end_time: this.getTime(this.timeStamp) + " 23:59:59",
      }).then((res) => {
        this.checkList = res.data;
      });
    },
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit("changeVisible", val);
      },
    },
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.getPersonData();
      } else {
        this.personData = {
          work_types_name: [],
          team_name_arr: [],
          unit_type_name_arr: [],
        };
        this.checkList = [];
      }
    },
  },
};
</script>
<style lang="less" scoped>
.check-in-detail {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  color: #c6def9;
  .person-detail {
    padding: 20px;
    background: #0e3c75;
    width: 240px;
    color: #fff;
    font-size: 14px;
    .person-portrait {
      padding: 40px;
      padding-bottom: 24px;
      text-align: center;
      img {
        width: 118px;
        height: 118px;
        vertical-align: top;
        border-radius: 50%;
        border: 4px solid #2268bf;
        margin: 0 auto;
      }
    }
    .person-name {
      font-size: 18px;
      margin-bottom: 18px;
      text-align: center;
    }
    .person-job {
      text-align: center;
      margin-bottom: 14px;
    }
    .person-status {
      width: 60px;
      line-height: 24px;
      background: #00c2c9;
      border-radius: 4px;
      text-align: center;
      margin: 0 auto;
      margin-bottom: 30px;
    }
    .person-detail-text {
      color: #c6def9;
      padding: 10px;
      line-height: 30px;
    }
    .check-status {
      color: #c6def9;
      border-top: 4px solid #164b8e;
      border-bottom: 4px solid #164b8e;
      padding: 10px;
      line-height: 30px;
    }
  }
  .time-detail {
    width: calc(100% - 290px);

    .time-picker {
      display: flex;
      justify-content: space-between;
      background: #0e3c75;
      padding: 20px;
      i {
        cursor: pointer;
      }
    }

    .time-line {
      margin-top: 10px;
      background: #0e3c75;
      padding: 20px;
      height: calc(100% - 110px);
      overflow-y: auto;
    }
  }
}
.time-line {
  .iconfont {
    transform: translateY(2px);
  }
  i {
    vertical-align: top;
    font-size: 24px;
  }
}

.time-line-container {
  display: flex;
  justify-content: space-between;
  transform: translateY(-3px);
  &:hover {
    .list-line-container {
      .mid-line {
        .dot {
          background: #00ffff;
          border: 2px solid #ffffff;
          border-radius: 50%;
        }
      }
    }
  }
  .time-description {
    width: calc(100% - 48px);
    height: 100px;
    .time-description-inner {
      padding: 20px 20px;
      line-height: 20px;
      color: #c6def9;
      border-radius: 6px;
      height: 40px;
      background: #134584;
      margin: 10px 0;
      position: relative;
      .arrow {
        width: 20px;
        height: 20px;
        background: url("@/assets/realname/arrow.png") no-repeat;
        background-size: 100% 100%;
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateX(-100%) translateY(-50%);
      }
      &:hover {
        background: #1c569f;
        .arrow {
          width: 20px;
          height: 20px;
          background: url("@/assets/realname/arrow-hover.png") no-repeat;
          background-size: 100% 100%;
        }
      }
    }
  }
  .list-line-container {
    width: 24px;
    .mid-line {
      width: 2px;
      height: 100px;
      background: #2f69b2;
      margin: 0 auto;
      position: relative;
      .dot {
        width: 14px;
        height: 14px;
        background: #1e4c85;
        border: 2px solid #2f69b2;
        border-radius: 50%;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translateX(-50%) translateY(-50%);
      }
    }
  }
  &:last-child {
    .mid-line {
      width: 2px;
      height: 50px;
      background: #2f69b2;
      margin: 0 auto;
      position: relative;
      .dot {
        width: 14px;
        height: 14px;
        background: #1e4c85;
        border: 2px solid #2f69b2;
        border-radius: 50%;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%) translateY(100%);
      }
    }
  }
}
</style>