group.js 5.9 KB

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