123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- // pages/group-details/group-details.js
- import httpRequestApi from '../../../utils/APIClient';
- import util from '../../../utils/util';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- titleIcon: '',
- title: '',
- bookInfo: '',
- lessonList: [],
- surplusNum: '',
- joinUserList: [],
- surplusList: [],
- timeList: [],
- productId: '',
- groupId: '',
- orderId: '',
- typeOf: '',
- title: '',
- headTextOne: '',
- headTextTwo: '',
- content: [],
- },
- //跳转到年级
- gradeDetails: function () {
- // wx.navigateTo({
- // url: '/pages/groupPage/grade-details/grade-details'
- // })
- // wx.setNavigationBarTitle({
- // title: '限量优惠团购'
- // })
- },
- //开团
- openGroup: function () {
-
- const productId = this.data.productId;
- const groupId = this.data.groupId;
- //开始发起团购
- httpRequestApi.SendGroupPurchas({
- productId,
- groupId
- }).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;
- }
- if (res.data.data.groupPurchaseOrder.groupType === 'BASE') {
- //掉起支付
- this.prePayMap(res.data.data.prePayMap, 'create');
- }
- }).fail((error) => {
- })
- },
- //参团
- jionGroup: function () {
-
- 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) => {
- })
- },
- //支付
- 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);
- }, 2000)
- }
- })
- },
- 'fail': function (res) {
- console.log('支付失败', res)
- }
- })
- },
- //跳转到拼团详情
- collage: function () {
- },
- //拼团详情
- jionSuccess: function (orderId, type) {
- httpRequestApi.getMygroupInfo(orderId).success(res => {
- console.log('拼团详情', res.data.data);
- const groupOrder = res.data.data.groupPurchaseOrder;
- const surplusNum = groupOrder.headcount - groupOrder.joinCount;
- if (type === 'join') {
- this.data.surplusList.pop();
- if (groupOrder.status === 'SUCCESSED') {
- this.showSuccess(groupOrder.organizer, groupOrder.organizerPrice)
- } else {
- this.goToDetail(groupOrder.id)
- }
- } else {
- for (var i = 0; i < surplusNum; i++) {
- this.data.surplusList.push(1);
- }
- }
- console.log(groupOrder.closeTime - groupOrder.gmtModified)
- //时间转换
- let timeNow = new Date()
- // const timeList = util.formatTime(groupOrder.closeTime - groupOrder.gmtModified);
- const timeList = util.formatTime(groupOrder.closeTime - Date.parse(new Date()));
- this.setData({
- surplusNum,
- joinUserList: res.data.data.joinUserList,
- surplusList: this.data.surplusList,
- timeList,
- })
- if(groupOrder.groupType === 'PROMOTION'){
- this.data.joinUserList.unshift(res.data.data.organizer);
- this.data.surplusList.pop();
- this.setData({
- joinUserList: this.data.joinUserList,
- surplusList: this.data.surplusList,
- surplusNum: this.data.surplusNum - 1
- })
- }
- console.log(this.data.joinUserList)
- // this.groupSuccess(res.data.data.groupPurchaseOrder.productId, detailId);
- }).fail(error => {
- console.log('错误', error)
- })
- },
- // 弹成功信息框
- showSuccess: function (organizerUid, price) {
- if (wx.getStorageSync('uid') == organizerUid) {
- this.setData({
- typeOf: 'success',
- title: '恭喜 !',
- headTextOne: '您发起的团购拼团成功',
- content: [{
- text: "领袖体质魅力无穷!",
- color: "#000"
- },
- {
- text: " 您可以继续发起新的团购,",
- color: "#000"
- },
- {
- text: " 不再需要支付本课程费用,拼团成功,",
- color: "#FF9B00"
- },
- {
- text: `您将得到${price / 100}元奖励。`,
- color: "#FF0000"
- }
- ],
- },()=>{
- this.popup.close()
- })
- } else {
- this.setData({
- typeOf: 'success',
- title: '拼团成功 ! ',
- headTextOne: '您参与的团购拼团成功',
- headTextTwo: '',
- content: [{
- text: "感谢团长的分享",
- color: "#000"
- },
- {
- text: " 您也可以发起新的团购分享给需要的朋友们,",
- color: "#000"
- },
- {
- text: "作为新的发起人,您无需在支付本课程费用;",
- color: "#FF0000"
- },
- {
- text: `团购成功,您将得到${price/ 100}元奖励。`,
- color: "#FF0000"
- }
- ],
- },()=>{
- this.popup.close()
- })
- }
- },
- // 去详情页面
- goToDetail: function (detailId) {
- setTimeout(() => {
- wx.navigateTo({
- url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}`
- })
- wx.setNavigationBarTitle({
- title: '拼团详情'
- })
- }, 3000)
- },
- //拼团是否成功并弹窗
- // groupSuccess: function (orderId, detailId) {
- // httpRequestApi.groupSuccess(orderId).success(res => {
- // console.log('团购是否成功', res.data.data)
- // const status = res.data.data.status;
- // const uid = res.data.data.uid;
- // if (status === 'SUCCESSED') {
- // if (wx.getStorageSync('uid') == uid) {
- // this.setData({
- // typeOf: 'success',
- // title: '恭喜 !',
- // headTextOne: '您发起的团购拼团成功',
- // content: [{
- // text: "领袖体质魅力无穷!",
- // color: "#000"
- // },
- // {
- // text: " 您可以继续发起新的团购,",
- // color: "#000"
- // },
- // {
- // text: " 不再需要支付本课程费用,拼团成功,",
- // color: "#FF9B00"
- // },
- // {
- // text: " 您将得到xxx元奖励。",
- // color: "#FF0000"
- // }
- // ],
- // })
- // } else {
- // this.setData({
- // typeOf: 'success',
- // title: '拼团成功 ! ',
- // headTextOne: '您参与的团购拼团成功',
- // headTextTwo: '订单号:12344',
- // content: [{
- // text: "感谢团长的分享",
- // color: "#000"
- // },
- // {
- // text: " 您也可以发起新的团购分享给需要的朋友们,",
- // color: "#000"
- // },
- // {
- // text: "作为新的发起人,您无需在支付本课程费用;",
- // color: "#FF0000"
- // },
- // {
- // text: "团购成功,您将得到xxx元奖励。",
- // color: "#FF0000"
- // }
- // ],
- // })
- // }
- // } else {
- // setTimeout(() => {
- // wx.navigateTo({
- // url: `/pages/groupPage/collage-details/collage-details?orderId=${detailId}`
- // })
- // wx.setNavigationBarTitle({
- // title: '拼团详情'
- // })
- // }, 3000)
- // }
- // }).fail(error => {
- // console.log('错误', eroor)
- // })
- // },
- //再次发起团
- group: function () {
- wx.showModal({
- title: '提示',
- content: '再次发起团',
- success(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.setNavigationBarTitle({
- title: '拼团详情'
- })
- if (!options.productId) return false;
- const productId = options.productId;
- const groupId = options.groupId;
- const orderId = options.id;
- this.setData({
- productId,
- groupId,
- orderId
- })
- //课本详情
- 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;
- this.setData({
- titleIcon: bookInfo.bgImg,
- title: bookInfo.title,
- bookInfo: bookInfo.description
- })
- 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) => {
- })
- //获取拼团信息
- this.jionSuccess(orderId);
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- this.popup = this.selectComponent("#popupup");
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|