<template>
  <div id="serviceKQ">
    <div v-show="tabName == 'ZZY'">
      <div class="container" style="top:0">
        <van-swipe class="service_swipe" :loop="true" :show-indicators="false">
          <!-- <van-swipe-item @click="handleBanner"> -->
          <van-swipe-item>
            <img style="width:100vw" src="@/assets/service/banner3.jpg" alt="" />
          </van-swipe-item>
        </van-swipe>
        <img class="card_zzy" src="@/assets/service/card_zzy.png" alt="" @click="handleMyCard" />
        <img class="order_btn" src="@/assets/service/order.png" alt="" @click="handleMyOrder" />
        <van-pull-refresh v-model="loading" @refresh="onRefresh('campList')">
          <ServiceListFour :list="campList" :notab="false"></ServiceListFour>
        </van-pull-refresh>
      </div>
    </div>
    <div v-show="tabName == 'KQ'">
      <div class="swipeDiv">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item>
            <img src="@/assets/keqiao/kq_main1.png" style="width:100%;height:100%" />
          </van-swipe-item>
          <van-swipe-item>
            <img src="@/assets/keqiao/kq_main2.png" style="width:100%;height:100%" />
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="container" style="margin-bottom:10">
        <!-- 顶部搜索、扫一扫、个人中心 -->
        <van-sticky>
          <!-- <div class="top_tool">
            <van-search class="search" v-model="search" shape="round" background="transparent" left-icon="" right-icon="search" placeholder="搜索活动、研学旅行、服务" @search="onSearch" />
          </div> -->
          <div class="redLink" @click="handleRedLink">
            <img src="@/assets/keqiao/redlink.png" alt="" />
          </div>
        </van-sticky>
        <div class="tabsCard">
          <van-tabs v-model="active" sticky offset-top="19.73vw" z-index="100" :ellipsis="false" :before-change="beforeChange" ref="tabs">
            <van-tab title="革命遗址">
              <van-pull-refresh v-model="loading" @refresh="onRefresh('uniList')">
                <ServiceListThird :list="uniList" :notab="true"></ServiceListThird>
              </van-pull-refresh>
            </van-tab>
            <van-tab title="文化传承">
              <van-pull-refresh v-model="loading" @refresh="onRefresh('weekList')">
                <ServiceListThird :list="weekList" :notab="true"></ServiceListThird>
              </van-pull-refresh>
            </van-tab>
            <van-tab title="红色军旅">
              <van-pull-refresh v-model="loading" @refresh="onRefresh('cityList')">
                <ServiceListThird :list="cityList" :notab="true"></ServiceListThird>
              </van-pull-refresh>
            </van-tab>
            <van-tab title="共同富裕">
              <van-pull-refresh v-model="loading" @refresh="onRefresh('selectList')">
                <ServiceListThird :list="selectList" :notab="true"></ServiceListThird>
              </van-pull-refresh>
            </van-tab>
            <van-tab title="大好河山">
              <van-pull-refresh v-model="loading" @refresh="onRefresh('riverList')">
                <ServiceListThird :list="riverList" :notab="true"></ServiceListThird>
              </van-pull-refresh>
            </van-tab>
          </van-tabs>
        </div>
      </div>
    </div>

    <Tabbar4 :active="tabName"></Tabbar4>
    <!-- <screen :reload="false"></screen> -->
  </div>
</template>

