Home.vue 12.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
<template>
  <div class="home">
    <div class="tieshi" v-if="tieshi">
      <van-icon @click="tieshi = false" name="clear" />
      <router-link to="/Tips">
        <img src="../assets/ts_icon.png" alt="" />
      </router-link>
    </div>
    <div class="swipe">
      <img class="logo" src="../assets/logo.png" alt="logo" />
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" v-if="swipeImgs">
        <van-swipe-item v-for="(image, index) in swipeImgs" :key="index">
          <img :src="image.imgUrl" @click="goBannerDetail(index)" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="content">
      <van-search v-model="searchValue" placeholder="搜索馆关键字、活动、研学旅行" shape="round" @search="onSearch()" />
      <div class="type_box">
        <div @click="handleCourseMore()">
          <img src="@/assets/service/homeicon1.png" alt="" />
          <p>研学课程</p>
        </div>
        <div @click="handleBaseMore()">
          <img src="@/assets/service/homeicon2.png" alt="" />
          <p>研学基地</p>
        </div>
        <div @click="handleHot()">
          <img src="@/assets/service/homeicon3.png" alt="" />
          <p>热门榜单</p>
        </div>
        <div @click="handleNewMore()">
          <img src="@/assets/service/homeicon4.png" alt="" />
          <p>官方资讯</p>
        </div>
        <div @click="handleTeacher()">
          <img src="@/assets/service/homeicon5.png" alt="" />
          <p>研学导师</p>
        </div>
      </div>
      <div class="infomation_box">
        <img class="news" src="@/assets/service/news.png" @click="handleNewMore()" alt="" />
        <div class="line"></div>
        <van-swipe vertical class="new-swipe" :autoplay="5000" :show-indicators="false">
          <van-swipe-item v-for="(item, index) in NewList" :key="index">
            <p class="new_item" @click="handleNewDetail(item)">{{ item.title }}</p>
          </van-swipe-item>
        </van-swipe>
      </div>
      <!-- 精选课程 -->
      <div class="qxy_box">
        <div class="qyx_title">
          <div class="title">精选课程</div>
          <div @click="handleCourseMore()">
            <span class="more">更多</span>
            <van-icon class="more_icon" name="arrow" />
          </div>
        </div>
        <CourseList v-if="!loadingCourse" :list="CustomerCourseList"></CourseList>
        <van-empty v-else :image="require('@/assets/empty.png')" description="加载中..." />
      </div>
      <!-- 研学基地 -->
      <div class="qxy_box">
        <div class="qyx_title">
          <div class="title">研选基地</div>
          <div @click="handleBaseMore()">
            <span class="more">更多</span>
            <van-icon class="more_icon" name="arrow" />
          </div>
        </div>
        <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>
        <BaseList v-if="!loadingBase" :list="BaseList"></BaseList>
        <van-empty v-else :image="require('@/assets/empty.png')" description="加载中..." />
      </div>
      <!-- 研学游记 -->
      <div class="qxy_box">
        <div class="qyx_title">
          <div class="title">研学游记</div>
          <div @click="handleStoryMore()">
            <span class="more">更多</span>
            <van-icon class="more_icon" name="arrow" />
          </div>
        </div>
        <StoryList v-if="!loadingStory" :list="StoryList"></StoryList>
        <van-empty v-else :image="require('@/assets/empty.png')" description="加载中..." />
      </div>
      <Tabbar active="service"></Tabbar>
      <div :is="background"></div>
    </div>
  </div>
</template>

