// packageE/community_solitaire/components/yz_cartList/yz_cartList.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      value: false,
      type: Boolean,
    },
    cardata: {
      value: [],
      type: Array,
    },
  },
  options: {
    multipleSlots: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    timer: null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    popupcartListbtn() {
      this.triggerEvent("popupcartListbtn", { clicktype: 0 });
    },
    reduceCartNum(evt) {
      let item = evt.currentTarget.dataset.item;
      item.name = 'minus';
      if (this.data.timer) clearTimeout(this.data.timer); //防抖
      this.data.timer = setTimeout(() => {
        this.triggerEvent("reduceCart", item);
      }, 200);
    },
    addCartNum(evt) {
      let item = evt.currentTarget.dataset.item;
      item.name = 'plus';
      this.data.timer = setTimeout(() => {
        this.triggerEvent("addCart", item);
      }, 200);
    },
    updateCartNum(evt) {
      let item = evt.target.dataset.item;
      item.total = evt.detail.value;
      if (evt.detail.value == "" || evt.detail.value == 0) {
        item.total = 0;
      }
      item.name = 'blur';
      this.data.timer = setTimeout(() => {
        this.triggerEvent("cartInputBlur", item);
      }, 500);
    },
  },
});
