group.js 2.8 KB

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