<script>
import CourseList from '@/views/Service/component/c_CourseList.vue'
import BaseList from '@/views/Service/component/c_BaseList.vue'
import StoryList from '@/views/GrowUp/c_StoryList.vue'
import Tabbar from '@/components/c_Tabbar.vue'
import Background from '../components/Background.vue'
import AllLoveGo from '../components/AllLoveGo.vue'
import './home.scss'
export default {
  components: {
    CourseList,
    BaseList,
    StoryList,
    Tabbar,
    Background,
    AllLoveGo,
  },
  data() {
    return {
      tieshi: true,
      navActive: 1,
      swipeImgs: '',
      StudyBaseList: '',
      AreaList: [],
      areaActive: 0,
      recommendList: [],
      recommendPage: 1,
      recommendCount: 0,
      CourseTypeList: '',
      tabActive: 0,
      tabBodyList: [],
      tabBodyPage: 1,
      tabBodyCount: 0,
      background: '',
      selectCity: false,
      cityList: [],

      userInfo: '',
      searchValue: '',
      loadingCourse: true,
      loadingBase: true,
      loadingStory: true,
      NewList: [], //资讯列表
      CustomerCourseList: [], //精选活动
      BaseList: [], //基地列表
      StoryList: [], //游记列表
      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() {
    sessionStorage.setItem('prePage', 'Home')
    let openId = sessionStorage.getItem('openId')
    if (process.env.NODE_ENV === 'production' && this.common.isWeiXin()) {
      if (!openId) {
        this.$router.push({ name: 'Authorize' })
        return
      }
      this.unionId = sessionStorage.getItem('unionId')
      this.getUserInfo()
    } else {
      this.unionId = this.TestUnionId
      this.$nextTick(() => {
        this.getUserInfo()
      })
    }
    this.GetNewList()
    this.GetBannerList()
    this.getCustomerCourseList() //精选活动
    this.GetBaseList()
  },
  methods: {
    // 获取资讯
    GetNewList() {
      this.yxAxios.post(`${this.proxyUrl}/manage/info/content/listWithNoContent`, { pageNum: 1, pageSize: 5 }).then((res) => {
        let NewList = res.data.rows
        console.log('资讯列表:', NewList)

        this.NewList = NewList
      })
    },
    // 精选课程
    getCustomerCourseList() {
      this.yxAxios
        .post(`${this.yanxueUrl}/api/SchoolManage/SchoolCourseListV2`, {
          labelIdList: [],
          ageType: 0, //适应对象
          days: 0, //线路天数
          isSelfSupport: '', //是否支持定制
          provinceName: '', //省份
          cityName: '', //城市
          // areaName: areaName, //区
          startPrice: -1,
          endPrice: -1,
          stype: 1,
          pageIndex: 1,
          pageSize: 4,
        })
        .then((res) => {
          let CustomerCourseList = res.data.data.data
          console.log('精选课程:', CustomerCourseList)
          for (let i in CustomerCourseList) {
            CustomerCourseList[i].course_labels = CustomerCourseList[i].course_labels?.split(',')
            if (CustomerCourseList[i].startDate) {
              CustomerCourseList[i].week = this.formatWeek(this.Moment(CustomerCourseList[i].startDate).format('d'))
              CustomerCourseList[i].startDate = this.Moment(CustomerCourseList[i].startDate).format('YYYY.M.D')
              CustomerCourseList[i].endDate = this.Moment(CustomerCourseList[i].endDate).format('YYYY.M.D')
            }
          }
          this.CustomerCourseList = CustomerCourseList
          this.loadingCourse = false
        })
    },
    // 获取研学基地
    GetBaseList() {
      this.yxAxios
        .post(`${this.yanxueUrl}/api/SchoolManage/SchoolStudyBaseList`, {
          provinceName: '浙江省',
          cityName: '绍兴市',
          areaName: this.provinceTabList[this.provinceActive].text,
          levelName: '',
          type: 0,
          StartPeopleCount: '-1',
          EndPeopleCount: '-1',
          stype: 0,
          pageIndex: 1,
          pageSize: 6,
        })
        .then((res) => {
          let BaseList = res.data.data.data
          console.log('基地列表:', BaseList)

          for (let i in BaseList) {
            BaseList[i].baseLabel = BaseList[i].baseLabel?.split(',')
          }
          this.BaseList = BaseList
          this.loadingBase = false
        })
    },

    // 改变地区
    provinceTabChange() {
      this.BaseList = []
      this.GetBaseList()
    },
    // 获取研学游记
    GetStoryList() {
      this.yxAxios.get(`${this.yanxueUrl}/api/StudiesWap/GetMyStoryList?pageIndex=1&pageSize=6`).then((res) => {
        let StoryList = res.data.data.items
        console.log('游记列表:', StoryList)

        this.StoryList = StoryList
        this.loadingStory = false
      })
    },

    handleNewDetail(item) {
      if (item.linkUrl) {
        this.yxAxios.post(`${this.proxyUrl}/manage/info/content/addReadNum`, { id: item.id }).then((res) => {
          if (res.data.code == 200) {
            location.href = item.linkUrl
          } else {
            this.$toast.fail(res.data.message)
          }
        })
      } else {
        this.$router.push({ name: 'ArticleDetail', query: { id: item.id } })
      }
    },
    // 点击研学导师
    handleTeacher() {
      this.$router.push({ name: 'Teacher' })
    },
    // 热门榜单
    handleHot() {
      this.$router.push({ name: 'RankingList' })
    },
    // 点击资讯更多
    handleNewMore() {
      this.$router.push({ name: 'Article' })
    },
    // 点击精选课程更多
    handleCourseMore() {
      this.$router.push({ name: 'SelectionCourse' })
    },
    // 点击研学基地更多
    handleBaseMore() {
      this.$router.push({ name: 'SelectionBase' })
    },
    // 点击研学游记更多
    handleStoryMore() {
      this.$router.push({ name: 'StoryList' })
    },
    goBannerDetail(index) {
      var t = this.swipeImgs[index].type
      if (t == 1) {
        window.location.href = this.swipeImgs[index].linkUrl
      } else {
        this.$router.push({
          path: '/BannerDetail',
          query: { id: this.swipeImgs[index].id },
        })
      }
    },

    GetBannerList() {
      var that = this
      this.http
        .GetBannerList({
          city: this.projectCity,
        })
        .then(function (res) {
          if (res.status == 1) {
            that.swipeImgs = res.data
          }
        })
    },
    onSearch() {
      if (this.searchValue != '') {
        this.$router.push({ name: 'SearchResult', query: { search: this.searchValue } })
      } else {
        this.$toast('请输入搜索内容')
      }
    },
    // 获取用户信息
    getUserInfo() {
      let userInfo = sessionStorage.getItem('userInfo')
      if (userInfo) {
        this.userInfo = JSON.parse(userInfo)

        this.showData = true
        this.GetStoryList()
      } else {
        this.$toast.loading({
          message: '加载中...',
          duration: 0,
          forbidClick: true,
        })
        this.yxAxios.get(`${this.proxyUrl}/api/wx/wx1305e88d2bc74073/getUserInfo?unionId=${this.unionId}`).then((res) => {
          this.$toast.clear()
          if (res.data.data) {
            this.showData = true
            this.userInfo = res.data.data
            this.GetStoryList()
            sessionStorage.setItem('userInfo', JSON.stringify(res.data.data))
          } else {
            console.log('getUserInfo失败')
            this.showData = true
          }
        })
      }
    },
    formatWeek(week) {
      return week == 1
        ? '周一'
        : week == 2
        ? '周二'
        : week == 3
        ? '周三'
        : week == 4
        ? '周四'
        : week == 5
        ? '周五'
        : week == 6
        ? '周六'
        : week == 0
        ? '周日'
        : ''
    },
  },
}
</script>
<style lang="stylus" scoped>
.bottomText {
  text-align: center;
  font-size: 1.2rem;
  color: #ccc;

  p {
    margin: 0;
  }
}

.home {
.tieshi{
			position: fixed;
			right: 20px;
			bottom: 25%;
			z-index: 1000;
			padding: 20px 20px 0 0;
			i{
				position: absolute;
				top: 0;
				right: 0;
				font-size: 3.6rem;
				z-index: 100;
				color: #c2c2c2;
			}
			img{
				width :160px;
			}
		}
  .swipe {
    position: relative;

    .logo {
      width: 25%;
      position: absolute;
      top: 20px;
      left: 20px;
      z-index: 100;
    }

    .scan {
      position: absolute;
      right: 20px;
      top: 20px;
      z-index: 100;
      color: white;
      font-size: 2.6rem;

      .tishi {
        position: absolute;
        left: -90px;
        bottom: -30px;
        width: 112px;
      }
    }

    img {
      width: 100%;
    }
  }


}
</style>