kcxq-x.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <view class="">
  3. <view class="ddxqship">
  4. <view class="u-rela" style="width: 100%; height: 100%;" v-if="!videoShow" @click="playVideo">
  5. <image :src="info.img" mode="aspectFill" style="width: 100%;height: 100%;"></image>
  6. <u-icon name="play-right-fill" size="80" color="#fff" class="u-abso"
  7. style="z-index: 9; left: 50%; top: 50%; transform: translate(-50%,-50%);"></u-icon>
  8. </view>
  9. <video v-if="videoShow" @timeupdate="timeupdate" :src="videoinfo.content" autoplay
  10. style="width: 100%;height: 100%;"></video>
  11. </view>
  12. <view class="ddxqfayu">
  13. <view class="indhuyr">
  14. <view class="indjbrr"></view>
  15. <text>课程详情</text>
  16. </view>
  17. <view style="margin-top: 30rpx;">
  18. <view class="fzctob">
  19. <view class="kcxquyr">
  20. <text>课程名称</text>
  21. </view>
  22. <view class="kcxquyra">
  23. <text>{{item.title}}</text>
  24. </view>
  25. </view>
  26. <view style="border-top: 2rpx dashed #e8e8e8;width: 100%;margin: 22rpx 0;"></view>
  27. <!-- <view class="fzctob">
  28. <view class="kcxquyr">
  29. <text>课程分类</text>
  30. </view>
  31. <view class="fzctob kcwwerrt">
  32. <text v-for="(item,index) in info.type_title" :key="index">{{item}}</text>
  33. </view>
  34. </view> -->
  35. </view>
  36. </view>
  37. <view class="ddxqfayu" v-for="(item1,index1) in catalog" :key="index1">
  38. <view class="indhuyr">
  39. <view class="indjbrr"></view>
  40. <text>{{item1.title}}</text>
  41. </view>
  42. <view style="margin-top: 10rpx;">
  43. <view class="fsxto kandyyr" v-for="(item2,index2) in item1.list" :key="index2" @click="changevideo(item2)">
  44. <view class="flztoa">
  45. <text>{{item2.title}}</text>
  46. <image src="/static/zy/zyb3.png" style="width: 24px;height: 24px;" mode=""></image>
  47. </view>
  48. <view class="flztoa" style="margin-top: 4px;" v-if="item2.type == 1">
  49. <text class="ooddte">{{item2.video_title}}</text>
  50. <text class="ooddte">时长: {{item2.video_time}}</text>
  51. </view>
  52. <view class="flztoa" style="margin-top: 4px;" v-if="item2.type == 5"
  53. @click="goWxLive(item2.url,item2)">
  54. <text class="ooddte">{{item2.video_title}}</text>
  55. <text class="ooddte">点击进入直播间</text>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="" style="height: 200rpx;"></view>
  61. <view class="kcquuer" v-if="!is_pay">
  62. <!-- <view style="width: 100%; width: 100%;text-align: center;line-height: 66rpx;color: #ff2424;"
  63. v-if="coupon">
  64. 已使用优惠券 {{coupon.title}} 优惠 {{coupon.price}} 元
  65. </view> -->
  66. <view class="flztoa">
  67. <view class="kqyyefh" @click="pay(0)">
  68. <text>¥{{item.current_price}}/领取</text>
  69. </view>
  70. <!-- <navigator class="kqyyefha" v-if="is_vip == 0" url="../index/hykt">
  71. <text>会员/¥{{info.vip_price}}</text>
  72. </navigator> -->
  73. <!-- <view style="text-decoration:line-through;" class="kqyyefh" v-if="is_vip == 1">
  74. <text>普通/¥{{info.price}}</text>
  75. </view>
  76. <view class="kqyyefha" @click="pay(1)" v-if="is_vip == 1">
  77. <text>会员/¥{{info.vip_price}}</text>
  78. </view> -->
  79. </view>
  80. </view>
  81. <!-- <view class="kcquuer" v-if="!is_buy">
  82. <view style="width: 100%; width: 100%;text-align: center;line-height: 66rpx;color: #ff2424;"
  83. v-if="coupon">已使用优惠券 {{coupon.title}} 优惠 {{coupon.price}} 元</view>
  84. <view class="flztoa">
  85. <view class="kqyyefh" @click="pay(0)" v-if="is_vip == 0">
  86. <text>普通/¥{{info.price}}</text>
  87. </view>
  88. <navigator class="kqyyefha" v-if="is_vip == 0" url="../index/hykt">
  89. <text>会员/¥{{info.vip_price}}</text>
  90. </navigator>
  91. <view style="text-decoration:line-through;" class="kqyyefh" v-if="is_vip == 1">
  92. <text>普通/¥{{info.price}}</text>
  93. </view>
  94. <view class="kqyyefha" @click="pay(1)" v-if="is_vip == 1">
  95. <text>会员/¥{{info.vip_price}}</text>
  96. </view>
  97. </view>
  98. </view> -->
  99. </view>
  100. </template>
  101. <style>
  102. page {
  103. background: #FAFAFA;
  104. }
  105. </style>
  106. <script>
  107. export default {
  108. data() {
  109. return {
  110. xqaxuye: false,
  111. info: {},
  112. videoinfo: {},
  113. catalog: [],
  114. is_pay: 0, //0需要购买 1不需要购买
  115. is_vip: '',
  116. videoShow: false,
  117. roomId: 0,
  118. customParams: {},
  119. seconds: 0,
  120. id: 0, // 课程id
  121. deviceType: 'wxapp',
  122. coupon: false,
  123. coupon_id:0,
  124. item:null
  125. }
  126. },
  127. onLoad(e) {
  128. // #ifdef APP-PLUS
  129. this.deviceType = 'wxh5'
  130. // #endif
  131. // #ifdef MP-WEIXIN
  132. this.deviceType = 'wxapp'
  133. // #endif
  134. let item = JSON.parse(e.item);
  135. this.id = item.id;
  136. // 课程章节列表
  137. this.getCourseChapter(item.id);
  138. this.item = item;
  139. this.is_pay = item.is_pay;
  140. this.is_vip = uni.getStorageSync('is_vip');
  141. },
  142. // 页面卸载 提交视频播放进度
  143. onUnload() {
  144. if (this.seconds != 0) {
  145. this.$post({
  146. data: {
  147. do: 'ChangeRecordHistory',
  148. data: {
  149. user_id: uni.getStorageSync('id'),
  150. course_id: this.id,
  151. catalog_id: this.videoinfo.catalog_id,
  152. chapter_id: this.videoinfo.id,
  153. chapter_time: this.formatSeconds(this.seconds)
  154. }
  155. }
  156. })
  157. }
  158. },
  159. methods: {
  160. getMyCoupon() {
  161. },
  162. timeupdate(e) {
  163. let time = e.detail.currentTime
  164. this.seconds = time
  165. },
  166. // 秒数处理为时分秒
  167. formatSeconds(value) {
  168. // 秒
  169. let second = parseInt(value)
  170. // 分
  171. let minute = 0
  172. // 小时
  173. let hour = 0
  174. // 天
  175. // let day = 0
  176. // 如果秒数大于60,将秒数转换成整数
  177. if (second >= 60) {
  178. // 获取分钟,除以60取整数,得到整数分钟
  179. minute = parseInt(second / 60)
  180. // 获取秒数,秒数取佘,得到整数秒数
  181. second = parseInt(second % 60)
  182. // 如果分钟大于60,将分钟转换成小时
  183. if (minute > 60) {
  184. // 获取小时,获取分钟除以60,得到整数小时
  185. hour = parseInt(minute / 60)
  186. // 获取小时后取佘的分,获取分钟除以60取佘的分
  187. minute = parseInt(minute % 60)
  188. // 如果小时大于24,将小时转换成天
  189. // if (hour > 23) {
  190. // // 获取天数,获取小时除以24,得到整天数
  191. // day = parseInt(hour / 24)
  192. // // 获取天数后取余的小时,获取小时除以24取余的小时
  193. // hour = parseInt(hour % 24)
  194. // }
  195. }
  196. }
  197. let h = parseInt(hour) > 9 ? parseInt(hour) : '0' + parseInt(hour)
  198. let m = parseInt(minute) > 9 ? parseInt(minute) : '0' + parseInt(minute)
  199. let s = parseInt(second) > 9 ? parseInt(second) : '0' + parseInt(second)
  200. let result = '' + s;
  201. if (minute > 0) {
  202. result = '' + m + ':' + result
  203. }
  204. if (hour > 0) {
  205. result = '' + h + ':' + result
  206. }
  207. // if (day > 0) {
  208. // result = '' + parseInt(day) + '天' + result
  209. // }
  210. result = result.includes(':') ? result : '00:' + result
  211. console.log('result:', result)
  212. return result
  213. },
  214. goWxLive(id, item2) {
  215. // #ifdef MP-WEIXIN
  216. console.log(id);
  217. let roomId = [id];
  218. let customParams = encodeURIComponent(JSON.stringify({
  219. path: 'pages/index/index',
  220. pid: 1
  221. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  222. this.roomId = roomId;
  223. this.customParams = customParams;
  224. uni.navigateTo({
  225. url: 'plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=' + roomId +
  226. '&custom_params=' + customParams
  227. })
  228. // #endif
  229. // #ifdef APP-PLUS
  230. console.log(item2)
  231. uni.navigateTo({
  232. url: '/pages/index/watchLive?id=' + item2.id
  233. })
  234. // #endif
  235. },
  236. playVideo() {
  237. // if (!this.is_buy) {
  238. // uni.showModal({
  239. // title: '此课程未购买'
  240. // })
  241. // return
  242. // }
  243. this.videoShow = true
  244. },
  245. changevideo(info) {
  246. if (this.is_buy) {
  247. this.videoinfo = info
  248. } else {
  249. uni.showModal({
  250. title: '此课程未购买'
  251. })
  252. }
  253. },
  254. getCourseChapter() {
  255. let that = this;
  256. that.$request.getCourseChapter({course_id: that.id}).then(res => {
  257. console.log(res)
  258. if(res.code == 0){
  259. this.videoinfo = res.data[0];
  260. }else{
  261. wx.showToast({
  262. title: res.message,
  263. icon: 'none'
  264. })
  265. }
  266. // that.labelList = res.data
  267. }).catch(err => {
  268. console.log(err)
  269. })
  270. return
  271. let user_id = uni.getStorageSync('id');
  272. // this.$post({
  273. // data: {
  274. // do: 'CourseInfo',
  275. // data: {
  276. // user_id: user_id,
  277. // id: id,
  278. // pw: '375'
  279. // }
  280. // }
  281. // }).then(res => {
  282. // let user_id = uni.getStorageSync('id')
  283. // this.$post({
  284. // data: {
  285. // do: 'GetMyCoupon',
  286. // data: {
  287. // user_id: user_id,
  288. // }
  289. // }
  290. // }).then(res1 => {
  291. // this.coupon = res1.data.coupon;
  292. // this.info = res.data;
  293. // console.log(this.info);
  294. // //有优惠券可以优惠
  295. // if(this.coupon){
  296. // this.info.origin_vip_price = this.info.vip_price;
  297. // this.info.origin_price = this.info.price;
  298. // this.info.vip_price = this.info.vip_price - this.coupon.price;
  299. // this.info.price = this.info.price - this.coupon.price;
  300. // if(this.info.vip_price <= 0){
  301. // this.info.vip_price = 0.01;
  302. // }
  303. // if(this.info.price <= 0){
  304. // this.info.price = 0.01;
  305. // }
  306. // this.coupon_id = this.coupon.id
  307. // }
  308. // this.catalog = res.data.catalog;
  309. // this.is_buy = res.data.is_buy;
  310. // if (res.data.is_buy) {
  311. // this.videoinfo = res.data.catalog[0].list[0];
  312. // } else {
  313. // this.videoinfo = '';
  314. // uni.showModal({
  315. // title: '此课程未购买'
  316. // })
  317. // }
  318. // })
  319. // })
  320. },
  321. pay(indexs) {
  322. let that = this;
  323. that.$request.receive({course_id: that.id}).then(res => {
  324. console.log(res)
  325. if(res.code == 0){
  326. if(that.data.item.current_price <= 0){
  327. wx.showToast({
  328. title: '领取成功',
  329. })
  330. that.getCourseChapter();
  331. }else{
  332. that.wechatpay(res.data);
  333. }
  334. }else{
  335. wx.showToast({
  336. title: res.message,
  337. icon: 'none'
  338. })
  339. }
  340. }).catch(err => {
  341. console.log(err)
  342. })
  343. },
  344. wechatpay(pay) {
  345. console.log(pay)
  346. var that = this
  347. // #ifdef APP-PLUS
  348. uni.requestPayment({
  349. provider: 'wxpay',
  350. orderInfo: pay.orderinfo,
  351. success() {
  352. uni.showToast({
  353. title: '支付成功'
  354. })
  355. that.getCourseChapter();
  356. },
  357. fail(res) {
  358. console.log(res)
  359. uni.showToast({
  360. title: '支付失败',
  361. icon: 'error'
  362. })
  363. }
  364. })
  365. // #endif
  366. // #ifdef MP-WEIXIN
  367. uni.requestPayment({
  368. provider: 'wxpay',
  369. timeStamp: pay.timeStamp,
  370. nonceStr: pay.nonceStr,
  371. package: pay.package,
  372. signType: 'MD5',
  373. paySign: pay.paySign,
  374. success() {
  375. uni.showToast({
  376. title: '支付成功'
  377. })
  378. that.getCourseChapter();
  379. },
  380. fail(res) {
  381. console.log(res)
  382. uni.showToast({
  383. title: '支付失败',
  384. icon: 'error'
  385. })
  386. }
  387. })
  388. // #endif
  389. }
  390. }
  391. }
  392. </script>
  393. <style lang="scss" scoped>
  394. .flztoa{
  395. justify-content: center;
  396. }
  397. .kandyyr {
  398. font-size: 14px;
  399. font-family: PingFang SC-常规体, PingFang SC;
  400. font-weight: normal;
  401. color: #333333;
  402. margin-top: 20px;
  403. }
  404. .ooddte {
  405. font-size: 12px;
  406. font-family: PingFang SC-常规体, PingFang SC;
  407. font-weight: normal;
  408. color: #999999;
  409. line-height: 17px;
  410. }
  411. </style>