group.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. isIOS: app.globalData.isIOS,
  16. alertFlag: false
  17. },
  18. groupIndex: 1
  19. })
  20. //推荐团购
  21. that.recommend = function () {
  22. console.log(that.data.listLength)
  23. httpRequestApi.getGroupList(that.data.groupIndex).success((res) => {
  24. const recommendListTemp = [];
  25. res.data.data.list.forEach(item => {
  26. const temp = {};
  27. temp.avatar = item.organizer.avatar;
  28. temp.wechatName = item.organizer.wechatName;
  29. temp.groupTitle = item.groupPurchaseOrder.groupTitle;
  30. temp.headCount = item.groupPurchaseOrder.headcount;
  31. temp.joinCount = item.groupPurchaseOrder.joinCount;
  32. temp.lastTime = item.groupPurchaseOrder.closeTime - item.currentTime <= 0 ? '时间不足,' : util.formatTime(item.groupPurchaseOrder.closeTime - item.currentTime).join(':');
  33. temp.id = item.groupPurchaseOrder.id;
  34. // that.data.groupData.recommendList.push(temp);
  35. recommendListTemp.push(temp);
  36. })
  37. const recommendListStr = "groupData.recommendList";
  38. // const recommendListThreeStr = "groupData.recommendListThree";
  39. that.setData({
  40. [recommendListStr]: recommendListTemp,
  41. // [recommendListThreeStr]: that.data.groupData.recommendList.slice(that.data.groupData.baseIndex, that.data.groupData.baseIndex + 3),
  42. listLength: res.data.data.totalNo
  43. })
  44. }).fail((error) => {
  45. console.log('错误', error)
  46. })
  47. }
  48. //请求数据封装
  49. that.getGroupList = function () {
  50. httpRequestApi.getAllBooks(1, 10).success((res) => {
  51. console.log('全部课', res.data.data.list)
  52. that.data.groupData.bookList = res.data.data.list;
  53. console.log(that.data.groupData.bookList)
  54. res.data.data.list.forEach(element => {
  55. that.data.groupData.selectFlag.push(true);
  56. });
  57. that.setData({
  58. groupData: that.data.groupData
  59. })
  60. }).fail((error) => {
  61. console.log('错误', error)
  62. })
  63. }();
  64. that.recommend();
  65. //点击换一换
  66. that.change = function () {
  67. that.data.groupIndex++
  68. if (that.data.groupIndex >= that.data.listLength) {
  69. that.setData({
  70. groupIndex: 1
  71. })
  72. } else {
  73. that.setData({
  74. groupIndex: that.data.groupIndex
  75. })
  76. }
  77. that.recommend(that.data.groupIndex)
  78. }
  79. //点击跳转
  80. that.more = function ({
  81. currentTarget
  82. }) {
  83. wx.navigateTo({
  84. url: `../main/books/books`
  85. })
  86. }
  87. //发起团购
  88. that.sendGroup = function () {
  89. that.data.groupData.sendGroupFlag = !that.data.groupData.sendGroupFlag;
  90. that.setData({
  91. groupData: that.data.groupData
  92. })
  93. }
  94. //选中团购课程
  95. that.selectImg = function ({
  96. currentTarget
  97. }) {
  98. const ind = currentTarget.dataset.ind;
  99. //判断单选
  100. that.data.groupData.selectFlag.forEach((item, index) => {
  101. if (index == ind) {
  102. that.data.groupData.selectFlag[ind] = !that.data.groupData.selectFlag[ind];
  103. } else {
  104. that.data.groupData.selectFlag[index] = true;
  105. }
  106. })
  107. that.setData({
  108. groupData: that.data.groupData
  109. })
  110. }
  111. //点击确定
  112. that.sure = function () {
  113. that.data.groupData.selectFlag.forEach((item, index) => {
  114. if (!item) {
  115. const productId = that.data.groupData.bookList[index].id;
  116. const title = that.data.groupData.bookList[index].title
  117. wx.navigateTo({
  118. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}`
  119. })
  120. }
  121. })
  122. }
  123. //跳转到我的团购
  124. that.myGroup = function () {
  125. wx.navigateTo({
  126. url: `/pages/groupPage/my-group/my-group`
  127. })
  128. wx.setNavigationBarTitle({
  129. title: '我的团购'
  130. })
  131. }
  132. // IOS提示不能参团
  133. that.showAlert = function () {
  134. let str = "groupData.alertFlag"
  135. that.setData({
  136. [str]: !that.data.groupData.alertFlag
  137. })
  138. console.log(that.data.groupData.alertFlag)
  139. }
  140. //跳转到团购详情页
  141. that.groupDetail = function ({
  142. currentTarget
  143. }) {
  144. if (that.data.groupData.isIOS) {
  145. that.showAlert();
  146. return;
  147. }
  148. const productId = currentTarget.dataset.productid;
  149. const id = currentTarget.dataset.id;
  150. const groupId = currentTarget.dataset.groupid;
  151. const ind = currentTarget.dataset.ind;
  152. const groupType = that.data.groupData.recommendList[ind].groupType;
  153. console.log(id)
  154. wx.navigateTo({
  155. // url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  156. url: `/pages/groupPage/group-details/group-details?productId=${id}`
  157. })
  158. // if(groupType === "PROMOTION") {
  159. // wx.navigateTo({
  160. // url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${id}&groupId=${groupId}`
  161. // })
  162. // }else {
  163. // wx.navigateTo({
  164. // url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  165. // })
  166. // }
  167. }
  168. //跳转到课程详情
  169. that.goToBook = function (e) {
  170. console.log(e.currentTarget.dataset)
  171. let id = e.currentTarget.dataset.id;
  172. let title = e.currentTarget.dataset.title;
  173. console.log(id)
  174. wx.navigateTo({
  175. url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
  176. })
  177. }
  178. }