group.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 (pageNo) {
  22. httpRequestApi.getGroupList(pageNo).success((res) => {
  23. // that.data.groupData.listLength = res.data.data.length;
  24. // that.data.groupData.recommendList = res.data.data.slice(start, end);
  25. // that.setData({
  26. // groupData: that.data.groupData
  27. // })
  28. // that.data.groupData.recommendList.forEach( (item) => {
  29. // if(item.groupPurchaseOrder.closeTime - Date.parse(new Date()) < 0 ) {
  30. // that.data.groupData.timeList.push('时间到了,')
  31. // } else {
  32. // that.data.groupData.timeList.push(util.formatTime(item.groupPurchaseOrder.closeTime - Date.parse(new Date())).join(':'))
  33. // }
  34. // })
  35. // that.setData({
  36. // groupData: that.data.groupData
  37. // })
  38. const recommendListTemp = [];
  39. res.data.data.forEach(item => {
  40. const temp = {};
  41. temp.avatar = item.organizer.avatar;
  42. temp.wechatName = item.organizer.wechatName;
  43. temp.groupTitle = item.groupPurchaseOrder.groupTitle;
  44. temp.headCount = item.groupPurchaseOrder.headcount;
  45. temp.joinCount = item.groupPurchaseOrder.joinCount;
  46. temp.lastTime = item.groupPurchaseOrder.closeTime - item.currentTime <= 0 ? '时间不足,' : util.formatTime(item.groupPurchaseOrder.closeTime - item.currentTime).join(':');
  47. temp.id = item.groupPurchaseOrder.id;
  48. // that.data.groupData.recommendList.push(temp);
  49. recommendListTemp.push(temp);
  50. })
  51. const recommendListStr = "groupData.recommendList";
  52. // const recommendListThreeStr = "groupData.recommendListThree";
  53. that.setData({
  54. [recommendListStr]: recommendListTemp,
  55. // [recommendListThreeStr]: that.data.groupData.recommendList.slice(that.data.groupData.baseIndex, that.data.groupData.baseIndex + 3),
  56. // listLength: res.data.data.length
  57. })
  58. }).fail((error) => {
  59. console.log('错误', error)
  60. })
  61. }
  62. //请求数据封装
  63. that.getGroupList = function () {
  64. httpRequestApi.getAllBooks(1, 10).success((res) => {
  65. console.log('全部课', res.data.data.list)
  66. that.data.groupData.bookList = res.data.data.list;
  67. console.log(that.data.groupData.bookList)
  68. res.data.data.list.forEach(element => {
  69. that.data.groupData.selectFlag.push(true);
  70. });
  71. that.setData({
  72. groupData: that.data.groupData
  73. })
  74. }).fail((error) => {
  75. console.log('错误', error)
  76. })
  77. }();
  78. that.recommend(1);
  79. //点击换一换
  80. that.change = function () {
  81. // that.data.groupData.baseIndex++;
  82. // if(that.data.groupData.listLength <= 3 * (that.data.groupData.baseIndex)) {
  83. // that.data.groupData.baseIndex = 0;
  84. // }
  85. // that.setData({
  86. // groupData: that.data.groupData
  87. // })
  88. // that.recommend(3 * that.data.groupData.baseIndex, 3 * (that.data.groupData.baseIndex + 1));
  89. // if (that.data.groupData.baseIndex / 3 >= that.data.listLength / 3) {
  90. // that.data.groupData.baseIndex = 0
  91. // }
  92. // const recommendListThreeStr = "groupData.recommendListThree";
  93. // const baseIndexStr = "groupData.baseIndex";
  94. // this.setData({
  95. // [recommendListThreeStr]: that.data.groupData.recommendList.slice(that.data.groupData.baseIndex + 3, that.data.groupData.baseIndex + 6),
  96. // [baseIndexStr]: that.data.groupData.baseIndex + 3
  97. // })
  98. // console.log(that.data.groupData.baseIndex / 3);
  99. // console.log(that.data.listLength / 3);
  100. // if(that.groupIndex )
  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. //跳转到课程详情
  193. that.goToBook = function (e) {
  194. console.log(e.currentTarget.dataset)
  195. let id = e.currentTarget.dataset.id;
  196. let title = e.currentTarget.dataset.title;
  197. console.log(id)
  198. wx.navigateTo({
  199. url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
  200. })
  201. }
  202. }