group.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. httpRequestApi.userIntoPage('pages/index/index','首页热团')
  64. }).fail((error) => {
  65. console.log('错误', error)
  66. })
  67. }();
  68. that.recommend();
  69. //点击换一换
  70. that.change = function () {
  71. that.data.groupIndex++
  72. console.log(that.data.listLength)
  73. console.log(that.data.groupIndex)
  74. if (that.data.groupIndex > that.data.listLength) {
  75. that.setData({
  76. groupIndex: 1
  77. })
  78. } else {
  79. that.setData({
  80. groupIndex: that.data.groupIndex
  81. })
  82. }
  83. that.recommend(that.data.groupIndex)
  84. }
  85. //点击跳转
  86. that.more = function ({
  87. currentTarget
  88. }) {
  89. wx.navigateTo({
  90. url: `../main/books/books`
  91. })
  92. }
  93. //发起团购
  94. that.sendGroup = function () {
  95. that.data.groupData.sendGroupFlag = !that.data.groupData.sendGroupFlag;
  96. that.setData({
  97. groupData: that.data.groupData
  98. })
  99. }
  100. //选中团购课程
  101. that.selectImg = function ({
  102. currentTarget
  103. }) {
  104. const ind = currentTarget.dataset.ind;
  105. //判断单选
  106. that.data.groupData.selectFlag.forEach((item, index) => {
  107. if (index == ind) {
  108. that.data.groupData.selectFlag[ind] = !that.data.groupData.selectFlag[ind];
  109. } else {
  110. that.data.groupData.selectFlag[index] = true;
  111. }
  112. })
  113. that.setData({
  114. groupData: that.data.groupData
  115. })
  116. }
  117. //点击确定
  118. that.sure = function () {
  119. that.data.groupData.selectFlag.forEach((item, index) => {
  120. if (!item) {
  121. const productId = that.data.groupData.bookList[index].id;
  122. const title = that.data.groupData.bookList[index].title
  123. wx.navigateTo({
  124. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}`
  125. })
  126. }
  127. })
  128. }
  129. //跳转到我的团购
  130. that.myGroup = function () {
  131. wx.navigateTo({
  132. url: `/pages/groupPage/my-group/my-group`
  133. })
  134. wx.setNavigationBarTitle({
  135. title: '我的团购'
  136. })
  137. }
  138. // IOS提示不能参团
  139. that.showAlert = function () {
  140. let str = "groupData.alertFlag"
  141. that.setData({
  142. [str]: !that.data.groupData.alertFlag
  143. })
  144. console.log(that.data.groupData.alertFlag)
  145. }
  146. //跳转到团购详情页
  147. that.groupDetail = function ({
  148. currentTarget
  149. }) {
  150. // if (that.data.groupData.isIOS) {
  151. // that.showAlert();
  152. // return;
  153. // }
  154. const productId = currentTarget.dataset.productid;
  155. const id = currentTarget.dataset.id;
  156. const groupId = currentTarget.dataset.groupid;
  157. const ind = currentTarget.dataset.ind;
  158. const groupType = that.data.groupData.recommendList[ind].groupType;
  159. console.log(id)
  160. wx.navigateTo({
  161. // url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  162. url: `/pages/groupPage/group-details/group-details?productId=${id}`
  163. })
  164. // if(groupType === "PROMOTION") {
  165. // wx.navigateTo({
  166. // url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${id}&groupId=${groupId}`
  167. // })
  168. // }else {
  169. // wx.navigateTo({
  170. // url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  171. // })
  172. // }
  173. }
  174. //跳转到课程详情
  175. that.goToBook = function (e) {
  176. console.log(e.currentTarget.dataset)
  177. let id = e.currentTarget.dataset.id;
  178. let title = e.currentTarget.dataset.title;
  179. console.log(id)
  180. wx.navigateTo({
  181. url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
  182. })
  183. }
  184. }