application.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // pages/channel/user/application/application.js
  2. // 引入 QCloud 小程序增强 SDK
  3. var qcloud = require('../../../../vendor/qcloud-weapp-client-sdk/index');
  4. // 引入配置
  5. var config = require('../../../../config');
  6. // 显示繁忙提示
  7. var showBusy = text => wx.showToast({
  8. title: text,
  9. icon: 'loading',
  10. duration: 10000
  11. });
  12. // 显示成功提示
  13. var showSuccess = text => {
  14. wx.hideToast();
  15. wx.showToast({
  16. title: text,
  17. icon: 'success'
  18. });
  19. };
  20. // 显示失败提示
  21. var showModel = (title, content) => {
  22. wx.hideToast();
  23. wx.showModal({
  24. title,
  25. content: JSON.stringify(content),
  26. showCancel: false
  27. });
  28. };
  29. var showMsg = (title, content) => {
  30. wx.hideToast();
  31. wx.showModal({
  32. title,
  33. content: content,
  34. showCancel: false
  35. });
  36. };
  37. //获取应用实例
  38. var busy=false;
  39. var app = getApp()
  40. Page({
  41. data: {
  42. userInfo: {},
  43. loading:true,
  44. users:[],
  45. busy:false,
  46. loading_show:false,
  47. users:[]
  48. },
  49. user_list(){
  50. var self = this;
  51. if(self.data.busy){
  52. return;
  53. }
  54. self.setData({
  55. loading:true,
  56. busy:true
  57. })
  58. qcloud.request({
  59. // 要请求的地址
  60. url: config.service.apiUrl+'friend_requests',
  61. success(result) {
  62. if(result.data.success==true){
  63. self.setData({
  64. users:result.data.followers.data
  65. })
  66. }
  67. console.log('request success', result);
  68. },
  69. fail(error) {
  70. console.log('request fail', error);
  71. },
  72. complete() {
  73. self.setData({
  74. loading:false,
  75. busy:false
  76. })
  77. busy=false;
  78. console.log('request complete');
  79. }
  80. });
  81. },
  82. onLoad: function () {
  83. console.log('onLoad');
  84. },
  85. agree:function(e){
  86. console.log(e);
  87. var follower_id=e.target.dataset.followerId;
  88. var self=this;
  89. if(busy||!follower_id){
  90. return;
  91. }
  92. if(wx.showLoading) {
  93. wx.showLoading({
  94. title: '操作中...',
  95. mask:true
  96. })
  97. }else{
  98. self.setData({
  99. loading_show:true,
  100. })
  101. }
  102. var data={};
  103. data.follower_id=follower_id;
  104. data.accept=1;
  105. qcloud.request({
  106. // 要请求的地址
  107. url: config.service.apiUrl+'friend_requests',
  108. method:"PUT",
  109. data: data,
  110. success(result) {
  111. if(wx.hideLoading) {
  112. wx.hideLoading();
  113. }else{
  114. self.setData({
  115. loading_show:false,
  116. })
  117. }
  118. if(result.data.success==true){
  119. showSuccess('操作成功');
  120. }else{
  121. showMsg("提示信息","操作失败");
  122. }
  123. self.user_list();
  124. console.log('request success', result);
  125. },
  126. fail(error) {
  127. if(wx.hideLoading) {
  128. wx.hideLoading();
  129. }else{
  130. self.setData({
  131. loading_show:false,
  132. })
  133. }
  134. console.log('request fail', error);
  135. },
  136. complete() {
  137. console.log('request complete');
  138. }
  139. });
  140. },
  141. onShow:function(){
  142. if(busy){
  143. return;
  144. }
  145. busy=true;
  146. var self=this;
  147. app.getUserInfo(function(userInfo){
  148. self.user_list();
  149. });
  150. }
  151. })