// pages/comment/comment.js
import {
  commentList
} from "../../../api/consultExpert"
Page({
      data: {
        value: 3,
        page: 1,
        isTriggered:false,
        lock: false,
        evaluation_type: 1,
        allList: [],
        goodList: [],
        commonList: [],
        doctor_id: '',
        total_quantity: 0,
        good_quantity: 0,
        bad_quantity: 0,
        scrollTop: 0,
        offsetTop: 0,

      },
      onfresh(doctor_id) {
        this.setData({
          page: 1,
          allList: [],
         goodList: [],
         commonList: [],
          lock: false
        })
        this.getEvaluationList(doctor_id);
      },
      onScroll(event) {
        wx.createSelectorQuery()
          .select('#scroller')
          .boundingClientRect((res) => {
            this.setData({
              scrollTop: event.detail.scrollTop,
              offsetTop: res.top,
            });
          })
          .exec();
      },
      handleRefresher(){
       this.setData({
         page:1,
         lock:false,
         commonList:[],
         allList:[],
         goodList:[],
       })
       this.getEvaluationList();
      },
          scrolltolower(e) {
            let {
              lock
            } = this.data;
            let addPage = this.data.page + 1;
            if (!lock) {
              this.setData({
                page: addPage
              });
              this.getEvaluationList();
            }
          },
          getEvaluationList() {
            let {
              evaluation_type,
              page,
              doctor_id
            } = this.data;
            commentList({
              doctor_id,
              page,
              per_page: 10,
              evaluation_type: evaluation_type
            }).then((res) => {
              if (res.data.length == 0) {
                this.setData({
                  lock: true,
                  isTriggered:false
                });
                return false;
              }
              if (evaluation_type == 1) {
                this.setData({
                  isTriggered:false,
                  allList: this.data.allList.concat(res.data)
                })
              } else if (evaluation_type == 2) {
                this.setData({
                  isTriggered:false,
                  goodList: this.data.goodList.concat(res.data)
                })
              } else {
             
                this.setData({
                  isTriggered:false,
                  commonList: this.data.commonList.concat(res.data)
                })
              }
              this.setData({
                total_quantity: res.total_quantity,
                good_quantity: res.good_quantity,
                bad_quantity: res.bad_quantity
              })
            })
          },
          onChange(event) {
            let currentindex = event.detail.index;
            let doctor_id = this.data.doctor_id;
            if (currentindex == 0) {
              this.setData({
                evaluation_type: 1
              });
            } else if (currentindex == 1) {
              this.setData({
                evaluation_type: 2
              });
            } else {
              this.setData({
                evaluation_type: 3
              });
            }
            this.onfresh(doctor_id);
          },
          /**
           * 生命周期函数--监听页面加载
           */
          onLoad(options) {
            this.setData({
              doctor_id: options.doctor_id
            })
            this.getEvaluationList(options.doctor_id);
          },

          /**
           * 生命周期函数--监听页面初次渲染完成
           */
          onReady() {

          },

          /**
           * 生命周期函数--监听页面显示
           */
          onShow() {

          },

          /**
           * 生命周期函数--监听页面隐藏
           */
          onHide() {

          },

          /**
           * 生命周期函数--监听页面卸载
           */
          onUnload() {

          },

          /**
           * 页面相关事件处理函数--监听用户下拉动作
           */
          onPullDownRefresh() {

          },

          /**
           * 页面上拉触底事件的处理函数
           */
          onReachBottom() {

          },

          /**
           * 用户点击右上角分享
           */
      
      })