<template>
  <div>
    <div v-if="showDefaultPath.includes($route.path)" :class="['footer', { iasf: isIasf }]">
      <div class="mask"></div>
      <ul v-if="isIasf" class="entry">
        <li :class="{ 'cursor-pointer': isLink(modules[14].form.link.linkName) }" @click="openLink(modules[14].form)">
          <img class="icon" :src="modules[14].form.pic" alt="">
          <p class="text">{{ modules[14].form.title }}</p>
        </li>
        <li :class="{ 'cursor-pointer': isLink(modules[15].form.link.linkName) }" @click="openLink(modules[15].form)">
          <img class="icon" :src="modules[15].form.pic" alt="">
          <p class="text">{{ modules[15].form.title }}</p>
        </li>
        <li :class="{ 'cursor-pointer': isLink(modules[16].form.link.linkName) }" @click="openLink(modules[16].form)">
          <img class="icon" :src="modules[16].form.pic" alt="">
          <p class="text">{{ modules[16].form.title }}</p>
        </li>
        <li :class="{ 'cursor-pointer': isLink(modules[17].form.link.linkName) }" @click="openLink(modules[17].form)">
          <img class="icon" :src="modules[17].form.pic" alt="">
          <p class="text">{{ modules[17].form.title }}</p>
        </li>
        <li :class="{ 'cursor-pointer': isLink(modules[18].form.link.linkName) }" @click="openLink(modules[18].form)">
          <img class="icon" :src="modules[18].form.pic" alt="">
          <p class="text">{{ modules[18].form.title }}</p>
        </li>
      </ul>
    </div>

    <!-- 这里需要读取后台的页脚设置，有3种样式 -->
    <template v-if="footers.length">
      <!-- 常规样式 -->
      <div v-if="styleId === 1" class="contact">
        <div class="inner">
          <div class="title">
            <h6>{{ footers[0].form.title }}</h6>
            <p class="text">{{ footers[0].form.des }}</p>
          </div>
          <div class="region">
            <img class="dot" src="https://huorantech.com/images/about/dot.png" alt="">
            <p class="name">{{ footers[0].form.area }}</p>
          </div>
          <div class="info">
            <img class="logo" :src="footers[1].form.pic" alt="">
            <div class="texts">
              <div class="item">
                <div class="line">
                  <img class="icon" src="https://huorantech.com/images/about/site.png" alt="">
                  {{ footers[1].form.siteName }}
                </div>
                <div class="line">
                  <img class="icon" src="https://huorantech.com/images/about/address.png" alt="">
                  {{ footers[1].form.address }}
                </div>
              </div>
              <div class="item">
                <div class="line">
                  <img class="icon" src="https://huorantech.com/images/about/phone.png" alt="">
                  {{ footers[1].form.phone }}
                </div>
                <div class="line">
                  <img class="icon" src="https://huorantech.com/images/about/mail.png" alt="">
                  {{ footers[1].form.mail }}
                </div>contact
              </div>
              <div class="qrcode">
                <img width="103" :src="footers[2].form.pic" alt="">
                <p class="text">{{ footers[2].form.title }}</p>
              </div>
              <div class="qrcode">
                <img width="103" :src="footers[3].form.pic" alt="">
                <p class="text">{{ footers[3].form.title }}</p>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 含网站导航 -->
      <div v-else-if="styleId === 2" class="footer">
        <div class="relative text-center">
          <img :src="footers[0].form.pic" alt="">
          <div class="columns flex j-center a-center m-t-20">
            <div v-for="(item, i) in columns" :key="i" class="column">
              <h6 @click="columnTo(item)">{{ item.columnName }}</h6>
              <ul v-if="item.children.length" class="children">
                <li v-for="(column, j) in item.children" :key="j" @click="columnTo(column)">{{ column.columnName }}
                </li>
              </ul>
            </div>
          </div>
          <div v-html="footers[0].form.info"></div>
        </div>
      </div>


      <!-- 英文字母 -->
      <div v-else-if="styleId === 3" class="footer3">
        <div class="bg"></div>
        <div class="inner">
          <div class="texts">
            <div class="info" v-html="footers[0].form.info"></div>
            <div class="flex text-center">
              <div class="qrcode">
                <p class="title">{{ footers[1].form.title }}</p>
                <img width="103" :src="footers[1].form.pic" alt="">
                <p class="text">{{ footers[1].form.des }}</p>
              </div>
              <div class="qrcode m-l-30">
                <p class="title">{{ footers[2].form.title }}</p>
                <img width="103" :src="footers[2].form.pic" alt="">
                <p class="text">{{ footers[2].form.des }}</p>
              </div>
            </div>
          </div>
          <div v-html="footers[3].form.info"></div>
        </div>
      </div>
    </template>

    <div class="tool">
      <div v-for="(item, i) in floatings" :key="i" class="float">
        <div class="item" :style="{ backgroundImage: 'url(' + item.pictureAddress + ')' }"></div>
        <div class="popup">
          <p v-if="item.schemeTitle" class="tips">{{ item.schemeTitle }}</p>
          <div v-html="item.schemeContentJson"></div>
        </div>
      </div>

      <div class="item topping" @click="topping"></div>
    </div>
  </div>
