// pages/today/index.js const app = getApp(); import ActionSheet, { ActionSheetTheme } from '../../components/action-sheet/index'; let pageStart = 1; Page({ /** * 页面的初始数据 */ data: { tapCheckHandle: undefined, aIconList: ['check-rectangle', 'star-filled', 'notification', 'info-circle'], taskList: [{'taskId':'1','title':'标题德外旗舰店1','note':'2022-11-11'},{'taskId':'2','title':'标题德外旗舰店2','note':'2022-11-11'}], todayList: [{'taskId':'1','title':'标题德外旗舰店1','note':'2022-11-11'},{'taskId':'2','title':'标题德外旗舰店2','note':'2022-11-11'}], delayList: [{'taskId':'1','title':'si哦大家艾吉奥是我','note':'2022-11-11','complete':true}, {'taskId':'2','title':'si哦大家艾吉奥是2321','note':'2022-11-11','complete':true}, {'taskId':'3','title':'打SD卡我怕','note':'2022-11-11','complete':true}, {'taskId':'4','title':'标无间道i文件舰店1','note':'2022-11-11','complete':true}, {'taskId':'5','title':'标题大家啊我i家1','note':'2022-11-11','complete':false}, {'taskId':'6','title':'标题德外而我却','note':'2022-11-11','complete':true}, {'taskId':'7','title':'标题德外旗额我去问1','note':'2022-11-11','complete':false}, {'taskId':'8','title':'千而万请问确京东卡来接我i的骄傲问你,我就是准备看看最棒的是的多长定德外旗舰店1','note':'2022-11-11','complete':true}, {'taskId':'9','title':'标请问请问破千万1','note':'2022-11-11','complete':true}, {'taskId':'10','title':'标而且我请问请问1','note':'2022-11-11','complete':true}, {'taskId':'11','title':'代欧王大炮物品代码','note':'2022-11-11','complete':true}, {'taskId':'12','title':'到ID我们','note':'2022-11-11','complete':true}, {'taskId':'13','title':'我去哦额陪娃欧美大片请我们','note':'2022-11-11','complete':true}, {'taskId':'14','title':'请问哦气雾剂群殴','note':'2022-11-11','complete':true} ], duration: 300, // swiper-item 切换过渡时间 categoryCur: 0, // 当前数据列索引 categoryMenu: ['任务清单','收藏任务','延期任务'], // 分类菜单数据, 字符串数组格式 categoryData: [], // 所有数据列 }, getList(type, currentPage) { let currentCur = this.data.categoryCur; let pageData = this.getCurrentData(currentCur); if (pageData.end) return; pageData.requesting = true; this.setCurrentData(currentCur, pageData); wx.showLoading({ title: '请稍候...', mask: true, }) app.$api.taskList({}).then(res =>{ this.setData({ taskList:res.data.taskList, }) let data = res.data || { taskList: [], over: false }; let listData = this.data.delayList || []; pageData.requesting = false; if (type === 'refresh') { pageData.listData = listData; pageData.end = data.over; pageData.page = currentPage + 1; } else { pageData.listData = pageData.listData.concat(listData); pageData.end = data.over; pageData.page = currentPage + 1; } this.setCurrentData(currentCur, pageData); }) }, // 更新页面数据 setCurrentData(currentCur, pageData) { let categoryData = this.data.categoryData categoryData[currentCur] = pageData this.setData({ categoryData: categoryData }) }, // 获取当前激活页面的数据 getCurrentData() { return this.data.categoryData[this.data.categoryCur] }, // 顶部tab切换事件 toggleCategory(e) { this.setData({ duration: 0 }); setTimeout(() => { this.setData({ categoryCur: e.detail.index }); }, 0); }, // 页面滑动切换事件 animationFinish(e) { this.setData({ duration: 300 }); setTimeout(() => { this.setData({ categoryCur: e.detail.current }); let pageData = this.getCurrentData(); if (pageData.listData.length === 0) { this.getList('refresh', pageStart); } }, 0); }, // 刷新数据 refresh() { this.getList('refresh', pageStart); }, // 加载更多 more() { this.getList('more', this.getCurrentData(this.data.categoryCur).page); }, changeCheck(e){ let currentCur = this.data.categoryCur; let categoryData = this.getCurrentData(); let currentCheck = categoryData.listData; currentCheck.forEach(x => { if (x.taskId == e.target.dataset.id){ x.complete = e.detail.checked; //TODO 请求,将完成状态更新 } }); this.setCurrentData(currentCur,categoryData); }, handleAction(e) { console.log(e.detail); this.data.tapCheckHandle = ActionSheet.show({ theme: ActionSheetTheme.List, selector: '#t-action-sheet', context: this, items: [ { label: '详情xxx', }, { label: '截止日期xxx', color: '#0052D9', }, { label: '配置提醒', color: '#0052D9', }, { label: '删除xxx', color: '#e34d59', }, ], }); }, handleSelected(e) { console.log(e.detail); }, selectCancel() { this.data.tapCheckHandle.close(); }, onLoad() { let categoryData = []; this.data.categoryMenu.forEach(index =>{ categoryData.push({ categoryCur: index, requesting: false, end: false, emptyShow: false, page: pageStart, listData: [] }); }) this.setData({ categoryData }); // 第一次加载延迟 350 毫秒 防止第一次动画效果不能完全体验 setTimeout(() => { this.refresh(); }, 350); } })