text: var app = getApp();
  var util = require('../../utils/util.js');
  var api = require('../../config/api.js');
  
  Page({
    data: {
      comments: [],
      allCommentList: [],
      picCommentList: [],
      typeId: 0,
      valueId: 0,
      showType: 0,
      allCount: 0,
      hasPicCount: 0,
      allPage: 1,
      picPage: 1,
      nowAllPage:0,
      nowPicPage:0,
      size: 20
    },
    getCommentCount: function () {
      let that = this;
      util.request(api.CommentCount, { valueId: that.data.valueId, typeId: that.data.typeId}).then(function (res) {
        if (res.code == 200) {
          that.setData({
            allCount: res.data.allCount,
            hasPicCount: res.data.hasPicCount
          });
        }
      });
    },
    getCommentList: function(){
      let that = this;
      util.request(api.CommentList, { 
        valueId: that.data.valueId, 
        typeId: that.data.typeId, 
        size: that.data.size,
        page: (that.data.showType == 0 ? that.data.allPage : that.data.picPage),
        showType: that.data.showType 
        }).then(function (res) {
        if (res.code == 200) {
          if (that.data.showType == 0) {
            that.setData({
                comments: that.data.allCommentList
            });
            if(that.data.allPage>that.data.nowAllPage){
              that.setData({
                allCommentList: that.data.allCommentList.concat(res.data),
                allPage: res.meta.current_page,
                nowAllPage: res.meta.current_page,
                comments: that.data.allCommentList.concat(res.data)
              });
            }
          } else {
            if(that.data.picPage>that.data.nowPicPage){
              that.setData({
                comments: that.data.picCommentList
              });
              that.setData({
                picCommentList: that.data.picCommentList.concat(res.data),
                picPage: res.meta.current_page,
                nowPicPage: res.meta.current_page,
                comments: that.data.picCommentList.concat(res.data)
              });
            }
            
          }
        }
      });
    },
    onLoad: function (options) {
      // 页面初始化 options为页面跳转所带来的参数
      this.setData({
        typeId: options.typeId,
        valueId: options.valueId
      });
      this.getCommentCount();
      this.getCommentList();
    },
    onReady: function () {
      // 页面渲染完成
  
    },
    onShow: function () {
      // 页面显示
  
    },
    onHide: function () {
      // 页面隐藏
  
    },
    onUnload: function () {
      // 页面关闭
  
    },
    switchTab: function () {
      this.setData({
        showType: this.data.showType == 1 ? 0 :1
      });
  
      this.getCommentList();
    },
    onReachBottom: function(){
      console.log('onPullDownRefresh');
      if ( this.data.showType == 0) {
  
        if (this.data.allCount / this.data.size < this.data.allPage) {
          return false;
        }
  
        this.setData({
          'allPage' : this.data.allPage + 1
        });
      } else {
        if (this.data.hasPicCount / this.data.size < this.data.picPage) {
          return false;
        }
  
        this.setData({
          'picPage': this.data.picPage + 1
        });
      }
  
  
  
      this.getCommentList();
    }
  })