<template>
  <view class="template-prefer tn-safe-area-inset-bottom">
    
    <!-- 顶部自定义导航 -->
    <tn-nav-bar :isBack="false" :bottomShadow="false" backgroundColor="#FFFFFF">
      <view class=""style="width: 72vw;overflow: hidden;">
        <tn-tabs :list="scrollList" :current="current" @change="tabChange" activeColor="#000" bold="true" :fontSize="36"></tn-tabs>
      </view>
    </tn-nav-bar>
    
    <!-- 更多信息-->
    <view class="tn-padding-top-sm tn-padding-bottom-sm" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
      <tn-scroll-list :indicatorWidth="100" :indicatorBarWidth="30" indicatorColor="#FFE2D9" indicatorActiveColor="#FF7043">
        <view class="tn-flex tn-margin-left-sm tn-margin-right-sm tn-margin-top">
          <block v-for="(item, index) in historyData" :key="index">
            <view class="tn-flex-1 tn-padding-sm tn-radius">
              <view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
                <view class="icon11__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur" :class="[`tn-bg-${item.color}--light tn-color-${item.color}`]">
                  <view :class="[`tn-icon-${item.icon}`]"></view>
                </view>  
                <view class="tn-color-black tn-text-sm tn-text-center tn-margin-top-sm">
                  <text class="tn-text-ellipsis" >{{ item.title }}</text>
                </view>
              </view>
            </view>
          </block>
        </view>
      </tn-scroll-list>
    </view>
    
    <view class="">
      <view class="nav_title--wrap">
        <view class="nav_title tn-cool-bg-color-15">
          <text class="tn-icon-relation tn-padding-right-sm tn-text-xxl"></text>
          <text class="tn-text-xl">好物推荐 · 商品优选</text>
          <text class="tn-icon-relation tn-padding-left-sm tn-text-xxl"></text>
        </view>
      </view>
    </view> 
       
    
    <!-- 页面内容 -->
    <view>
      <view class="tn-padding">
        <tn-waterfall ref="waterfall" v-model="list" @finish="handleWaterFallFinish">
          <template v-slot:left="{ leftList }">
            <view v-for="(item, index) in leftList" :key="item.id" class="product__item">
              <view class="item__image">
                <tn-lazy-load :threshold="-450" height="100%" :image="item.mainImage" :index="item.id" imgMode="widthFix"></tn-lazy-load>
              </view>
              <view class="item__data">
                <view class="item__title-container">
                  <view v-if="item.newProduct" class="item__store-type tn-cool-bg-color-8">图鸟社区</view>
                  <view v-else-if="item.storeType === 1" class="item__store-type tn-cool-bg-color-1">自营</view>
                  <text class="item__title">{{ item.title }}</text>
                </view>
                <view v-if="item.tags && item.tags.length > 0" class="item__tags-container">
                  <view v-for="(tagItem, tagIndex) in item.tags" :key="tagIndex" class="item__tag">{{ tagItem }}</view>
                </view>
                <view class="item__price-container">
                  <text class="item__price--unit">￥</text>
                  <text class="item__price--integer">{{ item.priceInteger }}</text>
                  <text class="item__price--dot">.</text>
                  <text class="item__price--decimal">{{ item.priceDecimal }}</text>
                </view>
              </view>
            </view>
          </template>
          <template v-slot:right="{ rightList }">
            <view v-for="(item, index) in rightList" :key="item.id" class="product__item">
              <view class="item__image">
                <tn-lazy-load :threshold="-450" height="100%" :image="item.mainImage" :index="item.id" imgMode="widthFix"></tn-lazy-load>
              </view>
              <view class="item__data">
                <view class="item__title-container">
                  <view v-if="item.storeType === 1" class="item__store-type tn-cool-bg-color-1">自营</view>
                  <text class="item__title">{{ item.title }}</text>
                </view>
                <view class="item__tags-container">
                  <view v-for="(tagItem, tagIndex) in item.tags" :key="tagIndex" class="item__tag">{{ tagItem }}</view>
                </view>
                <view class="item__price-container">
                  <text class="item__price--unit">￥</text>
                  <text class="item__price--integer">{{ item.priceInteger }}</text>
                  <text class="item__price--dot">.</text>
                  <text class="item__price--decimal">{{ item.priceDecimal }}</text>
                </view>
              </view>
            </view>
          </template>
        </tn-waterfall>
      </view>
      
      <tn-load-more :status="loadStatus"></tn-load-more>
      
      <!-- 底部tabbar start-->
      <view class="tabbar footerfixed">
        
        
        <view class="action" @click="">
          <view class="bar-icon">
            <!-- <view class="tn-icon-home-smile tn-color-gray--dark">
            </view> -->
            <image class="" src='https://resource.tuniaokj.com/images/tabbar/home_tn.png'></image>
            <!-- <image class="" src='https://resource.tuniaokj.com/images/bless/bless-home.png'></image> -->
          </view>
          <view class="tn-color-gray">首页</view>
        </view>
        <view class="action" @click="">
          <view class="bar-icon">
            <!-- <view class="tn-icon-discover tn-color-gray--dark">
            </view>  -->        
            <image class="" src='https://resource.tuniaokj.com/images/tabbar/information_tn.png'></image>
            <!-- <image class="" src='https://resource.tuniaokj.com/images/bless/bless-flower.png'></image> -->
          </view>
          <view class="tn-color-gray">圈子</view>
        </view>
        
        <!-- <view class="action bar-center">
          <view class="bar-circle tn-shadow-blur">
            <view class="tn-icon-camera-fill tn-color-white">
            </view>
          </view>
          <view class="tn-color-gray">发布</view>
        </view> -->
        
        <view class="action bar-center" @click="">
          <view class="nav-index-button">
            <view class="nav-index-button__content">
                <view class="nav-index-button__content--icon tn-flex tn-flex-row-center tn-flex-col-center">
                  <!-- <view class="tn-icon-logo-tuniao"></view> -->
                  <view class="bar-circle">
                    <!-- <image class="" src='https://resource.tuniaokj.com/images/login/1/login_top3.png'></image> -->
                    <image class="" src='https://resource.tuniaokj.com/images/bless/bless-tiger.png'></image>
                  </view>
                </view>  
            </view>
          
            <view class="nav-index-button__meteor">
              <view class="nav-index-button__meteor__wrapper">
                <view v-for="(item,index) in 6" :key="index" class="nav-index-button__meteor__item" :style="{transform: `rotateX(${-60 + (30 * index)}deg) rotateZ(${-60 + (30 * index)}deg)`}">
                  <view class="nav-index-button__meteor__item--pic"></view>
                </view>
              </view>
            </view>
          </view>
          <!-- <view class="tn-color-gray">发布</view> -->
        </view>
        
        <view class="action" @click="">
          <view class="bar-icon">
            <!-- <view class="tn-icon-image-text tn-color-gray--dark">
            </view> -->
            <image class="" src='https://resource.tuniaokj.com/images/tabbar/case_tnnew.png'></image>
            <!-- <image class="" src='https://resource.tuniaokj.com/images/bless/bless-china.png'></image> -->
          </view>
          <view class="tn-color-gray">优选</view>
        </view>
        <view class="action" @click="">
          <view class="bar-icon">
            <!-- <view class="tn-icon-my tn-color-gray--dark">
            </view> -->
            <image class="" src='https://resource.tuniaokj.com/images/tabbar/my_tn.png'></image>
            <!-- <image class="" src='https://resource.tuniaokj.com/images/bless/bless-money.png'></image> -->
          </view>
          <view class="tn-color-gray">我的</view>
        </view>
      </view>
      
      
      
      <view class="tn-padding-xl tn-margin-bottom"></view>
      
      <!-- 回到首页悬浮按钮-->
      <nav-index-button></nav-index-button>

    </view>
  </view>
