Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

358 рядки
10 KiB

  1. const app = getApp()
  2. const navigationBarHeight = (getApp().statusBarHeight + 44) + "px"
  3. const config = require("../../config/config")
  4. const Http = require("../../utils/HttpBasics.js")
  5. Page({
  6. data: {
  7. ifPay:app.globalData.platform,
  8. classTitle:"",//课程标题
  9. showIos:false,//ios字符提示
  10. showHie: false,//提示框
  11. anthology: 0,//选集
  12. classNumber: "",//有多少集
  13. imgHttps: app.globalData.imgHttps,
  14. extraClasses: 'addBox-transition ',
  15. navigationBarHeight,
  16. videoContext: "",
  17. ifpay: 0,//是否支付 0免费 1付费
  18. goPayFlag: false,//支付按钮显隐
  19. btnSuspend: true,//控制播放按钮
  20. columnIndex: 0,
  21. addFlag: true,
  22. thenIndex: 0,//播放选合集
  23. popupNum: 0,//弹出选集
  24. popupIndex: 0,////播放选集
  25. showPopup: false,//选集弹框
  26. id: "",//课程id
  27. data: {},//数据源
  28. iscollect: false,//是否收藏
  29. mp4Url: "",
  30. tiemLsit: [{//试看时间
  31. value: 1,
  32. name: 60
  33. }, {
  34. value: 2,
  35. name: 180,
  36. }, {
  37. value: 3,
  38. name: 300,
  39. }],
  40. },
  41. // goIndent(e){
  42. // console.log(e.dataset.url);
  43. // },
  44. showIos(){
  45. this.setData({
  46. showIos:true
  47. })
  48. },
  49. cancel(e) {
  50. this.setData({
  51. showHie: e.detail.data
  52. })
  53. },
  54. cancelIos(e) {
  55. this.setData({
  56. showIos: e.detail.data
  57. })
  58. },
  59. hiePopup() {
  60. this.setData({
  61. showPopup: false
  62. })
  63. },
  64. setShowPopup() {
  65. this.setData({
  66. showPopup: true
  67. })
  68. },
  69. setPopupIndex(e) {
  70. let index = e.currentTarget.dataset.index
  71. this.setData({
  72. popupIndex: index
  73. })
  74. },
  75. setPopupNum(e) {
  76. let index = e.currentTarget.dataset.index
  77. this.setData({
  78. popupNum: index
  79. })
  80. },
  81. setThenIndex(e) {
  82. let index = e.currentTarget.dataset.index
  83. let id = e.currentTarget.dataset.id
  84. console.log(id);
  85. this.getVideoUrl(id)
  86. this.setData({
  87. anthology: index
  88. })
  89. },
  90. siteVid(e) {//切换视频
  91. let index = e.currentTarget.dataset.index
  92. let id = e.currentTarget.dataset.id
  93. this.getVideoUrl(id)
  94. this.setData({
  95. anthology: index,
  96. goPayFlag: false,
  97. btnSuspend: true,
  98. })
  99. },
  100. hieaddCheck() {
  101. this.setData({
  102. extraClasses: 'addBox-transition',
  103. addFlag: true
  104. })
  105. },
  106. addCheck() {//动画
  107. this.setData({
  108. addFlag: false
  109. })
  110. if (this.data.extraClasses == 'addBox-transition addBox-moved') {
  111. this.setData({
  112. extraClasses: 'addBox-transition',
  113. })
  114. } else {
  115. this.setData({
  116. extraClasses: 'addBox-transition addBox-moved'
  117. })
  118. }
  119. },
  120. setColumnIndex(e) {
  121. let index = e.currentTarget.dataset.index
  122. this.setData({
  123. columnIndex: index
  124. })
  125. },
  126. order() {//支付
  127. Http.post({//下订单
  128. url: config.api.order,
  129. data: {
  130. couponId: this.data.id
  131. }
  132. }).then(res => {
  133. console.log(res.data, "订单成功");
  134. let id = res.data.id
  135. console.log(id);
  136. Http.post({//拿orderInfo
  137. url: config.api.pay,
  138. data: {
  139. orderId: res.data.id
  140. }
  141. }).then(item => {
  142. console.log(item, "orderId");
  143. tt.pay({
  144. service: 5,
  145. orderInfo: {
  146. order_id: item.data.orderId,
  147. order_token: item.data.token,
  148. },
  149. success(res) {
  150. if (res.code === 0) {
  151. this.getData()
  152. tt.showToast({
  153. title: '支付成功!', // 内容
  154. });
  155. // 支付成功处理逻辑,只有res.code=0时,才表示支付成功
  156. // 但是最终状态要以商户后端结果为准
  157. } else if (res.code === 1) {
  158. tt.showToast({
  159. title: '支付超时', // 内容
  160. icon: "none"
  161. });
  162. Http.post({
  163. url: config.api.ifPayOk,
  164. data: {
  165. code: 1,
  166. orderId: res.data.id
  167. }
  168. })
  169. } else if (res.code === 2) {
  170. tt.showToast({
  171. title: '支付失败', // 内容
  172. icon: "none"
  173. });
  174. } else if (res.code === 3) {
  175. tt.showToast({
  176. title: '支付关闭', // 内容
  177. icon: "none"
  178. });
  179. } else if (res.code === 4) {
  180. tt.showToast({
  181. title: '支付取消', // 内容
  182. icon: "none"
  183. });
  184. } else if (res.code === 9) {
  185. tt.showToast({
  186. title: '订单状态开发者自行获取', // 内容
  187. icon: "none"
  188. });
  189. }
  190. },
  191. fail(res) {
  192. // handle fail
  193. },
  194. })
  195. }).catch(err => {
  196. tt.showToast({
  197. title: '唤起支付失败', // 内容
  198. icon: "none"
  199. });
  200. })
  201. }).catch(err => {
  202. if (err.code === 3013) {
  203. this.setData({
  204. showHie: true
  205. })
  206. } else {
  207. tt.showToast({
  208. title: err.message, // 内容
  209. icon: "none"
  210. });
  211. }
  212. })
  213. },
  214. goPay() {
  215. this.order()
  216. console.log("我支付了");
  217. this.setData({
  218. goPayFlag: false,
  219. btnSuspend: true,
  220. })
  221. },
  222. time(e) {
  223. let time = e.detail.currentTime.toFixed(0);
  224. if (!this.data.ifpay || this.data.data.view) {//已经支付过或免费
  225. if(this.data.data.columnCoupons){
  226. this.setData({
  227. classNumber: this.data.data.columnCoupons.length
  228. })
  229. }
  230. return
  231. } else {//需要付费或已支付
  232. let tempTime = "" //预览时间
  233. if (this.data.data.columnCoupons) {//是不是集合
  234. this.setData({
  235. classNumber: this.data.data.columnCoupons.length
  236. })
  237. tempTime = this.data.tiemLsit.filter(item => {
  238. return this.data.data.columnCoupons[this.data.anthology].previewDuration == item.value
  239. })[0].name
  240. } else {
  241. tempTime = this.data.tiemLsit.filter(item => {
  242. return this.data.data.previewDuration == item.value
  243. })[0].name
  244. }
  245. if (time >= tempTime) {
  246. this.data.videoContext.pause()//暂停
  247. this.data.videoContext.exitFullScreen()//退出全屏
  248. this.setData({
  249. goPayFlag: true,
  250. btnSuspend: false,//禁止播放
  251. })
  252. }
  253. }
  254. },
  255. setCollect() {//设置收藏
  256. if (this.data.iscollect) {//已收藏
  257. Http.get({
  258. url: config.api.Fcollect,
  259. data: { id: this.data.id }
  260. }).then(res => {
  261. this.ifCollect()
  262. }).catch(err => {
  263. tt.showToast({
  264. title: err.data, // 内容
  265. icon: "none"
  266. });
  267. })
  268. } else {//未收藏
  269. Http.get({
  270. url: config.api.Tcollect,
  271. data: { id: this.data.id }
  272. }).then(res => {
  273. this.ifCollect()
  274. }).catch(err => {
  275. tt.showToast({
  276. title: err.data, // 内容
  277. icon: "none"
  278. });
  279. })
  280. }
  281. },
  282. ifCollect() {//是否收藏课程
  283. Http.get({
  284. url: config.api.iscollect,
  285. data: {
  286. id: this.data.id
  287. }
  288. }).then(res => {
  289. this.setData({
  290. iscollect: res.data
  291. })
  292. })
  293. },
  294. getData() {//订单详情
  295. Http.get({
  296. url: config.api.classDetails,
  297. data: { id: this.data.id }
  298. }).then(res => {
  299. this.setData({
  300. data: res.data,
  301. ifpay: res.data.isPayment
  302. })
  303. if (res.data.columnCoupons) {
  304. this.getVideoUrl(res.data.columnCoupons[0].videoId)
  305. } else {
  306. this.getVideoUrl(res.data.videoId)
  307. }
  308. }).catch(err => {
  309. tt.showToast({
  310. title: err.data, // 内容
  311. icon: "none"
  312. });
  313. })
  314. },
  315. getVideoUrl(id) {//获取视频url
  316. Http.get({
  317. url: config.api.getViodUrl,
  318. data: {
  319. videoId: id
  320. }
  321. }).then(res => {
  322. console.log(res);
  323. this.setData({
  324. mp4Url: res.data.videoUrl
  325. })
  326. })
  327. },
  328. onReady() {
  329. this.setData({
  330. videoContext: wx.createVideoContext('myVideo')
  331. })
  332. },
  333. onLoad(options) {
  334. if (options.id) {
  335. this.setData({
  336. id: options.id,
  337. classTitle:options.title
  338. })
  339. this.ifCollect()
  340. // this.getData()
  341. }
  342. },
  343. onShow(){
  344. this.getData()
  345. },
  346. onShareAppMessage: function () {
  347. // return custom share data when user share.
  348. },
  349. })