group.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. res.data.data.list.forEach(element => {
  26. that.data.groupData.selectFlag.push(true);
  27. });
  28. that.setData({
  29. groupData: that.data.groupData
  30. })
  31. }).fail((error) => {
  32. console.log('错误',error)
  33. })
  34. }();
  35. //点击跳转
  36. that.more = function ({currentTarget}) {
  37. let type;
  38. if(currentTarget.dataset.type == 'group') {
  39. wx.navigateTo({
  40. url: `/pages/groupPage/discount-group/discount-group`
  41. })
  42. }else {
  43. wx.navigateTo({
  44. url: `../main/books/books`
  45. })
  46. }
  47. }
  48. //发起团购
  49. that.sendGroup = function () {
  50. that.data.groupData.sendGroupFlag = !that.data.groupData.sendGroupFlag;
  51. that.setData({
  52. groupData: that.data.groupData
  53. })
  54. }
  55. //选中团购课程
  56. that.selectImg = function ({ currentTarget }) {
  57. const ind = currentTarget.dataset.ind;
  58. //判断单选
  59. that.data.groupData.selectFlag.forEach((item, index) => {
  60. if(index == ind) {
  61. that.data.groupData.selectFlag[ind] = !that.data.groupData.selectFlag[ind];
  62. }else {
  63. that.data.groupData.selectFlag[index] = true;
  64. }
  65. })
  66. that.setData({
  67. groupData: that.data.groupData
  68. })
  69. }
  70. //点击确定
  71. that.sure = function () {
  72. that.data.groupData.selectFlag.forEach( (item ,index) => {
  73. if(!item) {
  74. const productId = that.data.groupData.bookList[index].id;
  75. const title = that.data.groupData.bookList[index].title
  76. wx.navigateTo({
  77. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}`
  78. })
  79. }
  80. })
  81. }
  82. //跳转到我的团购
  83. that.myGroup = function () {
  84. wx.navigateTo({
  85. url: `/pages/groupPage/my-group/my-group`
  86. })
  87. wx.setNavigationBarTitle({
  88. title: '我的团购'
  89. })
  90. }
  91. //跳转到团购详情页
  92. that.groupDetail = function ({currentTarget}) {
  93. const productId = currentTarget.dataset.productid;
  94. const id = currentTarget.dataset.id;
  95. const groupId = currentTarget.dataset.groupid;
  96. wx.navigateTo({
  97. url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  98. })
  99. }
  100. //跳转到课程详情
  101. that.goToBook = function(e){
  102. console.log(e.currentTarget.dataset)
  103. let id = e.currentTarget.dataset.id;
  104. let title = e.currentTarget.dataset.title;
  105. wx.navigateTo({
  106. url: `/pages/main/singleBook/singleBook?id=${id}&title=${title}`
  107. })
  108. }
  109. }