group.js 3.7 KB

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