group.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import httpRequestApi from '../../utils/APIClient';
  2. import util from '../../utils/util';
  3. const app = getApp();
  4. export const groupInit = (that) => {
  5. that.setData({
  6. groupData: {
  7. recommendList: [],
  8. bookList: [],
  9. sendGroupFlag: true,
  10. selectFlag: [],
  11. isIPX: app.globalData.isIPX,
  12. timeList: [],
  13. listLength: '',
  14. baseIndex: 0
  15. }
  16. })
  17. //推荐团购
  18. that.recommend = function (start, end) {
  19. httpRequestApi.getGroupList().success( (res) => {
  20. console.log('推荐团购',res.data.data)
  21. that.data.groupData.listLength = res.data.data.length;
  22. that.data.groupData.recommendList = res.data.data.slice(start, end);
  23. that.data.groupData.recommendList.forEach( (item) => {
  24. if(item.groupPurchaseOrder.closeTime - Date.parse(new Date()) < 0 ) {
  25. that.data.groupData.timeList.push('时间到了,')
  26. } else {
  27. that.data.groupData.timeList.push(util.formatTime(item.groupPurchaseOrder.closeTime - Date.parse(new Date())).join(':'))
  28. }
  29. })
  30. console.log('截取之后', that.data.groupData.recommendList)
  31. that.setData({
  32. groupData: that.data.groupData
  33. })
  34. //util.formatTime(groupOrder.closeTime - Date.parse(new Date()))
  35. }).fail((error) => {
  36. console.log('错误',error)
  37. })
  38. }
  39. //请求数据封装
  40. that.getGroupList = function () {
  41. httpRequestApi.getAllBooks(1, 10).success((res) => {
  42. console.log('全部课',res.data.data.list)
  43. that.data.groupData.bookList = res.data.data.list;
  44. console.log(that.data.groupData.bookList)
  45. res.data.data.list.forEach(element => {
  46. that.data.groupData.selectFlag.push(true);
  47. });
  48. that.setData({
  49. groupData: that.data.groupData
  50. })
  51. }).fail((error) => {
  52. console.log('错误',error)
  53. })
  54. }();
  55. that.recommend(0, 3);
  56. //点击换一换
  57. that.change = function () {
  58. that.data.groupData.baseIndex++;
  59. if(that.data.groupData.listLength < 3 * (that.data.groupData.baseIndex)) {
  60. that.data.groupData.baseIndex = 0;
  61. }
  62. that.setData({
  63. groupData: that.data.groupData
  64. })
  65. that.recommend(3 * that.data.groupData.baseIndex, 3 * (that.data.groupData.baseIndex + 1));
  66. }
  67. //点击跳转
  68. that.more = function ({currentTarget}) {
  69. wx.navigateTo({
  70. url: `../main/books/books`
  71. })
  72. }
  73. //发起团购
  74. that.sendGroup = function () {
  75. that.data.groupData.sendGroupFlag = !that.data.groupData.sendGroupFlag;
  76. that.setData({
  77. groupData: that.data.groupData
  78. })
  79. }
  80. //选中团购课程
  81. that.selectImg = function ({ currentTarget }) {
  82. const ind = currentTarget.dataset.ind;
  83. //判断单选
  84. that.data.groupData.selectFlag.forEach((item, index) => {
  85. if(index == ind) {
  86. that.data.groupData.selectFlag[ind] = !that.data.groupData.selectFlag[ind];
  87. }else {
  88. that.data.groupData.selectFlag[index] = true;
  89. }
  90. })
  91. that.setData({
  92. groupData: that.data.groupData
  93. })
  94. }
  95. //点击确定
  96. that.sure = function () {
  97. that.data.groupData.selectFlag.forEach( (item ,index) => {
  98. if(!item) {
  99. const productId = that.data.groupData.bookList[index].id;
  100. const title = that.data.groupData.bookList[index].title
  101. wx.navigateTo({
  102. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}`
  103. })
  104. }
  105. })
  106. }
  107. //跳转到我的团购
  108. that.myGroup = function () {
  109. wx.navigateTo({
  110. url: `/pages/groupPage/my-group/my-group`
  111. })
  112. wx.setNavigationBarTitle({
  113. title: '我的团购'
  114. })
  115. }
  116. //跳转到团购详情页
  117. that.groupDetail = function ({currentTarget}) {
  118. const productId = currentTarget.dataset.productid;
  119. const id = currentTarget.dataset.id;
  120. const groupId = currentTarget.dataset.groupid;
  121. const ind = currentTarget.dataset.ind;
  122. const groupType = that.data.groupData.recommendList[ind].groupType;
  123. wx.navigateTo({
  124. url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  125. })
  126. // if(groupType === "PROMOTION") {
  127. // wx.navigateTo({
  128. // url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${id}&groupId=${groupId}`
  129. // })
  130. // }else {
  131. // wx.navigateTo({
  132. // url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  133. // })
  134. // }
  135. }
  136. //跳转到课程详情
  137. that.goToBook = function(e){
  138. console.log(e.currentTarget.dataset)
  139. let id = e.currentTarget.dataset.id;
  140. let title = e.currentTarget.dataset.title;
  141. console.log(id)
  142. wx.navigateTo({
  143. url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
  144. })
  145. }
  146. }