| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- var _request = require('../../../utils/request.js')
- var fomlds = []
- var rid
- var fomldsJSON = ''
- Page({
- data: {
- info: {},
- // 广告位
- ad: {
- name: '麗枫酒店',
- head: 'https://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/xcx/redpacket/ad/lifeng.jpg',
- detail: 'https://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/xcx/redpacket/ad/lifengad.jpg',
- url: ''
- },
- // 红包
- redpacketOpen: false,
- redpacketShow: false,
- selfPacket: 0,
- allPacket: 0,
- d5cPacket: 0,
- // 红包动画
- openA: '',
- total: {},
- // 排行榜
- friend: {
- page: 1,
- page_count: 1
- },
- friendList: [],
- rank: {
- page: 1,
- page_count: 1
- },
- rankList: [],
- per_page: 5
- },
- // 生命周期
- onLoad: function (options) {
- if (options.rid) {
- rid = options.rid
- } else {
- rid = 1
- }
- if (options.invite_id) {
- getApp().globalData.redPacketId = options.invite_id
- }
- },
- onReady:function(){
- },
- onShow: function (val) {
- this.getInfo()
- },
- onPullDownRefresh: function () {
- this.getRedPacket()
- this.getTotal()
- this.getFriend()
- this.getRank()
- wx.stopPullDownRefresh()
- },
- onHide: function (val) {
- this.sendFomlds()
- },
- // API请求
- getRedPacket: function () {
- var that = this
- var url = 'v1/hd/chunjie/' + rid + '/total_mon'
- var params = {
- }
- var success = function (res) {
- that.setData({
- selfPacket: res.data.self_receive_bonus,
- allPacket: res.data.invite_reward_bonus
- })
- if (that.data.selfPacket <= 0) {
- that.setData({
- redpacketShow: true,
- redpacketOpen: false
- })
- that.createAnimation()
- } else {
- that.setData({
- redpacketShow: false,
- redpacketOpen: true
- })
- }
- }
- _request.$get(url, params, success)
- },
- getInfo: function () {
- var that = this
- var url = 'v1/hd/chunjie/' + rid
- var pid = getApp().globalData.redPacketId
- var params = {
- invite_id: pid
- }
- var success = function (res) {
- that.getRedPacket()
- that.getTotal()
- that.getFriend()
- that.getRank()
- that.setData({
- info: res.data
- })
- var str = res.data.act.ad_json
- str = str.replace(/\ufeff/g)
- var jj = JSON.parse(str).adList
- var i = 0
- for (i in jj) {
- i++
- }
- var random = Math.floor(Math.random() * i)
- that.setData({
- ad: jj[random]
- })
- }
- _request.$get(url, params, success)
- },
- getTotal: function () {
- var that = this
- var url = 'v1/hd/chunjie/' + rid +'/give_out_money'
- var params = {
- }
- var success = function (res) {
- that.setData({
- d5cPacket: res.data.give_out_total_money
- })
- }
- _request.$get(url, params, success)
- },
- getFriend: function () {
- var that = this
- var url = 'v1/hd/chunjie/' + rid +'/invite/list'
- var params = {
- page: this.data.friend.page,
- per_page: this.data.per_page
- }
- var success = function (res) {
- var result = res.data.list
- that.setData({
- friendList: result
- })
- var page_count = Math.ceil(res.data.list_count / that.data.per_page)
- page_count > 0 ? page_count = page_count : page_count = 1
- that.setData({
- 'friend.page_count': page_count
- })
- }
- _request.$get(url, params, success)
- },
- getRank: function () {
- var that = this
- var url = 'v1/hd/chunjie/' + rid +'/open/list'
- var params = {
- page: this.data.rank.page,
- per_page: this.data.per_page
- }
- var success = function (res) {
- var result = res.data.list
- that.setData({
- rankList: result
- })
- var page_count = Math.ceil(res.data.list_count / that.data.per_page)
- page_count > 0 ? page_count = page_count : page_count = 1
- that.setData({
- 'rank.page_count': page_count
- })
- }
- _request.$get(url, params, success)
- },
- // 页面按钮
- getPopup: function (val) {
- if (val.currentTarget.dataset.val.is_me) {
- this.setData({
- redpacketShow: true
- })
- }
- },
- updatePrice: function (e) {
- this.formSubmit(e)
- this.getRedPacket()
- },
- friendUp: function (e) {
- this.formSubmit(e)
- if (this.data.friend.page > 1) {
- var page = this.data.friend.page - 1
- this.setData({
- 'friend.page': page
- })
- this.getFriend()
- }
- },
- friendDown: function (e) {
- this.formSubmit(e)
- if (this.data.friend.page < this.data.friend.page_count) {
- var page = this.data.friend.page + 1
- this.setData({
- 'friend.page': page
- })
- this.getFriend()
- }
- },
- rankUp: function (e) {
- this.formSubmit(e)
- if (this.data.rank.page > 1) {
- var page = this.data.rank.page - 1
- this.setData({
- 'rank.page': page
- })
- this.getRank()
- }
- },
- rankDown: function (e) {
- this.formSubmit(e)
- if (this.data.rank.page < this.data.rank.page_count) {
- var page = this.data.rank.page + 1
- this.setData({
- 'rank.page': page
- })
- this.getRank()
- }
- },
- robLuckyMoney: function (e) {
- this.formSubmit(e)
- var that = this
- var url = 'v1/hd/chunjie/' + rid + '/lucky_money'
- var params = {
- formIds: fomlds
- }
- var success = function (res) {
- var result = res.data.self_open_lucky_money.receive_bonus
- that.setData({
- selfPacket: result
- })
- that.sendFomlds()
- that.openPacket()
- that.getFriend()
- that.getRank()
- }
- _request.$post(url, params, success)
- },
- getRule: function (e) {
- this.formSubmit(e)
- wx.navigateTo({
- url: '/pages/parse/parse?id=5'
- })
- },
- lookRedPacket: function (e) {
- this.formSubmit(e)
- wx.navigateTo({
- url: '/pages/parse/parse?id=6'
- })
- },
- openPacket: function () {
- this.animation.rotateY(720).step()
- this.setData({
- openA: this.animation.export()
- })
- setTimeout(() => {
- this.setData({
- redpacketOpen: true
- })
- }, 1800)
- },
- closePacket: function (e) {
- this.formSubmit(e)
- this.getRedPacket()
- this.setData({
- redpacketShow: false
- })
- },
- getAd: function (e) {
- this.formSubmit(e)
- wx.navigateTo({
- url: '/pages/web/web?id=' + this.data.ad.ad_pic_link
- })
- },
- // 创建动画
- createAnimation: function () {
- this.animation = wx.createAnimation({
- duration: 1500,
- timingFunction: 'linear',
- delay: 100
- })
- },
- // 消息推送
- formSubmit: function (e) {
- let formId = e.detail.formId
- let type = e.detail.target.dataset.type
- this.dealFormIds(formId)
- },
- dealFormIds: function (formId) {
- formId: formId
- fomlds.push(formId)
- },
- sendFomlds: function () {
- fomldsJSON = JSON.stringify(fomlds)
- var that = this
- var url = 'v1/formid'
- var params = {
- formIds: fomlds
- }
- var success = function (res) {
- that.formIds = []
- }
- _request.$post(url, params, success)
- },
- // 分享
- onShareAppMessage: function (val) {
- if (val.from === 'button') {
- }
- return {
- title: '我已领取了' + (this.data.allPacket + this.data.selfPacket) / 100 +'元大红包,邀您一起领。',
- path: '/pages/start/start?url=pages/activity/redpacket/redpacket&rid=' + rid + '&invite_id=' + this.data.info.participant.wx_uid,
- imageUrl: 'https://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/xcx/redpacket/share.jpg',
- success: function(res) {
- },
- fail: function(res) {
- }
- }
- }
- })
|