<template>
  <view class="page flex-col">
    <view class="header">
      <headers titles="预约训练">
        <uni-icons @click="goback()" type="arrow-left" color="#000000"
                   size="22px"></uni-icons>
      </headers>
    </view>
    <scroll-view style="height: 100%;" scroll-y="true" class="itemContent" @scrolltolower="onReachBottomCus"
                 refresher-enabled @refresherrefresh="onRefresherrefresh" :refresher-triggered="isTriggered">
      <!-- 新增内容容器 -->
      <view class="box_2 flex-col">
        <view class="box_4 flex-col" v-for="item in appointmentList">
          <view class="group_5 flex-row justify-between">
            <view class="block_3 flex-col justify-between">
              <text class="text_2">{{ item.reservDay }}</text>
              <view class="group_6 flex-row justify-between">
                <view class="text-wrapper_1 flex-col">
                  <text class="text_3">{{ item.subjectStr }}</text>
                </view>
                <view class="text-wrapper_2 flex-col">
                  <text class="text_4">{{ item.coach }}</text>
                </view>
              </view>
            </view>
            <view class="text-wrapper_3 flex-col">
              <text class="text_5">{{ item.statusStr }}</text>
            </view>
          </view>
          <view class="text-wrapper_4 flex-row justify-between">
            <text class="text_6">时间范围：</text>
            <text class="text_7">{{ item.reservTime }}</text>
          </view>
          <view class="text-wrapper_5 flex-row justify-between">
            <text class="text_8">教练名称：</text>
            <text class="text_9">{{ item.coachName }}</text>
          </view>
        </view>
        <view class="box_5 flex-col">
          <view class="block_4 flex-row justify-between">
            <view class="group_7 flex-col justify-between">
              <text class="text_10">2025-02-20&nbsp;12:30</text>
              <view class="section_1 flex-row justify-between">
                <view class="text-wrapper_6 flex-col">
                  <text class="text_11">科目二</text>
                </view>
                <view class="text-wrapper_7 flex-col">
                  <text class="text_12">C2</text>
                </view>
              </view>
            </view>
            <view class="text-wrapper_8 flex-col">
              <text class="text_13">已审核</text>
            </view>
          </view>
          <view class="text-wrapper_9 flex-row justify-between">
            <text class="text_14">时间范围：</text>
            <text class="text_15">09:00-10:00</text>
          </view>
          <view class="text-wrapper_10 flex-row justify-between">
            <text class="text_16">教练名称：</text>
            <text class="text_17">马文峰</text>
          </view>
          <view class="block_5 flex-row">
            <view class="text-wrapper_11 flex-col">
              <text class="text_18">开始评价</text>
            </view>
          </view>
        </view>
      </view>
      <view class="box_6 flex-col">
        <view class="text-wrapper_12 flex-col">
          <text class="text_19">预约</text>
        </view>
      </view>
    </scroll-view>
  </view>
</template>
<script>
import headers from "@/components/header/headers.vue";
import request from "@/utils/request";

export default {
  components: {headers},
  data() {
    return {
      isTriggered: false,
      pageNo: 1,
      pageSize: 10,
      total: 0,
      appointmentList: [],
      constants: {}
    };
  },
  onLoad() {
    this.getList()
  },
  methods: {
    goback() {
      uni.navigateBack()
    },
    getList(){
      request({
        url: '/app-api/drivingSchool/system/reservationCourse/list',
        method: 'GET',
        params: {
          pageNum: this.pageNo,
          pageSize: this.pageSize,
        },
        tenantIdFlag: false
      }).then(res => {
        console.log('获取预约列表',res)
        if (this.pageNo === 1) {
          this.total = res.data.total
          this.appointmentList = []
          this.appointmentList = res.data.records
        }
        this.appointmentList = this.appointmentList.concat(res.data.records)
      })
    },
    /**
     * 上滑加载数据
     */
    onReachBottomCus() {
      //判断 如果页码*页容量大于等于总条数，提示该页数据加载完毕
      if (this.pageNo * this.pageSize >= this.total) {
        uni.$u.toast('没有更多数据了')
        return
      }
      //页码+1,调用获取数据的方法获取第二页数据
      this.pageNo++
      //此处调用自己获取数据列表的方法
      this.getList()
    },
    /**
     * 下拉刷新数据
     */
    onRefresherrefresh() {
      this.isTriggered = true
      this.pageNo = 1
      this.total = 0
      this.appointmentList = []
      this.getList()
    },
  }
};
</script>
<style lang='scss'>
@import '../common/common.scss';
@import './assets/style/index.rpx.scss';

// 新增样式
.content-box {
  margin-top: 88rpx; /* 根据头部高度调整 */
  padding: 20rpx;
  overflow-y: auto;
  height: calc(100vh - 88rpx); /* 确保内容区域高度正确 */
}

.header {
  width: 100%;
  background: #f4f5f6;
  box-sizing: border-box;
  padding-top: 88px;
}
</style>
