group.js 6.0 KB

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