addListLogic.js
1.64 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
import {observable} from 'mobx'
import {_createList, _getListUser, _editList, _getTaskList} from "../service/AppService";
import {ownerUserId,ownerUserName} from "../service/rpc";
import Toast from "react-native-simple-toast";
export default class addListLogic {
@observable
text = ""
@observable
userList = []
rowVersion = ""
ownerUserId=""
async create() {
console.log(JSON.stringify(this.userList.map(v=>({userId:v.userId,userName:v.name}))),)
try{
const result = await _createList({
ownerUserId,
objectName: this.text,
objectType: "MANUAL",
userList: JSON.stringify(this.userList),
})
const {errors,firstErrorMessage,id}=result
if(errors.length>0){
Toast.show(firstErrorMessage)
return
}
return id
}catch(e){
console.warn(e)
}
}
async edit(params) {
const userList=JSON.stringify(this.userList.map(v=>{return {userId:v.userId,userName:v.userName,}}))
console.log(userList)
try{
const data =await _editList({
objectName: this.text,
...params,
userList: userList,
rowVersion: this.rowVersion,
ownerUserId:this.ownerUserId,
})
const {errors,firstErrorMessage,}=data
if(errors.length>0){
Toast.show(firstErrorMessage)
}
}catch(e){
console.warn(e)
}
}
async getTaskList(id) {
try{
const data = await _getTaskList({id})
const {taskList, userList,errors,firstErrorMessage,} = data
if(errors.length>0){
Toast.show(firstErrorMessage)
}else{
const {rowVersion, objectName} = taskList
this.rowVersion = rowVersion
this.text = objectName
this.userList.replace(userList)
this.ownerUserId=ownerUserId
}
}catch(e){
}
}
}