followers.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. console.log('request complete');
  90. }
  91. });
  92. },
  93. load_more(){
  94. var self = this;
  95. var request_url=self.data.next_page_url;
  96. if(!request_url){
  97. return;
  98. }
  99. if(self.data.busy){
  100. return;
  101. }
  102. self.setData({
  103. loading:true,
  104. busy:true
  105. });
  106. qcloud.request({
  107. // 要请求的地址
  108. url: request_url,
  109. success(result) {
  110. if(result.data.success==true){
  111. var item=self.data.users;
  112. var obj=result.data.followers.data;
  113. for (var i=0;i<obj.length;i++){
  114. item.push(obj[i]);
  115. }
  116. self.setData({
  117. users:item
  118. });
  119. if(result.data.followers.next_page_url!==null){
  120. self.setData({
  121. next_data:true,
  122. next_page_url:result.data.followers.next_page_url
  123. })
  124. }else{
  125. self.setData({
  126. next_data:false,
  127. next_page_url:null
  128. })
  129. }
  130. }
  131. console.log('request success', result);
  132. },
  133. fail(error) {
  134. console.log('request fail', error);
  135. },
  136. complete() {
  137. self.setData({
  138. loading:false,
  139. busy:false
  140. })
  141. console.log('request complete');
  142. }
  143. });
  144. },
  145. onReachBottom: function() {
  146. var self = this;
  147. self.load_more();
  148. },
  149. del:function(e){
  150. console.log(e);
  151. var follower_id=e.target.dataset.followerId;
  152. var self=this;
  153. if(busy||!follower_id){
  154. return;
  155. }
  156. if(wx.showLoading) {
  157. wx.showLoading({
  158. title: '操作中...',
  159. mask:true
  160. })
  161. }else{
  162. self.setData({
  163. loading_show:true,
  164. })
  165. }
  166. var data={};
  167. data.follower_id=follower_id;
  168. qcloud.request({
  169. // 要请求的地址
  170. url: config.service.apiUrl+'followers',
  171. method:"DELETE",
  172. data: data,
  173. success(result) {
  174. if(wx.hideLoading) {
  175. wx.hideLoading();
  176. }else{
  177. self.setData({
  178. loading_show:false,
  179. })
  180. }
  181. if(result.data.success==true){
  182. showSuccess('操作成功');
  183. }else{
  184. showMsg("提示信息","操作失败");
  185. }
  186. self.user_list();
  187. console.log('request success', result);
  188. },
  189. fail(error) {
  190. if(wx.hideLoading) {
  191. wx.hideLoading();
  192. }else{
  193. self.setData({
  194. loading_show:false,
  195. })
  196. }
  197. console.log('request fail', error);
  198. },
  199. complete() {
  200. console.log('request complete');
  201. }
  202. });
  203. },
  204. onLoad: function () {
  205. console.log('onLoad');
  206. },
  207. onShow:function(){
  208. if(busy){
  209. return;
  210. }
  211. busy=true;
  212. var self=this;
  213. app.getUserInfo(function(userInfo){
  214. self.user_list();
  215. });
  216. }
  217. })