playShow.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // pages/playShow/playShow.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. id: null,
  11. item: null,
  12. creator: null
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.setData({ id: options.vid })
  19. this.loadInfo()
  20. },
  21. /**
  22. * 生命周期函数--监听页面初次渲染完成
  23. */
  24. onReady: function () {
  25. },
  26. /**
  27. * 生命周期函数--监听页面显示
  28. */
  29. onShow: function () {
  30. },
  31. /**
  32. * 生命周期函数--监听页面隐藏
  33. */
  34. onHide: function () {
  35. },
  36. /**
  37. * 生命周期函数--监听页面卸载
  38. */
  39. onUnload: function () {
  40. },
  41. /**
  42. * 页面相关事件处理函数--监听用户下拉动作
  43. */
  44. onPullDownRefresh: function () {
  45. },
  46. /**
  47. * 页面上拉触底事件的处理函数
  48. */
  49. onReachBottom: function () {
  50. },
  51. /**
  52. * 用户点击右上角分享
  53. */
  54. onShareAppMessage: function () {
  55. return {
  56. title: '视频秀',
  57. path: '/pages/playShow/playShow?vid=' + this.data.id,
  58. image: this.data.item.imgUrl
  59. }
  60. },
  61. loadInfo: function () {
  62. const urls = urlDef.urls;
  63. let stu = wx.getStorageSync('student');
  64. this.setData({ curStu: stu })
  65. util.apiPost(urls.person_video_list + '&q.videoId=' + this.data.id).then((rs) => {
  66. if (rs && rs.length > 0) {
  67. let o = rs[0]
  68. o.viewsCount = this.formatCount(o.viewsCount)
  69. this.setData({ item: o })
  70. util.apiPost(urls.video_loadInfo + this.data.id).then((rs) => {
  71. o.imgUrl = rs.img
  72. o.playUrl = rs.url
  73. this.setData({ item: o })
  74. })
  75. let goodEntity = { videoId: this.data.id, personId: stu.studentId, personType: 1 };
  76. util.apiPost(urls.person_video_view_save, goodEntity, 'application/json').then(rs => {
  77. }).catch(e => {
  78. });
  79. }
  80. })
  81. util.apiPost(urls.query_video_creator + '&q.id=' + this.data.id).then((rs) => {
  82. let u = rs
  83. if (rs) {
  84. u.imageUrl = '/images/head.png'
  85. } else {
  86. u = {}
  87. u.imageUrl = urls.oss_file + 'image/' + u.imageUrl
  88. }
  89. this.setData({ creator: u })
  90. })
  91. },
  92. doThumbsUp: function () {
  93. let o = this.data.item
  94. const urls = urlDef.urls;
  95. let pid = this.data.curStu.studentId;
  96. let pt = o.personType;
  97. let vid = o.videoId;
  98. let entity = {
  99. videoId: vid,
  100. personId: pid,
  101. personType: pt,
  102. actionType: 1
  103. };
  104. util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => {
  105. o.goodCount += 1
  106. this.setData({
  107. 'item': o
  108. })
  109. }).catch(e => {
  110. console.log(e);
  111. })
  112. },
  113. formatCount(n) {
  114. if (n >= 100000000) {
  115. return (n / 100000000).toFixed(2) + '亿';
  116. } else if (n >= 10000) {
  117. return (n / 10000).toFixed(2) + '万';
  118. } else if (n >= 1000) {
  119. return (n / 1000).toFixed(2) + '千';
  120. }
  121. return n;
  122. }
  123. })