123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- import httpRequestApi from '../../utils/APIClient';
- import util from '../../utils/util';
- const app = getApp();
- export const groupInit = (that) => {
- if(!that.data.groupData){
- that.setData({
- groupData: {
- recommendList: [],
- bookList: [],
- sendGroupFlag: true,
- selectFlag: [],
- isIPX: app.globalData.isIPX,
- timeList: [],
- listLength: '',
- baseIndex: 0,
- isIOS: app.globalData.isIOS,
- alertFlag: false,
- myGroupGoing: 0
- },
- groupIndex: 1
- })
- }
-
- that.recommend = function () {
- if(that.data.groupData.bookList.length === 0){
- that.getGroupList();
- }
- console.log(that.data.listLength)
- let osType = app.globalData.isIOS ? 'IOS' : 'ANDROID'
- httpRequestApi.getGroupList(that.data.groupIndex,osType).success((res) => {
-
- const recommendListTemp = [];
- res.data.data.list.forEach(item => {
- const temp = {};
- temp.avatar = item.organizer.avatar;
- temp.wechatName = item.organizer.wechatName;
- temp.productTitle = item.groupPurchaseOrder.productTitle;
- temp.headCount = item.groupPurchaseOrder.headcount;
- temp.joinCount = item.groupPurchaseOrder.joinCount;
- temp.lastTime = item.groupPurchaseOrder.closeTime - item.currentTime <= 0 ? '时间不足,' : util.lastHours(item.groupPurchaseOrder.closeTime - item.currentTime);
- temp.id = item.groupPurchaseOrder.id;
-
- recommendListTemp.push(temp);
- })
- const recommendListStr = "groupData.recommendList";
- const listLengthStr = "groupData.listLength";
- const totalSizeStr = "groupData.totalSize";
-
- that.setData({
- [recommendListStr]: recommendListTemp,
-
- listLength: res.data.data.totalNo,
- [listLengthStr]: res.data.data.totalNo,
- [totalSizeStr]: res.data.data.totalSize
- })
- that.getMyGroupGoing()
- }).fail((error) => {
- console.log('错误', error)
- })
- }
-
- that.getMyGroupGoing = function(){
- httpRequestApi.getMyGroupGoing().success(res=>{
- console.log(res)
- const str = 'groupData.myGroupGoing';
- that.setData({
- [str]: res.data.data
- })
- })
- },
-
- 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
- })
- httpRequestApi.userIntoPage('pages/index/index','首页热团').success((res)=>{
-
- })
- }).fail((error) => {
- console.log('错误', error)
- })
- };
- that.recommend();
-
- that.change = function () {
- that.data.groupIndex++
- console.log(that.data.listLength)
- console.log(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: '我的团购'
- })
- }
-
- that.showAlert = function () {
- let str = "groupData.alertFlag"
- that.setData({
- [str]: !that.data.groupData.alertFlag
- })
- console.log(that.data.groupData.alertFlag)
- }
-
- that.groupDetail = function ({
- currentTarget
- }) {
-
-
-
-
- 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=${id}`
- })
-
-
-
-
-
-
-
-
-
- }
- }
|