</template>
<script>
import mixins from '@/mixins/article'
export default {
  mixins: [mixins],
  data () {
    return {
      isIasf: false,
      showDefaultPath: ['/iasf'], // 展示默认页脚的页面
      showContactPath: ['/news', '/sfel', '/talent', '/careers', '/edu', '/news'], // 展示联系我们页脚的页面
      columns: [],
      modules: [],
      floatings: [],
      footers: [],
      styleId: 1,
    };
  },
  computed: {
    // 是否是sfel网站
    isSfel () {
      const id = this.$route.query.siteId || this.$store.getters.site
      return id == 3
    }
  },
  watch: {
    '$route': {
      handler () {
        this.getFloating()
        this.getFooter()
        if (this.$route.path === '/iasf') {
          this.isIasf = true
          this.getInfo()
        }
      },
      deep: true,
      immediate: true
    },
  },
  mounted () {
    this.getColumn()
  },
  methods: {
    // 资讯
    getColumn () {
      this.$post(this.api.listWithTreeMenuVisible, {
        siteId: this.$route.query.siteId || this.$store.state.content.site,
        columnName: '',
        templateId: '',
        typeId: '',
        isSort: 1
      }).then(({ data }) => {
        this.columns = data.slice(0, 5)
      }).catch(err => { })
    },
    // 获取iasf中文首页应用模块数据
    getInfo () {
      // 预览/详情
      this.$route.query.id && this.$post(`${this.api[this.preview ? 'getRedisCache' : 'findPage']}?columnId=${this.$route.query.id}`).then(({ data }) => {
        if (data.length) {
          // state：已发布（1）则取theEditedJson，草稿（0）则取jsonBeforeEditing
          const json = JSON.parse(this.preview ?
            data :
            data[data.length - 1][data[data.length - 1].state ? 'theEditedJson' : 'jsonBeforeEditing'])

          this.modules = json
        }
      }).catch(err => { })
    },
    // 查询悬浮栏
    async getFloating () {
      const { id } = this.$route.query
      if (id) {
        const { data } = await this.$post(`${this.api.columnDisplayFloatingBar}?columnId=${id}`)
        this.floatings = data
      } else {
        this.floatings = []
      }
    },
    // 查询页脚
    async getFooter () {
      const { id } = this.$route.query
      if (id) {
        const { data } = await this.$post(`${this.api.showTheFooterAccordingToTheColumn}?columnId=${id}`)
        if (data.length) {
          this.styleId = data[0].floatingBarStyle
          this.footers = data[0].footerContent ? JSON.parse(data[0].footerContent) : []
        } else {
          this.footers = []
        }
      } else {
        this.footers = []
      }
    },
    // 置顶
    topping () {
      document.documentElement.scrollTop = 0
      document.body.scrollTop = 0
    },
    // 判断是否有添加链接
    isLink (linkName) {
      return linkName !== '无' && linkName !== ''
    },
    // 打开链接
    async openLink (item) {
      const { link } = item
      if (link.linkName === '无' || link.linkName === '') return false
      let href = link.linkAddress
      const type = link.connectionType
      if (type === 1) { // 站内链接
        if (link.articleId) { // 文章
          // 查询文章详情。禁用的文章要提示
          const data = await this.$post(`${this.api.findArticle}?id=${link.articleId}`)
          if (data.data.isDisable) {
            return Util.errorMsg('该文章已禁用！')
          } else {
            href = '/article?articleId=' + link.articleId
          }
        } else { // 栏目
          href = '/column?id=' + link.columnId[link.columnId.length - 1]
        }
        href += '&siteId=' + (this.site)
        if (!link.articleId) href = this.$router.resolve(href).href
      } else if (type === 3) { // 站外链接
        if (link.otherArticleId) { // 文章
          // 查询文章详情。禁用的文章要提示
          const data = await this.$post(`${this.api.findArticle}?id=${link.otherArticleId}`)
          if (data.data.isDisable) {
            return Util.errorMsg('该文章已禁用！')
          } else {
            href = '/article?articleId=' + link.otherArticleId
          }
        } else { // 栏目
          href = '/column?id=' + link.otherColumnId[link.otherColumnId.length - 1]
        }
        href += '&siteId=' + link.site
        if (!link.otherArticleId) href = this.$router.resolve(href).href
      }
      // 如果是站内/站外链接，并且选择的是文章，则要获取当前长页名称传到文章详情里，面包屑点返回的时候需要返回到当前长页
      if ((type === 1 && link.articleId) || (type === 3 && link.otherArticleId)) {
        this.$post(`${this.api.findColumn}?id=${this.id}`).then(({ data }) => {
          href = this.$router.resolve(href + '&id=' + this.id + '&columnName=' + data.columnName + '&path=' + this.$route.path.replace('/', '')).href
          this.toHref(link.isOpen, href)
        }).catch(res => { })
      } else {
        this.toHref(link.isOpen, href)
      }
    },
    // 跳转地址
    toHref (isOpen, href) {
      if (isOpen) {
        var userAgent = navigator.userAgent;
        var isSafari = /Safari/.test(userAgent) && !/Chrome/.test(userAgent);
        if (isSafari) {
          window.location.href = href
        } else {
          window.open(href)
        }
      } else {
        window.location.href = href
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.footer {
  position: relative;
  padding: 48px 20% 25px;
  color: #fff;
  background-color: #091733;
  overflow: hidden;
  background: rgba(0, 5, 12, .8) url(../../assets/images/footer-bg.png) no-repeat;

  .meta {
    margin-bottom: 10px;
    font-size: 14px;
  }

  .column {
    margin: 0 20px;

    h6 {
      margin-bottom: 20px;
      font-size: 16px;
      white-space: nowrap;
      cursor: pointer;
    }
  }

  .children {
    li {
      margin: 12px 0;
      font-size: 14px;
      color: #6d7384;
      white-space: nowrap;
      cursor: pointer;
    }
  }

  .copyright {
    font-size: 14px;
    color: #6d7384;
  }

  &.iasf {
    padding-top: 50px;
    background: url(http://10.10.11.7/images/iasf/footer.jpg) 0 -400px/100% auto no-repeat;
    background-color: #091733;

    .children {
      li {
        color: #fff;
      }
    }

    .mask {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: rgba(0, 0, 0, 0.6);
    }
  }
}

.entry {
  position: relative;
  display: flex;
  justify-content: space-between;
  margin-bottom: 100px;

  li {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
  }

  img {
    max-width: 100px;
  }

  .text {
    margin-top: 15px;
    font-size: 1rem;
    font-family: PingFangSC-Medium, PingFang SC;
    color: #fff;
  }
}

.contact {
  position: relative;
  padding: 0 0 106px 0;
  background: url(https://huorantech.com/images/about/map.png) 0 0 / cover no-repeat;

  .inner {
    width: 1200px;
    margin: 0 auto;
  }

  .title {
    width: 419px;
    height: 258px;
    padding: 113px 0 0 43px;
    background-color: #0854fe;

    h6 {
      margin-bottom: 20px;
      font-size: 46px;
      color: #fff;
    }

    .text {
      font-size: 28px;
      color: #fff;
    }
  }

  .region {
    position: absolute;
    top: 152px;
    left: 70%;
    display: flex;
    align-items: center;
    font-size: 20px;
    color: #fff;

    img {
      margin-right: 20px;
    }
  }

  .info {
    margin: 86px 0 0 44px;

    .texts {
      display: flex;
      align-items: center;
      margin-top: 24px;
    }

    .item {
      margin-right: 70px;
    }

    .line {
      display: flex;
      align-items: center;
      margin-bottom: 20px;
      font-size: 16px;
      color: #fff;

      img {
        margin-right: 8px;
      }
    }
  }

  .qrcode {
    text-align: center;

    &:last-child {
      margin-left: 30px;
    }

    .text {
      margin-top: 10px;
      font-size: 12px;
      color: #fff;
      white-space: nowrap;
    }
  }
}

.footer3 {
  position: relative;
  padding: 30px 0;
  background-color: #000;

  .bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url(../../assets/images/footer-bg1.jpg) 0 0/cover no-repeat;
    opacity: .2;
  }

  .inner {
    position: relative;
    width: 1200px;
    margin: 0 auto;
  }

  .texts {
    display: flex;
    justify-content: space-between;
  }

  .qrcode {
    color: #fff;

    img {
      margin: 10px 0;
    }

    .title {
      font-size: 14px;
    }

    .text {
      font-size: 12px;
    }
  }
}

.tool {
  z-index: 10;
  position: fixed;
  bottom: 100px;
  right: 30px;

  .item {
    width: 45px;
    height: 45px;
    margin-bottom: 10px;
    border: 1px solid #e5e5e5;
    cursor: pointer;
    background-color: #fff;
    background-position: center center;
    background-repeat: no-repeat;

    &:hover {
      border-color: #1692ff;
    }
  }

  .topping {
    background: #fff url(https://huorantech.com/images/index/top.png) center center/auto no-repeat;

    &:hover {
      background-image: url(https://huorantech.com/images/index/top-1.png);
      background-color: #006eff;
    }
  }

  .popup {
    position: absolute;
    display: none;
    top: -100px;
    right: 45px;
    padding: 20px;
    background-color: #fff;
    background-clip: padding-box;
    border-right: 25px solid transparent;
    box-shadow: 0px 0px 8px 0 rgba(231, 231, 231, 0.3) inset;
  }

  .float {
    position: relative;

    &:hover .popup {
      display: block;
    }
  }
}

@media (max-width: 1500px) {
  .footer {
    padding: 64px 10% 25px;
  }
}

@media (max-width: 1350px) {
  .inner {
    width: 100% !important;
  }

  .footer {
    .info {
      flex-direction: column;

      .column {
        margin-top: 20px;
        margin-left: 0;
      }
    }
  }

  .contact {
    .info {
      margin-top: 90px;
    }

    .region {
      top: 300px;
      left: 50%;
    }
  }

  .entry {
    flex-direction: column;

    li {
      margin-bottom: 30px;
    }
  }

  .footer3 {
    padding: 30px;
  }
}

@media (max-width: 780px) {
  .contact {
    .info {
      .texts {
        flex-direction: column;
        align-items: flex-start;
      }

      .qrcode {
        margin: 0 0 20px 0;
      }
    }

    .region {
      top: 275px;
      left: 30px;
    }
  }

  .footer {
    .columns {
      flex-direction: column;
    }
  }

  .footer3 {
    .texts {
      flex-direction: column;
    }

    .info {
      margin-bottom: 20px;
    }
  }
}

@media (max-width: 480px) {
  .contact {
    .title {
      width: 100%;
    }
  }
}
</style>