buildtextdetail.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',
    ],
      buildtextlistid:'',
      bulidlisttail:'',
      newtoken:'',
      newbuildtextlistid:''

  },

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

  onLoad: function (options) {
      console.log(options);
      var buildtextlistid=wx.getStorageSync('buildtetid');
      this.setData({
          newtoken:wx.getStorageSync('token'),
        buildtextlistid: buildtextlistid
      })
      if(JSON.stringify(options)!='{}'){

          this.setData({
              newbuildtextlistid:options.buildid,
              // newtoken:options.gettoken
          })
      }else{
          this.setData({
              buildtextlistid:buildtextlistid,
          })
      }

    console.log(this.data.buildtextlistid)

     this.getinfo();
  },
    getinfo(){
        let that=this;
       console.log(that.data.newbuildtextlistid);
        var url='/api/portal/archives/archivesDetail'
        if(that.data.newbuildtextlistid!=''){

            var params = {
                // token: that.data.newtoken,
                token: wx.getStorageSync('token'),
                archives_id:that.data.newbuildtextlistid
            }
        }else{

            var params = {
                token: wx.getStorageSync('token'),
                archives_id:that.data.buildtextlistid
            }
        }

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

          console.log(res)
            that.setData({
                bulidlisttail:res,
                // edit_img:res.content_imgs.slice(0,15)
            })
          if (res.content_imgs!=null){
            that.setData({
             
               edit_img:res.content_imgs.slice(0,15)
            })
            }
            console.log(that.data.bulidlisttail)
        }).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.bulidlisttail.if_collect;
        let detailtext=that.data.bulidlisttail
        if(detailcollect==0){
            that.data.bulidlisttail.if_collect=1
        }else if(detailcollect==1){
            that.data.bulidlisttail.if_collect=0
        }
        that.setData({
            bulidlisttail:detailtext
        })

        //调取收藏的接口
        var url = '/api/portal/archives/doCollect';
        if(that.data.newbuildtextlistid!=''){
            var params = {
                token: wx.getStorageSync('token'),
                archives_id:that.data.newbuildtextlistid
            }
        }else{
            var params = {
                token: wx.getStorageSync('token'),
                archives_id:that.data.buildtextlistid
            }
        }

        app.post(url, params).then((res) => {
            // getCurrentPages()[getCurrentPages().length - 1].onLoad()

        }).catch((err) => {

        })

    },


    //点赞
    touchstar:function(e){

        let that=this;

        let detailtouch=that.data.bulidlisttail.if_touch;
        let detailtext=that.data.bulidlisttail
        if(detailtouch==0){
            that.data.bulidlisttail.if_touch=1;
            that.data.bulidlisttail.touch_num= that.data.bulidlisttail.touch_num+1
        }else if(detailtouch==1){
            that.data.bulidlisttail.if_touch=0;
            that.data.bulidlisttail.touch_num= that.data.bulidlisttail.touch_num-1
        }
        that.setData({
            bulidlisttail:detailtext
        })

        //调取收藏的接口
        var url = '/api/portal/archives/doTouch';
        if(that.data.newbuildtextlistid!=''){
            var params = {
                token: wx.getStorageSync('token'),
                archives_id:that.data.newbuildtextlistid
            }
        }else{
            var params = {
                token: wx.getStorageSync('token'),
                archives_id:that.data.buildtextlistid
            }
        }
        app.post(url, params).then((res) => {
            // getCurrentPages()[getCurrentPages().length - 1].onLoad()

        }).catch((err) => {

        })

    },


  //医院详情
  enterhostail(e) {
    wx.setStorageSync('hospitalid', e.currentTarget.dataset.hosid);
    wx.navigateTo({
      url: '../hometail/hometail?hospital_id=' + e.currentTarget.dataset.hosid,
    })
  },
    //分享
  buildshare(){

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
      let that=this;
      let buildid=that.data.buildtextlistid;
      console.log(buildid)
      let newtoken=that.data.newtoken
      console.log(buildid)
      return {
          title: '建档攻略分享', // 转发后 所显示的title
          // path: '/pages/home/buildtextdetail/buildtextdetail?buildid='+buildid+'&gettoken='+newtoken, // 相对的路径
          path:'/pages/index/index?buildid='+buildid+'&status='+1,//建档攻略分享1
          // 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)
          }
      }
  }
})