123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- // pages/grade-details/grade-details.js
- import httpRequestApi from '../../../utils/APIClient';
- import util from '../../../utils/util';
- 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,
- modalType: "text",
- isCloseShow: false,
- modalText: [{
- text: '您发起的团购尚未完成',
- type: 'bigOrange'
- },
- {
- text: '拼团成功,才能发起新的团购',
- type: 'bigOrange'
- },
- {
- text: '快喊朋友们一起助力',
- type: 'bigOrange'
- }
- ],
- isModalShow: false,
- formIsANAsshole: true,
- isPaying: 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
- })
- }
- },
- onShow: function(){
- this.setData({
- haveTapMoney : false
- })
- },
- //获取团购信息并掉起支付
- pay: function (e) {
- console.log(e)
- if(this.data.haveTapMoney){
- return false
- }
- this.setData({
- haveTapMoney : true
- })
- const productId = this.data.productId;
- const groupId = e.currentTarget.dataset.id;
- const osType = this.data.isIOS ? 'IOS' : 'ANDROID';
- const formId = e.detail.formId
- //开始发起团购
- this.setData({
- isPaying: true
- })
- httpRequestApi.SendGroupPurchas({
- productId,
- groupId,
- osType,
- formId
- }).success((res) => {
- console.log('发起团购', res);
-
- if (res.data.message) {
- if(res.data.code == '803'){
- // this.setData({
- // modalType: 'text',
- // isModalShow: true
- // })
- wx.navigateTo({
- url:`/pages/groupPage/my-group/my-group`
- })
- }else{
- 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') {
-
- wx.redirectTo({
- url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
- })
- wx.setNavigationBarTitle({
- title: '拼团详情'
- })
- // 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.navigateTo({
- url: `/pages/groupPage/collage-details/collage-details?orderId=${that.data.orderId}`
- })
- wx.setNavigationBarTitle({
- title: '拼团详情'
- })
- // 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 {
- //掉起支付
- console.log(res.data.data.groupPurchaseOrder)
- this.setData({
- groupCount:res.data.data.groupPurchaseOrder.headcount
- })
- // this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id, res.data.data.groupPurchaseOrder.headcount);
- this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id);
- }
- }).fail((error) => {
- })
- },
- //支付
- prePayMap: function (prePayMap, orderId, num) {
- // this.setData({
- // modalType: 'image',
- // isModalShow: true
- // })
- // return
-
- console.log(prePayMap)
- console.log(orderId)
- console.log(num)
- 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) {
- that.setData({
- modalType: 'image',
- isModalShow: true,
- haveTapMoney: false
- })
- console.log('支付成功', res)
- // wx.showModal({
- // title: '提示',
- // content: '支付成功',
- // success(res) {
- // if (num !== 1) {
- // that.popup.close();
- // setTimeout(() => {
- // wx.navigateTo({
- // url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
- // })
- // wx.setNavigationBarTitle({
- // title: '拼团详情'
- // })
- // }, 1800)
- // } else {
- // wx.redirectTo({
- // url: `/pages/groupPage/grade-details/grade-details?productId=${that.data.productId}`
- // })
- // }
- // }
- // })
- },
- 'fail': function (res) {
- console.log('支付失败', res)
- that.setData({
- haveTapMoney: false
- })
- }
- })
- },
- showAlert: function () {
- this.setData({
- alertFlag: !this.data.alertFlag
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options)
- if (options.goBackHome) {
- this.setData({
- goBackHome: true,
- alertFlag:true
- })
- }
- // const productId = options.productId;
- this.getBookInfo(options.productId);
- if(this.data.isIOS){
- this.areYouBookSuper('IOS',options.productId)
- } else {
- this.areYouBookSuper('ANDROID',options.productId)
- }
-
- this.getGroupInfo(options.productId)
- // if (productId) {
- this.setData({
- productId: options.productId
- })
- // }
- },
- // 课本鉴权
- areYouBookSuper: function (os,productId) {
- // const productArr = [];
- // productArr.push(productId);
- httpRequestApi.areYouSuperSecond(os,productId).success(res => {
- console.log(res)
- this.setData({
- imSuper: res.data.data.auth ? true : false,
- lastThreeYears: res.data.data.auth ? util.addThreeYears(res.data.data.auth.endTime) : false,
- knowFlag: res.data.data.auth ? false : true,
- menuFlag: res.data.data.auth ? true : false,
- haveCreatedHelp: res.data.data.createdShare, // 创建过助力团
- haveJoinHelp: res.data.data.joinShare, // 参加过助力团
- haveJoinNormal: res.data.data.joinOrder, // 参加过支付团
- tasteDay: res.data.data.auth ? ((res.data.data.auth.endTime - res.data.data.currentTime) / 86400000).toFixed(0) : ''
- })
- console.log(this.data.imSuper)
- console.log(this.data.lastThreeYears)
- })
- },
- 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
- });
- httpRequestApi.userIntoPage('pages/groupPage/grade-details/grade-details','课本详情页面').success((res)=>{
-
- })
- })
- },
- 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");
- },
- modalConfirmHandler: function(){
- this.setData({
- isModalShow: false
- })
- if(this.data.modalType === 'image'){
- if (this.data.groupCount !== 1) {
- this.popup.close();
- setTimeout(() => {
- wx.navigateTo({
- url: `/pages/groupPage/collage-details/collage-details?orderId=${this.data.orderId}`
- })
- wx.setNavigationBarTitle({
- title: '拼团详情'
- })
- }, 1800)
- } else {
- wx.redirectTo({
- url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}`
- })
- }
- }
- },
- modalCloseHandler: function(){
- this.setData({
- isModalShow: false
- })
- }
- })
|