Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

475 wiersze
15 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. showAddBox:{},
  8. ifPay: app.globalData.platform,
  9. classTitle: "",//课程标题
  10. showIos: false,//ios字符提示
  11. showHie: false,//提示框
  12. anthology: 0,//选集
  13. classNumber: "",//有多少集
  14. imgHttps: app.globalData.imgHttps,
  15. extraClasses: 'addBox-transition ',
  16. navigationBarHeight,
  17. videoContext: "",
  18. ifpay: 0,//是否支付 0免费 1付费
  19. goPayFlag: false,//支付按钮显隐
  20. btnSuspend: true,//控制播放按钮
  21. columnIndex: 1,
  22. addFlag: true,
  23. thenIndex: 0,//播放选合集
  24. popupNum: 0,//弹出选集
  25. popupIndex: 0,////播放选集
  26. showPopup: false,//选集弹框
  27. id: "",//课程id
  28. data: {},//数据源
  29. iscollect: false,//是否收藏
  30. mp4Url: "",
  31. tiemLsit: [
  32. {//不预览
  33. value: -1,
  34. name: 0
  35. },
  36. {//试看时间
  37. value: 1,
  38. name: 1000000000000000000//无限大=》免费观看
  39. }, {
  40. value: 2,
  41. name: 30,
  42. }, {
  43. value: 3,
  44. name: 60,
  45. }, {
  46. value: 4,
  47. name: 180,
  48. }
  49. , {
  50. value: 5,
  51. name: 300,
  52. }],
  53. },
  54. // goIndent(e){
  55. // console.log(e.dataset.url);
  56. // },
  57. showIos() {
  58. this.setData({
  59. showIos: true
  60. })
  61. },
  62. cancel(e) {
  63. this.setData({
  64. showHie: e.detail.data
  65. })
  66. },
  67. cancelIos(e) {
  68. this.setData({
  69. showIos: e.detail.data
  70. })
  71. },
  72. hiePopup() {
  73. this.setData({
  74. showPopup: false
  75. })
  76. },
  77. setShowPopup() {
  78. this.setData({
  79. showPopup: true
  80. })
  81. },
  82. setPopupIndex(e) {
  83. let index = e.currentTarget.dataset.index
  84. this.setData({
  85. popupIndex: index
  86. })
  87. },
  88. setPopupNum(e) {
  89. let index = e.currentTarget.dataset.index
  90. this.setData({
  91. popupNum: index
  92. })
  93. },
  94. setThenIndex(e) {
  95. tt.showLoading({
  96. title: '加载中...', // 内容
  97. });
  98. let index = e.currentTarget.dataset.index
  99. let id = e.currentTarget.dataset.id
  100. this.getVideoUrl(id)
  101. this.setData({
  102. anthology: index,
  103. goPayFlag: false,
  104. btnSuspend: true,
  105. })
  106. },
  107. siteVid(e) {//切换视频
  108. tt.showLoading({
  109. title: '加载中...', // 内容
  110. });
  111. let index = e.currentTarget.dataset.index
  112. let id = e.currentTarget.dataset.id
  113. this.getVideoUrl(id)
  114. this.setData({
  115. anthology: index,
  116. goPayFlag: false,
  117. btnSuspend: true,
  118. })
  119. },
  120. hieaddCheck() {
  121. let animation = tt.createAnimation({
  122. duration: 1000,
  123. timingFunction: "ease",
  124. });
  125. animation.opacity(0).step()
  126. this.setData({
  127. // extraClasses: 'addBox-transition',
  128. showAddBox:animation.export(),
  129. addFlag: true
  130. })
  131. },
  132. showAddCheck:function(){
  133. this.setData({
  134. addFlag: false
  135. })
  136. let animation = tt.createAnimation({
  137. duration: 1000,
  138. timingFunction: "ease",
  139. });
  140. animation.opacity(1).step()
  141. this.setData({
  142. showAddBox:animation.export(),
  143. })
  144. },
  145. // addCheck() {//动画
  146. // this.setData({
  147. // addFlag: false
  148. // })
  149. // if (this.data.extraClasses == 'addBox-transition addBox-moved') {
  150. // this.setData({
  151. // extraClasses: 'addBox-transition',
  152. // })
  153. // } else {
  154. // this.setData({
  155. // extraClasses: 'addBox-transition addBox-moved'
  156. // })
  157. // }
  158. // },
  159. setColumnIndex(e) {
  160. let index = e.currentTarget.dataset.index
  161. this.setData({
  162. columnIndex: index
  163. })
  164. },
  165. order() {//支付
  166. let _this = this
  167. Http.post({//下订单
  168. url: config.api.order,
  169. data: {
  170. couponId: this.data.id
  171. }
  172. }).then(res => {
  173. console.log(res.data, "订单成功");
  174. let id = res.data.id
  175. console.log(id);
  176. Http.post({//拿orderInfo
  177. url: config.api.pay,
  178. data: {
  179. orderId: res.data.id
  180. }
  181. }).then(item => {
  182. tt.pay({
  183. service: 5,
  184. orderInfo: {
  185. order_id: item.data.orderId,
  186. order_token: item.data.token,
  187. },
  188. success(res) {
  189. console.log(res.code, Http.address, "支付成功回调code");
  190. let id = res.id
  191. if (res.code === 0) {
  192. tt.request({
  193. url: Http.address + config.api.ifPayOk, // 目标服务器url
  194. method: "post",
  195. headers: {
  196. "Content-Type": "application/json;charset=UTF-8",
  197. token: app.globalData.token
  198. },
  199. data: {
  200. code: 0,
  201. orderId: id
  202. },
  203. success: (res) => {
  204. _this.setData({
  205. goPayFlag: false
  206. })
  207. _this.getData()
  208. },
  209. fail: (err) => {
  210. tt.showToast({
  211. title: err.message, // 内容
  212. icon: "none"
  213. });
  214. console.log("我失败; err", err);
  215. _this.getData()
  216. }
  217. });
  218. tt.showToast({
  219. title: '支付成功!', // 内容
  220. });
  221. // 支付成功处理逻辑,只有res.code=0时,才表示支付成功
  222. // 但是最终状态要以商户后端结果为准
  223. } else if (res.code === 1) {
  224. tt.showToast({
  225. title: '支付超时', // 内容
  226. icon: "none"
  227. });
  228. } else if (res.code === 2) {
  229. tt.showToast({
  230. title: '支付失败', // 内容
  231. icon: "none"
  232. });
  233. } else if (res.code === 3) {
  234. tt.showToast({
  235. title: '支付关闭', // 内容
  236. icon: "none"
  237. });
  238. } else if (res.code === 4) {
  239. tt.showToast({
  240. title: '支付取消', // 内容
  241. icon: "none"
  242. });
  243. } else if (res.code === 9) {
  244. tt.showToast({
  245. title: '订单状态开发者自行获取', // 内容
  246. icon: "none"
  247. });
  248. }
  249. },
  250. fail(res) {
  251. // handle fail
  252. },
  253. })
  254. }).catch(err => {
  255. tt.showToast({
  256. title: '唤起支付失败', // 内容
  257. icon: "none"
  258. });
  259. })
  260. }).catch(err => {
  261. if (err.code === 3013) {
  262. this.setData({
  263. showHie: true
  264. })
  265. } else {
  266. tt.showToast({
  267. title: err.message, // 内容
  268. icon: "none"
  269. });
  270. }
  271. })
  272. },
  273. goPay() {
  274. this.order()
  275. console.log("我支付了");
  276. this.setData({
  277. goPayFlag: false,
  278. btnSuspend: true,
  279. })
  280. },
  281. time(e) {
  282. let time = e.detail.currentTime.toFixed(0);
  283. if (!this.data.ifpay || this.data.data.view) {//已经支付过或免费
  284. if (this.data.data.columnCoupons) {//判断有没有集数
  285. this.setData({
  286. classNumber: this.data.data.columnCoupons.length
  287. })
  288. }
  289. return
  290. } else {//需要付费或已支付
  291. let tempTime = "" //预览时间
  292. if (this.data.data.columnCoupons) {//是不是集合
  293. this.setData({
  294. classNumber: this.data.data.columnCoupons.length
  295. })
  296. tempTime = this.data.tiemLsit.filter(item => {
  297. return this.data.data.columnCoupons[this.data.anthology].previewDuration == item.value
  298. })[0].name
  299. } else {
  300. tempTime = this.data.tiemLsit.filter(item => {
  301. return this.data.data.previewDuration == item.value
  302. })[0].name
  303. }
  304. if (time >= tempTime) {
  305. this.data.videoContext.pause()//暂停
  306. this.data.videoContext.exitFullScreen()//退出全屏
  307. this.setData({
  308. goPayFlag: true,
  309. btnSuspend: false,//禁止播放
  310. })
  311. }
  312. }
  313. },
  314. setCollect() {//设置收藏
  315. if (this.data.iscollect) {//已收藏
  316. Http.get({
  317. url: config.api.Fcollect,
  318. data: { id: this.data.id }
  319. }).then(res => {
  320. this.ifCollect()
  321. }).catch(err => {
  322. tt.showToast({
  323. title: err.message, // 内容
  324. icon: "none"
  325. });
  326. })
  327. } else {//未收藏
  328. Http.get({
  329. url: config.api.Tcollect,
  330. data: { id: this.data.id }
  331. }).then(res => {
  332. this.ifCollect()
  333. }).catch(err => {
  334. tt.showToast({
  335. title: err.message, // 内容
  336. icon: "none"
  337. });
  338. })
  339. }
  340. },
  341. ifCollect() {//是否收藏课程
  342. Http.get({
  343. url: config.api.iscollect,
  344. data: {
  345. id: this.data.id
  346. }
  347. }).then(res => {
  348. this.setData({
  349. iscollect: res.data
  350. })
  351. }).catch(err => {
  352. this.setData({
  353. iscollect: false
  354. })
  355. })
  356. },
  357. getData() {//课程详情
  358. Http.get({
  359. url: config.api.classDetails,
  360. data: { id: this.data.id }
  361. }).then(res => {
  362. this.setData({
  363. data: res.data,
  364. ifpay: res.data.isPayment,
  365. columnIndex: res.data.type == 1 ? 0 : 1
  366. })
  367. if (res.data.columnCoupons) {
  368. this.getVideoUrl(res.data.columnCoupons[0].videoId)
  369. } else {
  370. this.getVideoUrl(res.data.videoId)
  371. }
  372. }).catch(err => {
  373. tt.showToast({
  374. title: err.messagea, // 内容
  375. icon: "none"
  376. });
  377. })
  378. },
  379. getVideoUrl(id) {//获取视频url
  380. Http.get({
  381. url: config.api.getViodUrl,
  382. data: {
  383. videoId: id
  384. }
  385. }).then(res => {
  386. this.setData({
  387. mp4Url: res.data.videoUrl
  388. })
  389. tt.hideLoading();
  390. }).catch(err => {
  391. t.hideLoading();
  392. tt.showToast({
  393. title: err.messagea, // 内容
  394. icon: "none"
  395. });
  396. })
  397. },
  398. onReady() {
  399. this.setData({
  400. videoContext: wx.createVideoContext('myVideo')
  401. })
  402. },
  403. onLoad(options) {
  404. if (app.globalData.token) {
  405. if (options.id) {
  406. this.setData({
  407. id: options.id,
  408. classTitle: options.title
  409. })
  410. this.ifCollect()
  411. this.getData()
  412. }
  413. } else {
  414. app.tokenCallback = token => {
  415. if (options.id) {
  416. this.setData({
  417. id: options.id,
  418. classTitle: options.title
  419. })
  420. this.ifCollect()
  421. this.getData()
  422. }
  423. }
  424. }
  425. },
  426. onShow() {
  427. let animation = tt.createAnimation({
  428. duration: 0,
  429. // timingFunction: "ease",
  430. });
  431. animation.opacity(0).step()
  432. this.setData({
  433. showAddBox:animation.export(),
  434. })
  435. },
  436. onShareAppMessage: function (shareOption) {
  437. console.log(this.data.data.dyTitle);
  438. let that = this
  439. if (shareOption.channel == 'video') { // 判断是是不是分享视频
  440. return {
  441. channel: 'video', // 必写 video
  442. //     templateId: '',   // 分享的模版 id (如果未设置就是默认,下面会说如何设置)
  443. title: '知播堂',     // 分享的标题
  444. //     desc: '我是简介',     // 分享的内容介绍目前没有用
  445. //     path: `/pages/index/index`,  // 分享的路径
  446. extra: {
  447. videoTopics: ["知播堂", that.data.data.dyTitle] // 只有抖音才会有的属性
  448. },
  449. }
  450. } else { // 右上角分享
  451. return {
  452. templateId: '',         //分享的模版 id
  453. title: '',            //分享的标题
  454. desc: '',           // 分享的内容
  455. //      path: ``, // 分享的路径
  456. }
  457. }
  458. },
  459. })