123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- // pages/channel/user/followers/followers.js
- var qcloud = require('../../../../vendor/qcloud-weapp-client-sdk/index');
- // 引入配置
- var config = require('../../../../config');
- // 显示繁忙提示
- var showBusy = text => wx.showToast({
- title: text,
- icon: 'loading',
- duration: 10000
- });
- // 显示成功提示
- var showSuccess = text => {
- wx.hideToast();
- wx.showToast({
- title: text,
- icon: 'success'
- });
- };
- // 显示失败提示
- var showModel = (title, content) => {
- wx.hideToast();
- wx.showModal({
- title,
- content: JSON.stringify(content),
- showCancel: false
- });
- };
- var showMsg = (title, content) => {
- wx.hideToast();
- wx.showModal({
- title,
- content: content,
- showCancel: false
- });
- };
- //获取应用实例
- var busy=false;
- var app = getApp()
- Page({
- data: {
- userInfo: {},
- loading:true,
- users:[],
- busy:false,
- loading_show:false,
- users:[]
- },
- user_list(){
- var self = this;
- if(self.data.busy){
- return;
- }
- self.setData({
- loading:true,
- busy:true
- });
- var url=config.service.apiUrl+'followers';
- qcloud.request({
- // 要请求的地址
- url: url,
- success(result) {
- if(result.data.success==true){
- self.setData({
- users:result.data.followers.data
- })
- }
- if(result.data.followers.next_page_url!==null){
- self.setData({
- next_data:true,
- next_page_url:result.data.followers.next_page_url
- })
- }else{
- self.setData({
- next_data:false,
- next_page_url:null
- })
- }
- console.log('request success', result);
- },
- fail(error) {
- console.log('request fail', error);
- },
- complete() {
- self.setData({
- loading:false,
- busy:false
- })
- busy=false;
-
- wx.hideNavigationBarLoading();
- console.log('request complete');
- }
- });
- },
- load_more(){
- var self = this;
- var request_url=self.data.next_page_url;
- if(!request_url){
- return;
- }
- if(self.data.busy){
- return;
- }
- self.setData({
- loading:true,
- busy:true
- });
- qcloud.request({
- // 要请求的地址
- url: request_url,
- success(result) {
- if(result.data.success==true){
- var item=self.data.users;
- var obj=result.data.followers.data;
- for (var i=0;i<obj.length;i++){
- item.push(obj[i]);
- }
- self.setData({
- users:item
- });
- if(result.data.followers.next_page_url!==null){
- self.setData({
- next_data:true,
- next_page_url:result.data.followers.next_page_url
- })
- }else{
- self.setData({
- next_data:false,
- next_page_url:null
- })
- }
- }
- console.log('request success', result);
- },
- fail(error) {
- console.log('request fail', error);
- },
- complete() {
- self.setData({
- loading:false,
- busy:false
- })
- console.log('request complete');
- }
- });
- },
- onReachBottom: function() {
- var self = this;
- self.load_more();
- },
- del:function(e){
- console.log(e);
- var follower_id=e.target.dataset.followerId;
- var self=this;
- if(busy||!follower_id){
- return;
- }
- if(wx.showLoading) {
- wx.showLoading({
- title: '操作中...',
- mask:true
- })
- }else{
- self.setData({
- loading_show:true,
- })
- }
- var data={};
- data.follower_id=follower_id;
- qcloud.request({
- // 要请求的地址
- url: config.service.apiUrl+'followers',
- method:"DELETE",
- data: data,
- success(result) {
- if(wx.hideLoading) {
- wx.hideLoading();
- }else{
- self.setData({
- loading_show:false,
- })
- }
- if(result.data.success==true){
- showSuccess('操作成功');
- }else{
- showMsg("提示信息","操作失败");
- }
- self.user_list();
- console.log('request success', result);
- },
- fail(error) {
- if(wx.hideLoading) {
- wx.hideLoading();
- }else{
- self.setData({
- loading_show:false,
- })
- }
- console.log('request fail', error);
- },
- complete() {
- console.log('request complete');
- }
- });
- },
- onLoad: function () {
- console.log('onLoad');
- },
-
- onShow:function(){
- if(busy){
- return;
- }
- busy=true;
- var self=this;
- app.getUserInfo(function(userInfo){
- wx.showNavigationBarLoading();
- self.user_list();
- });
- }
- })
|