groupDetail.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import {
  2. get
  3. } from "../../../utils/http"
  4. // subPackagesB/pages/groupDetail/groupDetail.js
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. id: '', //拼团id
  11. grouping_id: '', //拼团记录ID
  12. store_id: '', //店铺id
  13. groupDetail: '', //拼团详情列表
  14. source: '', //拼团类型 (拼团类型,1美妆产品,2次卡)
  15. page: 1,
  16. limit: 3,
  17. total: '',
  18. pageA:1, //查看更多的数据
  19. limitA:10, //查看更多的数据
  20. checkGrouping: '', //是否有拼团资格,0不能参团,1可以参团
  21. groupingList: '', //拼团中列表
  22. groupingListAll:'', //拼团中前10条用来查看更多展示
  23. swiperPage: 1, //swiper可以滑动的页数
  24. autoplay:true, //swiper自动滚动
  25. isShare: false, //是否是分享点进来的
  26. storeName: '', //店铺名字
  27. groupStatus:'' , //订单状态 状态:0拼团中,1拼团成功,-1已取消(拼团失败),-2已结束(拼团失败)
  28. isGroupPop:false, //控制产看更多拼团中列表弹出框
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad(options) {
  34. console.log(options);
  35. let isShare = false
  36. if (options.isShare) {
  37. isShare = true
  38. }
  39. // 获取拼团id
  40. this.setData({
  41. store_id: wx.getStorageSync('store_id'),
  42. id: options.id,
  43. isShare,
  44. grouping_id: options.grouping_id,
  45. })
  46. // 检查是否有拼团资格
  47. this.getCheckGrouping()
  48. // 获取店铺信息
  49. this.getStoreInfo()
  50. // 获取拼团详情
  51. this.getGroupDetail()
  52. // 查看拼团记录详情改记录的状态
  53. if(this.data.isShare){
  54. this.getGroupOrderDetail()
  55. }
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady() {
  61. },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow() {
  66. this.setData({
  67. autoplay:true
  68. })
  69. },
  70. /**
  71. * 生命周期函数--监听页面隐藏
  72. */
  73. onHide() {
  74. // 关闭自动滚动
  75. this.setData({
  76. autoplay:false
  77. })
  78. },
  79. /**
  80. * 生命周期函数--监听页面卸载
  81. */
  82. onUnload() {
  83. },
  84. /**
  85. * 页面相关事件处理函数--监听用户下拉动作
  86. */
  87. onPullDownRefresh() {
  88. },
  89. /**
  90. * 页面上拉触底事件的处理函数
  91. */
  92. onReachBottom() {
  93. },
  94. /**
  95. * 用户点击右上角分享
  96. */
  97. onShareAppMessage() {
  98. return{
  99. path:`/subPackagesB/pages/groupDetail/groupDetail?grouping_id=${this.data.grouping_id}&id=${this.data.id}`
  100. }
  101. },
  102. // 获取拼团详情
  103. getGroupDetail() {
  104. get('v2/api/grouping/info', {
  105. id: this.data.id,
  106. store_id: this.data.store_id || wx.getStorageSync('store_id')
  107. }, (res) => {
  108. if (res.code == 200) {
  109. this.setData({
  110. groupDetail: res.data,
  111. // 拼团类型,1美妆产品,2次卡
  112. source: res.data.goods_type == 1 ? 'goods' : 'secondaryCard'
  113. })
  114. }
  115. // 获取拼团中列表
  116. if (!this.data.isShare) {
  117. this.getGroupingList()
  118. }
  119. })
  120. },
  121. // 获取拼团中列表
  122. getGroupingList(_page) {
  123. get('v2/api/grouping/grouping', {
  124. id: this.data.groupDetail.id,
  125. store_id: this.data.store_id || wx.getStorageSync('store_id'),
  126. page: _page || this.data.page,
  127. limit: this.data.limit
  128. }, (res) => {
  129. if (res.code == 200) {
  130. this.setData({
  131. groupingList: res.data.list,
  132. total: res.data.total
  133. })
  134. if (res.data.total > 3) {
  135. let swiperPage = Math.ceil(res.data.total / 3)
  136. this.setData({
  137. swiperPage
  138. })
  139. }
  140. }
  141. })
  142. },
  143. // 查看更多拼团中列表
  144. getGroupingListAll(_page){
  145. get('v2/api/grouping/grouping',{
  146. id: this.data.groupDetail.id,
  147. store_id: this.data.store_id || wx.getStorageSync('store_id'),
  148. page: _page||this.data.pageA,
  149. limit:this.data.limitA
  150. },(res)=>{
  151. if(res.code==200){
  152. let list = this.data.groupingListAll
  153. if(_page==1||this.data.pageA==1){
  154. console.log(1111);
  155. list = []
  156. }
  157. list.push(...res.data.list)
  158. this.setData({
  159. groupingListAll:list
  160. })
  161. }
  162. })
  163. },
  164. // 查看更多弹窗下拉触底
  165. refreshGroupList(){
  166. if(this.data.total>this.data.groupingListAll.length){
  167. this.getGroupingListAll(++this.data.pageA)
  168. }
  169. },
  170. // 切换swiper
  171. swiperChange(e) {
  172. let index = e.detail.current
  173. this.getGroupingList(index + 1)
  174. },
  175. // 检查是否又拼团资格
  176. getCheckGrouping() {
  177. get('v2/api/grouping/check', {}, (res) => {
  178. this.setData({
  179. // 结果,0不能参团,1可以参团
  180. checkGrouping: res.data.status
  181. })
  182. // 状态:0拼团中,1拼团成功,-1已取消(拼团失败),-2已结束(拼团失败)
  183. if(this.data.isShare&&this.data.groupStatus==-1||this.data.isShare&&this.data.groupStatus==-2){
  184. wx.redirectTo({
  185. url: `/subPackagesB/pages/groupFlow/groupFlow?group_id=${this.data.id}&&groupStatus=${this.data.groupStatus}`,
  186. })
  187. }
  188. if(this.data.isShare&&res.data.status==0){
  189. wx.redirectTo({
  190. url: `/subPackagesB/pages/groupFlow/groupFlow?group_id=${this.data.id}`,
  191. })
  192. }
  193. })
  194. },
  195. // 获取拼团记录详情
  196. getGroupOrderDetail() {
  197. get('v2/api/grouping/log_info', {
  198. id: this.data.grouping_id
  199. }, (res) => {
  200. if (res.code == 200) {
  201. let status = res.data.status
  202. if(res.data.status==1){
  203. status= -2
  204. }
  205. this.setData({
  206. groupStatus:status
  207. })
  208. // 防止没有接收到消息重新触发一次
  209. this.getCheckGrouping()
  210. console.log(this.data.groupStatus,'groupStatus');
  211. }
  212. })
  213. },
  214. // 去拼单
  215. goGrouping(e) {
  216. let grouping_id = e.currentTarget.dataset.grouping_id
  217. if (this.data.checkGrouping == 0) {
  218. wx.showToast({
  219. title: '您不满足拼单条件,新用户才可以参与拼单',
  220. icon: 'none',
  221. })
  222. return
  223. }
  224. wx.navigateTo({
  225. url: `/subPackagesB/pages/GroupConfirm/GroupConfirm?store_id=${this.data.store_id}&&productId=${this.data.groupDetail.goods_id}&&source=${this.data.source}&&groupPrice=${this.data.groupDetail.price}&&isGrouping=true&&original_price=${this.data.groupDetail.original_price}&&groupID=${this.data.id}&&isSuccess=true&&grouping_id=${grouping_id}`,
  226. })
  227. },
  228. // 单独购买
  229. toGoodsOrderConfrim() {
  230. wx.navigateTo({
  231. url: `/subPackagesB/pages/GroupConfirm/GroupConfirm?store_id=${this.data.store_id}&&productId=${this.data.groupDetail.goods_id}&&source=${this.data.source}&&groupPrice=${this.data.groupDetail.original_price}&&isGrouping=false`,
  232. })
  233. },
  234. // 发起拼团
  235. toGroupOrderConfrim() {
  236. wx.navigateTo({
  237. url: `/subPackagesB/pages/GroupConfirm/GroupConfirm?store_id=${this.data.store_id}&&productId=${this.data.groupDetail.goods_id}&&source=${this.data.source}&&groupPrice=${this.data.groupDetail.price}&&isGrouping=true&&original_price=${this.data.groupDetail.original_price}&&groupID=${this.data.id}`,
  238. })
  239. },
  240. // 分享页面跳转进参与拼团
  241. ShareGroup() {
  242. wx.navigateTo({
  243. url: `/subPackagesB/pages/GroupConfirm/GroupConfirm?store_id=${this.data.store_id}&&productId=${this.data.groupDetail.goods_id}&&source=${this.data.source}&&groupPrice=${this.data.groupDetail.price}&&isGrouping=true&&original_price=${this.data.groupDetail.original_price}&&groupID=${this.data.id}&&isSuccess=true&&grouping_id=${this.data.grouping_id}`,
  244. })
  245. },
  246. // 获取店铺信息
  247. getStoreInfo() {
  248. get('api/store/info', {
  249. store_id: this.data.store_id || wx.getStorageSync('store_id')
  250. }, (res) => {
  251. this.setData({
  252. storeName: res.data.store_name
  253. })
  254. })
  255. },
  256. // 打开弹窗
  257. openPop(){
  258. this.getGroupingListAll(1)
  259. this.setData({
  260. isGroupPop:true
  261. })
  262. },
  263. // 关闭弹窗
  264. closePop(){
  265. this.setData({
  266. isGroupPop:false,
  267. groupingListAll:[]
  268. })
  269. },
  270. })