groupOrder.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import {
  2. get,
  3. post
  4. } from "../../../utils/http"
  5. // subPackagesB/pages/groupOrder/groupOrder.js
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. // 状态:0拼团中,1拼团成功,-1已取消(拼团失败),-2已结束(拼团失败)
  12. GroupOrderList: '', //拼团记录详情
  13. grouping_id: '', //拼团记录ID
  14. groupStatus: '', //拼团状态
  15. store_id: '', //店铺ID
  16. groupGoodsDetail: '', //拼团商品详情
  17. group_id: "", //拼团活动ID
  18. isShow: true, //显示问号被邀请人
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. this.setData({
  25. grouping_id: options.userGroupId, //拼团记录ID
  26. groupStatus: options.groupStatus, //拼团状态
  27. store_id: wx.getStorageSync('store_id'), //店铺ID
  28. group_id: options.group_id, //拼团活动ID
  29. })
  30. // 获取拼团记录详情
  31. this.getGroupOrderDetail()
  32. // 获取拼团商品详情
  33. if (this.data.groupStatus != 1) {
  34. this.getGroupGoodsDetail()
  35. }
  36. },
  37. /**
  38. * 生命周期函数--监听页面初次渲染完成
  39. */
  40. onReady() {
  41. },
  42. /**
  43. * 生命周期函数--监听页面显示
  44. */
  45. onShow() {
  46. },
  47. /**
  48. * 生命周期函数--监听页面隐藏
  49. */
  50. onHide() {
  51. },
  52. /**
  53. * 生命周期函数--监听页面卸载
  54. */
  55. onUnload() {
  56. },
  57. /**
  58. * 页面相关事件处理函数--监听用户下拉动作
  59. */
  60. onPullDownRefresh() {
  61. },
  62. /**
  63. * 页面上拉触底事件的处理函数
  64. */
  65. onReachBottom() {
  66. },
  67. /**
  68. * 用户点击右上角分享
  69. */
  70. onShareAppMessage(res) {
  71. if (res.from == 'button') {
  72. console.log(res.target, res)
  73. }
  74. return {
  75. title: this.data.GroupOrderList.share_text, //分享内容标题
  76. path: `/subPackagesB/pages/groupDetail/groupDetail?isShare=true&&id=${this.data.group_id}&&grouping_id=${this.data.grouping_id}&&groupStatus=${this.data.groupStatus}`, //这里是被分享的人点击进来之后的页面
  77. imageUrl: this.data.GroupOrderList.share_image //这里是图片的路径
  78. }
  79. },
  80. // 获取拼团记录详情
  81. getGroupOrderDetail() {
  82. get('v2/api/grouping/log_info', {
  83. id: this.data.grouping_id
  84. }, (res) => {
  85. if (res.code == 200) {
  86. res.data.users.forEach(item => {
  87. if (item.is_host == 0) {
  88. this.setData({
  89. isShow: false
  90. })
  91. }
  92. })
  93. this.setData({
  94. GroupOrderList: res.data,
  95. })
  96. let statusTitle = res.data.status == 0 ? '拼团中' : "拼团"
  97. wx.setNavigationBarTitle({
  98. title: statusTitle,
  99. })
  100. }
  101. })
  102. },
  103. // 获取拼团商品详情
  104. getGroupGoodsDetail() {
  105. get('v2/api/grouping/info', {
  106. id: this.data.group_id,
  107. store_id: this.data.store_id || wx.getStorageSync('store_id')
  108. }, (res) => {
  109. if (res.code == 200) {
  110. this.setData({
  111. groupGoodsDetail: res.data
  112. })
  113. }
  114. })
  115. },
  116. // 取消拼团
  117. cancelGroup() {
  118. let source = this.data.groupGoodsDetail.goods_type == 1 ? 'goods' : 'secondaryCard'
  119. let that = this
  120. post('v2/api/grouping/cancel', {
  121. id: that.data.grouping_id
  122. }, (res) => {
  123. wx.showToast({
  124. title: '取消成功',
  125. success: setTimeout(function () {
  126. //要延时执行的代码
  127. wx.redirectTo({
  128. url: `/subPackagesB/pages/GroupConfirm/GroupConfirm?store_id=${that.data.store_id}&&productId=${that.data.groupGoodsDetail.goods_id}&&source=${source}&&groupPrice=${that.data.groupGoodsDetail.original_price}&&isGrouping=false`,
  129. })
  130. }, 2000) //延迟时间
  131. })
  132. })
  133. },
  134. // 拼团成功返回首页
  135. goHome() {
  136. wx.switchTab({
  137. url: '/pages/home/home',
  138. })
  139. },
  140. })