<template>
<view class="Tabbar" :style="'padding-bottom:' + bottomBlankHeignt + 'rpx;height:115rpx;'">
  <!-- <view class="tab-item" bindtap="goTimely">
    <image class="nav_icon21 image" src="/pages/images/{{channel==='sort' ? iconSrc + 'sort_h':'sort'}}.png"></image>
    <view class="{{channel==='store'?'active':''}}">及时达</view>
  </view> -->
  <view class="tab-item" @tap="goHome">
    <image class="nav_icon11 image" :src="'/static/pages/images/' + (channel==='home'? iconSrc + 'home_h':'home') + '.png'"></image>
    <view :class="channel==='home'?'active':''">积分商城</view>
  </view>
  <!-- <view class="tab-item" bindtap="goLive">
    <image class="nav_icon21 image" src="/pages/images/{{channel==='live'? iconSrc + 'live_h':'live'}}.png"></image>
    <view class="{{channel==='live'?'active':''}}">直播</view>
  </view> -->
  <view class="img4 tab-item" @tap="goCart">
    <image class="nav_icon41 image" :src="'/static/pages/images/' + (channel==='cart'? iconSrc + 'cart_h':'cart') + '.png'"></image>
    <view :class="channel==='cart'?'active':''">兑换清单
      <text class="dots" v-if="count > 0">{{count}}</text>
    </view>
  </view>
  <view class="tab-item" @tap="goOrder">
    <image class="nav_icon41 image" :src="'/static/pages/images/' + (channel==='order'? iconSrc + 'cart_h':'cart') + '.png'"></image>
    <view :class="channel==='order'?'active':''">积分订单</view>
  </view>
  <!-- <view class="img5 tab-item" bindtap="goUser">
   <image class="nav_icon51 image" src="/pages/images/{{channel==='user'? iconSrc + 'user_h':'user'}}.png"></image>
    <view class="{{channel==='user'?'active':''}}">我的</view>
  </view> -->
</view>
</template>

<script>
const app = getApp();
const req = require("../../utils/request.js");
import foot from "./index";

export default {
  data() {
    return {
      // channel: 'home',
      bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
      iconSrc: req.public.iconSrc,
      about: {},
      count: ""
    };
  },

  components: {
    foot
  },
  props: {
    channel: {
      type: String,
      default: 'home'
    },
    isUpdate: {
      type: Boolean,
      default: false
    },
    productType: {
      type: Number,
      default: 0
    }
  },
  watch: {
    "isUpdate": function (isUpdate) {
      // console.log('需要更新消息', isUpdate);
      if (!this.isReady) return;
      this.getCount();
    }
  },

  mounted() {
    // console.log('ready');
    this.isReady = true;
    this.getCount();
  },

  methods: {
    getCount() {
      let from = {};

      if (this.productType == 2) {
        from.purchaseType = 2;
      } else {
        from.purchaseType = 1;
      }

      req.getRequest('/api/purchase/count', from, res => {
        this.setData({
          count: res
        });
      });
    },

    /**
     * 跳转
     */
    goHome: function () {
      if (this.channel === "home") return;
      uni.redirectTo({
        url: '/integralshop/index/index'
      });
    },
    goTimely: function () {
      if (this.channel === "sort") return;
      app.globalData.switchTab('pages/timelyDelivery/index');
    },
    goLive: function () {
      if (this.channel === "live") return;
      app.globalData.switchTab('pages/live/live');
    },
    goCart: function () {
      if (this.channel === "cart") return;
      uni.redirectTo({
        url: '/integralshop/cart/cart'
      });
    },
    goUser: function () {
      if (this.channel === "user") return;
      app.globalData.switchTab('pages/user/user');
    },
    goOrder: function () {
      if (this.channel === "oredr") return;
      app.globalData.redirectTab('integralshop/order/order?orderType=11');
    }
  }
};
</script>
<style>
@import "./index.css";
</style>