group.js 5.7 KB

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