import throttle from '../../../utils/throttle';
Component({
  props: {
    componentData: {},
    catchChange: () => null,
    defaultNum: 0,
    targetId: '',
    maxNum: 99,
    numType: 'limit'
  },
  data: {
    isClick: true
  },

  didMount() {},

  methods: {
    // 点击加号
    onAddTap: throttle(function () {
      const {
        maxNum,
        numType
      } = this.props;

      if (this.props.defaultNum >= maxNum) {
        return my.showToast({
          content: numType === 'limit' ? '购买的商品不能超过限购数量' : '购买的商品不能超过库存最大数量'
        });
      }

      this.props.catchChange({
        number: 1,
        type: 'ADD'
      });
    }, 700),
    // 点击减号
    onDecTap: throttle(function () {
      this.props.catchChange({
        number: 1,
        type: 'SUBTRACT'
      });
    }, 700)
  }
});