commenthospitaldetail.js 6.7 KB
// pages/home/buildtextdetail/buildtextdetail.js
const app=getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        //图文编辑大图片和小图片
        edit_img: [
            // 'http://pi4orwnti.bkt.clouddn.com/editbig@2x.png',
            // 'http://pi4orwnti.bkt.clouddn.com/editbig@2x.png',
            // 'http://pi4orwnti.bkt.clouddn.com/editbig@2x.png',
        ],
        commenthospitalid:'',
        newcommenthospitalid:'',
        commenthospitaldetail:''

    },

    /**
     * 生命周期函数--监听页面加载
     */


    onLoad: function (options) {
        console.log(options)
        var commenthospitalid=wx.getStorageSync('commenthospitalid');

        if(JSON.stringify(options)!='{}'){
            this.setData({
                newcommenthospitalid:options.hospid
            })
        }else{
            this.setData({
                commenthospitalid:commenthospitalid
            })
        }



        this.getinfo()
    },


    getinfo(){
        let that=this;
        var url='/api/portal/hospital/getHospitalCommentDetail';
        if(that.data.newcommenthospitalid!=""){
            var params = {
                token: wx.getStorageSync('token'),
                hospital_comment_id:that.data.newcommenthospitalid
            }
        }else{
            var params = {
                token: wx.getStorageSync('token'),
                hospital_comment_id:that.data.commenthospitalid
            }
        }

        app.post(url, params).then((res) => {
            console.log(res)

            that.setData({
                commenthospitaldetail:res,
                edit_img:res.content_imgs
            })



        }).catch((err) => {

        })


    },
  viewImg(e) {
    let that = this;
    console.log(e)
    let index = e.currentTarget.dataset.index;
    wx.previewImage({
      current: that.data.edit_img[index],
      urls: that.data.edit_img,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
    //收藏
    collect:function(e){
        let that=this;

        let detailcollect=that.data.commenthospitaldetail.ifCollect;
        let detailtext=that.data.commenthospitaldetail
        if(detailcollect==false){
            that.data.commenthospitaldetail.ifCollect=true
        }else if(detailcollect==true){
            that.data.commenthospitaldetail.ifCollect=false

        }
        that.setData({
            commenthospitaldetail:detailtext
        })

        //调取收藏的接口
        var url = '/api/portal/hospital/doHospitalCommentCollect';

        if(that.data.newcommenthospitalid!=""){
            var params = {
                token: wx.getStorageSync('token'),
                hospital_comment_id:that.data.newcommenthospitalid
            }
        }else{
            var params = {
                token: wx.getStorageSync('token'),
                hospital_comment_id:that.data.commenthospitalid
            }
        }
        app.post(url, params).then((res) => {
            // getCurrentPages()[getCurrentPages().length - 1].onLoad()

        }).catch((err) => {

        })

    },


    //点赞
    touchstar:function(e){

        let that=this;

        let detailtouch=that.data.commenthospitaldetail.ifTouch;
        let detailtext=that.data.commenthospitaldetail
        if(detailtouch==false){
            that.data.commenthospitaldetail.ifTouch=true;
            that.data.commenthospitaldetail.touch_num= that.data.commenthospitaldetail.touch_num+1

        }else if(detailtouch==true){
            that.data.commenthospitaldetail.ifTouch=false;
            that.data.commenthospitaldetail.touch_num=that.data.commenthospitaldetail.touch_num-1;
            // if(that.data.commenthospitaldetail.touch_num<=0){

            //     that.data.commenthospitaldetail.touch_num=0
            // }else{
            //     that.data.commenthospitaldetail.touch_num= that.data.commenthospitaldetail.touch_num-1;
            // }


        }
        that.setData({
            commenthospitaldetail:detailtext
        })

        console.log(that.data.newcommenthospitalid)

        //调取点赞的接口
        var url = '/api/portal/hospital/doHospitalCommentTouch';
        if(that.data.newcommenthospitalid!=""){
            var params = {
                token: wx.getStorageSync('token'),
                hospital_comment_id:that.data.newcommenthospitalid
            }
        }else{
            var params = {
                token: wx.getStorageSync('token'),
                hospital_comment_id:that.data.commenthospitalid
            }
        }
        app.post(url, params).then((res) => {
            //getCurrentPages()[getCurrentPages().length - 1].onLoad()

        }).catch((err) => {

        })

    },

    //分享
    buildshare(){
        // wx.navigateTo({
        //     url: '../meshare/meshare',
        // })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

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

    },

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

    },

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

    },

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

    },

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

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        let that=this;
        let hospid=that.data.commenthospitalid;


        return {
            title: '评论医院详情分享', // 转发后 所显示的title
            // path: '/pages/home/buildtextdetail/buildtextdetail?buildid='+buildid+'&gettoken='+newtoken, // 相对的路径
            path:'/pages/index/index?hospid='+hospid+'&status='+4,//医院详情分享4
            // path:'',
            success: (res)=>{    // 成功后要做的事情
                console.log(res)
                // console.log(res.shareTickets[0])
                // console.log

                // wx.getShareInfo({
                //     shareTicket: res.shareTickets[0],
                //     success: (res)=> {
                //         that.setData({
                //             isShow:true
                //         })
                //         console.log(that.setData.isShow)
                //     },
                //     fail: function (res) { console.log(res) },
                //     complete: function (res) { console.log(res) }
                // })
            },
            fail: function (res) {
                // 分享失败
                console.log(res)
            }
        }
    }
})