import dayjs from 'dayjs' const app = getApp() let live_time: null | number = null Page({ data: { id: '', shareShow: false, detail: {} as any, zdUserInfo: {} as any, posterUrl: '', params: {}, play: false, popupShow: false, popupType: 'popup6', // 登录失败弹窗 popupParams: { close: true, } as any, }, videoContext: {} as WechatMiniprogram.VideoContext, onLoad(options) { const scene = app.globalData.scene this.setData({ id: options.id || scene.id, }) if (live_time) { clearInterval(live_time) } this.setData({ dateValue: dayjs().valueOf(), }) live_time = setInterval(() => { this.setData({ dateValue: dayjs().valueOf(), }) }, 1000) }, onShow() { app.waitLogin({ type: [0, 1] }).then(() => { app.mpBehavior({ PageName: 'PG_PatientLiveDetails' }) this.getDetail() this.setView() app.getZdUserInfo(this, true, () => { this.getPosterParams() }) }) }, onReady() { this.videoContext = wx.createVideoContext('video') }, getPosterParams() { wx.ajax({ method: 'POST', url: '?r=poster/prepare', data: { posterId: 'activity-invite', activityId: this.data.id, userId: this.data.zdUserInfo.UserId, }, }).then((res) => { this.setData({ params: res, }) }) }, setView() { wx.ajax({ method: 'POST', url: '?r=zd/activity/view', data: { Id: this.data.id, }, }).then((res) => { console.log('res: ', res) }) }, getDetail() { wx.ajax({ method: 'GET', url: '?r=zd/activity/detail', data: { Id: this.data.id, }, }).then((res) => { if (res.ReplayVideoUrl) { this.videoContext = wx.createVideoContext('video') } if (res.Type == 1) { wx.setNavigationBarTitle({ title: '会议详情', }) } else { wx.setNavigationBarTitle({ title: '活动详情', }) } this.setData({ detail: { ...res, EndTimeValue: dayjs(res.EndTime).valueOf(), BeginTimeValue: dayjs(res.BeginTime).valueOf(), SignUpDeadlineValue: dayjs(res.SignUpDeadline).valueOf(), DetailJson: res.DetailJson ? JSON.parse(res.DetailJson) : [], SignUpRecord: res.SignUpRecord.map((item) => { item.date = dayjs().from(item.CreateTime) item.UserId = '******'.slice(0, 6 - String(item.UserId).length) + item.UserId return item }), BeginTime: dayjs(res.BeginTime).format('YYYY-MM-DD HH:mm'), }, }) }) }, handleReplay() { app.mpBehavior({ PageName: 'BTN_PatientLiveReview' }) this.videoContext.requestFullScreen({}) this.videoContext.seek(0) this.videoContext.play() }, handleFullscreenExit() { this.videoContext.pause() }, handleLive() { const { Type } = this.data.detail app.mpBehavior({ PageName: 'BTN_PatientLiveEnter' }) app .zdPermissionVerification( 3, Type == 1 ? 1 : 10, `/patient/pages/liveDetail/index?id=${this.data.id}`, this.data.id, ) .then(() => { const { TencentMeetingCode } = this.data.detail wx.navigateToMiniProgram({ appId: 'wx33fd6cdc62520063', // 要跳转的微信小程序appid // path: `pages/sub-preMeeting/join-meeting/join-meeting?m=${TencentMeetingCode}`, // 要跳转到的页面路径 // path:`pages/index/index?chn=${channel}&code=${TencentMeetingCode}&pwd=${password}&nm={nickname}` path: `pages/index/index?code=${TencentMeetingCode}`, }) }) }, // handleLiveTest() { // wx.navigateToMiniProgram({ // appId: 'wx33fd6cdc62520063', // 要跳转的微信小程序appid // path: `pages/index/index?code=521826426`, // }) // }, handleResult() { wx.navigateTo({ url: `/patient/pages/liveResult/index?id=${this.data.id}`, }) }, handleSignUp() { app.mpBehavior({ PageName: 'BTN_PatientLiveSign' }) const { Type } = this.data.detail const { UserType } = this.data.zdUserInfo wx.ajax({ method: 'POST', url: '?r=zd/activity/sign-up', data: { Id: this.data.id, PreUserIdentity: UserType, }, }).then((res) => { app .zdPermissionVerification( 3, Type == 1 ? 1 : 10, `/patient/pages/liveResult/index?id=${this.data.id}&rewardScore=${res.rewardScore}`, this.data.id, ) .then(() => { wx.navigateTo({ url: `/patient/pages/liveResult/index?id=${this.data.id}&rewardScore=${res.rewardScore}`, }) }) }) }, handleShare() { this.setData({ shareShow: true, }) this.saveShare() }, saveShare() { const { UserType } = this.data.zdUserInfo wx.ajax({ method: 'POST', url: '?r=zd/activity/share', data: { Id: this.data.id, PreUserIdentity: UserType }, }).then((res) => { this.getDetail() }) }, handleMap() { const { LocationLAT, LocationLNG, Location } = this.data.detail wx.openLocation({ latitude: LocationLAT * 1, longitude: LocationLNG * 1, name: Location, fail(err) { console.log(err) }, }) }, handleShareClose() { this.setData({ shareShow: false, }) }, handlePosterFinish(e) { this.setData({ posterUrl: e.detail, }) }, handleDownload() { const that = this wx.getSetting({ success(res) { console.log(res) if ( res.authSetting['scope.writePhotosAlbum'] != undefined && res.authSetting['scope.writePhotosAlbum'] == true ) { that.saveImage() } else if (res.authSetting['scope.writePhotosAlbum'] == undefined) { //获取当前位置 that.saveImage() } else { wx.showModal({ title: '请求授权相册权限', content: '需要保存海报到相册,请确认授权', confirmColor: '#8c75d0', success(res) { if (res.cancel) { //取消授权 wx.showToast({ title: '拒绝授权', icon: 'none', duration: 1000, }) } else if (res.confirm) { //确定授权,通过wx.openSetting发起授权请求 wx.openSetting({ success(res) { if (res.authSetting['scope.writePhotosAlbum'] == true) { that.saveImage() } else { wx.showToast({ title: '授权失败', icon: 'none', duration: 1000, }) } }, }) } }, }) } }, }) }, saveImage() { wx.showLoading({ title: '加载中', }) wx.saveImageToPhotosAlbum({ filePath: this.data.posterUrl, success: () => { wx.hideLoading() wx.showToast({ title: '保存成功,请到相册中查看', }) }, fail: () => { wx.hideLoading() wx.showToast({ icon: 'none', title: '保存失败,请稍后重试', }) }, }) }, handleVideoPlay() { this.setData({ play: true, }) }, handleVideoPause() { this.setData({ play: false, }) }, handlePlayVideo() { this.videoContext.play() }, handleBack() { wx.navigateBack({ fail() { wx.reLaunch({ url: '/patient/pages/index/index', }) }, }) }, handleOffice() { this.setData({ popupShow: true, popupType: 'popup6', popupParams: { close: true, }, }) }, handlePopupCancel() { this.setData({ popupShow: false, }) }, handleAnswer() { wx.navigateTo({ url: `/pages/webview/index?url=${encodeURIComponent('https://shop.show.hbsaas.com/statics/#/?nId=bz56')}`, }) }, onShareAppMessage() { this.saveShare() return { title: `【会议报名】${this.data.detail.Name}`, path: `/patient/pages/liveDetail/index?id=${this.data.id}`, // imageUrl: this.data.detail.IntroductionUrl, } }, })