afterchildbirthrecover.js 8.4 KB
// pages/partneritem/afterchildbirthrecover/afterchildbirthrecover.js
const app = getApp();
var WxParse = require('../../../wxParse/wxParse.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //轮播图
    imgUrls: [],
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 500,

    currentTab: 0,
    wd: '',
    jd: '',
    compareId: '',
    detailInfo: [],
    address: [],
    common: '',
    labelinfo: '',
    number:'',
    days: '',
    hours: '',
    minutes: '',
    seconds: '',
    secretary: false,
    wxtary: '',
    edit_img:[],
    title:'',
    name:'',
    type:''
    // disable:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    let compareId = options.compareId;
    that.setData({
      compareId: compareId,
      name:options.name,
      type:options.type
    })
    // 获取经纬度
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        console.log(res)
        var latitude = res.latitude
        var longitude = res.longitude
        that.setData({
          wd: latitude,   //纬度
          jd: longitude   //经度
        })
        that.getDetail(latitude, longitude);
      }
    })
  },
  // 获取服务详情
  getDetail: function (latitude, longitude){
    let that = this;
    let url = "/api/portal/Compare/detail";
    let params = {
      lat: that.data.jd,
      lng: that.data.wd,
      compareId: that.data.compareId,
      page:1
  
    }
    app.post(url, params).then((res) => {
      console.log(res)
      that.setData({
        title: res.compare.title
      })
      wx.setNavigationBarTitle({
        title: res.compare.title //页面切换,更换页面标题
      })
      let number = res.compare.surplus_time;
      // 时间戳处理
      var totalSecond = number;
      var interval = setInterval(function () {
        // 秒数
        var second = totalSecond;
        // 天数位
        var day = Math.floor(second / 3600 / 24);
        var dayStr = day.toString();
        if (dayStr.length == 1) dayStr = '0' + dayStr;
        // 小时位
        var hr = Math.floor((second - day * 3600 * 24) / 3600);
        var hrStr = hr.toString();
        if (hrStr.length == 1) hrStr = '0' + hrStr;
        // 分钟位
        var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
        var minStr = min.toString();
        if (minStr.length == 1) minStr = '0' + minStr;
        // 秒位
        var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
        var secStr = sec.toString();
        if (secStr.length == 1) secStr = '0' + secStr;

        that.setData({
          days: dayStr,
          hours: hrStr,
          minutes: minStr,
          seconds: secStr,
        });
        totalSecond--;
        if (totalSecond <=0) {
          clearInterval(interval);
          // wx.showToast({
          //   title: '活动已结束',
          // });
          // 倒计时结束
          that.countDown();
          that.setData({
            days: '00',
            hours: '00',
            minutes: '00',
            seconds: '00',
          });
        }
      }.bind(this), 1000);

      let comdate = res.common;
      WxParse.wxParse('article', 'html', res.compare.content, that, 5)

       let newaddress = res.compare.address;
      for (var obj of newaddress){
        let latng = obj.latng;
        latng=latng.split(",");
        obj.jingdu = latng[0];
        obj.weidu=latng[1];
      }

      console.log(newaddress)
  

      that.setData({
        detailInfo: res.compare,
        address: newaddress,
        imgUrls: res.compare.banner.splice(0,5),
        labelinfo: res.compare.tag,
        common: comdate,
        wxtary: res.secretary,
        // edit_img: res.common.picArr
      })


      // console.log(that.data.edit_img)
    }).catch((errMsg) => {})
  },
  // 倒计时结束调用
  countDown: function(){
    let that = this;
    let url = "/api/portal/Compare/detail";
    let params = {
      compareId: that.data.compareId
    }
    app.post(url, params).then((res) => {
      console.log(res)
      // that.setData({
      //   disable:true
      // })
      console.log('倒计时结束');
    }).catch((errMsg) => {})
  },

  viewImg(e) {
    let that = this;
    console.log(e)
    let index = e.currentTarget.dataset.index;

    let paridx = e.currentTarget.dataset.paridx

    console.log(paridx)

    let img = [];
    for (var i = 0; i < that.data.common.length; i++) {

      if (i == paridx) {
        console.log(9090)
        img = that.data.common[i].picArr;

      }

    }
    console.log(img)
    wx.previewImage({
      current: img[index],
      urls: img,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },




  //链接去地图
  gotomap(e) {
    let that = this;
    let jingdu=e.currentTarget.dataset.jingdu;
    let weidu=e.currentTarget.dataset.weidu;
    let address=e.currentTarget.dataset.add;
    let name=e.currentTarget.dataset.name
    
    console.log(jingdu)
   console.log(weidu)
    wx.getLocation({//获取当前经纬度
      type: 'wgs84', //返回可以用于wx.openLocation的经纬度,官方提示bug: iOS 6.3.30 type 参数不生效,只会返回 wgs84 类型的坐标信息  
      success: function (res) {
        wx.openLocation({//​使用微信内置地图查看位置。
          latitude: Number(weidu),//要去的纬度-地址
          longitude: Number(jingdu),//要去的经度-地址
          name: name, //打开后显示的地址名称

          address: address //打开后显示的地址汉字
        })
      }
    })
  },

  // 咨询客服
  secreTap: function(){
    let that = this;
    that.setData({
      secretary: true
    })
  },
  // 关闭小秘书弹层
  hideTap: function(){
    let that = this;
    that.setData({
      secretary: false
    })
  },
  // 一键复制
  bindCopy: function () {
    let that = this;
    wx.setClipboardData({
      data: that.data.wxtary,
      success: function (res) {
        console.log("复制成功")
      }
    })
  },
  // 点击切换
  navbarTap: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  // 跳转到 确认订单
  buyTap: function(e){
    let compareId = e.currentTarget.dataset.compareid;
    wx.navigateTo({
      url: '../sureorder/sureorder?compareId=' + compareId,
    })
  },
  //时间戳转换时间
  toDate: function (number) {
    let n = number * 1000;
    let date = new Date(n);
    let Y = date.getFullYear() + '/';
    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
    let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();

    return (Y + M + D)
  },

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

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

  },

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

  },

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

  },

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

  },

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

  },

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