// pages/group-details/group-details.js import { getOpenidSessionKey } from '../../../utils/httpUtil'; import httpRequestApi from '../../../utils/APIClient'; import util from '../../../utils/util'; const app = getApp(); Page({ /** * 页面的初始数据 */ data: { titleIcon: '', title: '', bookInfo: '', lessonList: [], surplusNum: '', joinUserList: [], surplusList: [], timeList: [], productId: '', groupId: '', orderId: '', typeOf: '', titles: '', headTextOne: '', headTextTwo: '', content: [], organizer: '', hide: true, isIPX: app.globalData.isIPX, bookList: [], sendGroupFlag: true, selectFlag: [], flag: true, colonelName: '', article: '', alertFlag: false }, //tab切换 tabSwitch: function () { this.setData({ flag: !this.data.flag }) }, jurisdiction: function () { //隐藏弹框 this.setData({ hide: !this.data.hide }) //登录页信息 this.onLoad(); }, //发起团购 sendGroup: function () { this.setData({ sendGroupFlag: !this.data.sendGroupFlag }) }, //选中团购课程 selectImg: function ({ currentTarget }) { const ind = currentTarget.dataset.ind; //判断单选 this.data.selectFlag.forEach((item, index) => { if (index == ind) { this.data.selectFlag[ind] = !this.data.selectFlag[ind]; } else { this.data.selectFlag[index] = true; } }) this.setData({ selectFlag: this.data.selectFlag }) }, //点击确定 sure: function () { this.data.selectFlag.forEach((item, index) => { if (!item) { const productId = this.data.bookList[index].id; const title = this.data.bookList[index].title this.setData({ sendGroupFlag: !this.data.sendGroupFlag }) wx.navigateTo({ url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}` }) } }) }, //参团 jionGroup: function () { if(app.globalData.isIOS){ this.showAlert(); return; } const orderId = this.data.orderId; //开始发起团购 httpRequestApi.JoinGroupPurchas(orderId).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.prePayMap(res.data.data.prePayMap, 'join'); }).fail((error) => { }) }, showAlert: function(){ this.setData({ alertFlag: !this.data.alertFlag }) }, //支付 prePayMap: function (prePayMap, type) { console.log(prePayMap) const that = this; wx.requestPayment({ 'appId': prePayMap.appId, 'timeStamp': prePayMap.timeStamp, 'nonceStr': prePayMap.nonceStr, 'package': prePayMap.package, 'signType': 'MD5', 'paySign': prePayMap.sign, 'success': function (res) { console.log('支付成功') const type1 = type; wx.showModal({ title: '提示', content: '支付成功', success(res) { //获取拼团信息 console.log(that.data.orderId) wx.showLoading({ title: '支付查询中...', mask: true }) setTimeout(() => { wx.hideLoading(); console.log(that.data.orderId) that.jionSuccess(that.data.orderId, type1); // that.groupSuccess(orderId, detailId); }, 800) } }) }, 'fail': function (res) { console.log('支付失败', res) } }) }, //拼团详情 jionSuccess: function (orderId, type) { httpRequestApi.getMygroupInfo(orderId).success(res => { console.log('拼团详情', res); const groupOrder = res.data.data.groupPurchaseOrder; const surplusNum = groupOrder.headcount - groupOrder.joinCount; if (this.data.article === '') { this.getBooksInfo(res.data.data.groupPurchaseOrder.productId) } this.setData({ organizer: groupOrder.organizer, }) if (type === 'join') { this.data.surplusList.pop(); if (groupOrder.status === 'SUCCESSED') { this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice) } else { this.goToDetail(groupOrder.id) } } else if (type === 'create') { this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice) this.setData({ orderId: groupOrder.id }) } else { for (var i = 0; i < surplusNum; i++) { this.data.surplusList.push(1); } } let timeList = []; const stillGoing = groupOrder.closeTime - Date.parse(new Date()) <= 0 ? false : true if(stillGoing){ timeList = util.formatTime(groupOrder.closeTime - Date.parse(new Date())); } // 分享进来的并且团购失效 就跳转到详情页面 // if(this.data.goBackHome && (surplusNum ===0 || !stillGoing) ){ // console.log(' productID>>>>>>>>>>>>>>>>'+ res.data.data.groupPurchaseOrder.productId) // wx.navigateTo({ // url: `/pages/groupPage/grade-details/grade-details?productId=${res.data.data.groupPurchaseOrder.productId}` // }) // } this.setData({ surplusNum, joinUserList: res.data.data.joinUserList, surplusList: this.data.surplusList, timeList, stillGoing }) if (groupOrder.groupType === 'PROMOTION') { //this.data.joinUserList.unshift(res.data.data.organizer); this.setData({ colonelName: res.data.data.organizer.wechatName }) //this.data.surplusList.pop(); this.setData({ joinUserList: this.data.joinUserList, //surplusList: this.data.surplusList, surplusNum: this.data.surplusNum }) } }).fail(error => { console.log('错误', error) }) }, // 弹成功信息框 showSuccess: function (organizerUid, price) { debugger; if (wx.getStorageSync('uid') == organizerUid) { this.setData({ typeOf: 'success', titles: '恭喜 !', headTextOne: '您发起的团购拼团成功', headTextTwo: '领袖体质魅力无穷!', content: [{ text: " 您可以继续发起新的团购,", color: "#F97800" }, { text: " 不再需要支付本课程费用", color: "#F97800" }, { text: `拼团成功,您将得到奖学金`, color: "#F97800" } ], btnContent: '再接再厉 赚奖学金' }, () => { this.popup.close() }) } else { this.setData({ typeOf: 'success', titles: '拼团成功 ! ', headTextOne: '您参与的团购拼团成功', headTextTwo: '感谢团长的分享', content: [{ text: " 您也可以发起新的团购", color: "#F97800" }, { text: "作为新的发起人", color: "#F97800" }, { text: " 您无需在支付本课程费用 ", color: "#F97800" }, { text: `拼团成功,您将得到奖学金`, color: "#F97800" } ], btnContent: '我也试试 赚奖学金' }, () => { this.popup.close() }) } }, // 去详情页面 goToDetail: function (detailId) { setTimeout(() => { wx.redirectTo({ url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}` }) wx.setNavigationBarTitle({ title: '拼团详情' }) }, 1000) }, //跳到课程 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}` }) }, //再次发起团 group: function () { // const orderId = this.data.orderId; // this.goToDetail(orderId); wx.navigateTo({ url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}` }) //拼团是否成功并弹窗 // httpRequestApi.groupSuccess(orderId).success(res => { // console.log('团购是否成功', res.data.data) // debugger; // const status = res.data.data.status; // const uid = res.data.data.uid; // }).fail(error => { // console.log('错误', eroor) // }) //this.openGroup(); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // if (app.globalData.isIOS) { // wx.redirectTo({ // url: '../../index/index' // }) // return // } getOpenidSessionKey((res) => {}, (error) => { this.setData({ hide: !this.data.hide }) return; }); wx.setNavigationBarTitle({ title: '拼团详情' }) console.log(options) if (options.orderId) { const orderId = options.id; this.setData({ orderId }) this.jionSuccess(orderId); } else { // 从分享页面进入的 const orderId = options.productId ? options.productId : options.scene ? options.scene.replace('QR', '') : options.shareId; this.setData({ orderId }) this.jionSuccess(orderId); } if (options.scene || options.shareId) { this.setData({ goBackHome: true }) } }, // 下拉刷新 onPullDownRefresh: function () { //当前在团购页下拉加载 this.setData({ surplusList: [] },()=>{ this.jionSuccess(this.data.orderId); }) wx.showNavigationBarLoading() //在标题栏中显示加载 //模拟加载 setTimeout(function(){ wx.hideNavigationBarLoading() //完成停止加载 wx.stopPullDownRefresh() //停止下拉刷新 },1500); }, // 获取课本详情 getBooksInfo: 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; 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, }); }).fail((error) => { }) //全部课本 httpRequestApi.getAllBooks(1, 10).success((res) => { console.log('全部课', res.data.data.list) res.data.data.list.forEach(element => { this.data.selectFlag.push(true); }); this.setData({ bookList: res.data.data.list, selectFlag: this.data.selectFlag }) }).fail((error) => { console.log('错误', error) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { this.popup = this.selectComponent("#popupup"); } })