SelectionCourse.vue 7.75 KB
// 精选课程
<template>
  <div id="SelectionCourse">
    <van-search v-model="searchValue" placeholder="请输入课程关键词" @search="reloadData" />
    <!-- <van-tabs v-model="active" @click="tabChange">
      <van-tab :title="item.text" v-for="(item, index) in typeOption" :key="index"></van-tab>
    </van-tabs> -->
    <van-tabs v-model="provinceActive" :ellipsis="false" ref="tabs" color="#4092FF" @change="provinceTabChange">
      <van-tab :title="item.label" v-for="(item, index) in provinceTabList" :key="index"> </van-tab>
    </van-tabs>
    <van-list v-if="CourseData.length > 0" v-model="loading" :finished="finished" finished-text="没有更多了"
      :immediate-check="false" @load="getCourseData">
      <ServiceListSecond :list="CourseData" :courseTypeLableId="typeOption[active].id"></ServiceListSecond>
    </van-list>
    <van-empty v-if="finished && CourseData.length == 0" :image="require('@/assets/empty.png')" description="暂无活动" />
    <van-icon name="back-top" class="backtop" @click="backTop" />
  </div>
</template>

<script>
import ServiceListSecond from '@/views/Service/component/ServiceListSecond.vue'
export default {
  data () {
    return {
      pageLoading: true,
      pageSize: 10,
      pageNum: 1,
      loading: false,
      finished: false,
      searchValue: '',

      CourseData: [],
      typeOption: [],
      active: 0,
      provinceTabList: [
        { label: '推荐', text: '', value: 0, id: '' },
        { label: '越城', text: '越城区', value: 2, id: '' },
        { label: '柯桥', text: '柯桥区', value: 1, id: '' },
        { label: '上虞', text: '上虞区', value: 4, id: '' },
        { label: '诸暨', text: '诸暨市', value: 3, id: '' },
        { label: '嵊州', text: '嵊州市', value: 5, id: '' },
        { label: '新昌', text: '新昌县', value: 5, id: '' },
      ],
      provinceActive: 0,
    }
  },
  mounted () {
    let userInfo = localStorage.getItem('userInfo')
    if (userInfo) {
      userInfo = JSON.parse(userInfo)
      this.centerNo = userInfo.centerNo
    }

    // this.getCourseData()
    this.getType()
  },
  methods: {
    // 下拉刷新
    onRefresh () {
      this.pageNum = 1
      this.reloadData()
    },
    reloadData () {
      console.log('reloadData')
      this.pageNum = 1
      this.CourseData = []
      this.getCourseData()
    },
    // 精选活动
    getCourseData () {
      if (this.pageNum == 1) {
        this.$toast.loading({
          message: '加载中...',
          duration: 0,
          forbidClick: true,
        })
      }

      let labelIdList = []
      // 频道标签
      labelIdList.push(this.typeOption[this.active].id)

      let areaName = ''
      let startPrice = '-1',
        endPrice = '-1'
      this.yxAxios
        .post(`${this.yanxueUrlNew}/course/getCourseByArea`, {
          page: this.pageNum,
          pageSize: this.pageSize,
          provinceName: '浙江省',
          cityName: '绍兴市',
          areaName: this.provinceTabList[this.provinceActive].text,
        })
        // .post(`${this.yanxueUrl}/api/SchoolManage/SchoolCourseListV2`, {
        //   labelIdList: labelIdList,
        //   ageType: 0, //适应对象
        //   days: 0, //线路天数
        //   isSelfSupport: null, //是否支持定制
        //   // "provinceName":provinceName,//省份
        //   // "cityName":cityName,//城市
        //   areaName: areaName, //区
        //   startPrice: startPrice,
        //   endPrice: endPrice,
        //   courseName: this.searchValue,
        //   stype:1,
        //   pageIndex: this.pageNum,
        //   pageSize: this.pageSize,
        // })
        .then((res) => {
          this.$toast.clear()
          if (res.data.code == 200) {
            this.loading = false
            let CourseData = res.data.rows || []
            console.log('活动数据:', CourseData)
            if (this.pageSize * this.pageNum >= res.data.total) {
              this.finished = true
            } else {
              this.pageNum++
            }
            for (let i in CourseData) {
              CourseData[i].courseLabels = CourseData[i].courseLabels?.split(',')
              if (CourseData[i].startDate) {
                CourseData[i].week = this.formatWeek(this.Moment(CourseData[i].startDate).format('d'))
                CourseData[i].startDate = this.Moment(CourseData[i].startDate).format('YYYY.M.D')
                CourseData[i].endDate = this.Moment(CourseData[i].endDate).format('YYYY.M.D')
              }
            }
            this.CourseData = this.CourseData.concat(CourseData)
          } else {
            this.finished = true
            this.$toast(res.data.msg)
          }
        })
    },
    // 获取研学类型
    getType () {
      // this.yxAxios.post(`http://121.40.30.78:9000/StudyLabelDetail/List`, {
      this.yxAxios
        .post(`${this.yanxueUrl}/StudyLabelDetail/List`, {
          labelGroupId: 11,
          belongStation: '浙江省教育厅',
          platform: '电脑端',
          pageIndex: 1,
          pageSize: 10,
        })
        .then((res) => {
          if (res.data.status == 1) {
            let data = res.data.data.data
            // let typeOption = [{ text: '不限', value: 0, id: '' }]
            let typeOption = []
            for (let i in data) {
              typeOption.push({
                text: data[i].labelName,
                id: data[i].id,
                value: Number(i) + 1,
              })
            }
            console.log('研学类型:', typeOption)
            this.typeOption = typeOption
            this.getCourseData()
          } else {
            this.$toast(res.data.message)
          }
        })
    },

    // 返回顶部
    backTop () {
      document.getElementById('SelectionCourse').scrollIntoView()
    },
    // 格式化星期
    formatWeek (week) {
      return week == 1
        ? '周一'
        : week == 2
          ? '周二'
          : week == 3
            ? '周三'
            : week == 4
              ? '周四'
              : week == 5
                ? '周五'
                : week == 6
                  ? '周六'
                  : week == 0
                    ? '周日'
                    : ''
    },
    // 改变地区
    provinceTabChange () {
      this.CourseData = []
      this.getCourseData()
    },
    tabChange () {
      this.pageNum = 1
      this.CourseData = []
      this.getCourseData()
    },
  },
  components: {
    ServiceListSecond,
  },
}
</script>
<style lang="scss">
#SelectionCourse {
  width: 100%;
  min-height: 100%;
  background: #fff;
  padding-bottom: 40px;

  .drop_down_box {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .filter {
      flex-shrink: 0;
      font-size: 28px;
      padding: 0 30px;
    }
  }

  .characteristic_label {
    white-space: nowrap;
    overflow-x: auto;
    padding: 0 30px;
    padding-top: 20px;

    &::-webkit-scrollbar {
      display: none;
    }

    span {
      display: inline-block;
      padding: 10px;
      font-size: 24px;
      background: #f5f6fa;
      border-radius: 8px;
      border: 1px solid #f5f6fa;
      margin-right: 12px;

      &.active {
        background: #ebf4ff;
        color: #1373ea;
        border-color: #1373ea;
      }
    }
  }

  .page_loading {
    font-size: 24px;
    text-align: center;
    padding-top: 40px;
  }

  .backtop {
    position: fixed;
    bottom: 100px;
    right: 40px;
    font-size: 60px;
    background: #eee;
    border-radius: 10px;
    padding: 10px;
  }

  // .van-tab {
  //   font-size: 32px;
  // }
  // .van-dropdown-menu__bar {
  //   box-shadow: none;
  // }
  // .van-dropdown-menu__item {
  //   flex: none;
  //   width: 180px;
  // }
  // .van-dropdown-menu__title {
  //   font-size: 28px;
  //   color: #999;
  // }
  // .van-cell {
  //   color: #999;
  // }
}
</style>