shop_item.js 2.6 KB
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    check_num: Number, //已选择商品数量
    list: Array,
    type: Number,
    checkAll: Boolean
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    //查看商品详情
    look_detail(e) {
      let id = e.currentTarget.dataset.id;
      
      // wx.navigateTo({
      //   url: '/pages/shop_detail/shop_detail?id=' + id
      // })
    },
    enter(){
      console.log(this.data.list)
    },
    //加减商品数量
    num_change(e) {
      console.log(e)
      let num = Number(e.currentTarget.dataset.num)
      let type = e.currentTarget.dataset.type
      let index = e.currentTarget.dataset.index
      let id = e.currentTarget.dataset.id
      let product_id = e.currentTarget.dataset.product_id;
      let spec_sku_id=e.currentTarget.dataset.specid;
      console.log('属性idid ',spec_sku_id)
      if (type == 1) {
        num++
      } else {
        num--
        if (num < 1) {
          //触发删除商品的接口
          
          this.triggerEvent('delete_shop', { 
            index: index,
            id: id
           })
          return
        }
      }
      this.triggerEvent('change_num', {
        num: num,
        index: index,
        type: type,
        product_id: product_id,
        spec_sku_id:spec_sku_id
      })
    },
    lookdetail(e){
      let id=e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/shop_detail/shop_detail?id=' + id
      })
    },
    //改变商品选中状态   
    check_item(e){
      let index = e.currentTarget.dataset.index
      let check_type = e.currentTarget.dataset.check_type ? e.currentTarget.dataset.check_type:false
      let check_num = Number(this.data.check_num)
    
      if (!check_type){
        check_num ++
      } else {
        check_num --
      }
      this.triggerEvent('check_type', {
        index: index,
        check_type: !check_type,
        check_num: check_num,
      
      })
    }
  },

  lifetimes: {
    created() {
      // 在组件实例刚刚被创建时执行


    },
    attached() {
      // 在组件实例进入页面节点树时执行
    },
    ready() {
      // 在组件在视图层布局完成后执行
      this.setData({
        list: this.properties.list,
        type: this.properties.type,
        checkAll: this.properties.checkAll,
        check_num: this.properties.check_num ? this.properties.check_num:0
      })

      console.log(this.data.list)

    },
    detached() {
      // 在组件实例被从页面节点树移除时执行
    },
  }
})