<script>
import Tabbar4 from '@/component/Tabbar4'
import ServiceList from '@/views/Service/component/ServiceList.vue'
import ServiceListSecond from '@/views/Service/component/ServiceListSecond.vue'
import ServiceListThird from '@/views/Service/component/ServiceListThird.vue'
import ServiceListFour from '@/views/Service/component/ServiceListFour.vue'
import Screen from '@/views/Service/component/Screen.vue'
export default {
  props: ['centerNo'],
  data() {
    return {
      search: '',
      defaultHead: require('@/assets/head.png'),
      top_tab_active: 0,
      active: 1,
      uniList: [],
      weekList: [],
      cityList: [],
      selectList: [],
      riverList: [],
      tabName: 'KQ',
      campList: [],
      loading: false,
    }
  },
  mounted() {
    console.log('base mounted')
    // alert('servicebase show')
    this.initService()
  },
  activated() {
    console.log('base activated')
    this.initService()
  },
  methods: {
    onRefresh(list) {
      if (list == 'campList') {
        this.getCampList()
      } else if (list == 'uniList') {
        this.getUniList()
      } else if (list == 'weekList') {
        this.getWeekList()
      } else if (list == 'cityList') {
        this.getCityList()
      } else if (list == 'selectList') {
        this.getSelectList()
      } else if (list == 'riverList') {
        this.getRiverList()
      }
    },
    initService() {
      this.getUniList()
      this.getWeekList()
      this.getCityList()
      this.getSelectList()
      this.getRiverList()
      this.getCampList()
    },

    // 革命遗址
    getUniList() {
      this.$toast.loading()
      this.mgop({
        api: 'mgop.sz.hswsy.qxyList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'POST',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          area: '',
          province: '',
          city: '',
          searchType: '5',
          userId: this.centerNo,
          productTypeId: 'BQ0001',
          businessTypeId: 'BQ0001',
          channelCode: '',
        },
        onSuccess: (data) => {
          this.$toast.clear()
          let uniList = data.data.data
          for (let i in uniList) {
            uniList[i].course_labels = uniList[i].course_labels?.split(',')
            if (uniList[i].startDate) {
              uniList[i].week = this.formatWeek(this.Moment(uniList[i].startDate).format('d'))
              uniList[i].startDate = this.Moment(uniList[i].startDate).format('YYYY.M.D')
              uniList[i].endDate = this.Moment(uniList[i].endDate).format('YYYY.M.D')
            }
          }
          this.loading = false
          this.uniList = uniList
          console.log('革命遗址:', data)
        },
        onFail: (err) => {
          console.log('err', err)
        },
      })
    },
    // 文化传承
    getWeekList() {
      this.mgop({
        api: 'mgop.sz.hswsy.qxyList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'POST',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          area: '',
          province: '',
          city: '',
          searchType: '5',
          userId: this.centerNo,
          productTypeId: 'BQ0002',
          businessTypeId: 'BQ0001',
          channelCode: '',
        },
        onSuccess: (data) => {
          let weekList = data.data.data
          for (let i in weekList) {
            weekList[i].course_labels = weekList[i].course_labels?.split(',')
            if (weekList[i].startDate) {
              weekList[i].week = this.formatWeek(this.Moment(weekList[i].startDate).format('d'))
              weekList[i].startDate = this.Moment(weekList[i].startDate).format('YYYY.M.D')
              weekList[i].endDate = this.Moment(weekList[i].endDate).format('YYYY.M.D')
            }
          }
          this.loading = false
          this.weekList = weekList
          console.log('文化传承:', weekList)
        },
        onFail: (err) => {
          console.log('err', err)
        },
      })
    },
    // 红色军旅
    getCityList() {
      this.mgop({
        api: 'mgop.sz.hswsy.qxyList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'POST',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          area: '',
          province: '',
          city: '',
          searchType: '5',
          userId: this.centerNo,
          productTypeId: 'BQ0003',
          businessTypeId: 'BQ0001',
          channelCode: '',
        },
        onSuccess: (data) => {
          let cityList = data.data.data
          for (let i in cityList) {
            cityList[i].course_labels = cityList[i].course_labels?.split(',')
            if (cityList[i].startDate) {
              cityList[i].week = this.formatWeek(this.Moment(cityList[i].startDate).format('d'))
              cityList[i].startDate = this.Moment(cityList[i].startDate).format('YYYY.M.D')
              cityList[i].endDate = this.Moment(cityList[i].endDate).format('YYYY.M.D')
            }
          }
          this.loading = false
          this.cityList = cityList
          console.log('红色军旅:', cityList)
        },
        onFail: (err) => {
          console.log('err', err)
        },
      })
    },
    // 乡村振新
    getSelectList() {
      this.mgop({
        api: 'mgop.sz.hswsy.qxyList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'POST',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          area: '',
          province: '',
          city: '',
          searchType: '5',
          userId: this.centerNo,
          productTypeId: 'BQ0004',
          businessTypeId: 'BQ0001',
          channelCode: '',
        },
        onSuccess: (data) => {
          let selectList = data.data.data
          for (let i in selectList) {
            selectList[i].course_labels = selectList[i].course_labels?.split(',')
            if (selectList[i].startDate) {
              selectList[i].week = this.formatWeek(this.Moment(selectList[i].startDate).format('d'))
              selectList[i].startDate = this.Moment(selectList[i].startDate).format('YYYY.M.D')
              selectList[i].endDate = this.Moment(selectList[i].endDate).format('YYYY.M.D')
            }
          }
          this.loading = false
          this.selectList = selectList
          console.log('乡村振新:', selectList)
        },
        onFail: (err) => {
          console.log('err', err)
        },
      })
    },
    // 大好河山
    getRiverList() {
      this.mgop({
        api: 'mgop.sz.hswsy.qxyList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'POST',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          area: '',
          province: '',
          city: '',
          searchType: '5',
          userId: this.centerNo,
          productTypeId: 'BQ0005',
          businessTypeId: 'BQ0001',
          channelCode: '',
        },
        onSuccess: (data) => {
          let riverList = data.data.data
          for (let i in riverList) {
            riverList[i].course_labels = riverList[i].course_labels?.split(',')
            if (riverList[i].startDate) {
              riverList[i].week = this.formatWeek(this.Moment(riverList[i].startDate).format('d'))
              riverList[i].startDate = this.Moment(riverList[i].startDate).format('YYYY.M.D')
              riverList[i].endDate = this.Moment(riverList[i].endDate).format('YYYY.M.D')
            }
          }
          this.loading = false
          this.riverList = riverList
          console.log('大好河山:', riverList)
        },
        onFail: (err) => {
          console.log('err', err)
        },
      })
    },

    // 每周一营 6
    getCampList() {
      this.mgop({
        api: 'mgop.sz.hswsy.qxyList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'POST',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          area: '',
          province: '',
          city: '',
          searchType: '6',
          userId: this.centerNo,
          productTypeId: 'ZZY001',
          businessTypeId: 'JY0004',
          channelCode: 'GZH002',
        },
        onSuccess: (data) => {
          let campList = data.data.data
          for (let i in campList) {
            campList[i].course_labels = campList[i].course_labels?.split(',')
            if (campList[i].startDate) {
              campList[i].week = this.formatWeek(this.Moment(campList[i].startDate).format('d'))
              campList[i].startDate = this.Moment(campList[i].startDate).format('YYYY.M.D')
              campList[i].endDate = this.Moment(campList[i].endDate).format('YYYY.M.D')
            }
          }
          this.loading = false
          this.campList = campList
          console.log('每周一营:', data)
        },
        onFail: (err) => {
          console.log('err', err)
        },
      })
    },
    beforeChange(index) {
      // if (index != 0 && index != 1  && index != 2) {
      //   this.$toast('暂未开放,敬请期待!')
      //   return false
      // }
      return true
    },
    onSearch() {
      this.$toast('暂未开放,敬请期待!')
    },
    // 我的订单
    handleMyOrder() {
      this.$router.push({ name: 'ServiceOrderXST' })
    },
    // 我的优惠券
    handleMyCard() {
      // this.$toast('暂未开放,敬请期待!');
      this.$router.push({ name: 'CardBoxXST', query: { active: 1 } })
    },
    formatWeek(week) {
      return week == 1
        ? '周一'
        : week == 2
        ? '周二'
        : week == 3
        ? '周三'
        : week == 4
        ? '周四'
        : week == 5
        ? '周五'
        : week == 6
        ? '周六'
        : week == 0
        ? '周日'
        : ''
    },
    // 点击轮播
    handleBanner() {
      location.href = 'https://mp.weixin.qq.com/s/a4N3xr2nXZ-aG3OEakv-Dg'
    },
    handleRedLink() {
      let isWechat = localStorage.getItem('isWechat')
      if (isWechat==1) {
        return
      } else {
        location.href = 'https://www.wasee.com/wt/b46pjfuln&ua=WaseeVRAndroid'
      }
    },
  },
  components: {
    Tabbar4,
    ServiceList,
    Screen,
    ServiceListSecond,
    ServiceListThird,
    ServiceListFour,
  },
}
</script>
<style lang="scss" scoped>
#serviceKQ {
  width: 100%;
  height: 100%;
  background: #f8f8f8;
  // overflow: hidden;
  .swipeDiv {
    // height: 400px;
    height: 60vw;
    width: 100%;
  }
  .container {
    padding-bottom: 140px;
    .redLink {
      background: #fff;
      img {
        width: 714px;
        margin-left: 10px;
      }
    }
    .tabsCard {
      width: 100vw;
    }
    .top_tool {
      display: flex;
      align-items: center;
      // justify-content: center;
      justify-content: space-between;
      padding: 20px 24px;
      box-sizing: border-box;
      height: 108px;
      background-color: #fff;
      .logo {
        width: 82px;
      }
      .search {
        padding: 0;
        width: 100%;
        // width: 400px;
      }
      .scan {
        width: 44px;
      }
      .head {
        width: 60px;
      }
      .top_tab {
        width: 366px;
        border-radius: 33px;
        overflow: hidden;
        span {
          display: inline-block;
          width: 50%;
          line-height: 66px;
          text-align: center;
          font-size: 28px;
          color: #f3f3f3;
          background: rgba(255, 255, 255, 0.24);
          &.active {
            // color: #fff;
            color: black;
            background: rgba(255, 255, 255, 0.21);
          }
        }
      }
    }
    .service_swipe {
      img {
        width: 100%;
      }
    }
    .card_zzy {
      display: block;
      width: 704px;
      margin: 0 auto;
      margin-top: 20px;
    }
    .order_btn {
      width: 160px;
      position: fixed;
      bottom: 200px;
      right: 20px;
      z-index: 99;
    }
  }

  ::v-deep .van-tabs__wrap {
    box-shadow: 0 10px 10px rgba(238, 238, 238, 0.295);
    height: 88px;
  }
  ::v-deep .van-tab {
    // color: #fff;
    color: black;
    font-size: 28px;
    background-color: #fff;
  }
  ::v-deep .van-tab--active {
    // color: #fff;
    color: black;
    font-size: 32px;
    font-weight: bold;
  }
  ::v-deep .van-tabs__line {
    width: 48px;
    height: 6px;
    // background: #ffffff;
    background: #c90000;
    border-radius: 10px 10px 0px 0px;
  }
  .tab_img {
    width: 146px;
    transition: 0.3s linear;
  }
  .van-tab--active {
    .tab_img {
      transform: scale(1.2);
    }
  }
  .fixed_btn {
    position: fixed;
    bottom: 20vw;
    right: 0;
    span {
      display: block;
      width: 200px;
      text-align: center;
      line-height: 60px;
      font-size: 30px;
      background: rgb(100, 200, 250);
      border-top-left-radius: 30px;
      border-bottom-left-radius: 30px;
      margin-bottom: 30px;
    }
  }
}
.my-swipe .van-swipe-item {
  color: #fff;
  height: 60vw;
  font-size: 20px;
  // line-height: 400px;
  // line-height: 60vw;
  text-align: center;
  background-color: #39a9ed;
}
</style>
<style lang="scss">
// 长辈版
.elder {
  #serviceKQ {
    .container {
      .redLink {
        font-size: 44px;
        background: #ff696a;
      }
      .top_tool {
        .van-field__control {
          font-size: 44px;
        }
      }
      .van-tab {
        font-size: 40px;
      }
      .van-tab--active {
        font-size: 44px;
      }
    }
  }
}
</style>