group.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. let title;
  39. if(currentTarget.dataset.type == 'group') {
  40. type = true
  41. title = '限量优惠团购'
  42. }else {
  43. type = false
  44. title = '全部课'
  45. }
  46. wx.navigateTo({
  47. url: `/pages/groupPage/discount-group/discount-group?type=${type}&title=${title}`
  48. })
  49. }
  50. //发起团购
  51. that.sendGroup = function () {
  52. that.data.groupData.sendGroupFlag = !that.data.groupData.sendGroupFlag;
  53. that.setData({
  54. groupData: that.data.groupData
  55. })
  56. }
  57. //选中团购课程
  58. that.selectImg = function ({ currentTarget }) {
  59. const ind = currentTarget.dataset.ind;
  60. //判断单选
  61. that.data.groupData.selectFlag.forEach((item, index) => {
  62. if(index == ind) {
  63. that.data.groupData.selectFlag[ind] = !that.data.groupData.selectFlag[ind];
  64. }else {
  65. that.data.groupData.selectFlag[index] = true;
  66. }
  67. })
  68. that.setData({
  69. groupData: that.data.groupData
  70. })
  71. }
  72. //点击确定
  73. that.sure = function () {
  74. that.data.groupData.selectFlag.forEach( (item ,index) => {
  75. if(!item) {
  76. const productId = that.data.groupData.bookList[index].id;
  77. const title = that.data.groupData.bookList[index].title
  78. wx.navigateTo({
  79. url: `/pages/groupPage/grade-details/grade-details?productId=${productId}&title=${title}`
  80. })
  81. }
  82. })
  83. }
  84. //跳转到我的团购
  85. that.myGroup = function () {
  86. wx.navigateTo({
  87. url: `/pages/groupPage/my-group/my-group`
  88. })
  89. wx.setNavigationBarTitle({
  90. title: '我的团购'
  91. })
  92. }
  93. //跳转到团购详情页
  94. that.groupDetail = function ({currentTarget}) {
  95. const productId = currentTarget.dataset.productid;
  96. const id = currentTarget.dataset.id;
  97. const groupId = currentTarget.dataset.groupid;
  98. wx.navigateTo({
  99. url: `/pages/groupPage/group-details/group-details?productId=${productId}&id=${id}&groupId=${groupId}`
  100. })
  101. }
  102. }