123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- // pages/mpTodo/mpTodo.js
- const db = wx.cloud.database()
- const mptodo1 = db.collection('mptodo1')
- let skipNum = 0
- let checkVal = []
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- todoData: [],
- inpVal: '',
- allData: false,
- listType: false
- },
- //复选框选中的事件
- checkBoxHandle(event){
- console.log(event.detail.value)
- let _arr = event.detail.value
- checkVal = _arr
- },
- //完成选中事件
- doneCheckHandle(){
- wx.cloud.callFunction({
- name: 'mptodoDone1',
- data:{
- _arr: checkVal
- }
- }).then((res)=>{
- console.log(res)
- })
- },
- //输入框事件
- inpHandle(event){
- console.log(event.detail.value)
- let _val = event.detail.value
- this.setData({
- inpVal: _val
- })
- },
- //添加事件
- addHandle(){
- mptodo1.add({
- data:{
- title: this.data.inpVal,
- createTime: db.serverDate(),
- isDone: false
- }
- }).then((res)=>{
- console.log(res)
- this.setData({
- inpVal: ''
- })
- this.initData()
- })
- },
- //获取数据库里面的数据
- async getTodoList(){
- let _total = 0
- await mptodo1.where({
- isDone: this.data.listType
- }).count().then((res)=>{
- console.log(res)
- _total = res.total
- })
- mptodo1.where({
- isDone: this.data.listType
- }).orderBy('createTime','desc').limit(3).skip(skipNum).get().then((res)=>{
- let _arr = [...this.data.todoData,...res.data]
- let _allData = this.data.allData
- if(_arr.length >= _total){
- _allData = true
- }
- this.setData({
- todoData: _arr,
- allData: _allData
- })
- })
- },
- //显示更多
- showMoreHandle(){
- skipNum += 3
- this.getTodoList()
- },
- //初始化数据
- initData(){
- this.setData({
- inpVal:'',
- todoData: [],
- allData: false
- })
- skipNum = 0
- this.getTodoList()
- },
- //显示完成
- changeTypeHandle(event){
- this.setData({
- listType: event.detail.value
- })
- this.initData()
- },
- //完成选中项
- doneHandle(event){
- console.log(event)
- let _id = event.currentTarget.dataset.id
- mptodo1.doc(_id).update({
- data: {
- isDone: true
- }
- })
- .then((res)=>{
- this.initData()
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getTodoList()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|