group.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import httpRequestApi from '../../utils/APIClient';
  2. const app = getApp();
  3. export const groupInit = (that) => {
  4. that.setData({
  5. groupData: {
  6. recommendList: [],
  7. bookList: [],
  8. sendGroupFlag: true,
  9. selectFlag: [],
  10. isIPX: app.globalData.isIPX
  11. }
  12. })
  13. //请求数据封装
  14. that.getGroupList = function () {
  15. httpRequestApi.getGroupList().success( (res) => {
  16. console.log('推荐团购',res.data.data)
  17. that.data.groupData.recommendList = res.data.data.splice(0,6);
  18. that.setData({
  19. groupData: that.data.groupData
  20. })
  21. }).fail((error) => {
  22. console.log('错误',error)
  23. })
  24. httpRequestApi.getAllBooks(1, 10).success((res) => {
  25. console.log('全部课',res.data.data.list)
  26. that.data.groupData.bookList = res.data.data.list;
  27. console.log(that.data.groupData.bookList)
  28. res.data.data.list.forEach(element => {
  29. that.data.groupData.selectFlag.push(true);
  30. });
  31. that.setData({
  32. groupData: that.data.groupData
  33. })
  34. }).fail((error) => {
  35. console.log('错误',error)
  36. })
  37. }();
  38. //点击跳转
  39. that.more = function ({currentTarget}) {
  40. let type;
  41. if(currentTarget.dataset.type == 'group') {
  42. wx.navigateTo({
  43. url: `/pages/groupPage/discount-group/discount-group`
  44. })
  45. }else {
  46. wx.navigateTo({
  47. url: `../main/books/books`
  48. })
  49. }
  50. }
  51. //发起团购
  52. that.sendGroup = function () {
  53. that.data.groupData.sendGroupFlag = !that.data.groupData.sendGroupFlag;
  54. that.setData({
  55. groupData: that.data.groupData
  56. })
  57. }
  58. //选中团购课程
  59. that.selectImg = function ({ currentTarget }) {
  60. const ind = currentTarget.dataset.ind;
  61. //判断单选
  62. that.data.groupData.selectFlag.forEach((item, index) => {
  63. if(index == ind) {
  64. that.data.groupData.selectFlag[ind] = !that.data.groupData.selectFlag[ind];
  65. }else {
  66. that.data.groupData.selectFlag[index] = true;
  67. }
  68. })
  69. that.setData({
  70. groupData: that.data.groupData
  71. })
  72. }
  73. //点击确定
  74. that.sure = function () {
  75. that.data.groupData.selectFlag.forEach( (item ,index) => {
  76. if(!item) {
  77. const productId = that.data.groupData.bookList[index].id;
  78. const title = that.data.groupData.bookList[index].title
  79. wx.navigateTo({
  80. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}`
  81. })
  82. }
  83. })
  84. }
  85. //跳转到我的团购
  86. that.myGroup = function () {
  87. wx.navigateTo({
  88. url: `/pages/groupPage/my-group/my-group`
  89. })
  90. wx.setNavigationBarTitle({
  91. title: '我的团购'
  92. })
  93. }
  94. //跳转到团购详情页
  95. that.groupDetail = function ({currentTarget}) {
  96. const productId = currentTarget.dataset.productid;
  97. const id = currentTarget.dataset.id;
  98. const groupId = currentTarget.dataset.groupid;
  99. const ind = currentTarget.dataset.ind;
  100. const groupType = that.data.groupData.recommendList[ind].groupType;
  101. wx.navigateTo({
  102. url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  103. })
  104. // if(groupType === "PROMOTION") {
  105. // wx.navigateTo({
  106. // url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${id}&groupId=${groupId}`
  107. // })
  108. // }else {
  109. // wx.navigateTo({
  110. // url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  111. // })
  112. // }
  113. }
  114. //跳转到课程详情
  115. that.goToBook = function(e){
  116. console.log(e.currentTarget.dataset)
  117. let id = e.currentTarget.dataset.id;
  118. let title = e.currentTarget.dataset.title;
  119. console.log(id)
  120. wx.navigateTo({
  121. url: `/pages/groupPage/grade-details/grade-details?productId=${id}&title=${title}`
  122. })
  123. }
  124. }