<template>
  <div class="StoreDetail" v-if="pageShow">
    <div class="header" :class="[isFixed ? 'header-active' : '']">
      <div class="status-bar" :style="{height: statusBarHeight + 'px'}"></div>
      <div class="nav-bar">
        <image src="/static/img/left.png" @click="back"/>
        <h2>优惠详情</h2>
      </div>
    </div>
    <div class="back-wrapper" @click="back" v-show="!isFixed" :style="{marginTop : statusBarHeight + 'px'}">
      <image src="/static/img/left.png"/>
    </div>
    <swiper class="banner" indicatorDots circular :autoplay="true" :interval="5000">
      <swiper-item v-for="(item, index) in info.logoFiles" :key="index">
        <image :src="item.url" mode="aspectFill" />
      </swiper-item>
    </swiper>
    <div class="wrapper">
      <div class="top">
        <div class="top-right">
          <h2>{{ info.merchantInfo.merchantName }}</h2>
          <p @click="toAddress">{{ info.merchantInfo.address }}</p>
        </div>
      </div>
      <div class="detail">
        <h2>优惠详情</h2>
        <div class="detail-content">
          <h3>{{ info.title }}</h3>
          <p>{{ info.content }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'StoreDetail',
    appName: '优惠详情',
    customNavigation: true,

    data () {
      return {
        isFixed: false,
        statusBarHeight: 20,
        hideStatus: false,
        pageShow: false,
        info: {}
      }
    },

    onShow () {
    },

    onLoad (query) {
      this.id = query.id
      this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight

      this.$loading()
      this.getInfo(query.id)
    },
    methods: {
      back () {
        uni.navigateBack({
          delta: 1
        })
      },

      toAddress () {
        uni.openLocation({
          latitude: this.info.merchantInfo.lat,
          longitude: this.info.merchantInfo.lng,
          scale: 18
        })
      },

      getInfo (id) {
        this.$loading()
        this.$instance.post(`/api/appmerchantinfo/queryDiscountDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data

            this.$nextTick(() => {
              this.pageShow = true
            })
          }
        })
      },

      preview (url) {
        let imgs = this.list.map(v => v.accessUrl)

        uni.previewImage({
          urls: imgs,
          current: url
        })
      }
    },

    onPageScroll (params) {
      this.isFixed = params.scrollTop > 60
    }
  }
</script>

<style lang="scss" socped>
  .StoreDetail {
    padding-bottom: 20px;

    .banner {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
      width: 100%;
      height: 480px;

      image {
        width: 100%;
        height: 480px;
      }
    }

    .wrapper {
      position: absolute;
      z-index: 2;
      left: 0;
      top: 400px;
      width: 100%;
      padding: 0 16px;

      .top {
        display: flex;
        align-items: center;
        margin-bottom: 58px;
        padding: 24px;
        background: #FFFFFF;
        box-shadow: 0 0 8px 0 rgba(0,0,0,0.02);
        border-radius: 16px;

        .top-right {
          flex: 1;
        }

        image {
          width: 112px;
          height: 112px;
          margin-right: 24px;
        }

        h2 {
          margin-bottom: 12px;
          font-size: 34px;
          color: #333333;
        }

        p {
          font-size: 26px;
          color: #999999;
        }
      }

      .detail {
        margin: 0 16px;

        h2 {
          margin-bottom: 42px;
          font-size: 34px;
          color: #1D2229;
        }

        .detail-content {
          padding: 24px;
          background: #FFFFFF;
          box-shadow: 0 0 8px 0 rgba(0,0,0,0.02);
          border-radius: 32px;

          h3 {
            margin-bottom: 24px;
            font-size: 40px;
            color: #222222;
          }

          p {
            line-height: 1.3;
            font-size: 32px;
            color: #999999;
            text-align: justify;
            white-space: pre-line;
          }
        }
      }
    }

    div {
      box-sizing: border-box;
    }

    .back-wrapper {
      position: fixed;
      z-index: 11;
      left: 20px;
      top: 24px;
      width: 40px;
      height: 40px;

      image {
        width: 40px;
        height: 40px;
      }
    }

    .header {
      position: fixed;
      left: 0;
      top: 0;
      z-index: 0;
      width: 100%;
      opacity: 0;
      transition: all 0.2s ease;

      &.header-active {
        z-index: 1111;
        opacity: 1;
        background: linear-gradient(180deg, #2D7DFF 0%, #2D7DFF 40%);
      }

      .nav-bar {
        position: relative;
        height: 88px;
        line-height: 88px;
        color: #fff;
        font-size: 32px;
        text-align: center;

        image {
          position: absolute;
          top: 0;
          left: 0;
          z-index: 12;
          width: 40px;
          height: 40px;
          padding: 24px 20px 0 20px;
          box-sizing: content-box;
        }
      }
    }
  }
</style>
