staffEdit.php
5.38 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/update" id="edit">
<input type="hidden" value="<?=$id?>" name="id">
<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="<?=$item->username?>">
</div>
<div class="form-group col-sm-4 col-md-2">
<label>真实姓名</label>
<input type="text" class="form-control input-text" name="name" value="<?=$item->name?>">
</div>
<div class="form-group col-sm-4 col-md-2">
<label>手机号</label>
<input type="text" class="form-control input-text" name="phone" value="<?=$item->telephone?>">
</div>
<div class="form-group col-sm-4 col-md-2">
<label>身份证号码</label>
<input type="text" class="form-control input-text" name="idCard" value="<?=$item->idCard?>">
</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 value="" selected>请选择</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 ?>" <?php if(in_array($vv->id,$roles)) echo 'selected';?> ><?= $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" multiple="multiple" size="5" name="roles" multiple>
<option selected value>请选择</option>
<?php foreach ($this->session->role as $k => $v): ?>
<option value="<?= $v->id ?>" <?php if($item->departmentId == $v->id) echo 'selected';?> ><?= $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="save()">保存</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 save() {
var targetUrl = $("#edit").attr("action");
var data = $("#edit").serializeJson();
var newData = {};
var rolesid = [];
if(data['roles'].length == 1){
rolesid.push(data['roles']);
}else{
rolesid = data['roles'];
}
newData = {
// newData['HrVO'] = {
name:data['name'],
username:data['username'],
telephone:data['phone'],
idCard:data['idCard'],
password:data['password'],
roleIds:rolesid,
// 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+$("input[name='id']").val(),
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("操作失败")
}
})
// window.parent.msg('修改成功');
layer_close();
}
</script>
</body>
<html>