<template>
  <div>
    <div class="detailItem">
      <div class="imgparent">
        <van-nav-bar
          title="详细记录"
          left-text="返回"
          left-arrow
          @click-left="onClickLeft"
        />
      </div>
      <div class="approva_header">
        <p @click="showPicker = true">
          <img
            src="../assets/img/icon_rqxz.png"
            alt=""
          >
          <span>{{text}}</span>
          <img
            src="../assets/img/icon_xl.png"
            alt=""
          >
        </p>
      </div>
      <div>
        <van-list
          v-model="loading"
          :finished="finished"
          :finished-text="finishedText"
          @load="onLoad"
        >
          <div
            class="approba_nave"
            v-for="(item,index) in allHouseDetail"
            :key="index"
            @click="tijao(item.id)"
          >
            <p>
              <span class="soei">上班打卡 {{item.attendanceTableWork}}</span>
              <span>{{item.dateTime == null? '暂无数据' : item.dateTime }}</span>
            </p>
            <p>下班打卡 {{item.attendanceTableOffWork == null? '暂无数据' : item.attendanceTableOffWork}}</p>
          </div>
        </van-list>
      </div>
      <van-popup
        v-model="showPicker"
        position="bottom"
      >
        <van-datetime-picker
          type="date"
          @confirm="onConfirm"
          @cancel="showPicker = false"
        />
      </van-popup>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      allHouseDetail: [],
      loading: false,
      finished: false,
      text: "选择日期",
      value: "",
      showPicker: false,
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(),
      qurmond: {
        table: "attendance_table",
        pageNo: 1,
        pageSize: 4,
        orderBy: "create_time desc",
        fixedData: {
          condition: {
            // status: 1
          }
        }
      },
      page: 1, // 当前页码
      page_size: 100, // 每页多少条
      total: 0, // 总条数
      error: false, // 错误提示
      refreshing: false, // 下拉刷新
      finishedText: ""
    };
  },
  props: ["detailitem"],
  created() {
    this.appList();
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onConfirm(value) {
      const month = value;
      this.formatDateTime(month);
      this.showPicker = false;
    },
    // 提交
    onSubmit(values) {
      console.log("submit", values);
    },
    // 请求数据
    async appList() {
      const res = await this.$http.post(
        "/boman-web-core/attendance/detailedRecord",
        this.qurmond
      );
      console.log(res);
      if (res.data.code !== 200) {
        this.$msg.fail(res.data.msg);
        return false;
      }
      // this.allHouseDetail = res.data.data.rows;
      if (this.qurmond.pageNo == 1) {
        this.loading = false;
        this.allHouseDetail = res.data.data;
        this.total = res.total;
      } else {
        this.loading = false;
        this.allHouseDetail = this.allHouseDetail.concat(res.data.data);
        this.total = res.data.total;
      }
      if (res.data.data.length < this.qurmond.pageSize) {
        this.finished = true;
        this.finishedText = "没有更多啦";
      }
      if (res.data.data.length == 0) {
        this.finished = true;
        this.finishedText = "暂无数据";
        console.log(34);
      } else if (res.data.data.length < this.qurmond.pageSize) {
        console.log(12);
        this.finished = true;
        this.finishedText = "没有更多啦";
      }
      console.log(this.allHouseDetail);
    },
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      // setTimeout(() => {
      //   for (let i = 0; i < 10; i++) {
      //     this.list.push(this.list.length + 1);
      //   }
      //   // 加载状态结束
      //   this.loading = false;
      //   // 数据全部加载完成
      //   if (this.list.length >= 40) {
      //     this.finished = true;
      //   }
      // }, 1000);
      // 时间格式化
    },
    formatDateTime(inputTime) {
      let date = new Date(inputTime);
      let y = date.getFullYear();
      let m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      const time = y + "-" + m + "-" + d;
      this.text = time;
      console.log(time);

      return this.text;
      console.log(second);
      // return this.shoutime
    },
    tijao(index){
      //  this.$router.push("/ord?id=" + index);
    }
  }
};
</script>

<style lang="less">
.formtr {
  .stru {
    .van-field__control {
      text-align: right;
    }
  }

  .van-cell:not(:last-child)::after {
    border-bottom: 0;
  }
  .van-field__control--custom {
    justify-content: flex-end;
  }
  .van-cell {
    font-weight: 500;
    color: #343434;
    padding: 5.6vw 4.267vw;
  }
}
</style>


<style scoped lang="less">
.detailItem {
  background-color: #fff;
  //   height: 100vh;
  p {
    font-size: 3.333vw;
    padding: 0.833vw 0;
  }
  .imgparent {
    position: relative;
    .bottom {
      padding: 0 2.778vw;
      margin-bottom: 1.389vw;
      position: absolute;
      bottom: 0.556vw;
      background: linear-gradient(0deg, rgba(0, 0, 0, 0.85), transparent);
      justify-content: space-between;
      color: white;
      display: flex;
      left: 0;
      right: 0;
    }
  }
  .approba_nave {
    border-bottom: 0.267vw solid #dadada;
    margin: 5px 16px;
    padding: 10px 0;
    p {
      font-size: 2.667vw;
      font-family: PingFang SC;
      font-weight: 400;
      color: #343434;
    }
    p:nth-child(1) {
      display: flex;
      justify-content: space-between;
      margin-bottom: 1.333vw;
      i {
        font-style: normal;
        font-weight: 700;
      }
      .soei {
        font-size: 3.733vw;
        font-family: PingFang SC;
        font-weight: 400;
        color: #343434;
      }
      span:nth-child(2) {
        color: #aaa;
        font-weight: 500;
      }
    }
  }
}
.approva_header {
  height: 40px;
  p {
    padding: 0 4.267vw;
    display: flex;
    align-items: center;
    height: 40px;
    img:nth-child(1) {
      width: 4.267vw;
      height: 4.267vw;
    }
    img:nth-child(3) {
      width: 1.867vw;
      height: 1.867vw;
    }
    span {
      font-size: 3.467vw;
      font-family: PingFang SC;
      font-weight: 400;
      color: #343434;
      margin: 0 5px;
    }
  }
}
</style>