group.js 5.8 KB

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