You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.5 KiB
66 lines
1.5 KiB
3 years ago
|
import { post } from "./api.js"
|
||
|
export default class CustomGroup{
|
||
|
///所有客户,总数
|
||
|
allCount = 0;
|
||
|
///当前客户的所有信息
|
||
|
customerinfo = [];
|
||
|
///每一页的数量,服务器那边的数据
|
||
|
pagecount = 0;
|
||
|
///第几页,要从1开始,获取下一页的时候默认+1
|
||
|
pageindex = 0;
|
||
|
///每一页最大显示多少个数据,
|
||
|
maxPerPageCount = 9;
|
||
|
///获取数据的地址
|
||
|
url = '';
|
||
|
/**
|
||
|
* @param {String} _url 获取数据的网络地址
|
||
|
* 构造函数
|
||
|
*/
|
||
|
constructor(_url){
|
||
|
this.url = _url;
|
||
|
}
|
||
|
/**
|
||
|
* 清理数据,重新获取
|
||
|
*/
|
||
|
clear(){
|
||
|
this.customerinfo = [];
|
||
|
this.pageindex = 0;
|
||
|
this.allCount = 0;
|
||
|
}
|
||
|
/**
|
||
|
* 获取下一页的数据,如果你调用了清理方法,那么会直接从新获取
|
||
|
*/
|
||
|
async getNextPage(){
|
||
|
|
||
|
if(this.allCount != 0 && this.customerinfo.length == this.allCount){
|
||
|
return;
|
||
|
}
|
||
|
var Define = getApp().globalData.Define;
|
||
|
var nextIndex = this.pageindex + 1;
|
||
|
var data = {
|
||
|
pagecount : this.maxPerPageCount,
|
||
|
pageindex : nextIndex,
|
||
|
};
|
||
|
uni.showLoading({
|
||
|
|
||
|
});
|
||
|
console.log("获取客户数据:",this.url);
|
||
|
var res = await post(this.url,data);
|
||
|
uni.hideLoading();
|
||
|
var info = Define.onNetMessage(res);
|
||
|
if(!info){
|
||
|
return;
|
||
|
}
|
||
|
console.log("服务器返回了客户信息:",info);
|
||
|
for(var key in info){
|
||
|
var css = info[key];
|
||
|
if(key == 'customerinfo'){
|
||
|
for(var i = 0;i<css.length;i++){
|
||
|
this.customerinfo.push(css[i]);
|
||
|
}
|
||
|
}else{
|
||
|
this[key] = css;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|