123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- import httpRequestApi from '../../utils/APIClient';
- import util from '../../utils/util';
- const app = getApp();
- export const groupInit = (that) => {
- that.setData({
- groupData: {
- recommendList: [],
- bookList: [],
- sendGroupFlag: true,
- selectFlag: [],
- isIPX: app.globalData.isIPX,
- timeList: [],
- listLength: '',
- baseIndex: 0,
- isIOS: app.globalData.isIOS,
- alertFlag: false
- },
- groupIndex: 1
- })
- //推荐团购
- that.recommend = function () {
- console.log(that.data.listLength)
- httpRequestApi.getGroupList(that.data.groupIndex).success((res) => {
-
- const recommendListTemp = [];
- res.data.data.list.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);
- })
- const recommendListStr = "groupData.recommendList";
- // const recommendListThreeStr = "groupData.recommendListThree";
- that.setData({
- [recommendListStr]: recommendListTemp,
- // [recommendListThreeStr]: that.data.groupData.recommendList.slice(that.data.groupData.baseIndex, that.data.groupData.baseIndex + 3),
- listLength: res.data.data.totalNo
- })
- }).fail((error) => {
- console.log('错误', error)
- })
- }
- //请求数据封装
- that.getGroupList = function () {
- httpRequestApi.getAllBooks(1, 10).success((res) => {
- 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 => {
- that.data.groupData.selectFlag.push(true);
- });
- that.setData({
- groupData: that.data.groupData
- })
- }).fail((error) => {
- console.log('错误', error)
- })
- }();
- that.recommend();
- //点击换一换
- that.change = function () {
- that.data.groupIndex++
- if (that.data.groupIndex >= that.data.listLength) {
- that.setData({
- groupIndex: 1
- })
- } else {
- that.setData({
- groupIndex: that.data.groupIndex
- })
- }
- that.recommend(that.data.groupIndex)
- }
- //点击跳转
- that.more = function ({
- currentTarget
- }) {
- wx.navigateTo({
- url: `../main/books/books`
- })
- }
- //发起团购
- that.sendGroup = function () {
- that.data.groupData.sendGroupFlag = !that.data.groupData.sendGroupFlag;
- that.setData({
- groupData: that.data.groupData
- })
- }
- //选中团购课程
- that.selectImg = function ({
- currentTarget
- }) {
- const ind = currentTarget.dataset.ind;
- //判断单选
- that.data.groupData.selectFlag.forEach((item, index) => {
- if (index == ind) {
- that.data.groupData.selectFlag[ind] = !that.data.groupData.selectFlag[ind];
- } else {
- that.data.groupData.selectFlag[index] = true;
- }
- })
- that.setData({
- groupData: that.data.groupData
- })
- }
- //点击确定
- that.sure = function () {
- 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({
- url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}`
- })
- }
- })
- }
- //跳转到我的团购
- that.myGroup = function () {
- wx.navigateTo({
- url: `/pages/groupPage/my-group/my-group`
- })
- wx.setNavigationBarTitle({
- 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
- }) {
- 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;
- 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}`
- // })
- // }else {
- // wx.navigateTo({
- // url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
- // })
- // }
- }
- //跳转到课程详情
- 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}`
- })
- }
- }
|