group.js 5.9 KB

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