share_record.js 4.3 KB
// pages/record/record.js
const app = getApp();
var amapFile = require('../../libs/amap-wx.js');
var config = require('../../libs/config.js');
var bgM = wx.createInnerAudioContext();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    play: true, //true为播放,flase暂停
    //地图数据
    markers: [],//显示点的坐标对象
    latitude: '',//当前显示的点维度
    longitude: '',//当前显示点的经度
    scale: '12',
    src: '',
    startsec: '00:00',
    endsec: '00:00',
    palyrate: '',//播放的百分比
    musicsrc: ''
  },
  audioPlay: function (e) {//播放
    let that = this;
    that.setData({
      play: false
    })
    bgM.src = that.data.musicsrc;
    bgM.play();
    setTimeout(() => {
      bgM.currentTime
      bgM.onTimeUpdate(() => {
        let palyrate = (parseInt(bgM.currentTime) / parseInt(bgM.duration)) * 100;//播放的百分比
        that.setData({
          startsec: '00:' + (bgM.currentTime.toFixed(0) < 10 ? '0' + bgM.currentTime.toFixed(0) : bgM.currentTime.toFixed(0)),
          endsec: '00:' + (bgM.duration.toFixed(0) < 10 ? '0' + bgM.duration.toFixed(0) : bgM.duration.toFixed(0)),
          palyrate: palyrate
        })
      })
      bgM.onEnded(() => {
        that.setData({
          startsec: '00' + ':00',
          endsec: '00:' + (bgM.duration.toFixed(0) < 10 ? '0' + bgM.duration.toFixed(0) : bgM.duration.toFixed(0)),
          palyrate: 0,
          play: true
        })
      })
      that.setData({
        duration: bgM.duration
      })
    }, 1000)
  },
  audioPause: function () {//暂停
    let that = this;
    that.setData({
      play: true
    })
    bgM.pause();
  },
  //根据坐标显示点
  getlocationmap(location, id) {
    var that = this;
    let markers = that.data.markers;
    var key = config.Config.key;
    var myAmapFun = new amapFile.AMapWX({ key: '856d7698b954d8c2356bce3a3be86f1d' });
    myAmapFun.getRegeo({
      iconPath: "../../images/yingfu.png",
      iconWidth: 22,
      iconHeight: 32,
      location: location,
      success: function (data) {
        var newmarker = {
          id: id,
          latitude: data[0].latitude,
          longitude: data[0].longitude,
          iconPath: data[0].iconPath,
          width: data[0].width,
          height: data[0].height
        }
        markers[id] = newmarker;
        that.setData({
          markers: markers
        });
        console.log(that.data.markers)
        that.setData({
          latitude: data[0].latitude
        });
        that.setData({
          longitude: data[0].longitude
        });
        that.setData({
          textData: {
            name: data[0].name,
            desc: data[0].desc
          }
        })
      },
      fail: function (info) {

      }
    })
  },
  makertap(e) {
    console.log(e);
    var that = this;
    var id = e.markerId;
  },
  goindex(){
    wx.reLaunch({
      url: '../start/start',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  getdata(id){
    let that = this;
    let url = 'home/home/click_one';
    let params = {
      id: id
    }
    app.post(url, params,{}).then((res) => {
      if (res.code == 20000) {
        that.setData({
          musicsrc: res.url
        })
        for (let i in res.coordinate) {
          that.getlocationmap(res.coordinate[i], i);
        }
      }
    }).catch((errMsg) => {
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    if (options.poster_id != undefined){
      var poster_id = decodeURIComponent(options.poster_id)
      that.getdata(poster_id);
    }    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    bgM.pause();
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})