monthDetail.js 8.9 KB

// pages/cityWide/monthDetail/monthDetail.js
const app = getApp();
var WxParse = require('../../../wxParse/wxParse.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeid: '',
    currTab: 0,
    // monthStatr: true,
    detailCon: '',
    detailAddr: '',
    imgCourse: [],
    isFocus: false,
    monthCon: '',
    activeStau: 1,
    addrestatus:'',
    talkpeople: '', 
    lng:'',
    lat:'',
    code:false,
    codeimg:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let that = this;
    let activeid = options.activeid;
    that.setData({
      activeid: activeid
    })
    // that.getDetail()
  },
  

  // 活动详情接口
  getDetail: function(e){
    let that = this;
    let url = "/api/portal/Activity/detail";
    let params = {
      token: wx.getStorageSync('token'),
      activityId: that.data.activeid
    }

    var header={
      'token': wx.getStorageSync('token'),
    }
    app.post(url, params,header).then((res) => {
      console.log(res)

      WxParse.wxParse('article', 'html', res.activity.content, that, 5)
      let statu = res.activity.is_save;
      let activeType = res.activity.activity_type;
      let isJoin = res.activity.is_join;
      if (statu == 1){
        that.setData({
          isFocus: true
        })
      } else if (statu == 2){
        that.setData({
          isFocus: false
        })
      }

      //报名人数
      console.log(typeof(res.activity.sign))
      if (res.activity.sign==null){
        res.activity.sign=0
      }
     
      // 1是活动   2是微课   1是已报名   2是未报名
      if (activeType == 1 && isJoin ==2) {
        that.setData({
          activeStau:1,
          addrestatus:true,
          talkpeople:false,
          iconshow:true
        })
        wx.setNavigationBarTitle({
          title: '活动详情' //页面切换,更换页面标题
        })
      } else if (activeType == 2 && isJoin ==2){
        that.setData({
          activeStau:2,
          addrestatus: false,
          talkpeople: true,
          iconshow:false
        })
        wx.setNavigationBarTitle({
          title: '微课详情' //页面切换,更换页面标题
        })
      } else if (activeType == 1 && isJoin == 1) {
        that.setData({
          activeStau: 3,
          addrestatus: true,
          talkpeople: false,
          iconshow: true
        })
        wx.setNavigationBarTitle({
          title: '活动详情' //页面切换,更换页面标题
        })
      } else if (activeType == 2 && isJoin == 1) {
        that.setData({
          activeStau: 4,
          addrestatus: false,
          talkpeople: true,
          iconshow: false
        })
        wx.setNavigationBarTitle({
          title: '微课详情' //页面切换,更换页面标题
        })
      }

      that.setData({
        detailCon: res.activity,
        detailAddr: res.activity.addr,
        imgCourse: res.sign,
        monthCon: res.mes,
        lng: res.activity.latng[0],
        lat: res.activity.latng[1],
        is_write:res.is_write
        
      })

      console.log(that.data.detailCon)
    }).catch((errMsg) => {})
  },


  //链接去地图
  gomap() {
    console.log(88)
    let that = this;
    console.log(that.data.lat)
    console.log(that.data.lng)
    wx.getLocation({//获取当前经纬度
      type: 'wgs84', //返回可以用于wx.openLocation的经纬度,官方提示bug: iOS 6.3.30 type 参数不生效,只会返回 wgs84 类型的坐标信息  
      success: function (res) {
        wx.openLocation({//​使用微信内置地图查看位置。
          latitude: Number(that.data.lat),//要去的纬度-地址
          longitude: Number(that.data.lng),//要去的经度-地址
          name: that.data.detailCon.addr.addr,
          address: that.data.detailCon.addr.addr,
        })
      }
    })

    console.log(that.data.lng)
    
  },
  // 点击切换
  clickTab: function (e) {
    var that = this;
    if (that.data.currTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currTab: e.target.dataset.current
      })
    }
  },
  // 跳转到 活动报名
  activityTap:function(){
    wx.navigateTo({
      url: '../activityName/activityName?activeid=' + this.data.activeid,
    })
  },
  //微课报名
  listenlesson(){
    let is_write = this.data.is_write;
    if(is_write==1){
      wx.navigateTo({
        url: '../WeChatCulum/WeChatCulum?activeid=' + this.data.activeid,
      })
    }else{
      wx.navigateTo({
        url: '../../home/stageofpregnancy/stageofpregnancy',
      })
    }

  },


  submit: function (e) {
    console.log(e)
    console.log(typeof(e.detail.formId));
    let that=this;
    // let formId = e.detail.formId;
   
    let is_write = that.data.is_write;
    if (is_write == 1) {
      var url = '/api/portal/Activity/joinCourse';
      var params = {
        token: wx.getStorageSync('token'),
        activityId: this.data.activeid,
         formId: e.detail.formId
      }
      app.post(url, params).then((res) => {
        console.log(res);

        wx.navigateTo({
          url: '../WeChatCulum/WeChatCulum?activeid=' + this.data.activeid,
        })

      }).catch((err) => {

      })

      
    } else {
      wx.navigateTo({
        url: '../../home/stageofpregnancy/stageofpregnancy',
      })
    }



  },
  // 跳转到 报名名单
  listTap:function(){
    wx.navigateTo({
      url: '../nameList/nameList?activeid=' + this.data.activeid,
    })
  },
  // 跳转到 发表点评
  markTap:function(){
    wx.navigateTo({
      url: '../remark/remark?activeid=' + this.data.activeid,
    })
  },
  // 跳转到 微信直播课程
  lectureTap: function(){
    wx.navigateTo({
      url: '../WeChatCulum/WeChatCulum?activeid=' + this.data.activeid,
    })
  },
  // 点击收藏成功
  favoriteTab: function (e) {
    let that = this;
    let isFocus = that.data.isFocus;
    let url = "/api/portal/Activity/save";
    let params = {
      token: wx.getStorageSync('token'),
      activityId: that.data.activeid
    }
    app.post(url, params).then((res) => {
      wx.showToast({
        title: "收藏成功",
        icon: 'success',
        duration: 1000
      });
      that.setData({
        isFocus: true
      })
    }).catch((errMsg) => {})
  },
  // 取消收藏
  cancelCollect: function(e){
    let that = this;
    let isFocus = that.data.isFocus;

    let url = "/api/portal/Activity/saveDel";
    let params = {
      token: wx.getStorageSync('token'),
      activityId: that.data.activeid
    }
    app.post(url, params).then((res) => {
      wx.showToast({
        title: "取消收藏",
        icon: 'success',
        duration: 1000
      });
      that.setData({
        isFocus: false
      })
    }).catch((errMsg) => { })
  },

  //微课二维码

  seecode(){
    let that = this;

    that.setData({
      code:true
    })
    var url = '/api/portal/Activity/pic';
    var params = {
      token: wx.getStorageSync('token'),
      activityId: that.data.activeid

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



    }).catch((err) => {

    })
  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let that = this;
    let activeid = that.data.activeid;
    console.log(activeid)
    return {
      title: '活动详情分享', // 转发后 所显示的title
      // path: '/pages/home/buildtextdetail/buildtextdetail?buildid='+buildid+'&gettoken='+newtoken, // 相对的路径
      path:'/pages/index/index?activeid='+activeid +'&status='+5,//微课详情
     // path: '/pages/index/index?childrenid',

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