index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. userInfo: {
  7. nickName: '点击登录',
  8. avatarUrl: '/static/images/my.png'
  9. },
  10. referee: {
  11. level: "V0",
  12. levelName: '无'
  13. },
  14. hasLogin: false,
  15. myqr_show: false, //我的分享二维码
  16. myqr_url: "https://6a7a-jzmall-3gi3t6y452ddb0ff-1306484940.tcb.qcloud.la/member/member.png",
  17. myqr_blur: 100, //背景模糊值
  18. myqr_width: 640,
  19. myqr_top: 20,
  20. view_disabled: true,
  21. myqr_type: 0, //0会员卡 1引荐人海报
  22. plugid: '0775f898abc4d932f5e9a2f2b8f88bcb',
  23. },
  24. onLoad: function (options) {
  25. // 页面初始化 options为页面跳转所带来的参数
  26. },
  27. // 页面分享
  28. onShareAppMessage: function () {
  29. let that = this;
  30. if (!app.globalData.hasLogin) {
  31. wx.navigateTo({
  32. url: "/pages/auth/login/login"
  33. });
  34. return;
  35. }
  36. that.hidePoster();
  37. var title = "Hi,我送你超级鲸会员卡,快点击收下吧";
  38. var path = '/pages/member/card/receive/receiveCard?rId=' + that.data.userInfo.id;
  39. var imageUrl = 'https://6a7a-jzmall-3gi3t6y452ddb0ff-1306484940.tcb.qcloud.la/member/get.png';
  40. if (that.data.myqr_type == 1) {
  41. title = "鲸致引荐人,自购享优惠,分享躺赚钱";
  42. path = "/pages/ucenter/parter/recommend/recommend?rId=" + that.data.userInfo.id;
  43. imageUrl = that.data.myqr_url;
  44. }
  45. console.info(title)
  46. return {
  47. title: title,
  48. // desc: "我送你一份礼物,快点击收下吧~",
  49. path: path, //'/pages/member/card/receive/receiveCard?rId=' + this.data.userInfo.id,
  50. imageUrl: imageUrl //'https://6a7a-jzmall-3gi3t6y452ddb0ff-1306484940.tcb.qcloud.la/member/get.png'
  51. }
  52. },
  53. onReady: function () {},
  54. presentMemberCard() { //赠送会员卡
  55. this.setData({
  56. myqr_show: true,
  57. myqr_blur: 25,
  58. view_disabled: false,
  59. myqr_width: 640,
  60. myqr_top: 20,
  61. myqr_type: 0, //0会员卡 1引荐人海报
  62. myqr_url: "https://6a7a-jzmall-3gi3t6y452ddb0ff-1306484940.tcb.qcloud.la/member/member.png",
  63. })
  64. },
  65. hidePoster() {
  66. this.setData({
  67. myqr_show: false,
  68. myqr_blur: 100,
  69. view_disabled: true
  70. })
  71. },
  72. createQrcode: function () { //二维码生成
  73. let that = this;
  74. wx.showLoading();
  75. util.request(api.RefereePoster, {}, 'POST').then(function (res) {
  76. wx.hideLoading();
  77. if (res.errno == 0) {
  78. that.setData({
  79. myqr_show: true,
  80. myqr_blur: 25,
  81. view_disabled: false,
  82. myqr_url: res.data.imgUrl,
  83. myqr_width: 480,
  84. myqr_type: 1, //0会员卡 1引荐人海报
  85. myqr_top: 10,
  86. })
  87. } else {
  88. util.showErrorToast(res.errmsg);
  89. }
  90. });
  91. // wx.navigateTo({
  92. // url: '/pages/referee/poster/poster'
  93. // });
  94. },
  95. onShow: function () {
  96. console.info(app.globalData.hasLogin);
  97. //获取用户的登录信息
  98. if (app.globalData.hasLogin) {
  99. let userInfo = wx.getStorageSync('userInfo');
  100. this.setData({
  101. userInfo: userInfo,
  102. hasLogin: true
  103. });
  104. let that = this;
  105. util.request(api.RefereeIndex).then(function (res) {
  106. if (res.errno === 0) {
  107. console.log(res);
  108. that.setData({
  109. referee: res.data
  110. });
  111. }
  112. });
  113. }
  114. },
  115. onHide: function () {
  116. // 页面隐藏
  117. },
  118. onUnload: function () {
  119. // 页面关闭
  120. },
  121. goLogin() {
  122. if (!this.data.hasLogin) {
  123. wx.navigateTo({
  124. url: "/pages/auth/login/login"
  125. });
  126. }
  127. },
  128. goOrder() {
  129. if (this.data.hasLogin) {
  130. try {
  131. wx.setStorageSync('tab', 0);
  132. } catch (e) {
  133. }
  134. wx.navigateTo({
  135. url: "/pages/referee/order/order",
  136. });
  137. } else {
  138. wx.navigateTo({
  139. url: "/pages/auth/login/login"
  140. });
  141. }
  142. },
  143. goMyTeam() {
  144. if (this.data.hasLogin) {
  145. wx.navigateTo({
  146. url: "/pages/referee/team/team",
  147. });
  148. } else {
  149. wx.navigateTo({
  150. url: "/pages/auth/login/login"
  151. });
  152. }
  153. },
  154. goBlance(e) {
  155. let type = e.currentTarget.dataset.type;
  156. if (this.data.hasLogin) {
  157. wx.navigateTo({
  158. url: "/pages/referee/blance/blance?type=" + type,
  159. });
  160. } else {
  161. wx.navigateTo({
  162. url: "/pages/auth/login/login"
  163. });
  164. }
  165. },
  166. aboutUs: function () {
  167. wx.navigateTo({
  168. url: '/pages/ucenter/about/about'
  169. });
  170. },
  171. goHelp: function () {
  172. wx.navigateTo({
  173. url: '/pages/ucenter/help/help'
  174. });
  175. },
  176. goClause() {
  177. wx.navigateTo({
  178. url: '/pages/referee/protocol/sp'
  179. });
  180. },
  181. goCopyCode() {
  182. let that = this
  183. if (that.data.referee.code) {
  184. wx.setClipboardData({
  185. data: that.data.referee.code,
  186. success: function (res) {
  187. wx.showToast({
  188. title: '邀请码复制成功',
  189. icon: 'success',
  190. duration: 2000
  191. });
  192. }
  193. })
  194. }
  195. },
  196. goGrade() {
  197. wx.navigateTo({
  198. url: '/pages/referee/gradeInfo/gradeInfo',
  199. })
  200. },
  201. goSaveQrcode() {
  202. let that = this
  203. wx.showLoading({
  204. title: '生成中',
  205. });
  206. if (that.data.myqr_type == 0) {
  207. util.request(api.RefereeMemberPoster, {}).then(function (res) {
  208. wx.hideLoading();
  209. if (res.errno == 0) {
  210. that.goDownloadFile(res.data.imgUrl);
  211. } else {
  212. wx.showToast({
  213. title: res.errmsg,
  214. duration: 5000
  215. })
  216. }
  217. })
  218. } else { //海报保存
  219. that.goDownloadFile(that.data.myqr_url);
  220. }
  221. },
  222. goDownloadFile(url) {
  223. let that = this;
  224. wx.showLoading({
  225. title: '图片保存中',
  226. });
  227. console.log(that.data);
  228. wx.downloadFile({
  229. url: url,
  230. success: function (res) {
  231. console.log(res)
  232. wx.saveImageToPhotosAlbum({
  233. filePath: res.tempFilePath,
  234. success: function (res) {
  235. wx.hideLoading();
  236. wx.showModal({
  237. title: '存图成功',
  238. content: '图片成功保存到相册了,可以分享到朋友圈了',
  239. showCancel: false,
  240. confirmText: '好的',
  241. confirmColor: '#a78845',
  242. success: function (res) {
  243. if (res.confirm) {
  244. console.log('用户点击确定');
  245. that.hidePoster();
  246. }
  247. }
  248. })
  249. },
  250. fail: function (res) {
  251. wx.hideLoading();
  252. wx.showModal({
  253. title: '警告',
  254. content: '未授权或取消保存',
  255. showCancel: false
  256. })
  257. that.hidePoster();
  258. }
  259. })
  260. },
  261. fail: function (res) {
  262. wx.hideLoading();
  263. console.log(res);
  264. }
  265. })
  266. }
  267. })