NurseStationPersonAppletUl/pages/Ordervideolearning/Ordervideolearning.vue

469 lines
14 KiB
Vue
Raw Permalink Normal View History

2023-04-25 15:06:35 +08:00
<template>
<view class="app" v-if="list">
2023-05-04 14:02:14 +08:00
<image class="topimage" v-if='!videoshow' :src="baseurl + list.trainingItemPosterUrl" mode=""></image>
<video class="topimage" id="video" v-if="videoshow" :src="baseurl+videoitem.itemDirectoryUrl"
@timeupdate='videotimeupdate' :initial-time='videoitem.watchTime' @error='videoerror' :custom-cache="false"
@play='videoplays' @pause='videopause' @ended='videoended'></video>
2023-04-25 15:06:35 +08:00
<view class="title">
{{list.trainingItemTitle}}
</view>
<view class="border"></view>
<u-tabs :list="tablist" :is-scroll="false" :current="tabcurrent" @change="change" font-size='34' bar-height='3'>
</u-tabs>
<view class="detail" v-if="tabcurrent==0">
{{list.trainingItemDetails}}
</view>
<view class="directory" v-if="tabcurrent==1">
<view class="item" v-for="(item,index) in list.trainingOrderItemDirectoryVOList" :key="index">
<view class="text">
2023-04-26 16:04:38 +08:00
<span class='DirectoryName'>{{item.itemDirectoryName?item.itemDirectoryName:''}}</span>
<span class='texttitle'>{{item.itemDirectoryTitle?item.itemDirectoryTitle:''}}</span>
2023-04-25 15:06:35 +08:00
</view>
<view class="Introduce">
2023-04-26 16:04:38 +08:00
{{item.itemDirectoryIntroduce?item.itemDirectoryIntroduce:''}}
2023-04-25 15:06:35 +08:00
</view>
2023-05-05 14:47:47 +08:00
<view class="" v-if="list.trainingOrderStatus=='PAY'">
2023-04-26 15:42:47 +08:00
<view class="play" @tap='videoplay(item)'
:style="item.itemDirectoryWatchStatus=='NOT_WATCHED'?'background-color: #3D7DCA;color:#fff':''"
2023-05-04 14:02:14 +08:00
v-if="item.itemDirectoryWatchStatus=='NOT_WATCHED'&&!item.videoshow">
2023-04-26 15:42:47 +08:00
开始播放
</view>
2023-05-04 14:02:14 +08:00
<view class="play"
:style="item.itemDirectoryWatchStatus=='NOT_WATCHED'?'background-color: #3D7DCA;color:#fff':''"
v-if="item.itemDirectoryWatchStatus=='NOT_WATCHED'&&item.videoshow">
2023-05-04 15:24:55 +08:00
<image src="../../static/bofang.png" mode=""></image>
<view class="">
播放中
</view>
2023-05-04 14:02:14 +08:00
</view>
2023-04-26 15:42:47 +08:00
<view class="play" @tap='videoplay(item)'
:style="item.itemDirectoryWatchStatus=='WATCHED'?'background-color: #E3EAF5;color:#3D7DCA':''"
2023-05-04 14:02:14 +08:00
v-if="item.itemDirectoryWatchStatus=='WATCHED'&&!item.videoshow">
2023-04-26 15:42:47 +08:00
继续播放
</view>
2023-05-04 14:02:14 +08:00
<view class="play"
:style="item.itemDirectoryWatchStatus=='WATCHED'?'background-color: #3D7DCA;color:#fff':''"
v-if="item.itemDirectoryWatchStatus=='WATCHED'&&item.videoshow">
2023-05-04 15:24:55 +08:00
<image src="../../static/bofang.png" mode=""></image>
<view class="">
播放中
</view>
2023-05-04 14:02:14 +08:00
</view>
2023-04-26 15:42:47 +08:00
<view class="play" @tap='videoplay(item)'
:style="item.itemDirectoryWatchStatus=='FINISHED_READING'?'background-color: #E6E6E6;color:#76777B':''"
2023-05-04 14:02:14 +08:00
v-if="item.itemDirectoryWatchStatus=='FINISHED_READING'&&!item.videoshow">
2023-04-26 15:42:47 +08:00
已看完
</view>
2023-05-04 14:02:14 +08:00
<view class="play"
:style="item.itemDirectoryWatchStatus=='FINISHED_READING'?'background-color: #3D7DCA;color:#fff':''"
v-if="item.itemDirectoryWatchStatus=='FINISHED_READING'&&item.videoshow">
2023-05-04 15:24:55 +08:00
<image src="../../static/bofang.png" mode=""></image>
<view class="">
播放中
</view>
2023-05-04 14:02:14 +08:00
</view>
2023-04-25 15:06:35 +08:00
</view>
2023-04-26 15:42:47 +08:00
<view class="play" v-else @tap='novideoplay'>
开始播放
2023-04-25 15:06:35 +08:00
</view>
</view>
</view>
2023-05-04 14:02:14 +08:00
<!-- <u-popup v-model="videoshow" mode="center" closeable @close='videoshowfalse'>
2023-04-28 10:31:15 +08:00
<video id="video" v-if="videoshow" :src="baseurl+videoitem.itemDirectoryUrl" @timeupdate='videotimeupdate'
:initial-time='videoitem.watchTime' @error='videoerror' :custom-cache="false"
@play='videoplays'></video>
2023-05-04 14:02:14 +08:00
</u-popup> -->
2023-04-26 15:42:47 +08:00
<u-toast ref="uToast" />
2023-05-05 14:47:47 +08:00
<view class="bottomitem" v-if="bottombuyshow&&list.trainingOrderStatus=='WAIT_PAY'">
<view class="price">
{{list.trainingItemPrice?list.trainingItemPrice:0}}
</view>
<view class="buy" @tap='buy'>
购买
</view>
</view>
<u-popup v-model="buyshow" mode='bottom' height='500' class='popup' safe-area-inset-bottom>
<view class="popuptitle">请选择支付方式</view>
<view class="buyselect">
<image src="../../static/wechat.png" mode=""></image>
<view class="text">
微信支付
</view>
</view>
<view class="buybtn" @tap='tobuy'>
确认支付{{list.trainingItemPrice?list.trainingItemPrice:0}}
</view>
</u-popup>
2023-04-25 15:06:35 +08:00
</view>
2023-04-26 16:52:14 +08:00
<view class="" v-else style="padding-top: 100rpx;">
2023-04-26 16:45:04 +08:00
<u-empty text="暂无内容" mode="list" icon-size='240' font-size='32'></u-empty>
</view>
2023-04-25 15:06:35 +08:00
</template>
<script>
import baseurl from '@/api/baseurl.js'
import {
selectTrainingOrderVideoDetails,
insertTrainingItemWatchRecord,
getTrainingItemWatchRecord
} from '@/api/Ordervideolearning/index.js'
2023-05-05 14:47:47 +08:00
import {
trainingItemOrder,
appletTrainingOrderPay
} from '@/api/learning/index.js'
2023-04-25 15:06:35 +08:00
export default {
data() {
return {
list: undefined,
baseurl: undefined,
nurseStationPersonId: undefined,
tabcurrent: 0, //tabsindex
tablist: [{ //tabs的list
name: '详情'
}, {
name: '目录'
}],
trainingItemId: undefined, //上个页面id
trainingOrderNo: undefined, //上个页面orderno
videoshow: false, //视频开关
videoitem: {
watchTime: 0,
}, //视频对象
2023-05-05 14:47:47 +08:00
// trainingOrderStatus: undefined,
2023-04-27 09:09:43 +08:00
trainingOrderDetailsId: undefined,
2023-04-26 16:46:55 +08:00
videoerroshow: true,
2023-04-28 09:09:00 +08:00
videoContext: undefined,
2023-05-05 14:47:47 +08:00
bottombuyshow: false, //下面的购买divcss
buyshow: false, //购买弹框
2023-04-25 15:06:35 +08:00
};
},
2023-05-04 15:27:43 +08:00
onUnload() {
2023-05-05 08:29:03 +08:00
if (this.videoitem.itemDirectoryCode) {
if (this.videoerroshow) {
if (this.videoitem.watchTime) {
this.videoitem.watchTime = this.formatSeconds(this.videoitem.watchTime)
}
insertTrainingItemWatchRecord(this.videoitem).then(res => {})
2023-05-04 15:27:43 +08:00
}
}
2023-04-28 11:02:10 +08:00
},
2023-05-04 15:32:37 +08:00
onLaunch() {
// 锁定横屏
// plus.screen.lockOrientation("landscape-primary");
// 锁定竖屏
plus.screen.lockOrientation("portrait-primary");
},
2023-05-04 15:35:04 +08:00
// onHide() {
// var that = this
// uni.getSystemInfo({
// success: function(res) {
// if (res.platform == 'ios') {
// that.videoitem = {
// watchTime: 0
// }
// that.info();
// that.videoshow = false
// } else {}
// }
// });
// },
2023-04-25 15:06:35 +08:00
methods: {
2023-05-05 14:47:47 +08:00
//购买
tobuy() {
var that = this
const nurseStationId = uni.getStorageSync('nurseStationId');
if (nurseStationId) {
var obj = {
"trainingItemId": undefined,
"nurseStationId": undefined,
"nurseStationPersonId": undefined,
"trainingOrderAmount": undefined,
"nursePersonName": undefined,
}
obj.trainingItemId = this.list.trainingItemId
obj.nurseStationId = uni.getStorageSync('nurseStationId');
obj.nurseStationPersonId = this.nurseStationPersonId
obj.nursePersonName = uni.getStorageSync('nursePersonName');
obj.trainingOrderAmount = this.list.trainingItemPrice
trainingItemOrder(obj).then(res => {
if (res.code == 200) {
if (res.data.trainingOrderAmount > 0) {
let objs = {
"openid": uni.getStorageSync('openid'),
"nurseStationPersonId": res.data.nurseStationPersonId,
"orderNo": res.data.trainingOrderNo,
"payType": "WECHAT_PAY",
"orderChannel": "WECHAT_APPLET",
"buySource": "TRAINING",
"paymentPrice": res.data.trainingOrderAmount,
}
appletTrainingOrderPay(objs).then(response => {
if (response.code == 200) {
uni.requestPayment({
timeStamp: response.data.timeStamp,
nonceStr: response.data.nonceStr,
package: response.data.prepayId,
signType: response.data.signType,
paySign: response.data.paySign,
success: function(res) {
that.buyshow = false
that.bottombuyshow = false
that.info();
that.$refs.uToast.show({
title: '支付成功',
type: 'success',
duration: 1500,
})
},
fail: function(err) {
that.$refs.uToast.show({
title: '取消支付',
type: 'error',
duration: 1500,
url: `/pages/Orderdetails/Orderdetails?trainingOrderNo=${res.data.trainingOrderNo}`
})
that.buyshow = false
}
});
} else {
this.buyshow = false
this.$refs.uToast.show({
title: response.msg,
type: 'error',
duration: 2000
})
}
})
} else {
that.buyshow = false
that.bottombuyshow = false
that.info();
}
} else {
this.buyshow = false
this.$refs.uToast.show({
title: res.msg,
type: 'error',
duration: 2000
})
}
})
} else {
that.buyshow = false
that.$refs.uToast.show({
title: '请您重新登录',
type: 'error',
duration: 1500,
url: "/pages/login/login"
})
}
},
//打开购买弹框
buy() {
this.buyshow = true
},
2023-05-04 14:02:14 +08:00
//播放到末尾
videoended(e) {
this.videoContext.stop()
2023-04-26 16:46:55 +08:00
if (this.videoerroshow) {
2023-05-04 16:50:12 +08:00
if (this.videoitem.watchTime) {
this.videoitem.watchTime = this.formatSeconds(this.videoitem.watchTime)
}
2023-04-26 16:46:55 +08:00
insertTrainingItemWatchRecord(this.videoitem).then(res => {
this.videoitem.watchTime = 0
2023-05-04 16:54:52 +08:00
this.videoContext = undefined
2023-05-04 15:09:51 +08:00
this.videoitem.videoshow = false
2023-04-26 16:46:55 +08:00
this.videoshow = false
2023-05-04 14:02:14 +08:00
this.videoitem = {
watchTime: 0
}
this.info();
2023-04-26 16:46:55 +08:00
})
2023-04-26 16:25:38 +08:00
}
2023-04-25 15:06:35 +08:00
},
2023-05-04 14:02:14 +08:00
//播放进度变化
videotimeupdate(e) {
//e.detail.currentTime是已经播放了多久e.detail.duration是该视频多长
this.videoitem.watchTime = e.detail.currentTime
},
//关闭播放弹出框
videopause() {
// if (this.videoerroshow) {
// if (this.videoitem.watchTime) {
// this.videoitem.watchTime = this.formatSeconds(this.videoitem.watchTime)
// }
// insertTrainingItemWatchRecord(this.videoitem).then(res => {
// this.videoitem.watchTime = 0
// this.info();
// this.videoshow = false
// })
// }
},
2023-04-26 16:45:04 +08:00
//视频播放出错
videoerror(e) {
2023-05-04 15:09:51 +08:00
this.videoitem = {
watchTime: 0
}
2023-04-27 16:20:12 +08:00
this.$refs.uToast.show({
title: '暂无视频',
type: 'error',
duration: '2000'
})
this.videoerroshow = false
this.videoshow = false
2023-05-04 15:09:51 +08:00
this.info();
2023-04-26 16:45:04 +08:00
},
2023-04-26 15:42:47 +08:00
//novideoplay未购买
novideoplay() {
this.$refs.uToast.show({
title: '您未购买',
type: 'error',
2023-04-26 15:51:49 +08:00
duration: '2000'
2023-04-26 15:42:47 +08:00
})
},
2023-04-25 15:06:35 +08:00
//视频播放
2023-04-27 17:16:04 +08:00
videoplays() {
2023-04-28 10:30:27 +08:00
var that = this
uni.getSystemInfo({
success: function(res) {
if (res.platform == 'ios') {
2023-04-28 10:33:21 +08:00
if (that.videoitem.watchTime) {
that.videoContext.seek(that.videoitem.watchTime)
2023-04-28 10:30:27 +08:00
}
} else {}
}
});
2023-04-27 17:16:04 +08:00
},
2023-04-25 15:06:35 +08:00
videoplay(item) {
2023-05-04 14:02:14 +08:00
if (this.videoContext) {
this.videoshow = false
this.videoContext.stop()
if (this.videoerroshow) {
2023-05-04 16:50:12 +08:00
if (this.videoitem.watchTime == 0) {
this.videoitem.watchTime = '00:00:00'
} else {
2023-05-04 14:02:14 +08:00
this.videoitem.watchTime = this.formatSeconds(this.videoitem.watchTime)
}
2023-05-04 16:50:12 +08:00
insertTrainingItemWatchRecord(this.videoitem).then(res => {})
2023-04-26 16:04:38 +08:00
}
2023-05-04 14:02:14 +08:00
}
uni.showLoading({
title: '获取视频中'
});
setTimeout(el => {
this.info();
this.videoerroshow = true
if (item.itemDirectoryUrl) {
if (!item.watchTime) {
2023-05-04 16:50:12 +08:00
item.watchTime = 0
2023-05-04 14:02:14 +08:00
}
this.list.trainingOrderItemDirectoryVOList.forEach(e => {
e.videoshow = false
})
item.trainingOrderId = this.list.trainingOrderId
item.trainingItemId = this.list.trainingItemId
item.nurseStationPersonId = this.nurseStationPersonId
item.nursePersonName = uni.getStorageSync('nursePersonName')
item.trainingItemTitle = this.list.trainingItemTitle
if (item.itemDirectoryWatchStatus == 'WATCHED') {
getTrainingItemWatchRecord(item.trainingOrderId, item.trainingItemId, item
.trainingItemDirectoryId, item.nurseStationPersonId).then(res => {
if (res.code == 200) {
if (res.data.watchTime) {
item.watchTime = res.data.watchTime
item.watchTime = this.formatsecond(item.watchTime)
}
2023-04-26 16:04:38 +08:00
}
2023-05-04 14:02:14 +08:00
})
}
this.videoitem = item
this.videoitem.videoshow = true
this.videoshow = true
this.videoContext = uni.createVideoContext('video', this)
uni.hideLoading();
} else {
this.$refs.uToast.show({
title: '暂无视频',
type: 'error',
duration: '2000'
2023-04-26 16:04:38 +08:00
})
2023-05-04 14:02:14 +08:00
uni.hideLoading();
2023-04-26 16:04:38 +08:00
}
2023-05-04 14:02:14 +08:00
}, 500)
2023-04-25 15:06:35 +08:00
},
info() {
2023-04-27 09:09:43 +08:00
selectTrainingOrderVideoDetails(this.trainingItemId, this.trainingOrderNo, this.trainingOrderDetailsId)
.then(
res => {
this.list = res.data
2023-05-04 15:16:12 +08:00
if (this.videoitem.itemDirectoryCode) {
2023-05-04 14:02:14 +08:00
this.list.trainingOrderItemDirectoryVOList.forEach(e => {
if (e.itemDirectoryCode == this.videoitem.itemDirectoryCode) {
e.videoshow = true
} else {
e.videoshow = false
}
})
}
2023-04-27 09:09:43 +08:00
})
2023-04-25 15:06:35 +08:00
},
//点击tabs
change(index) {
this.tabcurrent = index;
},
//时分秒转秒
formatsecond(value) {
value = value.split(':')
2023-04-28 09:09:00 +08:00
var number = 0
2023-04-25 15:06:35 +08:00
value.forEach(e => {
e = Number(e)
})
value[0] = value[0] * 24 * 60
value[1] = value[1] * 60
2023-04-28 09:09:00 +08:00
value.forEach(e => {
e = Number(e)
if (e > 0) {
number = number + e
}
})
return number
2023-04-25 15:06:35 +08:00
},
//秒转时分秒
formatSeconds(value) {
let result = parseInt(value)
let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result /
60 % 60));
let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
let res = '';
res += `${h}:`;
res += `${m}:`;
res += `${s}`;
return res;
},
},
onLoad(options) {
const that = this
2023-05-04 15:15:36 +08:00
this.videoitem = {
watchTime: 0
}
2023-04-25 15:06:35 +08:00
this.baseurl = baseurl
2023-05-05 14:47:47 +08:00
// this.trainingOrderStatus = options.trainingOrderStatus
2023-04-25 15:06:35 +08:00
this.trainingItemId = options.trainingItemId
this.trainingOrderNo = options.trainingOrderNo
2023-04-27 09:09:43 +08:00
this.trainingOrderDetailsId = options.trainingOrderDetailsId
2023-04-25 15:06:35 +08:00
this.info();
const value = uni.getStorageSync('nursePersonId');
if (value) {
that.nurseStationPersonId = value
} else {}
2023-05-05 14:47:47 +08:00
if (options.trainingItemType) {
this.bottombuyshow = true
}
2023-04-25 15:06:35 +08:00
},
}
</script>
<style lang="scss">
@import "./Ordervideolearning.scss";
</style>