// pages/grade-details/grade-details.js import httpRequestApi from '../../../utils/APIClient'; const app = getApp(); Page({ /** * 页面的初始数据 */ data: { productId: '', payList: [], titleIcon: '', title: '', bookInfo: '', lessonList: [], content: [{ text: "转发给自己的朋友们", color: "#000" }, { text: " 分享好课,追随您一起学习进步", color: "#000" }, { text: " 您的魅力不是吹的!", color: "#000" }, { text: `在限定时间内成功拼团,您将得到奖学金。`, color: "#FF4600" } ], share: false, isIPX: app.globalData.isIPX, isIOS: app.globalData.isIOS, flag: true, knowFlag: true, menuFlag: false }, //tab切换 tabSwitch: function (e) { if(e.currentTarget.dataset.flag === "know" && this.data.knowFlag === false){ this.setData({ knowFlag: true, menuFlag: false }) } if(e.currentTarget.dataset.flag === "menu" && this.data.menuFlag === false){ this.setData({ knowFlag: false, menuFlag: true }) } }, //获取团购信息并掉起支付 pay: function ({ currentTarget }) { const productId = this.data.productId; const groupId = currentTarget.dataset.id; const osType = this.data.isIOS ? 'IOS' : 'ANDROID'; //开始发起团购 httpRequestApi.SendGroupPurchas({ productId, groupId, osType }).success((res) => { console.log('发起团购', res); if (res.data.message) { wx.showModal({ title: '提示', content: res.data.message, success(res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) return false; } this.setData({ orderId: res.data.data.groupPurchaseOrder.id }) // 如果已经拥有当前课程,则无需支付,直接进入拼团成功页面 if (res.data.data.groupPurchaseOrder.groupType === 'PROMOTION') { let that = this; wx.showModal({ title: '重新发起团购', content: '您会获得奖励哦', success() { console.log(res) that.popup.close(); if (res.data.data.groupPurchaseOrder.headCount !== 1) { setTimeout(() => { wx.redirectTo({ url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}` }) wx.setNavigationBarTitle({ title: '拼团详情' }) }, 1800) } } }) } else if (this.data.isIOS) { let that = this; wx.showModal({ title: '提示', content: '开团成功', success(res) { console.log(res) that.popup.close(); setTimeout(() => { wx.navigateTo({ url: `/pages/groupPage/collage-details/collage-details?orderId=${that.data.orderId}` }) wx.setNavigationBarTitle({ title: '拼团详情' }) }, 1800) } }) } else { //掉起支付 this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id, res.data.data.groupPurchaseOrder.headCount); } }).fail((error) => { }) }, //支付 prePayMap: function (prePayMap, orderId, num) { console.log(prePayMap) const that = this; //console.log(new Date().getTime()) wx.requestPayment({ 'appId': prePayMap.appId, 'timeStamp': prePayMap.timeStamp, 'nonceStr': prePayMap.nonceStr, 'package': prePayMap.package, 'signType': 'MD5', 'paySign': prePayMap.sign, 'success': function (res) { console.log('支付成功', res) wx.showModal({ title: '提示', content: '支付成功', success(res) { console.log(res) that.popup.close(); if (num !== 1) { setTimeout(() => { wx.navigateTo({ url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}` }) wx.setNavigationBarTitle({ title: '拼团详情' }) }, 1800) } } }) }, 'fail': function (res) { console.log('支付失败', res) } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options) if (options.share) { this.setData({ share: options.share }) } // const productId = options.productId; this.getBookInfo(options.productId); this.areYouBookSuper(options.productId) this.getGroupInfo(options.productId) // if (productId) { this.setData({ productId: options.productId }) // } }, // 课本鉴权 areYouBookSuper: function (productId) { const productArr = []; productArr.push(productId); httpRequestApi.areYouSuper(productArr).success(res => { console.log(res) this.setData({ imSuper: res.data.data }) }) }, getBookInfo: function (productId) { //课本详情 httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => { console.log('课本详情', res.data.data); const bookInfo = res.data.data.product; const lessonList = res.data.data.lessonList; wx.setNavigationBarTitle({ title: '语文 ' + bookInfo.subTitle }) const data = app.towxml.toJson( bookInfo.description, 'markdown', this ) this.setData({ titleIcon: bookInfo.bgImg, title: bookInfo.title, bookInfo: bookInfo.description, article: data }) const lessonTemp = []; lessonList.forEach(item => { const temp = {}; temp.id = item.id; temp.title = item.title; temp.readNum = item.readCount; lessonTemp.push(temp); }); this.setData({ lessonList: lessonTemp }); }) }, getGroupInfo: function (productId) { //团购内容 httpRequestApi.getGroupPurchaseInfo(productId).success((res) => { console.log(res) this.setData({ payList: res.data.data }) }) }, goToClass: function (e) { let id = e.currentTarget.dataset.id; let title = e.currentTarget.dataset.title; wx.navigateTo({ url: `../../main/class/class?id=${id}&title=${title}` }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { //获取弹窗组件 this.popup = this.selectComponent("#popup"); } })