<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_jiaxiaoxiangqing/FigmaDDSSlicePNG53ddee177d4f9800624b95a9ec941112.png"
          @click="handleBack"
      />
      <text class="text_2">驾校</text>

    </view>
    <view class="group_4 flex-col">
      <image
          style="width: 100%; height: 100%;"
          referrerpolicy="no-referrer"
          src="/static/lanhu_jiaxiaoxiangqing/FigmaDDSSlicePNGcd54efcc9a8c89af0ef99c8275464828.png"
      />
    </view>
    <view class="group_5 flex-col">
      <text class="text_3">{{ schoolDetails.corpName }}</text>
      <view class="text-wrapper_1 flex-row justify-between">
        <text class="text_4">营业中</text>
        <text class="text_5">08:00-18:00</text>
      </view>
      <view class="block_2 flex-row">
        <view class="text-group_1 flex-col justify-between">
          <text class="text_6">山东省济南市历下区工业路城投伴山居三区</text>
          <text class="text_7">距离4.0km</text>
        </view>
        <view class="image-wrapper_2 flex-col">
          <image
              class="label_2"
              referrerpolicy="no-referrer"
              src="/static/lanhu_jiaxiaoxiangqing/FigmaDDSSlicePNGb598f2a62156745f7ba827352fd17464.png"
          />
        </view>
      </view>
    </view>

    <!-- <view class="container">

        <view class="section-title">
          <text class="title">报名类型</text>
        </view>


        <view class="class-list">
          <view class="class-item" v-for="(item, index) in schoolClassList" :key="index">
            <image class="class-image" :src="item.photo" />
            <view class="class-info">
              <text class="class-name">{{ item.tittle }}</text>
          <view class="class-details">
            <text class="class-type">{{ item.name }}</text>
            <text class="class-license">{{ item.type }}</text>
          </view>
              <view class="class-price">
                <text class="price">￥{{ item.price - item.favour }}</text>
                <text class="original-price">￥{{ item.price }}</text>
              </view>

            </view>
          </view>
        </view>


        <view class="view-all" @click="goClassList()">
          <text>查看全部班型 ({{ schoolClassList.length }})</text>
          <image src="/static/arrow.png" class="arrow-icon" />
        </view>
      </view> -->


    <view class="group_6 flex-col">
      <view class="box_4 flex-row justify-between">
        <view class="box_5 flex-col"></view>
        <text class="text_8">报名类型</text>
      </view>
      <view class="box_6 flex-row" v-for="(item, index) in schoolClassList" :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_2 flex-col justify-between">
            <text class="text_9">{{ item.tittle }}</text>
            <view class="text-wrapper_2 flex-row justify-between">
              <text class="text_10">￥{{ item.price - item.favour }}</text>
              <text class="text_11">￥{{ item.price }}</text>
            </view>
          </view>
          <view class="text-wrapper_3 flex-col">
            <text class="text_12">{{ item.type }}</text>
          </view>
          <view class="text-wrapper_4 flex-col">
            <text class="text_13">{{ item.name }}</text>
          </view>
        </view>
      </view>

      <view class="box_12 flex-row">
        <view class="image-text_2 flex-row justify-between" @click="goClassList()">
          <text class="text-group_3">查看全部班型({{ schoolAllClassList.length }})</text>
          <image
              class="thumbnail_2"
              referrerpolicy="no-referrer"
              src="/static/lanhu_jiaxiaoxiangqing/FigmaDDSSlicePNGb5045194768d2baa618848ea60e5a9e4.png"
          />
        </view>
      </view>
    </view>

    <view class="group_8 flex-col">
      <view class="group_9 flex-row justify-between">
        <view class="block_3 flex-col"></view>
        <text class="text_24">团队教练</text>
      </view>
      <view class="group_10 flex-row justify-between" v-for="(item, index) in schoolCoachList" :key="index">
        <view class="image-text_3 flex-row justify-between">
          <image
              class="label_3"
              referrerpolicy="no-referrer"
              :src="imagesUrl + '/' + item.image"
          />
          <view class="text-group_4 flex-col justify-between">
            <text class="text_25">{{ item.name }}</text>
            <text class="text_26">5.0</text>
            <text class="text_27">教龄&nbsp;{{ item.seniority }}年</text>
          </view>
          <view class="box_13 flex-col"></view>
        </view>
        <text class="text_28">学员&nbsp;598人</text>
      </view>

    </view>

  </view>
</template>
<script>
import request from "@/utils/request";
import config from "@/config.js"

export default {
  data() {
    return {
      imagesUrl: config.imagesUrl,
      constants: {},
      schoolId: undefined,
      tenantId: undefined,
      schoolDetails: {},
      schoolClassList: [],
      schoolAllClassList: [],
      schoolCoachList: [],

    };
  },
  onLoad(options) {
    if (options.id) {
      this.schoolId = options.id;
      this.tenantId = options.tenantId
      console.log("首页传入数据", options)
      console.log("驾校id", this.schoolId)
      console.log("驾校租户id", this.tenantId)
      this.getSchoolDetails();
      this.getSchoolClass();
      this.getSchoolAllClass()
      this.getSchoolCoach()
    }
  },
  methods: {
    handleBack() {
      uni.navigateBack({
        delta: 1
      });
    },
    getSchoolDetails() {
      request({
        url: '/userClient/base/companySmallProgram/noTenantIdGet',
        method: 'GET',
        params: {
          id: this.schoolId
        },
        tenantIdFlag: false
      }).then(res => {
        this.schoolDetails = res.data;
        this.tenantId = res.data.tenantId
        console.log('租户id', this.tenantId)
        console.log('学校详情', this.schoolDetails);
      }).catch(err => {
        console.error('获取驾校详情失败', err);
      });
    },
    getSchoolClass() {
      console.log('tenantId', this.tenantId)
      request({
        url: '/app-api/dl-drive-school-course-small/noTenantIdPage',
        method: 'GET',
        params: {
          pageNo: 1,
          pageSize: 3,
          tenantId: this.tenantId,
        },
        tenantIdFlag: false
      }).then(res => {
        this.schoolClassList = res.data.records;
        this.total = res.data.total;
        console.log('驾校课程列表', this.schoolClassList);
      })
    },

    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);
      })
    },

    getSchoolCoach() {
      request({
        url: '/app-api/dl-drive-school-coach-small/page',
        method: 'GET',
        params: {
          tenantId: this.tenantId,
        },
        tenantIdFlag: false
      }).then(res => {
        // 对数据进行排序
        const sortedList = res.data.records.sort((a, b) => b.seniority - a.seniority);
        // 取排序后的前三条数据
        this.schoolCoachList = sortedList.slice(0, 3);
        this.total = res.data.total;
        console.log('驾校教练列表', this.schoolCoachList);
      })
    },

    goClassList() {
      uni.navigateTo({
        url: '/newPages/courseList/index?tenantId=' + this.tenantId,
      });
    },
    // 跳转到详情页
    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';
</style>
