staffAdd.php
5.05 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
<?php $this->load->view('common/header'); ?>
<body>
<div class="panel panel-default">
<div class="panel-body">
<form action="system/user/add" id="add">
<div class="row cl">
<div class="form-group col-sm-4 col-md-2">
<label>用户名</label>
<input type="text" class="form-control input-text" name="username" value="">
</div>
<div class="form-group col-sm-4 col-md-2">
<label>真实姓名</label>
<input type="text" class="form-control input-text" name="name" value="">
</div>
<div class="form-group col-sm-4 col-md-2">
<label>手机号</label>
<input type="text" class="form-control input-text" name="phone" value="">
</div>
<div class="form-group col-sm-4 col-md-2">
<label>身份证号码</label>
<input type="text" class="form-control input-text" name="" value="">
</div>
</div>
<div class="row cl">
<div class="form-group col-sm-4 col-md-2">
<label>设置密码</label>
<input type="text" class="form-control input-text" value="" name="password" id="password">
</div>
<div class="form-group col-sm-4 col-md-2 pt-25">
<button class="btn btn-primary" onclick="random()">随机生成密码</button>
</div>
</div>
<div class="row cl">
<div class="form-group col-sm-4 col-md-2">
<label>所属网点</label>
<select class="select" name="children" size="5" multiple>
<option selected value>请选择</option>
<?php foreach ($this->session->departments as $k => $v): ?>
<option value="<?= $v->id ?>"><?= $v->name ?></option>
<?php if ($v->children && !empty($v->children)): ?>
<?php foreach ($v->children as $kk => $vv): ?>
<option value="<?= $vv->id ?>"><?= $vv->name ?></option>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-sm-4 col-md-2">
<label>角色</label>
<select class="select" size="5" name="roles" multiple>
<option selected value>请选择</option>
<?php foreach ($this->session->role as $k => $v): ?>
<option value="<?= $v->id ?>"><?= $v->nameZh ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</form>
</div>
</div>
<div class="row cl pt-20 pb-20 col-sm-12">
<div class="col-sm-offset-4 col-sm-2">
<button class="btn btn-primary btn-block" onclick="saveStaff()">保存</button>
</div>
<div class="col-sm-2">
<button class="btn btn-warning btn-block" onclick="layer_close()">取消</button>
</div>
</div>
<?php $this->load->view('common/footer'); ?>
<script>
function random() {
var password = 'aoeuaoeu';
$('#password').val(password);
}
function saveStaff() {
var targetUrl = $("#add").attr("action");
var data = $("#add").serializeJson();
var newData = {};
newData = {
// newData['HrVO'] = {
name:data['name'],
username:data['username'],
telephone:data['phone'],
// phone:data['phone'],
password:data['password'],
roleIds:data['roles'],
// roles:data['roles'],
departmentId:data['children']
};
// newData['DepartmentVO'] = {
// children:data['children']
// departmentId:data['children']
// };
// console.log(JSON.stringify(newData));
// return false;
$.ajax({
type: 'post',
url: apiBaseUrl + targetUrl,
cache: false,
data: JSON.stringify(newData),
dataType: 'json',
contentType: "application/json; charset=UTF-8",
success: function (data) {
// console.log(data);
if (data.msg) {
layer.alert(data.msg);
} else if (data.code != 0) {
layer.alert('操作失败');
} else {
layer.msg('操作成功');
}
if (data.code) {
setTimeout(function () {
window.parent.reload();
layer_close();
}, 500);
}
},
error: function () {
layer.alert("操作失败")
}
})
}
</script>
</body>
<html>