var app = getApp();
Component({
  properties: {
    params: {
      type: null
    },
    index: {
      type: null
    },
    data: {
      type: null
    },
    designer: {
      type: null
    },
    sessionurl: {
      type: null
    },
    Identification: {
      type: null
    },
    grouid: {
      type: null
    },
    total: {
      type: null
    },
    bottomShow: {
      type: null
    },
    isBottomnum: {
      type: null
    }
  },
  data: {
    language: '',
    showMore: true,
    page: 1,
    total_page: 0,
    isLoadMore: true
  }, // 私有数据，可用于模板渲染

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
      let language = wx.getStorageSync('langIndex');
      this.setData({ 'language': language.en});
      this.triggerEvent('isLoadMorebtn', this.data.isLoadMore);
      // this.setData({
      // 	total_page: Math.ceil(this.data.total / 12)
      // })
      // if (this.data.page >= this.data.total_page) {
      // 	this.setData({
      // 		isLoadMore: false
      // 	})
      // }
    },
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {

  }, // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {

  },

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },

  methods: {
    gotoDetail(e) {
      let id = e.currentTarget.dataset.good.goodid;
      if(e.currentTarget.dataset.good.plugin_id != 69){
        wx.navigateTo({
          url: '/packageA/detail_v2/detail_v2?id=' + id
        });
      }else{
        wx.navigateTo({ url: '/packageA/detail_v2/detail_v2?id=' + id + '&name=69'}); 
      }
    },
    // 获取更多数据
    getMoreData() {
      let that = this;
      if (that.data.page >= that.data.total_page) {
        return;
      } else {
        that.setData({
          page: that.data.page + 1
        });
        let urlStr = app.getNetAddresss('home-page.get-page-goods');
        urlStr += '&page=' + that.data.page;
        urlStr += '&group_id=' + that.data.grouid;
        app._getNetWork({
          url: urlStr,
          success: function(resdata) {
            var res = resdata.data;
            if (res.result == 1) {
              let data = that.data.data;
              that.setData({
                data: data.concat(res.data.data)
              });
              if (that.data.page >= that.data.total_page) {
                that.setData({
                  isLoadMore: false
                });
                that.triggerEvent('isLoadMorebtn',  that.data.isLoadMore);
              }
            } else {
              that.setData({
                page: that.data.page - 1,
                isLoadMore: false
              });
              that.triggerEvent('isLoadMorebtn',  that.data.isLoadMore);
            }
          },
          fail: function(res) {
            console.log(res);
          }
        });
      }
    }
  },
  observers: {
    'isBottomnum': function(num) {
      if(num>1){
        this.getMoreData();
      }
			
    },
    'params': function() {
      this.setData({
        showMore: true,
        page: 1,
        total_page: 0,
        isLoadMore: true
      });
      this.triggerEvent('isLoadMorebtn', this.data.isLoadMore);
      this.setData({
        total_page: Math.ceil(this.data.total / 12)
      });
      if (this.data.page >= this.data.total_page) {
        this.setData({
          isLoadMore: false
        });
        this.triggerEvent('isLoadMorebtn',  this.data.isLoadMore);
      }
    }
  }
});
