followers.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // pages/channel/user/followers/followers.js
  2. var qcloud = require('../../../../vendor/qcloud-weapp-client-sdk/index');
  3. // 引入配置
  4. var config = require('../../../../config');
  5. // 显示繁忙提示
  6. var showBusy = text => wx.showToast({
  7. title: text,
  8. icon: 'loading',
  9. duration: 10000
  10. });
  11. // 显示成功提示
  12. var showSuccess = text => {
  13. wx.hideToast();
  14. wx.showToast({
  15. title: text,
  16. icon: 'success'
  17. });
  18. };
  19. // 显示失败提示
  20. var showModel = (title, content) => {
  21. wx.hideToast();
  22. wx.showModal({
  23. title,
  24. content: JSON.stringify(content),
  25. showCancel: false
  26. });
  27. };
  28. var showMsg = (title, content) => {
  29. wx.hideToast();
  30. wx.showModal({
  31. title,
  32. content: content,
  33. showCancel: false
  34. });
  35. };
  36. //获取应用实例
  37. var busy=false;
  38. var app = getApp()
  39. Page({
  40. data: {
  41. userInfo: {},
  42. loading:true,
  43. users:[],
  44. busy:false,
  45. loading_show:false,
  46. users:[]
  47. },
  48. user_list(){
  49. var self = this;
  50. if(self.data.busy){
  51. return;
  52. }
  53. self.setData({
  54. loading:true,
  55. busy:true
  56. });
  57. var url=config.service.apiUrl+'followers';
  58. qcloud.request({
  59. // 要请求的地址
  60. url: url,
  61. success(result) {
  62. if(result.data.success==true){
  63. self.setData({
  64. users:result.data.followers.data
  65. })
  66. }
  67. if(result.data.followers.next_page_url!==null){
  68. self.setData({
  69. next_data:true,
  70. next_page_url:result.data.followers.next_page_url
  71. })
  72. }else{
  73. self.setData({
  74. next_data:false,
  75. next_page_url:null
  76. })
  77. }
  78. console.log('request success', result);
  79. },
  80. fail(error) {
  81. console.log('request fail', error);
  82. },
  83. complete() {
  84. self.setData({
  85. loading:false,
  86. busy:false
  87. })
  88. busy=false;
  89. wx.hideNavigationBarLoading();
  90. console.log('request complete');
  91. }
  92. });
  93. },
  94. load_more(){
  95. var self = this;
  96. var request_url=self.data.next_page_url;
  97. if(!request_url){
  98. return;
  99. }
  100. if(self.data.busy){
  101. return;
  102. }
  103. self.setData({
  104. loading:true,
  105. busy:true
  106. });
  107. qcloud.request({
  108. // 要请求的地址
  109. url: request_url,
  110. success(result) {
  111. if(result.data.success==true){
  112. var item=self.data.users;
  113. var obj=result.data.followers.data;
  114. for (var i=0;i<obj.length;i++){
  115. item.push(obj[i]);
  116. }
  117. self.setData({
  118. users:item
  119. });
  120. if(result.data.followers.next_page_url!==null){
  121. self.setData({
  122. next_data:true,
  123. next_page_url:result.data.followers.next_page_url
  124. })
  125. }else{
  126. self.setData({
  127. next_data:false,
  128. next_page_url:null
  129. })
  130. }
  131. }
  132. console.log('request success', result);
  133. },
  134. fail(error) {
  135. console.log('request fail', error);
  136. },
  137. complete() {
  138. self.setData({
  139. loading:false,
  140. busy:false
  141. })
  142. console.log('request complete');
  143. }
  144. });
  145. },
  146. onReachBottom: function() {
  147. var self = this;
  148. self.load_more();
  149. },
  150. del:function(e){
  151. console.log(e);
  152. var follower_id=e.target.dataset.followerId;
  153. var self=this;
  154. if(busy||!follower_id){
  155. return;
  156. }
  157. if(wx.showLoading) {
  158. wx.showLoading({
  159. title: '操作中...',
  160. mask:true
  161. })
  162. }else{
  163. self.setData({
  164. loading_show:true,
  165. })
  166. }
  167. var data={};
  168. data.follower_id=follower_id;
  169. qcloud.request({
  170. // 要请求的地址
  171. url: config.service.apiUrl+'followers',
  172. method:"DELETE",
  173. data: data,
  174. success(result) {
  175. if(wx.hideLoading) {
  176. wx.hideLoading();
  177. }else{
  178. self.setData({
  179. loading_show:false,
  180. })
  181. }
  182. if(result.data.success==true){
  183. showSuccess('操作成功');
  184. }else{
  185. showMsg("提示信息","操作失败");
  186. }
  187. self.user_list();
  188. console.log('request success', result);
  189. },
  190. fail(error) {
  191. if(wx.hideLoading) {
  192. wx.hideLoading();
  193. }else{
  194. self.setData({
  195. loading_show:false,
  196. })
  197. }
  198. console.log('request fail', error);
  199. },
  200. complete() {
  201. console.log('request complete');
  202. }
  203. });
  204. },
  205. onLoad: function () {
  206. console.log('onLoad');
  207. },
  208. onShow:function(){
  209. if(busy){
  210. return;
  211. }
  212. busy=true;
  213. var self=this;
  214. app.getUserInfo(function(userInfo){
  215. wx.showNavigationBarLoading();
  216. self.user_list();
  217. });
  218. }
  219. })