home.js
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import * as types from '../constants/ActionTypes';
import {insertTodo,getTodo,finsish_Todo,removeToto} from '../../utils/homeUtil';
import calendarUtil from '../../utils/calendarUtil';
import { message } from 'antd';
import moment from 'moment';
import { getCurrentMonthFirst, getNextMonthFirst } from "../../utils/commonUtils"
//新增待办
export function createTodo(values){
return dispatch => {
return insertTodo(values)
.then(data => {
if(data&&data.code>=300){
message.error(data.message,2,)
}else{
message.success('创建成功',2);
dispatch(loadTodo(values.currentDay));
}
})
.catch(err => { throw err; });
};
}
//获取待办事项列表
// currentDay : moment day;
//state : string 0未完成,1已完成
export function loadTodo(currentDay,state){
return dispatch => {
const months=calendarUtil.getMonthsStartEnd(currentDay.format('YYYY'),currentDay.format('MM'));
let parmas=''
if(currentDay){
parmas=parmas+`&begin_time=${moment(months[0]).unix()}&end_time=${moment(months[1]).unix()}`;
}
if(state){
parmas=parmas+`&state=${state}`
}
dispatch(loadTodoForDay(currentDay));
return getTodo(parmas)
.then(data => {
const {items,total_count}= data;
dispatch({
type: types.TO_DO_LIST,
todoList:items,
todoListCount:total_count
})
})
.catch(err => { throw err; });
};
}
//获取指定一天
export function loadTodoForDay(currentDay,state){
return dispatch => {
const start=moment(currentDay.format('YYYY-MM-DD')+' 00:00:01' );
const end=moment(currentDay.format('YYYY-MM-DD')+' 23:59:59');
let parmas=''
if(currentDay){
parmas=parmas+`&begin_time=${start.unix()}&end_time=${end.unix()}`;
}
if(state=="0"){
parmas=parmas+`&state=${state}`
}
return getTodo(parmas)
.then(data => {
const {items=[]}= data;
dispatch({
type: types.TO_DO_TODAY_LIST,
todayList:items
})
})
.catch(err => { throw err; });
};
}
export function finishTodo(todo){
return dispatch => {
return finsish_Todo(todo.id)
.then(data => {
if(data&&data.state){
message.success('操作成功',2)
dispatch(loadTodo(moment(todo.begin_time*1000)));
}else{
message.error(data.message,2)
}
return data;
})
.catch(err => { throw err; });
};
}
export function deleteTodo(todo){
return dispatch => {
return removeToto(todo.id)
.then(data => {
if(data&&data.action){
message.success("删除成功",2)
dispatch(loadTodo(moment(todo.begin_time*1000)));
}else{
message.error(data.message,2)
}
return data;
})
.catch(err => { throw err; });
};
}
export function loadDone(offset,limit){
return dispatch => {
return getTodo(offset,limit,1)
.then(data => {
const {items,total_count}= data;
dispatch({
type: types.DONE_LIST,
doneList:items,
doneListCount:total_count
})
})
.catch(err => { throw err; });
};
}
// 获取一个月的社保代办
export function getOneMonths() {
let parmas = ""
const begin_time = getCurrentMonthFirst();
const end_time = getNextMonthFirst()
parmas = `&begin_time=${begin_time}&end_time=${(end_time - 1)}&state=0`;
return dispatch => {
return getTodo(parmas)
.then(data => {
const { items, total_count } = data;
dispatch({
type: types.DONE_LIST,
doneList: items,
doneListCount: total_count
})
return data
})
.catch(err => { throw err; });
};
}