You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
6.0 KiB
JavaScript

// pages/index/index.js
import {
getTaskList, saveTask
} from '../../api/api'
import {formatTime} from '../../utils/util'
const app = getApp();
import ActionSheet, { ActionSheetTheme } from 'tdesign-miniprogram/action-sheet/index';
Page({
/**
* 页面的初始数据
*/
data: {
role: 'admin',
visible: false,
tabs: ['进行中', '已结束'],
selectDate: [new Date().getTime()],
minDate: new Date().getTime() - 60 * 60 * 24 * 181 * 1000,
maxDate: new Date().getTime(),
sendList: [],
refreshing: false,
tab: 0,
keyword: "",
select: {
page: 1,
size: 10,
isEnd: false
},
currentId: '',
statusBarHeight: app.globalData.statusBarHeight
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// this.getData()
},
handleAction(e) {
console.log(e.target.dataset.id)
this.data.currentId = e.target.dataset.id
ActionSheet.show({
theme: ActionSheetTheme.List,
selector: '#t-action-sheet',
context: this,
items: [
{
label: '编辑任务'
},
{
label: '删除任务',
color: '#e34d59'
},
],
});
},
handleSelected(e) {
console.log(e.detail.index);
if (e.detail.index === 0) {
wx.navigateTo({
url: '/pages/task-edit/task-edit?id=' + this.data.currentId,
})
} else {
saveTask({
id: this.data.currentId,
state: 0
}).then(res => {
this.data.select = {
page: 1,
size: 10,
isEnd: false
}
this.data.sendList = [];
this.getData()
})
}
},
bindscrolltolower: function () {
this.getData()
},
handleRefresherRefresh(e) {
this.data.select = {
page: 1,
size: 10,
isEnd: false
}
this.data.sendList = [];
this.getData()
},
onTabsChange(event) {
console.log(`Change tab, tab-panel value is ${event.detail.value}.`);
this.setData({
tab: event.detail.value
})
this.data.sendList = []
this.data.selectDate = []
this.data.select = {
page: 1,
size: 10,
isEnd: false
}
this.getData()
},
handleCalendar() {
this.setData({ visible: true });
},
handleConfirm(e) {
console.log(e.detail.value);
this.data.select = {
page: 1,
size: 10,
isEnd: false
}
this.data.sendList = [];
this.data.selectDate = e.detail.value
this.getData()
},
handleSearch(e) {
this.data.select = {
page: 1,
size: 10,
isEnd: false
}
this.data.sendList = [];
this.getData()
},
getData() {
if (this.data.select.isEnd) {
return
}
console.log(this.data.keyword)
const param = {
pageNo: this.data.select.page,
keyword: this.data.keyword,
taskState: this.data.tab + 1,
role: this.data.role,
userId: this.data.role != 'admin' ? app.globalData.currentUser.id : undefined,
teamId: this.data.role != 'admin' ? app.globalData.currentUser.jtTeamId : undefined,
startDate: this.data.selectDate.length > 1 ? formatTime(this.data.selectDate[0]) : '',
endDate: this.data.selectDate.length > 1 ? formatTime(this.data.selectDate[1]) + ' 23:59:59' : ''
}
getTaskList(param).then(res => {
const arr = [...this.data.sendList]
if (res.data && res.data.records && res.data.records.length > 0) {
this.data.select.page++
} else {
this.data.select.isEnd = true
}
const arr1 = res.data.records.map(e => {
return {
...e,
completeRate: (e.finishCount/e.totalCount * 100).toFixed(2)
}
})
const datas = arr.concat(arr1 || [])
this.setData({
refreshing: false,
sendList: datas,
select: this.data.select
})
}).catch(() => {
this.setData({
refreshing: false
})
})
},
goDetail(e) {
if (e.currentTarget.dataset.id) {
wx.navigateTo({
url: '/pages/detail/detail?id=' + e.currentTarget.dataset.id+'&isSubmit=' + e.currentTarget.dataset.submit+'&taskDoneId=' + e.currentTarget.dataset.done,
})
}
},
add() {
wx.navigateTo({
url: '/pages/task-edit/task-edit',
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({
role: app.globalData.currentUser.jtRoleCode,
tab: 0
})
this.data.tab = 0
this.data.sendList = [],
this.data.selectDate = []
this.data.select = {
page: 1,
size: 10,
isEnd: false
},
this.getData()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})