group.js 6.1 KB

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