<template>
  <view class="page flex-col">
    <view class="group_1 flex-row">
      
    </view>
    <view class="group_2 flex-row">
      <image
        class="label_1"
        referrerpolicy="no-referrer"
        src="/static/lanhu_kechengliebiao/FigmaDDSSlicePNG53ddee177d4f9800624b95a9ec941112.png"
		@click="goBack()"
      />
      <text class="text_2">课程</text>
      
    </view>
	<scroll-view
	      class="scroll-view"
	      scroll-y
	      :style="{ height: scrollHeight + 'px' }"
	    >
    <view class="group_6 flex-col" v-for="(item, index) in schoolAllClassList" :key="index" @click="goToDetail(item.id)">
      <view class="image-text_1 flex-row">
        <image
          class="image_2"
          referrerpolicy="no-referrer"
          :src="imagesUrl + '/' + item.photo"
        />
        <view class="text-group_1 flex-col justify-between">
          <text class="text_3">{{ item.tittle }}</text>
          <view class="text-wrapper_1 flex-row justify-between">
            <text class="text_4">￥{{ item.price - item.favour }}</text>
            <text class="text_5">￥{{ item.price }}</text>
          </view>
        </view>
        <view class="text-wrapper_2 flex-col">
          <text class="text_6">{{ item.type }}</text>
        </view>
        <view class="text-wrapper_3 flex-col">
          <text class="text_7">{{ item.name }}</text>
        </view>
      </view>
    </view>
	</scroll-view>
	
  </view>
</template>
<script>
import request from "@/utils/request";
import config from "@/config.js"

export default {
  data() {
    return {
		imagesUrl: config.imagesUrl,
		tenantId: undefined,
		schoolAllClassList: [],
		scrollHeight: 0,
    };
  },
  onLoad(options) {
    if (options.tenantId) {
  	  this.tenantId = options.tenantId
  	  console.log("首页传入数据", options)
  	  console.log("驾校租户id", this.tenantId)
  	  this.getSchoolAllClass()
    }
  },
  onReady() {
      // 动态计算滚动区域高度
      this.calculateScrollHeight();
    },
  methods: {
	  goBack() {
		  uni.navigateBack({
			  delta: 1 
		  });
	  },
	  getSchoolAllClass() {
	    request({
	      url: '/app-api/dl-drive-school-course-small/list',
	      method: 'GET',
	      params: {
	        tenantId: this.tenantId, 
	      },
	      tenantIdFlag: false 
	    }).then(res => {
	        this.schoolAllClassList = res.data;
	        this.total = res.data.total; 
	        console.log('驾校课程列表', this.schoolAllClassList);
	    })
	  },
	  
	  calculateScrollHeight() {
	        // 获取屏幕高度
	        const screenHeight = uni.getSystemInfoSync().windowHeight;
	        // 获取顶部区域高度（根据实际情况调整）
	        const topHeight = 100; // 假设顶部区域高度为 100px
	        // 计算滚动区域高度
	        this.scrollHeight = screenHeight - topHeight;
	    },
	// 跳转到详情页
	goToDetail(courseId) {
	  uni.navigateTo({
		url: `/newPages/courseDetail/index?courseId=${courseId}&tenantId=${this.tenantId}`,
	  });
	},
  }
};
</script>
<style lang='scss'>
@import '../common/common.scss';
@import './assets/style/index.rpx.scss';

.scroll-view {
  flex: 1;
  overflow-y: auto;
}
</style>
