courseDetail.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. var app = getApp();
  2. var util = require("../../../../utils/util.js")
  3. let wxparse = require("../../../../wxParse/wxParse.js");
  4. let pageid = ""
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. appAssetsUrl:app.appAssetsUrl,
  11. isCollected: false,
  12. show: true,
  13. options: "",
  14. videoplay:"",
  15. videoFile:"",
  16. parm: {
  17. type: "2",
  18. sid: '',
  19. vipid: util.getUserId()
  20. },
  21. pram: {
  22. type: "1",
  23. cid: '',
  24. sid: ''
  25. }
  26. },
  27. collect: function () {
  28. let isCollected = !this.data.isCollected
  29. this.setData({
  30. isCollected: isCollected
  31. })
  32. wx.showToast({
  33. title: isCollected ? '收藏成功' : '取消收藏',
  34. icon: 'success',
  35. duration: 2000
  36. })
  37. },
  38. courselisten:function(e){
  39. if (e.currentTarget.dataset.isbuy == "1"){
  40. wx.showToast({
  41. title: '已切换至' + this.data.data.video[e.currentTarget.dataset.index].title+',请观看!',
  42. icon:'none'
  43. })
  44. this.setData({
  45. videoFile: this.data.data.video[e.currentTarget.dataset.index].videoFile
  46. })
  47. }else{
  48. if (e.currentTarget.dataset.item == "1") {
  49. this.setData({
  50. videoFile: this.data.data.video[e.currentTarget.dataset.index].videoFile
  51. })
  52. } else if (e.currentTarget.dataset.item == "0") {
  53. wx.showToast({
  54. title: '购买课程后即可观看!',
  55. icon:'none',
  56. duration:2500
  57. })
  58. }
  59. }
  60. },
  61. upgrade() {
  62. let _this = this;
  63. if (util.UserLoginStatus()){
  64. wx.showActionSheet({
  65. itemList: ['微信支付', '会员卡支付'],
  66. success(res) {
  67. if (res.tapIndex === 0) {
  68. _this.data.pram.type = "1";
  69. app._post_form('cou/buy', 'application/json',
  70. JSON.stringify(_this.data.pram),
  71. function (result) {
  72. console.log(result)
  73. if (result.code === 0) {
  74. wx.showLoading({
  75. title: '正在处理...',
  76. mask: true
  77. })
  78. wx.requestPayment({
  79. 'timeStamp': result.data.timestamp,
  80. 'nonceStr': result.data.nonce_str,
  81. 'package': 'prepay_id=' + result.data.prepay_id,
  82. 'signType': 'MD5',
  83. 'paySign': result.data.sign,
  84. success: function (res) {
  85. if (res) {
  86. wx.hideLoading();
  87. wx.showModal({
  88. title: '温馨提示',
  89. content: "购买成功!",
  90. showCancel: false
  91. })
  92. }
  93. /* wx.request({
  94. url: App.apiRoot + 'notification.do',
  95. data: {
  96. formid: formid,
  97. cardNo: vipcard,
  98. orderNo: order,
  99. type: '1'
  100. },
  101. header: { 'content-type': 'application/json' },
  102. success(res) {
  103. if (res.code === 0 || res.code === '0') {
  104. console.log("已推送消息");
  105. }
  106. },
  107. fail: function (res) {
  108. console.log("推送失败");
  109. }
  110. })*/
  111. _this.loadData(_this.data.options.id)
  112. },
  113. fail: function (res) {
  114. wx.hideLoading();
  115. wx.showToast({
  116. title: '购买失败!',
  117. icon: 'none',
  118. duration: 1500
  119. })
  120. }
  121. })
  122. } else {
  123. wx.showModal({
  124. title: '温馨提示',
  125. content: result.msg,
  126. showCancel: false
  127. })
  128. }
  129. }
  130. )
  131. } else if (res.tapIndex === 1) {
  132. _this.data.pram.type = "yue";
  133. wx.showToast({
  134. title: '暂未开通!',
  135. duration: 1500
  136. })
  137. }
  138. },
  139. fail(res) { }
  140. })
  141. }
  142. },
  143. /**
  144. * 生命周期函数--监听页面加载
  145. */
  146. onLoad: function (options) {
  147. this.data.pram.sid =util.getUserId();
  148. pageid = this.options.id
  149. wx.setNavigationBarTitle({ title: '课程详情' })
  150. let _this = this;
  151. _this.loadData(options.id);
  152. _this.data.options = options;
  153. // _this.data.pram.cid = _this.options.id
  154. },
  155. loadData: function(id){
  156. let _this = this;
  157. app._post_form('cou/one/' + id + "/" + util.getUserId(),"",null,function (res) {
  158. console.log(res)
  159. if(res.code===0){
  160. _this.data.pram.cid = res.data.id + ""
  161. _this.setData(res);
  162. for (var i = 0; i < res.data.video.length; i++) {
  163. _this.data.videoplay = res.data.video[i].videoFile
  164. }
  165. // _this.setData({
  166. // videoplay: _this.data.videoplay
  167. // })
  168. console.log(_this.data.data.title,'data')
  169. _this.setData({
  170. videoFile:res.data.videoFile
  171. })
  172. setTimeout(function () {
  173. wxparse.wxParse('content', 'html', res.data.content, _this, 5);
  174. }, 1000)
  175. }
  176. })
  177. },
  178. /**
  179. * 生命周期函数--监听页面初次渲染完成
  180. */
  181. onReady: function () {
  182. //获得popup组件
  183. this.popup = this.selectComponent("#popup");
  184. },
  185. // showPopup() {
  186. // console.log(123)
  187. // this.popup.showPopup();
  188. // },
  189. //取消事件
  190. _error() {
  191. // console.log('你点击了取消');
  192. this.popup.hidePopup();
  193. },
  194. //确认事件
  195. _success() {
  196. console.log('你点击了确定');
  197. this.signUp()
  198. },
  199. showShareMenu: function () {
  200. wx.showShareMenu();
  201. this.setData({
  202. show: true
  203. })
  204. console.log("显示了当前页面的转发按钮");
  205. },
  206. hideShareMenu() {
  207. wx.hideShareMenu();
  208. this.setData({
  209. show: false
  210. })
  211. console.log("隐藏了当前页面的转发按钮");
  212. },
  213. /**
  214. * 用户点击右上角分享
  215. */
  216. onShareAppMessage(){
  217. let _this=this
  218. console.log(pageid)
  219. var title = _this.data.data.title
  220. var introduction = _this.data.data.introduction
  221. return {
  222. title: title,
  223. path: '/pages/home/index/courseDetail/courseDetail?id=' + pageid,//这里的path是当前页面的path,必须是以 / 开头的完整路径,后面拼接的参数 是分享页面需要的参数 不然分享出去的页面可能会没有内容
  224. desc: introduction,
  225. success: (res) => {
  226. console.log("转发成功", res);
  227. console.log("成功了")
  228. },
  229. fail: (res) => {
  230. console.log("转发失败", res);
  231. }
  232. }
  233. },
  234. /**
  235. * 生命周期函数--监听页面显示
  236. */
  237. onShow: function () {
  238. },
  239. /**
  240. * 生命周期函数--监听页面隐藏
  241. */
  242. onHide: function () {
  243. },
  244. /**
  245. * 生命周期函数--监听页面卸载
  246. */
  247. onUnload: function () {
  248. },
  249. /**
  250. * 页面相关事件处理函数--监听用户下拉动作
  251. */
  252. onPullDownRefresh: function () {
  253. },
  254. /**
  255. * 页面上拉触底事件的处理函数
  256. */
  257. onReachBottom: function () {
  258. },
  259. /**
  260. * 用户点击右上角分享
  261. */
  262. })