invite-friends.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. const util = require('../../utils/util');
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. navbarHeight: 0,
  9. isShow: false,
  10. uid: 0,
  11. poster: '../../images/icon-7.png'
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. this.setData({
  18. navbarHeight: util.getNavbarHeight(),
  19. uid: app.db.get('element_uid')
  20. })
  21. //改变头部电量条背景色
  22. wx.setNavigationBarColor({
  23. frontColor: '#ffffff',
  24. backgroundColor: '#ffffff',
  25. });
  26. wx.getSystemInfo({
  27. success: (res) => {
  28. this.setData({
  29. screenWidth: res.screenWidth
  30. });
  31. }
  32. })
  33. this.getUserInvitePoster()
  34. },
  35. /**
  36. * 显示
  37. */
  38. show() {
  39. this.setData({
  40. isShow: true
  41. })
  42. },
  43. /**
  44. * 关闭
  45. */
  46. hideWindow() {
  47. this.setData({
  48. isShow: false
  49. })
  50. },
  51. /**
  52. * 返回上一页
  53. */
  54. back() {
  55. wx.navigateBack({
  56. delta: 1,
  57. });
  58. },
  59. /**
  60. * 生命周期函数--监听页面初次渲染完成
  61. */
  62. onReady: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面隐藏
  71. */
  72. onHide: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面卸载
  76. */
  77. onUnload: function () {
  78. },
  79. /**
  80. * 页面相关事件处理函数--监听用户下拉动作
  81. */
  82. onPullDownRefresh: function () {
  83. },
  84. /**
  85. * 页面上拉触底事件的处理函数
  86. */
  87. onReachBottom: function () {
  88. },
  89. /**
  90. * 获取推广海报
  91. */
  92. getUserInvitePoster: function () {
  93. let page = this, uid = page.data.uid
  94. app.api.getUserInvitePoster({id: uid}, function (res) {
  95. if (res.code > 0) {
  96. page.setData({
  97. poster: res.data,
  98. isShow: true
  99. })
  100. } else {
  101. wx.showToast({
  102. title: res.msg,
  103. icon: 'none'
  104. })
  105. }
  106. })
  107. },
  108. /**
  109. * 保存海报
  110. */
  111. downloadPoster: function () {
  112. let image = this.data.poster
  113. if (image) {
  114. wx.getSetting({
  115. success(res) {
  116. if (!res['authSetting']['scope.writePhotosAlbum']) {
  117. //引导用户授权
  118. wx.authorize({
  119. scope: 'scope.writePhotosAlbum',
  120. success() {
  121. wx.downloadFile({
  122. url: image,
  123. success(response) {
  124. if (response.statusCode == 200) {
  125. wx.saveImageToPhotosAlbum({
  126. filePath: response.tempFilePath,
  127. success(res_) {
  128. wx.showToast({
  129. title: '保存图片成功',
  130. })
  131. },
  132. fail(res_) {
  133. wx.showToast({
  134. title: '保存图片失败',
  135. icon: 'none'
  136. })
  137. }
  138. })
  139. }
  140. },
  141. fail(response) {
  142. wx.showToast({
  143. title: '接口调用失败',
  144. icon: 'none'
  145. })
  146. }
  147. })
  148. }
  149. })
  150. } else {
  151. //已授权,直接下载
  152. wx.downloadFile({
  153. url: image,
  154. success(response) {
  155. if (response.statusCode == 200) {
  156. wx.saveImageToPhotosAlbum({
  157. filePath: response.tempFilePath,
  158. success(res_) {
  159. wx.showToast({
  160. title: '保存图片成功',
  161. })
  162. },
  163. fail(res_) {
  164. wx.showToast({
  165. title: '保存图片失败',
  166. icon: 'none'
  167. })
  168. }
  169. })
  170. }
  171. },
  172. fail(response) {
  173. wx.showToast({
  174. title: '接口调用失败',
  175. icon: 'none'
  176. })
  177. }
  178. })
  179. }
  180. }
  181. })
  182. }
  183. },
  184. /**
  185. * 活动规则
  186. */
  187. activityRule: function () {
  188. wx.navigateTo({
  189. url: '../activity-rule/activity-rule',
  190. })
  191. }
  192. })