index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var user = require('../../../utils/user.js');
  4. var WxParse = require('../../../lib/wxParse/wxParse.js');
  5. var app = getApp();
  6. Page({
  7. data: {
  8. userInfo: {
  9. nickName: '点击登录',
  10. avatarUrl: '/static/images/my.png'
  11. },
  12. detail:[],
  13. hasLogin: false,
  14. myqr_show:false,//我的分享二维码
  15. myqr_url:null,
  16. myqr_blur:0//背景模糊值
  17. },
  18. onLoad: function(options) {
  19. // 页面初始化 options为页面跳转所带来的参数
  20. },
  21. onReady: function() {
  22. },
  23. onShow: function() {
  24. //获取用户的登录信息
  25. if (app.globalData.hasLogin) {
  26. let userInfo = wx.getStorageSync('userInfo');
  27. this.setData({
  28. userInfo: userInfo,
  29. hasLogin: true
  30. });
  31. let that = this;
  32. util.request(api.DisCommission).then(function(res) {
  33. //console.log(res);
  34. if (res.errno === 0) {
  35. let data=res.data;
  36. data.canout=data.total-data.cashout-data.checking;
  37. data.canout=that.toFixed(data.canout);
  38. that.setData({
  39. detail: data
  40. });
  41. }
  42. });
  43. }
  44. },
  45. toFixed:function (num){
  46. return num.toFixed(2);
  47. },
  48. onHide: function() {
  49. // 页面隐藏
  50. },
  51. onUnload: function() {
  52. // 页面关闭
  53. },
  54. goChild(){
  55. if (this.data.hasLogin) {
  56. wx.navigateTo({
  57. url: "/pages/ucenter/parter/child/index"
  58. });
  59. } else {
  60. wx.navigateTo({
  61. url: "/pages/auth/login/login"
  62. });
  63. };
  64. },
  65. goDetail() {
  66. if (this.data.hasLogin) {
  67. wx.navigateTo({
  68. url: "/pages/ucenter/parter/detail/detail"
  69. });
  70. } else {
  71. wx.navigateTo({
  72. url: "/pages/auth/login/login"
  73. });
  74. };
  75. },
  76. goCashout() {
  77. if (this.data.hasLogin) {
  78. let m=this.data.detail.total-this.data.detail.cashout-this.data.detail.checking;
  79. wx.navigateTo({
  80. url: "/pages/ucenter/parter/cashout/index?m="+m
  81. });
  82. } else {
  83. wx.navigateTo({
  84. url: "/pages/auth/login/login"
  85. });
  86. };
  87. },
  88. goCreateQrcode:function(){//二维码生成
  89. let that=this;
  90. util.request(api.QrStarCodeCreate, {
  91. path:'/pages/index/index'
  92. }, 'POST').then(function(res) {
  93. //console.log(res);
  94. if(res.errno==0){
  95. that.setData({
  96. myqr_url:res.data.imgUrl,
  97. myqr_show:true,
  98. myqr_blur:5
  99. });
  100. }
  101. });
  102. },
  103. goSaveQrcode:function(){//保存二维码图片
  104. let that=this;
  105. console.info(that.data.myqr_url);
  106. wx.downloadFile({
  107. url: that.data.myqr_url,
  108. success:function(res){
  109. if(res.statusCode===200){
  110. let img=res.tempFilePath;
  111. wx.saveImageToPhotosAlbum({
  112. filePath: img,
  113. success(res){
  114. that.goCloseMyqr('个人专属二维码图片已保存到您的相册');
  115. },
  116. fail(res){
  117. that.goCloseMyqr('网络或授权问题 图片保存失败 请重试');
  118. }
  119. })
  120. }
  121. else
  122. that.goCloseMyqr('网络或授权问题 图片保存失败 请重试');
  123. },
  124. fail(res){
  125. that.goCloseMyqr('网络或授权问题 图片保存失败 请重试');
  126. }
  127. })
  128. },
  129. goCloseMyqr:function(msg){//关闭分享图片的弹层
  130. this.setData({
  131. myqr_blur:0,
  132. myqr_show:false
  133. });
  134. if(msg){
  135. wx.showToast({
  136. title: msg,
  137. icon: 'none',
  138. duration: 3000
  139. })
  140. }
  141. },
  142. qrtouchstart:function(){
  143. this.setData({
  144. myqr_blur:0,
  145. myqr_show:false
  146. });
  147. },
  148. goFootprint() {
  149. if (this.data.hasLogin) {
  150. wx.navigateTo({
  151. url: "/pages/ucenter/footprint/footprint"
  152. });
  153. } else {
  154. wx.navigateTo({
  155. url: "/pages/auth/login/login"
  156. });
  157. };
  158. },
  159. })