import { get } from "../../../utils/http" // subPackagesB/pages/groupDetail/groupDetail.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { id: '', //拼团id grouping_id: '', //拼团记录ID store_id: '', //店铺id groupDetail: '', //拼团详情列表 source: '', //拼团类型 (拼团类型,1美妆产品,2次卡) page: 1, limit: 3, total: '', pageA: 1, //查看更多的数据 limitA: 10, //查看更多的数据 checkGrouping: '', //是否有拼团资格,0不能参团,1可以参团 groupingList: '', //拼团中列表 groupingListAll: '', //拼团中前10条用来查看更多展示 swiperPage: 1, //swiper可以滑动的页数 autoplay: true, //swiper自动滚动 isShare: false, //是否是分享点进来的 storeName: '', //店铺名字 groupStatus: '', //订单状态 状态:0拼团中,1拼团成功,-1已取消(拼团失败),-2已结束(拼团失败) isGroupPop: false, //控制产看更多拼团中列表弹出框 shareInfo: '', //分享文案 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (options.shareUserId) { app.globalData.shareUserId = options.shareUserId //赋值全局分享人ID } console.log(options); let isShare = false if (options.isShare) { isShare = true } if (options.q) { let ticket = decodeURIComponent(options.q) console.log(ticket); var reg1 = new RegExp("(^|\\?|&)" + 'id' + "=([^&]*)(\\s|&|$)", "i"); var reg2 = new RegExp("(^|\\?|&)" + 'shareUserId' + "=([^&]*)(\\s|&|$)", "i"); if (reg1.test(ticket)) { options.id = unescape(RegExp.$2.replace(/\+/g, " ")); }; if (reg2.test(ticket)) { app.globalData.shareUserId = unescape(RegExp.$2.replace(/\+/g, " ")); console.log(unescape(RegExp.$2.replace(/\+/g, " ")), 'options.q'); }; } // 获取拼团id this.setData({ store_id: wx.getStorageSync('store_id'), id: options.id, isShare, grouping_id: options.grouping_id, }) // 检查是否有拼团资格 this.getCheckGrouping() // 获取店铺信息 this.getStoreInfo() // 获取拼团详情 this.getGroupDetail() // 查看拼团记录详情改记录的状态 if (this.data.isShare) { this.getGroupOrderDetail() } // 绑定分享参数 wx.onCopyUrl(() => { let userID = wx.getStorageSync('userInfo') return { query: `grouping_id=${this.data.grouping_id}&id=${this.data.id}&shareUserId=${userID.uid}` } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ autoplay: true }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { // 关闭自动滚动 this.setData({ autoplay: false }) }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, // 获取分享图片文案 getShareInfo() { get('v2/api/share/info', { id: this.data.groupDetail.goods_id, // 产品类型,project类型,goods美妆产品,card次卡,grouping拼团商品 type: 'grouping' }, res => { this.setData({ shareInfo: res.data }) }) }, /** * 用户点击右上角分享 */ onShareAppMessage() { let userID = wx.getStorageSync('userInfo') return { title: this.data.shareInfo.share_text, imageUrl: this.data.shareInfo.share_image, path: `/subPackagesB/pages/groupDetail/groupDetail?grouping_id=${this.data.grouping_id}&id=${this.data.id}&shareUserId=${userID.uid}` } }, // 获取拼团详情 getGroupDetail() { get('v2/api/grouping/info', { id: this.data.id, store_id: this.data.store_id || wx.getStorageSync('store_id') }, (res) => { if (res.code == 200) { this.setData({ groupDetail: res.data, // 拼团类型,1美妆产品,2次卡 source: res.data.goods_type == 1 ? 'goods' : 'secondaryCard' }) this.getShareInfo() } // 获取拼团中列表 if (!this.data.isShare) { this.getGroupingList() } }) }, // 获取拼团中列表 getGroupingList(_page) { get('v2/api/grouping/grouping', { id: this.data.groupDetail.id, store_id: this.data.store_id || wx.getStorageSync('store_id'), page: _page || this.data.page, limit: this.data.limit }, (res) => { if (res.code == 200) { this.setData({ groupingList: res.data.list, total: res.data.total }) if (res.data.total > 3) { let swiperPage = Math.ceil(res.data.total / 3) this.setData({ swiperPage }) } } }) }, // 查看更多拼团中列表 getGroupingListAll(_page) { get('v2/api/grouping/grouping', { id: this.data.groupDetail.id, store_id: this.data.store_id || wx.getStorageSync('store_id'), page: _page || this.data.pageA, limit: this.data.limitA }, (res) => { if (res.code == 200) { let list = this.data.groupingListAll if (_page == 1 || this.data.pageA == 1) { console.log(1111); list = [] } list.push(...res.data.list) this.setData({ groupingListAll: list }) } }) }, // 查看更多弹窗下拉触底 refreshGroupList() { if (this.data.total > this.data.groupingListAll.length) { this.getGroupingListAll(++this.data.pageA) } }, // 切换swiper swiperChange(e) { let index = e.detail.current this.getGroupingList(index + 1) }, // 检查是否又拼团资格 getCheckGrouping() { get('v2/api/grouping/check', {}, (res) => { this.setData({ // 结果,0不能参团,1可以参团 checkGrouping: res.data.status }) // 状态:0拼团中,1拼团成功,-1已取消(拼团失败),-2已结束(拼团失败) if (this.data.isShare && this.data.groupStatus == -1 || this.data.isShare && this.data.groupStatus == -2) { wx.redirectTo({ url: `/subPackagesB/pages/groupFlow/groupFlow?group_id=${this.data.id}&&groupStatus=${this.data.groupStatus}&isShare=${this.data.isShare}`, }) } if (this.data.isShare && res.data.status == 0) { wx.redirectTo({ url: `/subPackagesB/pages/groupFlow/groupFlow?group_id=${this.data.id}`, }) } }) }, // 获取拼团记录详情 getGroupOrderDetail() { get('v2/api/grouping/log_info', { id: this.data.grouping_id }, (res) => { if (res.code == 200) { let status = res.data.status if (res.data.status == 1) { status = -2 } this.setData({ groupStatus: status }) // 防止没有接收到消息重新触发一次 this.getCheckGrouping() console.log(this.data.groupStatus, 'groupStatus'); } }) }, // 去拼单 goGrouping(e) { let grouping_id = e.currentTarget.dataset.grouping_id if (this.data.checkGrouping == 0) { wx.showToast({ title: '您不满足拼单条件,新用户才可以参与拼单', icon: 'none', }) return } wx.navigateTo({ 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}`, }) }, // 单独购买 toGoodsOrderConfrim() { wx.navigateTo({ 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`, }) }, // 发起拼团 toGroupOrderConfrim() { wx.navigateTo({ 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}`, }) }, // 分享页面跳转进参与拼团 ShareGroup() { wx.navigateTo({ 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}`, }) }, // 获取店铺信息 getStoreInfo() { get('api/store/info', { store_id: this.data.store_id || wx.getStorageSync('store_id') }, (res) => { this.setData({ storeName: res.data.store_name }) }) }, // 打开弹窗 openPop() { this.getGroupingListAll(1) this.setData({ isGroupPop: true }) }, // 关闭弹窗 closePop() { this.setData({ isGroupPop: false, groupingListAll: [] }) }, })