taskDetailLogic.js
5 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import {observable} from 'mobx'
import {
_getTask,
_updateTask,
_commentList,
_commentCreate,
_postFileIds,
_getFiles,
_del
} from "../service/AppService";
import moment from 'moment';
import 'moment/locale/zh-cn';
import {upload,ownerUserId} from "../service/rpc";
import Toast from "react-native-simple-toast";
export default class taskDetailLogic {
@observable
expireDate = ''
@observable
remindDate = ""
@observable
children = []
@observable
annex = []
@observable
annexResult = []
@observable
text = ''
@observable
name = ""
@observable
isStar = false
@observable
comment = []
@observable
userList = []
id = ""
objectType = ""
objectId = ""
objectCategory = ""
rowVersion = ""
ownerUserId = ""
listId = ""
task = null
isDone = false
ownerUserName = ""
async getTask() {
try {
const result = await _getTask({id: this.id})
const {errors, firstErrorMessage, task, subtaskList, userList} = result
if (errors.length > 0) {
// Toast.show(firstErrorMessage)
} else {
const {
deadlineDate, hasDeadline, hasSubtask, id, isDone, isOverdue,
isStar, listId, needReminding, objectCategory, objectDescription
, objectId, objectName, objectType, ownerUserId, ownerUserName, remndingTime, rowVersion, subtaskCount, subtaskDoneCount,
} = task
this.task = task
this.objectType = objectType
this.objectId = objectId
this.name = objectName
this.objectCategory = objectCategory
this.isStar = isStar
this.rowVersion = rowVersion
this.ownerUserId = ownerUserId
this.ownerUserName = ownerUserName
this.listId = listId
if (needReminding) {
this.remindDate = moment(remndingTime - 0).format("YYYY-MM-DD HH:mm:ss")
}
if (hasDeadline) {
this.expireDate = moment(deadlineDate - 0).format("YYYY-MM-DD")
}
if (hasSubtask) {
this.children.clear()
subtaskList.map(v => {
if (!v.isDone) {
v.isDone = false
}
this.children.push(v)
})
}
if (isDone) {
this.isDone = isDone
}
this.userList.replace(userList)
}
} catch (e) {
}
}
async getFiles() {
try {
const data = await _getFiles({
businessId: this.id,
businessType: "COLLABORATION_TASK",
businessCategory: "TASK",
})
const {errors, firstErrorMessage,} = data
if (errors.length > 0) {
// Toast.show(firstErrorMessage)
} else {
const {attachmentList} = data
this.annexResult.replace(attachmentList)
}
} catch (e) {
}
}
async send() {
try {
const result = await _commentCreate({
businessId: this.id,
businessType: "TASKLIST_TASK",
Anonymous: false,
userId: ownerUserId,
content: this.text
})
const {errors, firstErrorMessage,} = result
if (errors.length > 0) {
Toast.show(firstErrorMessage)
} else {
this.text = ""
}
} catch (e) {
}
}
async uploadFile(pic) {
this.annex.clear()
if (pic instanceof Array) {
pic.map(v => {
const {path} = v
this.annex.push("file://" + path)
})
} else {
this.annex.push("file://" + pic.path)
}
try {
const result = await Promise.all(this.annex.map(v => upload(v)))
const result1 = await Promise.all(result.map(v => _postFileIds({
fileId: v.id,
businessId: this.id,
businessType: "COLLABORATION_TASK",
businessCategory: "TASK",
})))
console.log(result1)
} catch (e) {
}
}
async getCommentList() {
try {
const data = await _commentList({
businessType: "TASKLIST_TASK",
businessId: this.id,
})
const {result, errors, firstErrorMessage} = data
if (errors.length > 0) {
// Toast.show(firstErrorMessage)
} else {
this.comment.replace(result)
}
} catch (e) {
}
}
async update() {
const options =
{
id: this.id,
objectType: this.objectType,
objectId: this.objectId,
objectCategory: this.objectCategory,
objectName: this.name,
isStar: this.isStar,
rowVersion: this.rowVersion,
ownerUserId: this.ownerUserId,
listId: this.listId,
isDone: this.isDone,
ownerUserName: this.ownerUserName
}
if (!!this.expireDate) {
options.hasDeadline = true
options.deadlineDate = moment(new Date(this.expireDate).getTime()).format("YYYY-MM-DD HH:mm:ss")
} else {
options.hasDeadline = false
}
if (!!this.remindDate) {
options.needReminding = true
options.remndingTime = this.remindDate
} else {
options.needReminding = false
}
if (this.children.length > 0) {
options.hasSubtask = true
options.subtaskList = JSON.stringify(this.children.peek())
} else {
options.hasSubtask = false
}
const userList = JSON.stringify(this.userList.map(v => {
return {userId: v.userId, username: v.userName}
}))
console.log(userList)
options.userList = userList
try {
const data = await _updateTask(options)
} catch (e) {
}
}
async del(attachmentId) {
try {
const data = await _del({attachmentId})
const {errors, firstErrorMessage} = data
if (errors.length > 0) {
Toast.show(firstErrorMessage)
} else {
}
} catch (e) {
}
}
}