123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486 |
- // 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,
- flag: true,
- colonelName: '',
- article: '',
- alertFlag: false,
- stillGoing: true,
- surplusNum: '1',
- timeList: ['6', '6', '6'],
- modalType: "image",
- isModalShow: false,
- modalCloseShow: false,
- modalText: [{
- text: '您已经参加过本次团购',
- type: 'bigOrange'
- },
- {
- text: '快喊朋友们一起助力',
- type: 'bigOrange'
- }
- ],
- groupStatus: false,
- formIsANAsshole: true,
- dataLoading: true,
- isLoading: false,
- isIOS: app.globalData.isIOS,
- damnDialogLine1: '您已拥有本课三年使用权或曾获得过体验权',
- // damnDialogLine2:'',
- damnDialogShow: false,
- knowFlag: true,
- menuFlag: false,
- ifGroupSuccessed: false,
- groupOSType: 'IOS',
- hideBottomBtn: true
- },
- //tab切换
- //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
- })
- }
- },
- jurisdiction: function () {
- //隐藏弹框
- this.setData({
- hide: !this.data.hide
- })
- //登录页信息
- this.onLoad(this.data.onLoadOption);
- },
- //参团
- jionGroup: function (e) {
- console.log(this.data.haveTapJoin)
- if (this.data.haveTapJoin) {
- return false
- }
- this.setData({
- haveTapJoin: true
- })
- const orderId = this.data.orderId;
- const formId = e.detail.formId
- console.log(e)
- //开始发起团购
- httpRequestApi.JoinGroupPurchas(orderId, formId).success((res) => {
- console.log('参加团购', res);
- if (res.data.message) {
- switch (res.data.code) {
- case 801:
- this.setData({
- isModalShow: true,
- modalType: 'text',
- haveTapJoin: false
- })
- break;
- case 802:
- this.setData({
- damnDialogShow: true,
- haveTapJoin: false
- })
- break;
- case 806:
- console.log(this.data.haveTapJoin)
- wx.pageScrollTo({
- scrollTop: 0,
- duration: 17
- })
- this.setData({
- alertFlag: true,
- haveTapJoin: false
- })
- break;
- default:
- wx.showModal({
- title: '提示',
- content: res.data.message,
- success(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- this.setData({
- haveTapJoin: false
- })
- }
- })
- break;
- }
- return false;
- }
- //掉起支付
- if (res.data.data.groupPurchaseOrder.os === 'IOS') {
- this.getGroupInfo(res.data.data.groupPurchaseOrder.id);
- } else {
- this.prePayMap(res.data.data.prePayMap);
- }
- })
- },
- showAlert: function () {
- this.setData({
- alertFlag: !this.data.alertFlag
- })
- },
- //支付
- prePayMap: function (prePayMap) {
- console.log(prePayMap)
- wx.requestPayment({
- 'appId': prePayMap.appId,
- 'timeStamp': prePayMap.timeStamp,
- 'nonceStr': prePayMap.nonceStr,
- 'package': prePayMap.package,
- 'signType': 'MD5',
- 'paySign': prePayMap.sign,
- 'success': res => {
- this.setData({
- isModalShow: true,
- haveTapJoin: false
- })
- },
- 'fail': res => {
- console.log('支付失败', res)
- this.setData({
- haveTapJoin: false
- })
- }
- })
- },
- //拼团详情
- getGroupInfo: function (orderId) {
- httpRequestApi.getMygroupInfo(orderId).success(res => {
- const groupOrder = res.data.data.groupPurchaseOrder;
- if (groupOrder.os === 'ANDROID' && app.globalData.isIOS) {
- wx.redirectTo({
- url: `/pages/groupPage/grade-details/grade-details?productId=${res.data.data.groupPurchaseOrder.productId}&goBackHome=1`
- })
- return;
- }
- // 团员进入collage页面
- const myUid = wx.getStorageSync('uid');
- if (myUid === groupOrder.organizer) {
- wx.redirectTo({
- url: `../collage-details/collage-details?orderId=${orderId}&goBackHome=${this.data.goBackHome}`
- })
- return;
- }
- res.data.data.joinUserList.forEach(item => {
- if (item.uid === myUid) {
- wx.redirectTo({
- url: `../collage-details/collage-details?orderId=${orderId}&goBackHome=${this.data.goBackHome}`
- })
- return;
- }
- })
- const surplusNum = groupOrder.headcount - groupOrder.joinCount;
- this.setData({
- organizerUid: groupOrder.organizer,
- ifGroupSuccessed: groupOrder.status === 'SUCCESSED' ? true : false
- })
- for (var i = 0; i < surplusNum; i++) {
- this.data.surplusList.push(1);
- }
- // 剩余时间 如果团购已结束则不显示
- let timeLast = '';
- const stillGoing = groupOrder.closeTime - Date.parse(new Date()) <= 0 ? false : true
- if (stillGoing) {
- timeLast = util.lastHours(groupOrder.closeTime - Date.parse(new Date()));
- }
- this.setData({
- groupPurchaseInfo: res.data.data.groupPurchaseInfo,
- organizer: res.data.data.organizer,
- surplusNum,
- joinUserList: res.data.data.joinUserList,
- surplusList: this.data.surplusList,
- timeLast,
- stillGoing,
- productId: groupOrder.productId,
- groupId: groupOrder.groupId,
- rewardMoney: res.data.data.groupPurchaseInfo.organizerPrice / 100,
- dataLoading: false,
- groupOsType: groupOrder.os,
- isLoading: false
- })
- if (this.data.article === '') {
- this.getBooksInfo(res.data.data.groupPurchaseOrder.productId)
- }
- httpRequestApi.userIntoPage('pages/groupPage/group-details/group-details','团购详情页面').success((res)=>{
-
- })
- if (groupOrder.groupType === 'PROMOTION') {
- this.setData({
- colonelName: res.data.data.organizer.wechatName,
- promotion: true
- // joinUserList: this.data.joinUserList
- })
- }
- })
- },
- // 去详情页面
- goToDetail: function (detailId) {
- setTimeout(() => {
- wx.redirectTo({
- url: `/pages/groupPage/collage-details/collage-details?orderId=${this.data.orderId}&goBackHome=true`
- })
- 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) {
- console.log(this.data.isIOS)
- this.setData({
- options:options
- })
- if (options.scene || options.shareId) {
- console.log(123)
- this.setData({
- isLoading: true
- })
- }
-
- console.log('onload', options)
- wx.setNavigationBarTitle({
- title: '拼团详情'
- })
- getOpenidSessionKey((res) => {
- if (options.orderId) {
- const orderId = options.id;
- this.setData({
- orderId
- })
- this.getGroupInfo(orderId);
- } else {
- // 从分享页面进入的
- const orderId = options.productId ? options.productId : options.scene ? options.scene.replace('QR', '') : options.shareId;
- this.setData({
- orderId
- })
- this.getGroupInfo(orderId);
- }
- if (options.scene || options.shareId) {
- this.setData({
- goBackHome: true
- })
- }
- }, (error) => {
- wx.setStorageSync('userSourseType','group')
- this.setData({
- hide: !this.data.hide,
- onLoadOption: options
- })
- return;
- });
- },
- // 页面滚动
- pageScroll: function (e) {
- console.log(e.target.offsetTop)
- if (e.target.offsetTop < 600) {
- this.setData({
- hideBottomBtn: true
- })
- }
- if (e.target.offsetTop > 600) {
- this.setData({
- hideBottomBtn: false
- })
- }
- // if(e.target.offsetTop > 600){
- // this.setData({
- // btnClass: 'middle-btn'
- // })
- // }
- },
- // 鉴权
- areYouSuperSecond: function (productId) {
- httpRequestApi.areYouSuperSecond(productId).success(() => {
- console.log(res)
- this.setData({
- imSuper: res.data.data.auth ? true : false,
- haveCreatedHelp: res.data.data.createdShare, // 创建过助力团
- haveJoinHelp: res.data.data.joinShare, // 参加过助力团
- })
- });
- // 增加一条记录
- const data = {
- "shareTypeEnum": "POSTER",
- "shareContentEnum": "GROUP",
- "productId": productId
- }
- if (this.data.option.shareId) {
- data.shareTypeEnum = 'LINK'
- httpRequestApi.shareTagRecord(data).success(res => {
- console.log(res)
- })
- }
- if (this.data.option.scene) {
- httpRequestApi.shareTagRecord(data).success(res => {
- console.log(res)
- })
- }
- },
- // 下拉刷新
- onPullDownRefresh: function () {
- //当前在团购页下拉加载
- this.setData({
- surplusList: []
- }, () => {
- this.getGroupInfo(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");
- },
- judgeUser: function (callBack) {
- },
- modalConfirmHandler: function () {
- this.setData({
- isModalShow: false
- })
- if (this.data.modalType === 'image') {
- this.goToDetail();
- }
- },
- modalCloseHandler: function () {
- this.setData({
- isModalShow: false
- })
- if (this.data.modalType === 'image') {
- this.goToDetail();
- }
- },
- })
|