// pages/info/pddInfo/index.js import productApi from "../../../utils/https/common"; import util from "../../../utils/util" let app = getApp(); let timer = null; Page({ /** * 页面的初始数据 */ data: { info:null, showRuleFlag:false, kjId:null, isKj:false,//是否是被邀请进来砍价的 本人去除 isFollow:true,//是否已经关注公众号 showShareFlag:false,//是否显示公众号的二维码 userInfo:null, helpList:[] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 获取用户信息 后面的砍价接口和发起活动接口需要用到 productApi.user_post("uservice/user/getMyInfo",{}).then(r=>{ this.setData({ userInfo:r.data }) let userid = r.data.id,service="activity.haggle/get_haggle_detail"; // 如果不是当前用户并且打开了分享的页面的话 是砍价页面 if(options.userid && userid && options.userid!=userid){ this.setData({ isKj:true }) } else { this.setData({ isKj:false }) } // 对于所有打开了分享页面的人来说 都调用的是邀请接口 if(options.userid){ service="activity.haggle/get_haggle_detail" } productApi.user_post(service+'?id='+options.id,{ id:options.id }).then(res=>{ if(!res.data.user_record || !res.data.user_record.id){ res.data.user_record = { bargined_money:0 } } this.setData({ kjId:res.data.user_record.id }) // 判断是否助力过 res.data.isHelp = false; if(res.data.myHelpKj && res.data.myHelpKj.id){ res.data.isHelp = true; } this.setData({ info:res.data }) // 只有发起了的活动才需要倒计时 if(res.data.user_record.id && res.data.user_record.over_time){ // 获取砍价记录 productApi.user_post("activity.haggle/help_list?limit=10&page=1&id="+res.data.user_record.id,{ limit:10, page:1, id:res.data.user_record.id }).then(r=>{ this.setData({ helpList:r.data.data }) }) this.setTime(); timer = setInterval(()=>{ this.setTime() },1000) // 判断是否是自己发起的活动 if(res.data.user_record.user_id==userid){ this.setData({ isKj:false }) } if(this.data.isKj){ // 发起者状态是砍价完成,提示用户:我已经砍价完成了,你也快来试试吧,点击否停留当前页面,点击是,跳转砍价专区 if(res.data.user_record.flag=='over'){ wx.showModal({ title:"提示", content:"我已经砍价完成了,你也快来试试吧,点击否停留当前页面", success:function(r){ if(r.confirm){ wx.redirectTo({ url: '/pages/list/kj/index' }) } } }) } // 如果状态是砍价失败,提示用户:{发起者昵称}发起的砍价活动已结束,你也快来试试吧,点击否返回商城首页,点击是,跳转砍价专区 else if(res.data.originOriginateInfo.flag=='fail' || res.data.originOriginateInfo.flag=='expired'){ wx.showModal({ title:"提示", content:res.data.user_record.user_phone+"发起的砍价活动已结束,你也快来试试吧", success:function(r){ if(r.confirm){ wx.redirectTo({ url: '/pages/list/kj/index' }) } else { wx.reLaunch({ url: '/pages/index/index', }) } } }) } } } }) }) }, gotoProduct:function(){ productApi._post('product/get_product_detail',{ id:this.data.info.detail.goods_id }).then(res=>{ util.gotoDetail(res.data); }) }, // 如果已经发起活动的话需要倒计时 setTime(){ let info = this.data.info; let overTime = new Date(info.user_record.over_time.replace(/-/g,'/')).getTime(),now = new Date().getTime(); if(overTime<=now){ info.isOver=true; } else { let t = (overTime - now)/1000; let h = Math.floor(t/(60*60)); t = t - h * 60*60; let m = Math.floor(t/60),s=Math.floor(t-m*60); if(h<10) { h="0"+h; } if(m<10) { m="0"+m; } if(s<10) { s="0"+s; } info.h = h; info.m = m; info.s = s; } this.setData({ info:info }) }, // 隐藏关注二维码 hideShare:function(){ this.setData({ showShareFlag:false }) }, // 保存二维码到手机 saveImg:function(){ wx.downloadFile({ url: 'https://resources.jszhwlpt.com/d3c2d106-b893-474f-bf5c-091bd04f247f.jpeg', success:function(res){ wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath }) } }) }, // 隐藏或显示活动规则 showRule:function(){ this.setData({ showRuleFlag:!this.data.showRuleFlag }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if(this.data.info && this.data.info.originOriginateInfo && this.data.info.originOriginateInfo.id){ this.setTime(); timer = setInterval(()=>{ this.setTime() },1000) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { clearInterval(timer); timer = null; }, // 详情和下单的第一步 gotoDetail:function(e){ let info = this.data.info.detail || null,type=e?e.currentTarget.dataset.type:null; if(!info) return; if(type=='fail'){ wx.showModal({ title:"提示", content:"您未砍价成功,是否原价购买", confirmColor:"#E14135", success:function(res){ if(res.confirm){ this.gotoProduct() } } }) } else { this.gotoProduct() } }, // 真实的获取产品信息去下单 pushOrderData:function(){ productApi._get('productfront/getProductInfo',{ productId:this.data.info.baseInfo.productId }).then(res=>{ if(!res.data){ wx.showToast({ title:"该产品不存在或已下架", icon:'none' }) return; } let skuIndex = res.data.skuInfo.findIndex(item=>item.id==this.data.info.baseInfo.skuId); if(skuIndex==-1) { wx.showToast({ title:"该产品规格不存在", icon:'none' }) return; } let sku = res.data.skuInfo[skuIndex]; app.globalData.shoppingCart=[{ baseInfo:res.data.baseInfo, modelInfo:sku.modelInfo, skuInfo:sku, productNum:1 }]; if(this.data.info.originOriginateInfo.flag=='over'){ app.globalData.kjOrderId = this.data.info.originOriginateInfo.id || null; } else { app.globalData.kjOrderId = null; } app.globalData.discounts = 0; wx.navigateTo({ url: '../../order/index', }) }) }, // 帮好友砍一刀 kanjia:function(){ if(!this.data.isFollow){ // 未关注需要先关注公众号 this.setData({ showShareFlag:true }) return; } let userInfo = this.data.userInfo,info = this.data.info; productApi.user_post("activity.haggle/help_bargain",{ originate_id:info.user_record.id }).then(res=>{ if(res.code==200){ wx.showToast({ title: '砍价成功', icon:'success' }) this.onLoad({userid:info.user_record.user_id,id:info.user_record.id}) } }) }, // 发起砍价 startKj:function(){ if(!this.data.isFollow){ // 未关注需要先关注公众号 this.setData({ showShareFlag:true }) return; } let info = this.data.info; let userInfo = this.data.userInfo; productApi.user_post('activity.haggle/bargain_launch',{ act_id:info.detail.act_id, id:info.detail.id }).then(res=>{ if(res.code==1){ wx.showToast({ title: '发起成功', icon:'success' }) this.onLoad({id:info.detail.id}) } }) }, // 喊好友砍一刀 shareHelp:function(){ }, // 我也要参与 join:function(){ this.onLoad({id:this.data.info.baseInfo.id}); }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { let kjId = this.data.kjId,info = this.data.info; let shareObj = { title: kjId?"就差你这一刀了,快来帮帮我~":(info.detail.productName+info.detail.skuName), // 默认是小程序的名称(可以写slogan等) path: kjId?('/pages/kj/info/index?userid='+info.user_record.user_id+'&id='+kjId):('/pages/kj/info/index?&id='+info.detail.id), // 默认是当前页面,必须是以‘/’开头的完整路径 imageUrl: info.baseInfo.headImg, //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4 success: function(res){ // 转发成功之后的回调 if(res.errMsg == 'shareAppMessage:ok'){ wx.showToast({ title: '转发成功,马上就要砍成了~', }) } }, fail: function(){ // 转发失败之后的回调 if(res.errMsg == 'shareAppMessage:fail cancel'){ }else if(res.errMsg == 'shareAppMessage:fail'){ // 转发失败,其中 detail message 为详细失败信息 }     }, }; console.log(shareObj) return shareObj; } })