childbirthnotedetail.js 6.1 KB
// pages/home/childbirthnotedetail/childbirthnotedetail.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',
    ],
    childtailid: '',
    childtail: '',
    newchildtailid: ''

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var childtailid = wx.getStorageSync('childtailid');
    if (JSON.stringify(options) != '{}') {

      this.setData({
        newchildtailid: options.childrenid
      })
    } else {

      this.setData({
        childtailid: childtailid
      })
    }
    this.getinfo();

  },
  getinfo() {
    let that = this;
    console.log(that.data.newchildtailid);
    var url = '/api/portal/childbirth/childbirthDetail';
    if (that.data.newchildtailid != '') {

      var params = {
        token: wx.getStorageSync('token'),
        childbirth_id: that.data.newchildtailid
      }
    } else {

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

    app.post(url, params).then((res) => {
      console.log(res);
      var newchildtail = res;
      if (newchildtail.production_type == 1) {
        newchildtail.production_type = "顺产"
      } else if (newchildtail.production_type == 2) {
        newchildtail.production_type = "剖腹产"
      }

      if (newchildtail.sex == 1) {
        newchildtail.sex = "男宝"
      } else if (newchildtail.sex == 2) {
        newchildtail.sex = "女宝"
      }
      that.setData({
        childtail: newchildtail,

      })
      if (newchildtail.content_imgs == null) {
        newchildtail.content_imgs = []
      } else {
        that.setData({
          edit_img: newchildtail.content_imgs.slice(0, 15)
        })
      }

      console.log(that.data.childtail)
      // 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.childtail.if_collect;
    let detailtext = that.data.childtail
    if (detailcollect == 0) {
      that.data.childtail.if_collect = 1
    } else if (detailcollect == 1) {
      that.data.childtail.if_collect = 0
    }
    that.setData({
      childtail: detailtext
    })

    //调取收藏的接口
    var url = '/api/portal/childbirth/doCollect';

    if (that.data.newchildtailid != '') {
      var params = {
        token: wx.getStorageSync('token'),
        childbirth_id: that.data.newchildtailid
      }
    } else {
      var params = {
        token: wx.getStorageSync('token'),
        childbirth_id: that.data.childtailid
      }
    }

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

    }).catch((err) => {

    })

  },


  //点赞
  touchstar: function(e) {

    let that = this;

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

    //调取收藏的接口
    var url = '/api/portal/childbirth/doTouch ';
    if (that.data.newchildtailid != '') {
      var params = {
        token: wx.getStorageSync('token'),
        childbirth_id: that.data.newchildtailid
      }
    } else {
      var params = {
        token: wx.getStorageSync('token'),
        childbirth_id: that.data.childtailid
      }
    }
    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',
    })
  },
  //分享
  childshare() {
    // wx.navigateTo({
    //   url: '../melist/melist',
    // })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

    return {
      title: '分娩笔记分享', // 转发后 所显示的title
      // path: '/pages/home/buildtextdetail/buildtextdetail?buildid='+buildid+'&gettoken='+newtoken, // 相对的路径
      path: '/pages/index/index?childrenid=' + childrenid + '&status=' + 2, //分娩笔记分享2

      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)
      }
    }
  }
})