/*
 * @Descripttion: 远程探视中转页
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: HJ
 * @Date: 2021-12-03 16:41:33
 * @LastEditors: OBKoro1
 * @LastEditTime: 2022-01-12 14:41:25
 */
import TIM from '../utils/tim-wx'
const app = getApp()

const pageOptions = {
  // 页面数据
  data: {
    isFirstOnShow: true // 是否为首次执行onShow
  },
  // 页面载入时
  onLoad(e) {
    console.log();
    this.init(e)
  },
  // 页面初始化
  init(e) {
    if (wx.TUIKit) {
      wx.redirectTo({
        url: `/remote/room/room?roomID=${e.id}&userID=${app.globalData.baseInfo.memberId}&template=${e.template}&memberType=${e.memberType}`
      })
      return
    }
    // 创建 SDK 实例，TIM.create() 方法对于同一个 SDKAppID 只会返回同一份实例
    wx.TUIKit = TIM.create({ SDKAppID: +wx.$unienv.VUE_APP_TRTC_SDKAPPID })
    wx.TUIKitEvent = TIM.EVENT
    // 监听系统级事件
    wx.TUIKit.on(wx.TUIKitEvent.SDK_READY, this.onSDKReady)

    wx.redirectTo({
      url: `/remote/room/room?roomID=${e.id}&userID=${app.globalData.baseInfo.memberId}&template=${e.template}&memberType=${e.memberType}`
    })

    setTimeout(() => {
      this.isJump = true
    }, 1000)
  },
  onShow() {
    if (this.isJump) {
      wx.navigateBack()
    }
  },
  // SDK处于SDK状态
  onSDKReady() {
    console.log('SDK处于SDK状态')
  },
  // 分享时，注：onShareAppMessage不能为async异步函数，会导致不能及时取得返回值，使得分享设置无效
  onShareAppMessage() {
    /* const title = ''
    const path = ''
    const imageUrl = ``

    return {
      title,
      path,
      imageUrl,
    } */
  }
}

Page(pageOptions)
