-
Notifications
You must be signed in to change notification settings - Fork 37
/
action.js
86 lines (66 loc) · 2.08 KB
/
action.js
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
import { actionMixin, fetch } from 'maka'
import React from 'react'
@actionMixin('base', 'lodash', 'moment', 'modal', 'message')
export default class action {
constructor(option) {
Object.assign(this, option.mixins)
}
onInit = () => {
if (this.component.props.setOkListener)
this.component.props.setOkListener(this.onOk)
this.load()
}
load = async () => {
if (this.component.props.personId || this.component.props.personId == 0) {
var resp = await fetch.post('/v1/person/findById', { id: this.component.props.personId })
this.base.setState({ 'data.form': resp })
}
}
onOk = async () => {
return await this.save()
}
save = async () => {
const form = this.base.gs('data.form')
const msg = this.checkSave(form)
if (msg.length > 0) {
this.message.error(
<ul style={{ textAlign: 'left' }}>
{msg.map(o => <li>{o}</li>)}
</ul>
)
return false
}
var isModify = (form.id || form.id == 0)
var resp
if (isModify) {
resp = await fetch.post('/v1/person/update', form)
}
else {
resp = await fetch.post('/v1/person/create', form)
}
this.base.setState({ 'data.form': resp })
this.message.success(isModify ? '修改人员成功' : '新增人员成功')
return resp
}
checkSave = (form) => {
var msg = []
!form.name && msg.push('请录入姓名!');
!form.department && msg.push('请录入部门!');
!form.sex && msg.push('请录入性别!');
!form.birthday && msg.push('请录入生日!');
!form.mobile && msg.push('请录入手机!');
return msg
}
loadSex = async () => {
return [{
id: 0,
name: '女'
}, {
id: 1,
name: '男'
}]
}
loadDepartment = async () => {
return await fetch.post('/v1/department/queryAll', {})
}
}