Skip to content

Commit

Permalink
优化 多处细节
Browse files Browse the repository at this point in the history
  • Loading branch information
Chadwuo committed Jan 18, 2022
1 parent 7c076f9 commit 4f7b441
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 136 deletions.
7 changes: 4 additions & 3 deletions cloudfunctions/lijiFunctions/lookupGiftFriend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const db = cloud.database()
var $ = db.command.aggregate
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext();
let whereVal = event.where || {
_openid: wxContext.OPENID,
}
return await db.collection('gift').aggregate()
.match({
_openid: wxContext.OPENID,
})
.match(whereVal)
.skip(event.page * event.limit)
.limit(event.limit)
.lookup({
Expand Down
3 changes: 2 additions & 1 deletion miniprogram/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"van-dropdown-item": "@vant/weapp/dropdown-item/index",
"barrage": "/components/barrage",
"van-submit-bar": "@vant/weapp/submit-bar/index",
"van-notice-bar": "@vant/weapp/notice-bar/index"
"van-notice-bar": "@vant/weapp/notice-bar/index",
"van-datetime-picker": "@vant/weapp/datetime-picker/index"
}
}
88 changes: 46 additions & 42 deletions miniprogram/pages/bookDetails/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const app = getApp()
const dayjs = require('dayjs');
const db = wx.cloud.database()
Page({
data: {
Expand All @@ -7,41 +8,56 @@ Page({
pageNo: 0,
pageEnd: false,
},
// 分页获取数据
getPage(page, limit) {
return db.collection('gift')
.where({
userId: app.globalData.user._id,
bookId: this.data.bookId
formatDate(date) {
return dayjs(date).format('YYYY-MM-DD');
},
loadData(page) {
// 如果服务已经停止
if (app.globalData.serviceStopped) {
this.setData({
service_stopped: true,
giftList: []
})
.orderBy('luckyDay', 'desc')
.skip(page * limit)
.limit(limit)
.get()
return
}
if (page == 0) {
this.data.giftList = []
}
let that = this
wx.cloud.callFunction({
name: 'lijiFunctions',
data: {
type: 'lookupGiftFriend',
page: page,
limit: 10,
where: {
userId: app.globalData.user._id,
bookId: this.data.bookId
}
}
}).then(res => {
if (res.result.list.length === 0) {
that.data.pageEnd = true
return
}
let datas = this.data.giftList.concat(res.result.list)
datas.map(i => {
if (i.luckDay) {
i.luckDay = that.formatDate(i.luckDay)
}
})
that.setData({
giftList: datas,
pageNo: that.data.pageNo + 1
});
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this
that.setData({
bookId: options.bookId,
});
this.data.pageNo = 0
this.getPage(this.data.pageNo, 10).then(res => {
if (res.data.length === 0) {
this.setData({
pageEnd: true,
});
}
this.setData({
giftList: res.data,
pageNo: this.data.pageNo + 1
});
})
wx.setNavigationBarTitle({
title: ''
})
this.data.bookId = options.bookId
this.loadData(0)
},
/**
* 生命周期函数--监听页面初次渲染完成
Expand Down Expand Up @@ -82,20 +98,8 @@ Page({
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
let that = this
if (!this.data.pageEnd) {
// this.setData({
// loading: true,
// });
this.getPage(this.data.pageNo, 10).then(res => {
if (res.data.length > 0) {
let datas = that.data.giftList.concat(res.data)
this.data.pageNo + 1
this.setData({
giftList: datas
});
}
})
this.loadData(this.data.pageNo)
}
},

Expand Down
2 changes: 1 addition & 1 deletion miniprogram/pages/bookDetails/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<van-empty wx:if="{{giftList.length===0}}" description="还没有记录哦~"></van-empty>
<view class='nav acea-row row-middle' wx:for="{{giftList}}" wx:key="index">
<view class='content'>
<view class='title'>{{item.name}}</view>
<view class='title'>{{item.friendInfo.name}}</view>
<view class='info'>{{item.name}}</view>
<view class='info'>{{item.luckDay}}</view>
</view>
Expand Down
37 changes: 14 additions & 23 deletions miniprogram/pages/books/books.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,29 @@ Page({
})
},

loadData() {
loadData(page) {
if (page == 0) {
this.data.giftBooks = []
}
this.setData({
pageNo: 0,
isHideTips: app.globalData.user.tips_hide_book
})
let that = this
wx.cloud.callFunction({
name: 'lijiFunctions',
data: {
type: 'lookupBookGift',
page: this.data.pageNo,
page: page,
limit: 10
}
}).then(res => {
const resList = that.computeTotal(res.result.list)
if (res.result.list.length === 0) {
that.data.pageEnd = true
return
}
const resList = that.computeTotal(this.data.giftBooks.concat(res.result.list))
that.setData({
giftBooks: resList,
giftList: resList,
pageNo: that.data.pageNo + 1
});
})
Expand All @@ -134,7 +140,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.loadData()

},

/**
Expand All @@ -148,7 +154,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {

this.loadData(0)
},

/**
Expand Down Expand Up @@ -180,22 +186,7 @@ Page({
*/
onReachBottom: function () {
if (!this.data.pageEnd) {
wx.cloud.callFunction({
name: 'lijiFunctions',
data: {
type: 'lookupBookGift',
page: this.data.pageNo,
limit: 10
}
}).then(res => {
if (res.result.list.length > 0) {
const resList = that.computeTotal(this.data.giftBooks.concat(res.result.list))
this.setData({
giftList: resList,
pageNo: that.data.pageNo + 1
});
}
})
this.loadData(this.data.pageNo)
}
},

Expand Down
18 changes: 16 additions & 2 deletions miniprogram/pages/friendDetails/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const app = getApp()
const dayjs = require('dayjs');
const db = wx.cloud.database()
Page({
data: {
Expand All @@ -12,6 +13,9 @@ Page({
sadCount: '0',
sadTotal: '0.00',
},
formatDate(date) {
return dayjs(date).format('YYYY-MM-DD');
},
// 计算统计往来记录
computedGiftTotal() {
const $ = db.command.aggregate
Expand Down Expand Up @@ -76,7 +80,12 @@ Page({
});
} else {
that.setData({
giftList: res.data,
giftList: res.data.map(i => {
if (i.luckDay) {
i.luckDay = that.formatDate(i.luckDay)
}
return i
}),
pageNo: that.data.pageNo + 1
});
}
Expand Down Expand Up @@ -145,7 +154,12 @@ Page({
let datas = this.data.giftList.concat(res.data)
this.data.pageNo + 1
this.setData({
giftList: datas
giftList: datas.map(i => {
if (i.luckDay) {
i.luckDay = that.formatDate(i.luckDay)
}
return i
}),
});
}
})
Expand Down
4 changes: 0 additions & 4 deletions miniprogram/pages/friends/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.onShow()

setTimeout(() => {
wx.stopPullDownRefresh()
}, 2000);
},

/**
Expand Down
1 change: 0 additions & 1 deletion miniprogram/pages/friends/friends.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"navigationBarTitleText": "亲友",
"enablePullDownRefresh": true,
"usingComponents": {}
}
21 changes: 14 additions & 7 deletions miniprogram/pages/giftAdd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Page({
* 页面的初始数据
*/
data: {
minDate: new Date().setFullYear((new Date().getFullYear()-1)),
luckDay: dayjs().format('YYYY-MM-DD'),
minDate: new Date().setMonth((new Date().getMonth() - 6)),
luckDay: '',
luckDayFormat: dayjs().format('YYYY-MM-DD'),
name: '',
bookId: '',
bookName: '',
Expand All @@ -19,7 +20,7 @@ Page({
friendName: '',
showCalendar: false,
tip: '',
price: 0
price: 0,
},
formatDate(date) {
return dayjs(date).format('YYYY-MM-DD');
Expand Down Expand Up @@ -57,12 +58,10 @@ Page({
title: '保存成功',
})
that.setData({
luckDay: dayjs().format('YYYY-MM-DD'),
name: '',
bookId: '',
bookName: '',
money: '',
type: '收',
wishes: '',
friendName: '',
friendId: '',
Expand All @@ -87,6 +86,11 @@ Page({
friendId: res.data[0]._id,
tip: `已有同名联系人【${res.data[0].name}】,记录会添加在与该亲友的来往记录中`
});
} else {
// 名字改了 数据库没有相关人信息,friendId 置空
that.setData({
friendId: '',
});
}
})
},
Expand All @@ -106,10 +110,12 @@ Page({
showCalendar: false
});
},
// 日历选择
onConfirm(event) {
this.setData({
showCalendar: false,
luckDay: this.formatDate(event.detail),
luckDayFormat: this.formatDate(event.detail),
luckDay: event.detail,
});
},
onGiftTypeChange(event) {
Expand Down Expand Up @@ -167,7 +173,8 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {

// 这什么问题 在data里赋值不起作用???
this.data.luckDay = new Date()
},

/**
Expand Down
2 changes: 1 addition & 1 deletion miniprogram/pages/giftAdd/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<van-tab title="收礼" name="收"></van-tab>
<van-tab title="送礼" name="送"></van-tab>
</van-tabs>
<van-cell title="{{ luckDay }}" is-link icon="calendar-o" bind:click="onDisplay" />
<van-cell title="{{ luckDayFormat }}" is-link icon="calendar-o" bind:click="onDisplay" />
<van-field label="姓名" left-icon="contact" right-icon="friends-o" model:value="{{ friendName }}" placeholder="亲友" bind:click-icon="onSelectFriends" bind:blur="onFriendBlur" />
<van-field label="事由" left-icon="point-gift-o" model:value="{{ name }}" placeholder="事由" />
<van-field label="礼金" left-icon="balance-o" model:value="{{ money }}" type="digit" placeholder="{{type}}礼金额" bind:blur="onMoneyBlur" />
Expand Down
Loading

0 comments on commit 4f7b441

Please sign in to comment.