|
@@ -11,36 +11,59 @@ export const groupInit = (that) => {
|
|
|
isIPX: app.globalData.isIPX,
|
|
|
timeList: [],
|
|
|
listLength: '',
|
|
|
- baseIndex: 0
|
|
|
- }
|
|
|
+ baseIndex: 0,
|
|
|
+ isIOS: app.globalData.isIOS,
|
|
|
+ alertFlag: false
|
|
|
+ },
|
|
|
+ groupIndex: 1
|
|
|
})
|
|
|
//推荐团购
|
|
|
- that.recommend = function (start, end) {
|
|
|
- httpRequestApi.getGroupList().success( (res) => {
|
|
|
- console.log('推荐团购',res.data.data)
|
|
|
- that.data.groupData.listLength = res.data.data.length;
|
|
|
- that.data.groupData.recommendList = res.data.data.slice(start, end);
|
|
|
- that.data.groupData.recommendList.forEach( (item) => {
|
|
|
- if(item.groupPurchaseOrder.closeTime - Date.parse(new Date()) < 0 ) {
|
|
|
- that.data.groupData.timeList.push('时间到了,')
|
|
|
- } else {
|
|
|
- that.data.groupData.timeList.push(util.formatTime(item.groupPurchaseOrder.closeTime - Date.parse(new Date())).join(':'))
|
|
|
- }
|
|
|
+ that.recommend = function (pageNo) {
|
|
|
+ httpRequestApi.getGroupList(pageNo).success((res) => {
|
|
|
+ // that.data.groupData.listLength = res.data.data.length;
|
|
|
+ // that.data.groupData.recommendList = res.data.data.slice(start, end);
|
|
|
+ // that.setData({
|
|
|
+ // groupData: that.data.groupData
|
|
|
+ // })
|
|
|
+ // that.data.groupData.recommendList.forEach( (item) => {
|
|
|
+ // if(item.groupPurchaseOrder.closeTime - Date.parse(new Date()) < 0 ) {
|
|
|
+ // that.data.groupData.timeList.push('时间到了,')
|
|
|
+ // } else {
|
|
|
+ // that.data.groupData.timeList.push(util.formatTime(item.groupPurchaseOrder.closeTime - Date.parse(new Date())).join(':'))
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // that.setData({
|
|
|
+ // groupData: that.data.groupData
|
|
|
+ // })
|
|
|
+ const recommendListTemp = [];
|
|
|
+ res.data.data.forEach(item => {
|
|
|
+ const temp = {};
|
|
|
+ temp.avatar = item.organizer.avatar;
|
|
|
+ temp.wechatName = item.organizer.wechatName;
|
|
|
+ temp.groupTitle = item.groupPurchaseOrder.groupTitle;
|
|
|
+ temp.headCount = item.groupPurchaseOrder.headcount;
|
|
|
+ temp.joinCount = item.groupPurchaseOrder.joinCount;
|
|
|
+ temp.lastTime = item.groupPurchaseOrder.closeTime - item.currentTime <= 0 ? '时间不足,' : util.formatTime(item.groupPurchaseOrder.closeTime - item.currentTime).join(':');
|
|
|
+ temp.id = item.groupPurchaseOrder.id;
|
|
|
+ // that.data.groupData.recommendList.push(temp);
|
|
|
+ recommendListTemp.push(temp);
|
|
|
})
|
|
|
- console.log('截取之后', that.data.groupData.recommendList)
|
|
|
+ const recommendListStr = "groupData.recommendList";
|
|
|
+ // const recommendListThreeStr = "groupData.recommendListThree";
|
|
|
that.setData({
|
|
|
- groupData: that.data.groupData
|
|
|
+ [recommendListStr]: recommendListTemp,
|
|
|
+ // [recommendListThreeStr]: that.data.groupData.recommendList.slice(that.data.groupData.baseIndex, that.data.groupData.baseIndex + 3),
|
|
|
+ // listLength: res.data.data.length
|
|
|
})
|
|
|
- //util.formatTime(groupOrder.closeTime - Date.parse(new Date()))
|
|
|
}).fail((error) => {
|
|
|
- console.log('错误',error)
|
|
|
+ console.log('错误', error)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
//请求数据封装
|
|
|
that.getGroupList = function () {
|
|
|
httpRequestApi.getAllBooks(1, 10).success((res) => {
|
|
|
- console.log('全部课',res.data.data.list)
|
|
|
+ console.log('全部课', res.data.data.list)
|
|
|
that.data.groupData.bookList = res.data.data.list;
|
|
|
console.log(that.data.groupData.bookList)
|
|
|
res.data.data.list.forEach(element => {
|
|
@@ -50,28 +73,44 @@ export const groupInit = (that) => {
|
|
|
groupData: that.data.groupData
|
|
|
})
|
|
|
}).fail((error) => {
|
|
|
- console.log('错误',error)
|
|
|
+ console.log('错误', error)
|
|
|
})
|
|
|
}();
|
|
|
|
|
|
- that.recommend(0, 3);
|
|
|
+ that.recommend(1);
|
|
|
|
|
|
//点击换一换
|
|
|
that.change = function () {
|
|
|
- that.data.groupData.baseIndex++;
|
|
|
- if(that.data.groupData.listLength <= 3 * (that.data.groupData.baseIndex)) {
|
|
|
- that.data.groupData.baseIndex = 0;
|
|
|
- }
|
|
|
- that.setData({
|
|
|
- groupData: that.data.groupData
|
|
|
- })
|
|
|
- that.recommend(3 * that.data.groupData.baseIndex, 3 * (that.data.groupData.baseIndex + 1));
|
|
|
+ // that.data.groupData.baseIndex++;
|
|
|
+ // if(that.data.groupData.listLength <= 3 * (that.data.groupData.baseIndex)) {
|
|
|
+ // that.data.groupData.baseIndex = 0;
|
|
|
+ // }
|
|
|
+ // that.setData({
|
|
|
+ // groupData: that.data.groupData
|
|
|
+ // })
|
|
|
+ // that.recommend(3 * that.data.groupData.baseIndex, 3 * (that.data.groupData.baseIndex + 1));
|
|
|
+
|
|
|
+ // if (that.data.groupData.baseIndex / 3 >= that.data.listLength / 3) {
|
|
|
+ // that.data.groupData.baseIndex = 0
|
|
|
+ // }
|
|
|
+ // const recommendListThreeStr = "groupData.recommendListThree";
|
|
|
+ // const baseIndexStr = "groupData.baseIndex";
|
|
|
+ // this.setData({
|
|
|
+ // [recommendListThreeStr]: that.data.groupData.recommendList.slice(that.data.groupData.baseIndex + 3, that.data.groupData.baseIndex + 6),
|
|
|
+ // [baseIndexStr]: that.data.groupData.baseIndex + 3
|
|
|
+ // })
|
|
|
+ // console.log(that.data.groupData.baseIndex / 3);
|
|
|
+ // console.log(that.data.listLength / 3);
|
|
|
+ // if(that.groupIndex )
|
|
|
+ that.recommend(that.data.groupIndex++)
|
|
|
}
|
|
|
//点击跳转
|
|
|
- that.more = function ({currentTarget}) {
|
|
|
- wx.navigateTo({
|
|
|
- url: `../main/books/books`
|
|
|
- })
|
|
|
+ that.more = function ({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: `../main/books/books`
|
|
|
+ })
|
|
|
}
|
|
|
//发起团购
|
|
|
that.sendGroup = function () {
|
|
@@ -81,13 +120,15 @@ export const groupInit = (that) => {
|
|
|
})
|
|
|
}
|
|
|
//选中团购课程
|
|
|
- that.selectImg = function ({ currentTarget }) {
|
|
|
+ that.selectImg = function ({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
const ind = currentTarget.dataset.ind;
|
|
|
//判断单选
|
|
|
that.data.groupData.selectFlag.forEach((item, index) => {
|
|
|
- if(index == ind) {
|
|
|
+ if (index == ind) {
|
|
|
that.data.groupData.selectFlag[ind] = !that.data.groupData.selectFlag[ind];
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
that.data.groupData.selectFlag[index] = true;
|
|
|
}
|
|
|
})
|
|
@@ -97,8 +138,8 @@ export const groupInit = (that) => {
|
|
|
}
|
|
|
//点击确定
|
|
|
that.sure = function () {
|
|
|
- that.data.groupData.selectFlag.forEach( (item ,index) => {
|
|
|
- if(!item) {
|
|
|
+ that.data.groupData.selectFlag.forEach((item, index) => {
|
|
|
+ if (!item) {
|
|
|
const productId = that.data.groupData.bookList[index].id;
|
|
|
const title = that.data.groupData.bookList[index].title
|
|
|
wx.navigateTo({
|
|
@@ -117,16 +158,32 @@ export const groupInit = (that) => {
|
|
|
title: '我的团购'
|
|
|
})
|
|
|
}
|
|
|
+ // IOS提示不能参团
|
|
|
+ that.showAlert = function () {
|
|
|
+ let str = "groupData.alertFlag"
|
|
|
+ that.setData({
|
|
|
+ [str]: !that.data.groupData.alertFlag
|
|
|
+ })
|
|
|
+ console.log(that.data.groupData.alertFlag)
|
|
|
+ }
|
|
|
//跳转到团购详情页
|
|
|
- that.groupDetail = function ({currentTarget}) {
|
|
|
+ that.groupDetail = function ({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
+ if (that.data.groupData.isIOS) {
|
|
|
+ that.showAlert();
|
|
|
+ return;
|
|
|
+ }
|
|
|
const productId = currentTarget.dataset.productid;
|
|
|
const id = currentTarget.dataset.id;
|
|
|
const groupId = currentTarget.dataset.groupid;
|
|
|
const ind = currentTarget.dataset.ind;
|
|
|
const groupType = that.data.groupData.recommendList[ind].groupType;
|
|
|
- wx.navigateTo({
|
|
|
- url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
|
|
|
- })
|
|
|
+ console.log(id)
|
|
|
+ wx.navigateTo({
|
|
|
+ // url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
|
|
|
+ url: `/pages/groupPage/group-details/group-details?productId=${id}`
|
|
|
+ })
|
|
|
// if(groupType === "PROMOTION") {
|
|
|
// wx.navigateTo({
|
|
|
// url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${id}&groupId=${groupId}`
|
|
@@ -139,13 +196,13 @@ export const groupInit = (that) => {
|
|
|
|
|
|
}
|
|
|
//跳转到课程详情
|
|
|
- that.goToBook = function(e){
|
|
|
+ that.goToBook = function (e) {
|
|
|
console.log(e.currentTarget.dataset)
|
|
|
let id = e.currentTarget.dataset.id;
|
|
|
let title = e.currentTarget.dataset.title;
|
|
|
console.log(id)
|
|
|
wx.navigateTo({
|
|
|
- url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
|
|
|
- })
|
|
|
+ url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
|
|
|
+ })
|
|
|
}
|
|
|
}
|