doctortail.js 5.6 KB
// pages/home/doctortail/doctortail.js
var WxParse = require('../../../wxParse/wxParse.js');
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    doctorid: '',
    doctorlist: '',
    doctordetail:'',
    page:1,
    num:5,
    commentdoctorlist:[],
    status:1,
    //用户评论医生id
    commentdoctor_id:'',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    that.setData({
      doctorid: wx.getStorageSync('doctorid'),
      doctorlist: wx.getStorageSync('doctolist'),
    })
    that.getdoctorinfo();
    // that.getcommentlist();
  },

  //获取医生详情信息
  getdoctorinfo(){
    let that=this;
    let doctorlist = that.data.doctorlist

    for(var i=0;i<doctorlist.length;i++){
      if (doctorlist[i].doctor_id == that.data.doctorid){
        WxParse.wxParse('article', 'html', doctorlist[i].profile, that, 5)
        that.setData({
          doctordetail: doctorlist[i]
        })
        }
    }
    console.log(that.data.doctordetail)

  },

  //获取用户对医生的评论
  getcommentlist(){
    let that=this;
    console.log(that.data.doctorid)
    var url = '/api/portal/hospital/getDoctorCommentList';
    var params = {
      token: wx.getStorageSync('token'),
      doctor_id: that.data.doctorid,
      page:that.data.page,
      num:that.data.num,
     status:that.data.status

    }
    app.post(url, params).then((res) => {
      console.log(res);
      // that.setData({
      //   commentdoctorlist: that.data.commentdoctorlist.concat(res)
      // })

      let newdoctorlist=res;
      for (var i = 0; i < newdoctorlist.length;i++){
        newdoctorlist[i].content_text = newdoctorlist[i].content_text.substring(0,80)
        // newdoctorlist[i].content_imgs = newdoctorlist[i].content_imgs.splice(0, 5)
      }
      that.setData({
        commentdoctorlist: that.data.commentdoctorlist.concat(newdoctorlist)
      })



    }).catch((err) => {

    })

  },


    //医生评论详情页
    commentdoctordetail(e){

        wx.setStorageSync('commentdoctorid', e.currentTarget.dataset.id)
        wx.navigateTo({
            url: '../commentdoctordetail/commentdoctordetail',
        })
    },

  //最新 最热
  new: function () {
    this.setData({
      page:1,
      status: 1,
      commentdoctorlist:[]
    })
    this.getcommentlist();
  },
  hot: function () {
    this.setData({
      page:1,
      status: 2,
      commentdoctorlist:[]
    })
    this.getcommentlist();
  },


  //收藏
  collect: function (e) {
    console.log(333)
    let that = this;
    that.setData({
      commentdoctor_id: e.currentTarget.dataset.id
    })
    var collect_id = that.data.commentdoctor_id;
    console.log(collect_id);

    var list = that.data.commentdoctorlist;
    for (var i = 0; i < list.length; i++) {



      if (collect_id == list[i].id) {
        var collect = list[i].ifCollect;

        if (collect == false) {
          list[i].ifCollect= true;
        } else if (collect == true) {
          list[i].ifCollect = false
        }
      }

    }
    that.setData({
      commentdoctorlist: list
    })

   // 调取收藏的接口
    var url = '/api/portal/hospital/doDoctorCommentCollect';
    var params = {
      token: wx.getStorageSync('token'),
      doctor_comment_id: that.data.commentdoctor_id
    }
    app.post(url, params).then((res) => {
      console.log(res);
      // getCurrentPages()[getCurrentPages().length - 1].onLoad()

    }).catch((err) => {

    })

  },
  //点赞
  touchstar: function (e) {
    console.log(222)
    let that = this;
    that.setData({
      commentdoctor_id: e.currentTarget.dataset.id
    })
    var collect_id = that.data.commentdoctor_id;

    var list = that.data.commentdoctorlist;
    for (var i = 0; i < list.length; i++) {
      if (collect_id == list[i].id) {
        var touchstar = list[i].ifTouch;
        if (touchstar == false) {
          list[i].ifTouch = true;
          list[i].touch_num = list[i].touch_num+1
        } else if (touchstar == true) {
          list[i].ifTouch = false;
          list[i].touch_num = list[i].touch_num-1;
        }
      }

    }
    that.setData({
      commentdoctorlist: list
    })

    //调取点赞的接口
    var url = '/api/portal/hospital/doDoctorCommentTouch ';
    var params = {
      token: wx.getStorageSync('token'),
      doctor_comment_id: that.data.commentdoctor_id
    }
    app.post(url, params).then((res) => {
      console.log(res);
      // getCurrentPages()[getCurrentPages().length - 1].onLoad()

    }).catch((err) => {

    })

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      commentdoctorlist:[],
      page:1
    })
    this.getcommentlist()
  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      let that=this;
      that.data.page++;
    that.getcommentlist();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //点评医生
    commentdoctor:function(e){
      console.log(e)
      wx.setStorageSync('commentdoctorid', e.currentTarget.dataset.doctorid)
      wx.setStorageSync('personhospitalid', e.currentTarget.dataset.personhospitalid)
        wx.navigateTo({
            url: '../commentdoctor/commentdoctor',
        })
    }

})