index.js 6.9 KB

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