<template>
  <div class="AppPointsChange">
    <AiTopFixed>
      <div class="header">
        <div class="header-left">
          <span>★</span>
          积分余额：{{userIntegral}}
        </div>
        <div class="header-right">
          <div @click="toMyOrder">我的订单</div>
        </div>
      </div>
    </AiTopFixed>
    <div class="list-content">
      <div class="select">
        <div :class="search.newStatus == 1 ? 'active' : ''" @click="clickNew()">最新上架</div>
        <div class="price active" @click="clickPrice()">价格<span class="top" :class="search.priceStatus == 1 ? 'active' : ''">⏶</span><span class="bottom" :class="search.priceStatus != 1 ? 'active' : ''">⏷</span></div>
        <div class="sure" :class="search.status == 2 ? 'active' : ''" @click="clickStatus()">可兑换的
          <img src="./components/imgs/check-icon.png" alt="" v-if="search.status == 2">
        </div>
      </div>
      <div class="type">
        <div class="type-item" :class="index == typeIndex ? 'active' : ''" v-for="(item, index) in typeList" :key="index" @click="typeClick(index)">{{item}}</div>
      </div>
      <div class="item" :class="item.status != 0 ? 'lack-item' : ''" v-for="(item, index) in list" :key="index" @click="toDetail(item)">
        <div class="left">
          <img :src="item.imageUrl" alt="">
        </div>
        <div class="right">
          <p>{{item.merchandiseName}}</p>
          <h3>{{item.merchandiseIntegral}}<span>积分</span></h3>
        </div>
        <img src="./components/imgs/lack-icon.png" alt="" class="status" v-if="item.status != 0"/>
      </div>
    </div>
    <!-- <AiEmpty v-else></AiEmpty> -->
  </div>
</template>

<script>
import {mapState} from "vuex";

export default {
  name: 'AppPointsChange',
  appName: '积分兑换',
  data() {
    return {
      current: 1,
      list: [],
      typeList: ['全部', '100分以下', '500分以下', '1000分以下', '5000分以下'],
      typeIndex: 0,
      search: {
        status: '',
        newStatus: '',
        priceStatus: '1'
      },
      userIntegral: ''
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad() {
    this.getList()
    this.getIntegral()
    uni.$on('reloadIntegral', () => {
      this.getIntegral()
    })
  },
  onShow() {
    document.title = '积分兑换'
  },
  methods: {
    getIntegral() {
      this.$http.post('/app/appintegraluser/appGirdIntegral?current=1&size=1').then((res) => {
        if (res.code == 0) {
          this.userIntegral = res.data.nowIntegral
        }
      })
    },
    getList() {
      this.$http.post('/app/appintegralmerchandise/listByGirdMember', null, {
        params: {
          ...this.search,
          size: 20,
          current: this.current,
          queryIntegralType: this.typeIndex
        },
      })
      .then((res) => {
        if (res.code == 0) {
          this.list = this.current > 1 ? [...this.list, ...res.data.records] : res.data.records
        }
      })
    },
    getListInit() {
      this.current = 1
      this.datas = []
      this.getList()
    },
    typeClick(index) {
      this.typeIndex = index
    },
    toDetail(item) {
      uni.navigateTo({url:`./detail?id=${item.id}&userIntegral=${this.userIntegral}`})
    },
    toMyOrder() {
      uni.navigateTo({url:`./myOrder`})
    },
    clickStatus() {
      this.search.status = this.search.status == 2 ? '' : 2
      this.getListInit()
    },
    clickNew() {
      this.search.newStatus = this.search.newStatus == 1 ? '' : 1
      this.getListInit()
    },
    clickPrice() {
      this.search.priceStatus = this.search.priceStatus == 1 ? '' : 1
      this.getListInit()
    },
  },
  onReachBottom() {
    this.current = this.current + 1
    this.getList()
  },
}
</script>

<style lang="scss" scoped>
.AppPointsChange {
  min-height: 100%;
  ::v-deep .AiTopFixed .content {
   background: #F2F2F2 !important;
   padding: 24px 16px;
  }

  .header {
    padding: 28px 24px;
    width: 100%;
    box-sizing: border-box;
    background: #FFF;
    box-shadow: 0 8px 16px 0 rgba(0,0,0,0.02);
    border-radius: 16px;
    display: flex;
    justify-content: space-between;
    font-family: PingFangSC-Regular;
    font-size: 28px;
    color: #CA906A;
    .header-left {
      line-height: 56px;
      span {
        display: inline-block;
        width: 40px;
        height: 40px;
        line-height: 36px;
        text-align: center;
        background: #CA906A;
        border-radius: 50%;
        color: #fff;
        font-size: 30px;
        margin-right: 8px;
        vertical-align: middle;
      }
    }
    .header-right {
      div {
        width: 176px;
        height: 56px;
        text-align: center;
        line-height: 56px;
        background: #FFFFFF;
        border: 1px solid #CA906A;
        border-radius: 28px;
      }
    }
  }

  .list-content{
    padding: 4px 32px 16px;
    background-color: #fff;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    .select {
      display: flex;
      div {
        flex: 1;
        text-align: center;
        height: 88px;
        line-height: 88px;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        font-size: 28px;
        color: #666;
      }
      .active {
        color: #CA906A;
      }
      .price {
        position: relative;
        span {
          position: absolute;
          left: 140px;
          width: 6px;
          height: 6px;
          color: #999;
        }
        .top {
          top: -10px;
        }
        .bottom {
          top: 6px;
        }
        .active {
          color: #CA906A;
        }
      }
      .sure {
        img {
          width: 32px;
          height: 32px;
          margin-left: 8px;
          vertical-align: middle;
        }
      }
    }
    .type {
      width: 100%;
      padding: 16px 0;
      box-sizing: border-box;
      overflow-x: scroll;
      display: flex;
      word-break: keep-all;
      .type-item{
        height: 48px;
        line-height: 48px;
        background: #F2F2F2;
        border-radius: 24px;
        padding: 0 16px;
        margin-right: 16px;
        font-size: 26px;
        color: #333;
        border: 1px solid #F2F2F2;
        box-sizing: border-box;
      }
      .active {
        color: #CA906A;
        background-color: #fff;
        border: 1px solid #CA906A;
      }
    }
    .item{
      width: 100%;
      padding: 32px 0 40px 0;
      display: flex;
      position: relative;
      .left {
        img {
          width: 168px;
          height: 176px;
        }
      }
      .right {
        width: calc(100% - 168px);
        padding-left: 24px;
        box-sizing: border-box;
        p {
          width: 100%;
          height: 80px;
          line-height: 40px;
          font-family: PingFangSC-Medium;
          font-weight: 500;
          font-size: 28px;
          color: #333;
          word-break: break-all;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          margin-bottom: 32px;
        }
        h3 {
          line-height: 60px;
          font-family: PingFangSC-SNaNpxibold;
          font-weight: 600;
          font-size: 44px;
          color: #FF6900;
          span {
            font-family: PingFangSC-Medium;
            font-weight: 500;
            font-size: 24px;
          }
        }
      }
      .status {
        position: absolute;
        bottom: 0;
        right: 0;
        width: 160px;
        height: 160px;
      }

    }
    .lack-item {
      opacity: 0.5;
    }
  }

  .height-144{
    height: 144px;
  }

  .footer {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
  }

  .btn {
    width: 100%;
    height: 112px;
    line-height: 112px;
    text-align: center;
    background: #3975C6;
    font-size: 32px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #fff;
  }
}
</style>
