redpacket.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. var _request = require('../../../utils/request.js')
  2. var fomlds = []
  3. var rid
  4. var fomldsJSON = ''
  5. Page({
  6. data: {
  7. info: {},
  8. // 广告位
  9. ad: {
  10. name: '麗枫酒店',
  11. head: 'https://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/xcx/redpacket/ad/lifeng.jpg',
  12. detail: 'https://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/xcx/redpacket/ad/lifengad.jpg',
  13. url: ''
  14. },
  15. // 红包
  16. redpacketOpen: false,
  17. redpacketShow: false,
  18. selfPacket: 0,
  19. allPacket: 0,
  20. d5cPacket: 0,
  21. // 红包动画
  22. openA: '',
  23. total: {},
  24. // 排行榜
  25. friend: {
  26. page: 1,
  27. page_count: 1
  28. },
  29. friendList: [],
  30. rank: {
  31. page: 1,
  32. page_count: 1
  33. },
  34. rankList: [],
  35. per_page: 5
  36. },
  37. // 生命周期
  38. onLoad: function (options) {
  39. if (options.rid) {
  40. rid = options.rid
  41. } else {
  42. rid = 1
  43. }
  44. if (options.invite_id) {
  45. getApp().globalData.redPacketId = options.invite_id
  46. }
  47. },
  48. onReady:function(){
  49. },
  50. onShow: function (val) {
  51. this.getInfo()
  52. },
  53. onPullDownRefresh: function () {
  54. this.getRedPacket()
  55. this.getTotal()
  56. this.getFriend()
  57. this.getRank()
  58. wx.stopPullDownRefresh()
  59. },
  60. onHide: function (val) {
  61. this.sendFomlds()
  62. },
  63. // API请求
  64. getRedPacket: function () {
  65. var that = this
  66. var url = 'v1/hd/chunjie/' + rid + '/total_mon'
  67. var params = {
  68. }
  69. var success = function (res) {
  70. that.setData({
  71. selfPacket: res.data.self_receive_bonus,
  72. allPacket: res.data.invite_reward_bonus
  73. })
  74. if (that.data.selfPacket <= 0) {
  75. that.setData({
  76. redpacketShow: true,
  77. redpacketOpen: false
  78. })
  79. that.createAnimation()
  80. } else {
  81. that.setData({
  82. redpacketShow: false,
  83. redpacketOpen: true
  84. })
  85. }
  86. }
  87. _request.$get(url, params, success)
  88. },
  89. getInfo: function () {
  90. var that = this
  91. var url = 'v1/hd/chunjie/' + rid
  92. var pid = getApp().globalData.redPacketId
  93. var params = {
  94. invite_id: pid
  95. }
  96. var success = function (res) {
  97. that.getRedPacket()
  98. that.getTotal()
  99. that.getFriend()
  100. that.getRank()
  101. that.setData({
  102. info: res.data
  103. })
  104. var str = res.data.act.ad_json
  105. str = str.replace(/\ufeff/g)
  106. var jj = JSON.parse(str).adList
  107. var i = 0
  108. for (i in jj) {
  109. i++
  110. }
  111. var random = Math.floor(Math.random() * i)
  112. that.setData({
  113. ad: jj[random]
  114. })
  115. }
  116. _request.$get(url, params, success)
  117. },
  118. getTotal: function () {
  119. var that = this
  120. var url = 'v1/hd/chunjie/' + rid +'/give_out_money'
  121. var params = {
  122. }
  123. var success = function (res) {
  124. that.setData({
  125. d5cPacket: res.data.give_out_total_money
  126. })
  127. }
  128. _request.$get(url, params, success)
  129. },
  130. getFriend: function () {
  131. var that = this
  132. var url = 'v1/hd/chunjie/' + rid +'/invite/list'
  133. var params = {
  134. page: this.data.friend.page,
  135. per_page: this.data.per_page
  136. }
  137. var success = function (res) {
  138. var result = res.data.list
  139. that.setData({
  140. friendList: result
  141. })
  142. var page_count = Math.ceil(res.data.list_count / that.data.per_page)
  143. page_count > 0 ? page_count = page_count : page_count = 1
  144. that.setData({
  145. 'friend.page_count': page_count
  146. })
  147. }
  148. _request.$get(url, params, success)
  149. },
  150. getRank: function () {
  151. var that = this
  152. var url = 'v1/hd/chunjie/' + rid +'/open/list'
  153. var params = {
  154. page: this.data.rank.page,
  155. per_page: this.data.per_page
  156. }
  157. var success = function (res) {
  158. var result = res.data.list
  159. that.setData({
  160. rankList: result
  161. })
  162. var page_count = Math.ceil(res.data.list_count / that.data.per_page)
  163. page_count > 0 ? page_count = page_count : page_count = 1
  164. that.setData({
  165. 'rank.page_count': page_count
  166. })
  167. }
  168. _request.$get(url, params, success)
  169. },
  170. // 页面按钮
  171. getPopup: function (val) {
  172. if (val.currentTarget.dataset.val.is_me) {
  173. this.setData({
  174. redpacketShow: true
  175. })
  176. }
  177. },
  178. updatePrice: function (e) {
  179. this.formSubmit(e)
  180. this.getRedPacket()
  181. },
  182. friendUp: function (e) {
  183. this.formSubmit(e)
  184. if (this.data.friend.page > 1) {
  185. var page = this.data.friend.page - 1
  186. this.setData({
  187. 'friend.page': page
  188. })
  189. this.getFriend()
  190. }
  191. },
  192. friendDown: function (e) {
  193. this.formSubmit(e)
  194. if (this.data.friend.page < this.data.friend.page_count) {
  195. var page = this.data.friend.page + 1
  196. this.setData({
  197. 'friend.page': page
  198. })
  199. this.getFriend()
  200. }
  201. },
  202. rankUp: function (e) {
  203. this.formSubmit(e)
  204. if (this.data.rank.page > 1) {
  205. var page = this.data.rank.page - 1
  206. this.setData({
  207. 'rank.page': page
  208. })
  209. this.getRank()
  210. }
  211. },
  212. rankDown: function (e) {
  213. this.formSubmit(e)
  214. if (this.data.rank.page < this.data.rank.page_count) {
  215. var page = this.data.rank.page + 1
  216. this.setData({
  217. 'rank.page': page
  218. })
  219. this.getRank()
  220. }
  221. },
  222. robLuckyMoney: function (e) {
  223. this.formSubmit(e)
  224. var that = this
  225. var url = 'v1/hd/chunjie/' + rid + '/lucky_money'
  226. var params = {
  227. formIds: fomlds
  228. }
  229. var success = function (res) {
  230. var result = res.data.self_open_lucky_money.receive_bonus
  231. that.setData({
  232. selfPacket: result
  233. })
  234. that.sendFomlds()
  235. that.openPacket()
  236. that.getFriend()
  237. that.getRank()
  238. }
  239. _request.$post(url, params, success)
  240. },
  241. getRule: function (e) {
  242. this.formSubmit(e)
  243. wx.navigateTo({
  244. url: '/pages/parse/parse?id=5'
  245. })
  246. },
  247. lookRedPacket: function (e) {
  248. this.formSubmit(e)
  249. wx.navigateTo({
  250. url: '/pages/parse/parse?id=6'
  251. })
  252. },
  253. openPacket: function () {
  254. this.animation.rotateY(720).step()
  255. this.setData({
  256. openA: this.animation.export()
  257. })
  258. setTimeout(() => {
  259. this.setData({
  260. redpacketOpen: true
  261. })
  262. }, 1800)
  263. },
  264. closePacket: function (e) {
  265. this.formSubmit(e)
  266. this.getRedPacket()
  267. this.setData({
  268. redpacketShow: false
  269. })
  270. },
  271. getAd: function (e) {
  272. this.formSubmit(e)
  273. wx.navigateTo({
  274. url: '/pages/web/web?id=' + this.data.ad.ad_pic_link
  275. })
  276. },
  277. // 创建动画
  278. createAnimation: function () {
  279. this.animation = wx.createAnimation({
  280. duration: 1500,
  281. timingFunction: 'linear',
  282. delay: 100
  283. })
  284. },
  285. // 消息推送
  286. formSubmit: function (e) {
  287. let formId = e.detail.formId
  288. let type = e.detail.target.dataset.type
  289. this.dealFormIds(formId)
  290. },
  291. dealFormIds: function (formId) {
  292. formId: formId
  293. fomlds.push(formId)
  294. },
  295. sendFomlds: function () {
  296. fomldsJSON = JSON.stringify(fomlds)
  297. var that = this
  298. var url = 'v1/formid'
  299. var params = {
  300. formIds: fomlds
  301. }
  302. var success = function (res) {
  303. that.formIds = []
  304. }
  305. _request.$post(url, params, success)
  306. },
  307. // 分享
  308. onShareAppMessage: function (val) {
  309. if (val.from === 'button') {
  310. }
  311. return {
  312. title: '我已领取了' + (this.data.allPacket + this.data.selfPacket) / 100 +'元大红包,邀您一起领。',
  313. path: '/pages/start/start?url=pages/activity/redpacket/redpacket&rid=' + rid + '&invite_id=' + this.data.info.participant.wx_uid,
  314. imageUrl: 'https://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/xcx/redpacket/share.jpg',
  315. success: function(res) {
  316. },
  317. fail: function(res) {
  318. }
  319. }
  320. }
  321. })