/* eslint-disable eqeqeq */ import dayjs from 'dayjs' import { parseScene } from '../../../utils/util' const app = getApp() let live_time: null | number = null Page({ data: { id: '', shareShow: false, dateValue: 0, detail: {} as any, zdUserInfo: {} as any, posterUrl: '', params: {}, play: false, currentVideoSrc: '', lightList: [], timeData: {}, optionsScene: {} as any, popupShow: false, popupType: 'popup6', // 登录失败弹窗 popupParams: { close: true, } as any, }, videoContext: {} as WechatMiniprogram.VideoContext, onLoad(options) { this.setData({ id: options.id, }) if (options.scene) { const optionsScene: any = parseScene(options.scene) this.setData({ optionsScene: optionsScene || {}, id: options.id || optionsScene?.id, }) } else if (options.proMethodId) { this.setData({ 'optionsScene.proMethodId': options.proMethodId, }) } 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', detailId: this.data.id, promotionMethodId: this.data.optionsScene.proMethodId, }) this.getDetail() this.setView() this.getLightList() app.getZdUserInfo(this, true, () => { this.getPosterParams() }) }) }, onReady() { this.videoContext = wx.createVideoContext('video') }, getLightList() { wx.ajax({ method: 'GET', url: '?r=zd/activity/get-high-light-list', data: { activityId: this.data.id }, }).then((res) => { res.map((item: any) => { item.duration = dayjs(item.duration * 1000).format('mm:ss') return item }) this.setData({ lightList: res, }) }) }, 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, }, }) }, 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'), }, currentVideoSrc: res.ReplayVideoUrl, }) }) }, handleLightVideo(e) { const { url } = e.currentTarget.dataset this.setData({ currentVideoSrc: url, }) this.videoContext.requestFullScreen({}) this.videoContext.seek(0) this.videoContext.play() }, handleReplay() { app.mpBehavior({ PageName: 'BTN_PatientLiveReview' }) this.setData({ currentVideoSrc: this.data.detail.ReplayVideoUrl, }) this.videoContext.requestFullScreen({}) this.videoContext.seek(0) this.videoContext.play() }, handleFullscreenExit() { this.videoContext.pause() }, handleBanner() { const { detail, zdUserInfo, dateValue } = this.data if (detail.IsSignUp && zdUserInfo.AuditStatus) { if (zdUserInfo.AuditStatus == 1 || zdUserInfo.AuditStatus == 3 || zdUserInfo.AuditStatus == 4) { if (detail.SignUpStatus == 2) { if (detail.BeginTimeValue * 1 < dateValue * 1) { this.handleLive() } } } } }, 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() { const { SubscribeTemplateList } = this.data.detail app.mpBehavior({ PageName: 'BTN_PatientLiveSign' }) wx.requestSubscribeMessage({ tmplIds: SubscribeTemplateList, success: (res) => { const subscribe = SubscribeTemplateList.map((item) => { return res[item] === 'accept' ? 1 : 2 }) this.handleSignUpCallback(subscribe) }, fail: () => { this.handleSignUpCallback([2, 2]) }, }) }, handleSignUpCallback(res = [2, 2]) { const { Type } = this.data.detail const { UserType } = this.data.zdUserInfo const optionsScene = this.data.optionsScene wx.ajax({ method: 'POST', url: '?r=zd/activity/sign-up', data: { Id: this.data.id, PreUserIdentity: UserType, promotionMethodId: optionsScene.proMethodId, subscribe: [...res], }, }).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(() => { this.getDetail() }) }, handleMap() { const { LocationLAT, LocationLNG, Location } = this.data.detail wx.openLocation({ latitude: LocationLAT * 1, longitude: LocationLNG * 1, name: Location, }) }, handleShareClose() { this.setData({ shareShow: false, }) }, handlePosterFinish(e) { this.setData({ posterUrl: e.detail, }) }, handleDownload() { const that = this wx.getSetting({ success(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() { wx.ajax({ method: 'GET', url: '?r=zd/common/get-channel-wx-code', data: { ChannelType: this.data.detail.Type == 1 ? '1' : '11', Id: this.data.id, }, }).then((res) => { this.setData({ popupShow: true, popupType: 'popup6', popupParams: { qrCode: res, close: true, }, }) }) }, handlePopupCancel() { this.setData({ popupShow: false, }) }, handleAnswer() { const link = this.data.detail.QuestionnaireUrl wx.navigateTo({ url: `/pages/webview/index?url=${encodeURIComponent(link)}`, }) }, handleTimeChange(e) { this.setData({ timeData: e.detail, }) }, handleTimeFinish() { this.setData({ dateValue: dayjs().valueOf(), 'detail.LeftTime': 0, }) }, handleLightDetail(e) { const {index} = e.currentTarget.dataset; wx.navigateTo({ url: `/patient/pages/liveDetailVideo/index?id=${this.data.id}&index=${index}`, }) }, onShareAppMessage() { this.saveShare() return { title: `【会议报名】${this.data.detail.Name}`, path: `/patient/pages/liveDetail/index?id=${this.data.id}`, // imageUrl: this.data.detail.IntroductionUrl, } }, })