<template>
<!--components/shopping-cart/shopping-cart.wxml-->
<view class="contact" id="contact" @tap="goshopCar">
  <image src="/static/pages/images/cart.png"></image>
  <text class="dots dflex" v-if="count > 0">{{count}}</text>
</view>
</template>

<script>
// components/shopping-cart/shopping-cart.js
const req = require("../../utils/request");

export default {
  data() {
    return {
      count: ""
    };
  },

  components: {},
  props: {
	  //是否更新
    isUpdate: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    "isUpdate": function (isUpdate) {
      // console.log('需要更新消息', isUpdate);
      if (!this.isReady) return;
      this.getCount();
    }
  },

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

  methods: {
    getCount() {
      req.getRequest('/api/purchase/count', {
        purchaseType: 1
      }, data => {
        this.setData({
          count: data
        });
        // console.log(this);
      });
    },

    goshopCar() {
      uni.switchTab({
        url: '/pages/cart/cart'
      });
    }

  }
};
</script>
<style>
@import "./index.css";
</style>