groupDetail.js 9.4 KB

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