</template>

<script>
  import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
  import NavIndexButton from '@/libs/components/nav-index-button.vue'
  export default {
    name: 'TemplateMyblog',
    mixins: [template_page_mixin],
    components: {
      NavIndexButton
    },
    data() {
      return {
        historyData: [
          {
            title: '分销中心',
            icon: 'organizatio',
            color: 'orange',
          },
          {
            title: '积分商城',
            icon: 'level',
            color: 'purple',
          },
          {
            title: '限时秒杀',
            icon: 'clock',
            color: 'blue',
          },
          {
            title: '社区团购',
            icon: 'team',
            color: 'purplered',
          },
          {
            title: '大转盘',
            icon: 'group-circle',
            color: 'teal',
          },
          {
            title: '商品核销',
            icon: 'scan',
            color: 'orangered',
          },
          {
            title: '满减优惠',
            icon: 'coupon',
            color: 'indigo',
          },
          {
            title: '视频直播',
            icon: 'video',
            color: 'green',
          }
        ],
        current: 0,
        scrollList: [
          {name: '推荐', count: '10'},
          {name: '周边'},
          {name: '科技'},
          {name: '音乐'},
          {name: '电影'},
          {name: '游戏'}
        ],
        loadStatus: 'loadmore',
        list: [],
        data: [
          {
            title: '图鸟科技 设计师专属笔记本 告别卡慢热',
            mainImage: 'https://resource.tuniaokj.com/images/shop/computer1.jpg',
            storeType: 1, // 1 自营 2 第三方店铺
            newProduct: true, // 是否为新品
            tags: ['满1000减80','免息'],
            price: 6999
          },
          {
            title: '图鸟科技 开发便携笔记本 告别笨重外出',
            mainImage: 'https://resource.tuniaokj.com/images/shop/computer2.jpg',
            storeType: 1, // 1 自营 2 第三方店铺
            newProduct: false, // 是否为新品
            tags: ['免息'],
            price: 7999
          },
          {
            title: '图鸟科技 T10 宇宙9000 10G全网通',
            mainImage: 'https://resource.tuniaokj.com/images/shop/phonecase2.jpg',
            storeType: 1, // 1 自营 2 第三方店铺
            newProduct: true, // 是否为新品
            tags: [],
            price: 4999
          },
          {
            title: '图鸟科技 T10Pro 宇宙9010 10G全网通',
            mainImage: 'https://resource.tuniaokj.com/images/shop/phonecase1.jpg',
            storeType: 1, // 1 自营 2 第三方店铺
            newProduct: true, // 是否为新品
            tags: [],
            price: 6999
          },
          {
            title: '图鸟科技 运动手表 不用插卡即可通话',
            mainImage: 'https://resource.tuniaokj.com/images/shop/watch1.jpg',
            storeType: 1, // 1 自营 2 第三方店铺
            newProduct: false, // 是否为新品
            tags: [],
            price: 2999
          },
          {
            title: '图鸟科技 页面设计 专为第三方提供精美酷炫页面',
            mainImage: 'https://resource.tuniaokj.com/images/shop/card.jpg',
            storeType: 2, // 1 自营 2 第三方店铺
            newProduct: false, // 是否为新品
            tags: ['酷炫'],
            price: 10999
          },
          {
            title: '图鸟科技 海报设计 想不到就过来聊聊吧',
            mainImage: 'https://resource.tuniaokj.com/images/shop/prototype1.jpg',
            storeType: 2, // 1 自营 2 第三方店铺
            newProduct: false, // 是否为新品
            tags: ['哎呀'],
            price: 399
          },
          {
            title: '图鸟科技 环保袋',
            mainImage: 'https://resource.tuniaokj.com/images/shop/bag1.jpg',
            storeType: 1, // 1 自营 2 第三方店铺
            newProduct: false, // 是否为新品
            tags: ['合作免费送'],
            price: 0
          },
          {
            title: '图鸟科技 纸杯',
            mainImage: 'https://resource.tuniaokj.com/images/shop/cup2.jpg',
            storeType: 1, // 1 自营 2 第三方店铺
            newProduct: false, // 是否为新品
            tags: ['合作免费送'],
            price: 0
          },
          {
            title: '图鸟科技 抱枕',
            mainImage: 'https://resource.tuniaokj.com/images/shop/pillow.jpg',
            storeType: 1, // 1 自营 2 第三方店铺
            newProduct: false, // 是否为新品
            tags: [],
            price: 99
          }
        ]
      }
    },
    onLoad() {
      this.getRandomData()
    },
    onReachBottom() {
      this.getRandomData()
    },
    methods: {
      // tab选项卡切换
      tabChange(index) {
        this.current = index
      },
      // 获取随机数据
      getRandomData() {
        this.loadStatus = 'loading'
        for (let i = 0; i < 10; i++) {
          let index = this.$tn.number.randomInt(0, this.data.length - 1)
          let item = JSON.parse(JSON.stringify(this.data[index]))
          let price = this.getPrice(item.price)
          item.id = this.$tn.uuid()
          item.priceInteger = price[0]
          item.priceDecimal = price[1]
          this.list.push(item)
        }
      },
      // 瀑布流加载完毕事件
      handleWaterFallFinish() {
        this.loadStatus = 'loadmore'
      },
      // 获取价格整数和小数部分
      getPrice(price) {
        const priceStr = String(price)
        if (priceStr.indexOf('.') !== -1) {
          return priceStr.split('.')
        } else {
          return [priceStr, '00']
        }
      },
      // 跳转到
      navTuniaoUI(e) {
        uni.navigateTo({
          url: '/pages/index/index'
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .template-prefer {
    // background-color: $tn-bg-gray-color;
    min-height: 100vh;
  }
  
  /* 图标容器11 start */
  .icon11 {
    &__item {
      width: 30%;
      background-color: #FFFFFF;
      border-radius: 10rpx;
      padding: 30rpx;
      margin: 20rpx 10rpx;
      transform: scale(1);
      transition: transform 0.3s linear;
      transform-origin: center center;
      
      &--icon {
        width: 100rpx;
        height: 100rpx;
        font-size: 60rpx;
        border-radius: 50%;
        margin-bottom: 18rpx;
        position: relative;
        z-index: 1;
        
        &::after {
          content: " ";
          position: absolute;
          z-index: -1;
          width: 100%;
          height: 100%;
          left: 0;
          bottom: 0;
          border-radius: inherit;
          opacity: 1;
          transform: scale(1, 1);
          background-size: 100% 100%;
          background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/icon_bg.png);
        }
      }
    }
  }  
  
  /* 标题 start */
  .nav_title {
    -webkit-background-clip: text;
    color: transparent;
    
    &--wrap {
      position: relative;
      display: flex;
      height: 120rpx;
      align-items: center;
      justify-content: center;
      font-weight: bold;
      background-image: url(https://resource.tuniaokj.com/images/title_bg/title44.png);
      background-size: cover;
    }
  }
  /* 标题 end */
  
  .product__item {
    background-color: #FFFFFF;
    border-radius: 10rpx;
    overflow: hidden;
    margin: 0 10rpx;
    margin-bottom: 20rpx;
    box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
    
    .item {
      /* 图片 start */
      &__image {
        width: 100%;
        height: auto;
        background-color: #FFFFFF;
      }
      /* 图片 end */
      
      /* 内容 start */
      &__data {
        padding: 8rpx 14rpx;
      }
      
      /* 标题 start */
      &__title-container {
        text-align: justify;
        line-height: 38rpx;
        vertical-align: middle;
      }
      &__store-type {
        height: 28rpx;
        font-size: 20rpx;
        position: relative;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0 4rpx;
        border-radius: 6rpx;
        white-space: nowrap;
        text-align: center;
        top: -2rpx;
        margin-right: 6rpx;
      }
      &__title {
        
      }
      /* 标题 end */
      
      /* 标签 start */
      &__tags-container {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-start;
      }
      &__tag {
        margin: 10rpx;
        color: #E83A30;
        border: 2rpx solid #E83A30;
        padding: 0 6rpx;
        border-radius: 10rpx;
        font-size: 20rpx;
        
        &:first-child {
          margin-left: 0rpx !important;
        }
      }
      /* 标签 end */
      
      /* 价格 start */
      &__price-container {
        font-size: 24rpx;
        color: #E83A30;
        font-weight: bold;
      }
      &__price {
        &--unit {
          
        }
        &--integer {
          font-size: 38rpx;
        }
        &--decimal {
          
        }
      }
      /* 价格 end */
      /* 内容 end */
    }
  }
  
  /* 底部tabbar start*/
  .footerfixed{
   position: fixed;
   width: 100%;
   bottom: 0;
   z-index: 999;
   background-color: #FFFFFF;
   box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
  }
  
  .tabbar {
    display: flex;
    align-items: center;
    min-height: 110rpx;
    justify-content: space-between;
  	padding: 0;
  	height: calc(110rpx + env(safe-area-inset-bottom) / 2);
  	padding-bottom: calc(env(safe-area-inset-bottom) / 2);
  }
  
  .tabbar .action {
  	font-size: 22rpx;
  	position: relative;
  	flex: 1;
  	text-align: center;
  	padding: 0;
  	display: block;
  	height: auto;
  	line-height: 1;
  	margin: 0;
  	overflow: initial;
  }
  
  .bar-center{
    animation: suspension 3s ease-in-out infinite;
  }
  
  @keyframes suspension {
    0%, 100% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(-0.8rem);
    }
  }  
  
  .tabbar .action .bar-icon {
  	width: 100rpx;
  	position: relative;
  	display: block;
  	height: auto;
  	margin: 0 auto 10rpx;
  	text-align: center;
  	font-size: 42rpx;
    // line-height: 50rpx;
  }
  
  .tabbar .action .bar-icon image {
  	width: 50rpx;
  	height: 50rpx;
  	display: inline-block;
  }
  
  .tabbar .action .bar-circle {
    position: relative;
    display: block;
    margin: 0rpx auto 0rpx;
    text-align: center;
    font-size: 52rpx;
    line-height: 90rpx;
    // background-color: #01BEFF;
    width: 100rpx !important;
    height: 100rpx !important;
    overflow: hidden;
    // border-radius: 50%;
    // box-shadow: 0px 10px 30px rgba(70,23,129, 0.12),
    //   0px -8px 40px rgba(255, 255, 255, 1),
    //   inset 0px -10px 10px rgba(70,23,129, 0.05),
    //   inset 0px 10px 20px rgba(255, 255, 255, 1);
    // box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(1, 190, 255, 0.5);
  }
  
  .tabbar .action .bar-circle image {
    width: 100rpx;
  	height: 100rpx;
  	display: inline-block;
    margin: 0rpx auto 0rpx;
  }
  
  /* 流星+悬浮 */
  .nav-index-button {
    animation: suspension 3s ease-in-out infinite;
    z-index: 999999;
    
    
    &__content {
      position: absolute;
      width: 100rpx;
      height: 100rpx;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      
      &--icon {
        width: 100rpx;
        height: 100rpx;
        font-size: 60rpx;
        border-radius: 50%;
        margin-bottom: 18rpx;
        position: relative;
        z-index: 1;
        transform: scale(0.85);
        
        &::after {
          content: " ";
          position: absolute;
          z-index: -1;
          width: 100%;
          height: 100%;
          left: 0;
          bottom: 0;
          border-radius: inherit;
          opacity: 1;
          transform: scale(1, 1);
          background-size: 100% 100%;
          // background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/icon_bg6.png);
        }
      }
    }
    
    &__meteor {
      position: absolute;
      top: 50%;
      left: 50%;
      width: 100rpx;
      height: 100rpx;
      transform-style: preserve-3d;
      transform: translate(-50%, -50%) rotateY(75deg) rotateZ(10deg);
      
      &__wrapper {
        width: 100rpx;
        height: 100rpx;
        transform-style: preserve-3d;
        animation: spin 20s linear infinite;
      }
      
      &__item {
        position: absolute;
        width: 100rpx;
        height: 100rpx;
        border-radius: 1000rpx;
        left: 0;
        top: 0;
        
        &--pic {
          display: block;
          width: 100%;
          height: 100%;
          background: url(https://resource.tuniaokj.com/images/cool_bg_image/arc1.png) no-repeat center center;
          background-size: 100% 100%;
          animation: arc 4s linear infinite;
        }
      }
    }
  }
  
  
  @keyframes suspension {
    0%, 100% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(-0.6rem);
    }
  }
  
  @keyframes spin {
    0% {
      transform: rotateX(0deg);
    }
  
    100% {
      transform: rotateX(-360deg);
    }
  }
  
  @keyframes arc {
    to {
      transform: rotate(360deg);
    }
  }
  
</style>
