当点击查询后,点击选项卡的时候,计数显示为0。如果在我要找车或者其他选项卡位的时候,显示的全部是初始化状态的计数,
想要的结果,当在相应的选项卡位的时候,点击查询,显示相应的计数。在相应的卡位下拉刷新退出查询状态,显示相应的计数
组件代码:
<view class="comment-title">全部信息(共有{{result}}条)</view>
index.wxml代码:
<form bindsubmit="formSubmit">
<view class="search-input-group">
<view class="input-group">
<input class="search-input" placeholder="出发地" value="{{startPoint}}" bindinput="onStartPointEvent" />
<image class="thumbnail" src="../../images/return.png" />
<input class="search-input" placeholder="终点" value="{{goal}}" bindinput="onGoalEvent" />
</view>
<button class="search-button" size="mini" formType="submit">查询</button>
</view>
</form>
<segment-carpool items="{{items}}" result="{{result}}" resultthree="{{result3}}" resultfous="{{result4}}" binditemchengde="onItemChengdeEvent" defaultIndex="0" >
<view slot="0" class="segment-page wehicle-page">
<whole wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></whole>
</view>
<view slot="1" class="segment-page people-page">
<wehicle wx:for="{{listones}}" wx:key="key" wx:for-item="listone" list1="{{listone}}"></wehicle>
</view>
<view slot="2" class="segment-page train-page">
<people wx:if="{{listtwos}}" wx:for="{{listtwos}}" wx:key="key" wx:for-item="listtwo" list2="{{listtwo}}"></people>
</view>
<view slot="3" class="segment-page money-page">
<train wx:for="{{listthrees}}" wx:key="key" wx:for-item="listthree" list3="{{listthree}}"></train>
</view>
<view slot="4" class="segment-page money-page" >
<money wx:for="{{listfours}}" wx:key="key" wx:for-item="listfour" list4="{{listfour}}"></money>
</view>
</segment-carpool>
<loadingmore hasmore="{{hasmore}}" nomore="{{nomore}}"></loadingmore>
index.js代码:
data: {
items: ["全部", "我要找车", "我要找人", "我找货车", "我要找货"],
hasmore: true,
nomore: false,
wehicles: [],
result: 0,
startPoint:'',
goal: '',
isQuerying: false,
},
/**
* 按条件查询数据
*/
formSubmit(event) {
console.log(event);
const that = this;
that.setData({
isQuerying: true
})
let list = db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
});
if (event > 0) {
list = list.skip(event);
}
list.limit(5).orderBy("create_time", "desc").get().then(res => {
const wehicles = res.data;
let nomore = true;
let hasmore = true
if (wehicles.length == 0) {
hasmore = false
} else {
nomore = false
}
let newWehicles = [];
if (event > 0) {
newWehicles = that.data.wehicles.concat(wehicles);
} else {
newWehicles = wehicles;
}
newWehicles.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
wehicles: newWehicles,
hasmore: hasmore,
nomore: nomore,
})
});
let list1 = db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
carpool:'我要找车'
});
if (event > 0) {
list1 = list1.skip(event);
}
list1.limit(5).orderBy("create_time", "desc").get().then(res => {
const listones = res.data;
let nomore = true;
let hasmore = true
if (listones.length == 0) {
hasmore = false
} else {
nomore = false
}
let newones = [];
if (event > 0) {
newones = that.data.listones.concat(listones);
} else {
newones = listones;
}
newones.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
listones: newones,
hasmore: hasmore,
nomore: nomore
})
});
et list2 = db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
carpool:'我要找人'
});
if (event > 0) {
list2 = list2.skip(event);
}
list2.limit(5).orderBy("create_time", "desc").get().then(res => {
const listtwos = res.data;
let nomore = true;
let hasmore = true
if (listtwos.length == 0) {
hasmore = false
} else {
nomore = false
}
let newtwos = [];
if (event > 0) {
newtwos = that.data.listtwos.concat(listtwos);
} else {
newtwos = listtwos;
}
newtwos.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
listtwos: newtwos,
hasmore: hasmore,
nomore: nomore
})
});
let list3 = db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
carpool:'我找货车'
});
if (event > 0) {
list3 = list3.skip(event);
}
list3.limit(5).orderBy("create_time", "desc").get().then(res => {
const listthrees = res.data;
let nomore = true;
let hasmore = true
if (listthrees.length == 0) {
hasmore = false
} else {
nomore = false
}
let newthrees = [];
if (event > 0) {
newthrees = that.data.listthrees.concat(listthrees);
} else {
newthrees = listthrees;
}
newthrees.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
listthrees: newthrees,
hasmore: hasmore,
nomore: nomore
})
});
let list4 = db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
carpool:'我要找货'
});
if (event > 0) {
list4 = list4.skip(event);
}
list4.limit(5).orderBy("create_time", "desc").get().then(res => {
const listfours = res.data;
let nomore = true;
let hasmore = true
if (listfours.length == 0) {
hasmore = false
} else {
nomore = false
}
let newfours = [];
if (event > 0) {
newfours = that.data.listfours.concat(listfours);
} else {
newfours = listfours;
}
newfours.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
listfours: newfours,
hasmore: hasmore,
nomore: nomore,
})
});
that.setData({
startPoint:'',
goal:'',
})
},
/**
* 初始化总计数
*/
oncount(event) {
const that = this;
db.collection('wehicle').where({}).count().then(res => {
that.setData({
result: res.total
})
});
},
/**
* 获取选项卡计数
*/
onItemChengdeEvent(event) {
console.log(event)
const that = this;
var index = event.detail.index;
if (index == 0) {
if(!that.data.isQuerying){
db.collection('wehicle').where({}).count().then(res => {
that.setData({
result: res.total,
})
});
}else{
db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
}).count().then(res => {
that.setData({
result: res.total,
})
});
}
} else if (index == 1) {
if(!that.data.isQuerying){
db.collection('wehicle').where({carpool: '我要找车',}).count().then(res => {
that.setData({
result: res.total,
})
});
}else{
db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
carpool:'我要找车'
}).count().then(res => {
that.setData({
result: res.total,
})
});
}
} else if (index == 2) {
if(!that.data.isQuerying){
db.collection('wehicle').where({carpool: '我要找人',}).count().then(res => {
that.setData({
result: res.total,
})
});
}else{
db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
carpool:'我要找人'
}).count().then(res => {
that.setData({
result: res.total,
})
});
}
} else if (index == 3) {
if(!that.data.isQuerying){
db.collection('wehicle').where({carpool: '我找货车',}).count().then(res => {
that.setData({
result:res.total
})
});
}else{
db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
carpool:'我找货车'
}).count().then(res => {
that.setData({
result: res.total,
})
});
}
} else {
if(!that.data.isQuerying){
db.collection('wehicle').where({carpool: '我要找货',}).count().then(res => {
that.setData({
result: res.total,
})
});
}else{
db.collection("wehicle").where({
startPoint: that.data.startPoint,
goal: that.data.goal,
carpool:'我要找货车'
}).count().then(res => {
that.setData({
result: res.total,
})
});
}
}
},
/**
* 获取数据库数据
*/
lowdrelease(start = 0) {
const that = this;
let list = db.collection("wehicle");
if (start > 0) {
list = list.skip(start);
}
list.limit(5).orderBy("create_time", "desc").get().then(res => {
const wehicles = res.data;
let nomore = false;
let hasmore = true
if (!wehicles) {
nomore = true
}else{
hasmore = false
}
let newWehicles = [];
if (start > 0) {
newWehicles = that.data.wehicles.concat(wehicles);
} else {
newWehicles = wehicles;
}
newWehicles.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
wehicles: newWehicles,
hasmore: hasmore,
nomore: nomore
})
});
let list1 = db.collection("wehicle").where({carpool:'我要找车'});
if (start > 0) {
list1 = list1.skip(start);
}
list1.limit(5).orderBy("create_time", "desc").get().then(res => {
const listones = res.data;
let nomore = false;
let hasmore = true
if (!listones) {
nomore = true
}else{
hasmore = false
}
let newones = [];
if (start > 0) {
newones = that.data.listones.concat(listones);
} else {
newones = listones;
}
newones.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
listones: newones,
hasmore: hasmore,
nomore: nomore
})
});
let list2 = db.collection("wehicle").where({carpool:'我要找人'});
if (start > 0) {
list2 = list2.skip(start);
}
list2.limit(5).orderBy("create_time", "desc").get().then(res => {
const listtwos = res.data;
let nomore = false;
let hasmore = true
if (!listtwos) {
nomore = true
}else{
hasmore = false
}
let newtwos = [];
if (start > 0) {
newtwos = that.data.listtwos.concat(listtwos);
} else {
newtwos = listtwos;
}
newtwos.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
listtwos: newtwos,
hasmore: hasmore,
nomore: nomore
})
});
let list3 = db.collection("wehicle").where({carpool:'我找货车'});
if (start > 0) {
list3 = list3.skip(start);
}
list3.limit(5).orderBy("create_time", "desc").get().then(res => {
const listthrees = res.data;
let nomore = false;
let hasmore = true
if (!listthrees) {
nomore = true
}else{
hasmore = false
}
let newthrees = [];
if (start > 0) {
newthrees = that.data.listthrees.concat(listthrees);
} else {
newthrees = listthrees;
}
newthrees.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
listthrees: newthrees,
hasmore: hasmore,
nomore: nomore
})
});
let list4 = db.collection("wehicle").where({carpool:'我要找货'});
if (start > 0) {
list4 = list4.skip(start);
}
list4.limit(5).orderBy("create_time", "desc").get().then(res => {
const listfours = res.data;
let nomore = false;
let hasmore = true
if (!listfours) {
nomore = true
}
else{
hasmore = false
}
let newfours = [];
if (start > 0) {
newfours = that.data.listfours.concat(listfours);
} else {
newfours = listfours;
}
newfours.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
listfours: newfours,
hasmore: hasmore,
nomore: nomore
})
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.oncount();
this.lowdrelease();
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
this.lowdrelease(0);
this.oncount();
this.setData({
isQuerying:false
})
wx.stopPullDownRefresh();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
if (!this.data.isQuerying) {
this.lowdrelease(this.data.wehicles.length);
}else{
this.formSubmit(this.data.wehicles.length)
}
},
})