<template>
  <div class="base_detail">
    <div class="header">
      <van-swipe class="my-swipe" indicator-color="white" v-if="detailData.coverList && detailData.coverList.length > 0">
        <van-swipe-item v-for="n in detailData.coverList" :key="n.id">
          <video
            v-if="n.cover_url.indexOf('.mp4') > -1"
            id="video"
            :src="n.cover_url"
            poster=""
            controls="controls"
            windowlessvideo="true"
            playsinline="true"
            webkit-playsinline="true"
            x5-playsinline="true"
            x-webkit-airplay="allow"
            width="100%"
            height="260px"
            type="video/mp4"
          ></video>
          <img v-if="n.cover_url.indexOf('.mp4') == -1" :src="n.cover_url" />
        </van-swipe-item>
      </van-swipe>
      <img v-else src="@/assets/service/defCoure.jpg" alt="" />
    </div>

    <div class="uni_text">
      <p class="course_name">{{ detailData.baseName }}</p>
      <p class="course_info">{{ detailData.baseInfo }}</p>
      <!-- 商品标签 -->
      <div class="tag_box">
        <template v-for="(tag, index) in detailData.baseLabel">
          <span class="tag" v-if="tag != ''" :key="index">{{ tag }}</span>
        </template>
      </div>
      <p class="address" v-if="detailData.signAddress" @click="handleAddress">
        {{ detailData.signAddress }}
        <span>导航 <van-icon class="icon" name="guide-o" /></span>
      </p>
    </div>
    <!-- 商品详情 -->
    <base-des v-if="detailData" :detailData="detailData"></base-des>
    <div class="Collection">
      <div class="box">
        <div class="btn" @click="handleShare"></div>
        <div class="btn" @click="handleContact"></div>
      </div>
    </div>
    <div class="share_mask" v-if="showShareDes" @click="showShareDes = false">
      <img class="share_des" src="@/assets/home/share.png" alt="" />
    </div>
  </div>
</template>
<script>
import BaseDes from './c_BaseDes.vue'
import './BaseDetail.scss'
export default {
  name: 'ServiceBaseDetail',
  data() {
    return {
      courseId: '',
      BindType: '', //普通出行1 定制出行2
      detailData: '',
      packageData: [], //未处理过格式的套餐表
      packageActive: 0,
      packageTypeActive: 0,
      packageArr: [], //套餐时间价格
      initPackageArr: false, //packageArr已生成
      showCourseTable: true,
      showCustomized: false, //我要定制弹窗
      AagentUser: '', //代理人联系方式
      unionId: '',
      appId: '',
      centerNo: '',
      copyUrl: '', //达人分享链接
      showShareDes: false,
    }
  },
  mounted() {
    this.baseId = this.$route.query.baseId
    sessionStorage.setItem('prePage', 'ServiceBaseDetail')
    sessionStorage.setItem('prePageQuery', JSON.stringify({ baseId: this.baseId }))
    if (process.env.NODE_ENV === 'production' && this.common.isWeiXin()) {
      let openId = sessionStorage.getItem('openId')
      if (!openId) {
        this.$router.push({ name: 'Authorize'})
        return
      }
      this.unionId = sessionStorage.getItem('unionId')
      this.getUserInfo()
    } else {
      this.unionId = this.TestUnionId
      this.getUserInfo()
    }
    this.GetBaseDetail()
  },
  methods: {
    // 获取用户信息
    getUserInfo() {
      let userInfo = sessionStorage.getItem('userInfo')
      if (userInfo) {
        userInfo = JSON.parse(userInfo)
        this.centerNo = userInfo.centerNo
      } else {
        this.$toast.loading({
          message: '加载中...',
          duration: 0,
          forbidClick: true,
        })
        this.yxAxios.get(`${this.proxyUrl}/api/wx/${this.appId}/getUserInfo?unionId=${this.unionId}`).then((res) => {
          this.$toast.clear()
          if (res.data.data) {
            this.centerNo = res.data.data.centerNo
            sessionStorage.setItem('userInfo', JSON.stringify(res.data.data))

            if (res.data.data.schoolNames || res.data.data.schoolNames == [] || res.data.data.schoolNames == 'null') {
              sessionStorage.setItem('schoolNames', JSON.stringify(res.data.data.schoolNames))
              this.$store.commit('changeSchool', res.data.data.schoolNames)
              if (!sessionStorage.getItem('schoolNamesChoose')) {
                sessionStorage.setItem('schoolNamesChoose', JSON.stringify(res.data.data.schoolNames[0]))
              }
            } else {
              sessionStorage.setItem('schoolNames', [])
              this.$store.commit('changeSchool', [])
            }
          }
        })
      }
    },

    // 获取产品详情
    GetBaseDetail() {
      if (!this.baseId) {
        this.$toast.fail('基地id缺失，请从正确的途径访问')
        return
      }
      this.$toast.loading({
        message: '加载中...',
        duration: 0,
        forbidClick: true,
      })
      this.yxAxios.get(`${this.yanxueUrl}/api/Manage/GetOneBase?id=${this.baseId}`).then((res) => {
        this.$toast.clear()
        if (res.data.status == 1) {
          this.detailData = res.data.data
          this.ReadBase()
          this.BaseVisit()
        } else {
          this.$toast.fail(res.data.message)
        }
      })
    },
    // 分享
    handleShare() {
      // this.yxAxios.post(`https://zlyx.shunzhi.net/api/BaseManage/ZlBaseShareRecord`,{
      this.yxAxios.post(`https://zlyx.shunzhi.net/api/BaseManage/ZlBaseShareRecord`,{
        baseId: this.baseId,
        baseName:this.detailData.baseName,
        location:this.detailData.address,
        area:this.detailData.area
      })
      this.showShareDes = true
    },
    // 浏览量
    ReadBase() {
      this.yxAxios.get(`${this.yanxueUrl}/api/Manage/ReadBase?id=${this.baseId}`)
    },
    //浏览量
    BaseVisit() {
      this.yxAxios.post(`${this.yanxueUrl}/api/BaseManage/BaseVisit`, {
        baseId: this.baseId,
        userId: this.centerNo,
      })
    },
    // 点击地址
    handleAddress() {
      console.log(111)
      window.location.href = `http://uri.amap.com/marker?position=${this.detailData.signLong},${this.detailData.signLat}&name=${this.detailData.signAddress}&coordinate=gaode&callnative=1`
    },
    // 点击联系方式
    handleContact() {
      let mobile = this.detailData.mobile[0]
      if (mobile) {
        window.location.href = `tel:${mobile}`
      } else {
        this.$toast('暂无联系方式')
      }
    },
  },
  components: {
    BaseDes,
  },
}
</script>
