You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
simple-yewu/frontend/views/user/index.php

192 lines
8.2 KiB

<?php
use \common\libs\MyLib;
?>
<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js"></script>
<script type="text/javascript" language="javascript" src="/js/func.js"></script>
<script type="text/javascript" language="javascript">
//编辑
function edit(id) {
var params = $('#searchForm').serialize();
window.location.href = '/user/edit?id=' + id + '&back_params=' + encodeURIComponent(params);
}
//删除
function del(id) {
if(confirm('是否确认删除?')) {
$.post('/user/delete',{id:id},function(obj){
alert(obj.msg);
if(obj.success) {
window.location.reload();
}
},'json');
}
}
$(function(){
$("#search-btn").click(function(){
$('#page').val(0);
var params = $('#searchForm').serialize();
window.location.href = "/user/index?" + params;
});
$('#add-btn').click(function(){
window.location.href = "/user/edit?id=0";
});
$('#del-btn').click(function(){
if(confirm('是否确认删除?')) {
var params = $('#delFrm').serialize();
$.post('/user/all-delete',params,function(obj){
alert(obj.msg);
if(obj.success) {
window.location.reload();
}
},'json');
}
});
$('#all').click(function(){
if($(this).prop('checked')==true) {
$('input:checkbox').each(function() {
$(this).prop('checked', true);
});
} else {
$('input:checkbox').each(function () {
$(this).prop('checked',false);
});
}
});
//未删除,不让登陆的,可以说是异常
$(".abnormal").click(function(){
alert('异常,请联系管理员!');
return false;
});
});
</script>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
<form id="searchForm">
<input type="hidden" id="page" name="page" value="<?=$page?>">
<tr>
<td class="td_bg">
工号:<input name="username" type="text" value="<?=$username?>">
真实姓名:<input name="name" type="text" value="<?=$name?>">
电话:<input name="phone" type="text" value="<?=$phone?>">
是否离职:
<select name="is_leave">
<option value="">全部</option>
<option value="1" <?=$is_leave == '1' ? 'selected' : ''?>>是</option>
<option value="0" <?=$is_leave == '0' ? 'selected' : ''?>>否</option>
</select>
分组:<select name="group_id">
<option value="0">全部</option>
<?php
foreach($group_items as $group) {
echo '<option value="'.$group->id.'"';
if($group->id == $group_id)
echo ' selected ';
echo '>'.$group->name.'</option>';
}
?>
</select>
<input type="button" class="act_btn" id="search-btn" name="search-btn" value="搜索">
</td>
</tr>
<tr>
<td class="td_bg">
<input type="button" class="act_btn" id="add-btn" name="add-btn" value="添加">
<input type="button" class="act_btn" id="del-btn" name="del-btn" value="批量删除">
</td>
</tr>
</form>
</table>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
<tr>
<td align="center" width="24" align="center" class="bg_tr">
<input type="checkbox" id="all">
</td>
<td width="100" align="center" align="center" class="bg_tr">工号</td>
<td align="center" class="bg_tr">真实姓名</td>
<td width="100" align="center" class="bg_tr">联系电话</td>
<td width="60" align="center" class="bg_tr">允许登录</td>
<td align="center" class="bg_tr">所属岗位</td>
<td width="60" align="center" class="bg_tr">角色</td>
<td width="60" align="center" class="bg_tr">是否离职</td>
<td width="60" align="center" class="bg_tr">状态</td>
<td width="30" align="center" class="bg_tr">操作</td>
</tr>
<form id="delFrm">
<?php
foreach($items as $index => $item) {
?>
<tr onMouseOver=overColor(this) onMouseOut=outColor(this)>
<td align="center" class="td_bg" nowrap ><input type="checkbox" name="ids[]" value="<?=$item->id?>"></td>
<td align="left" class="td_bg" nowrap ><?=$item->username?></td>
<td class="td_bg" nowrap><?=$item->name?></td>
<td class="td_bg" nowrap><?=$item->phone?></td>
<td align="center" class="td_bg" nowrap><?=$item->is_login==1?'是':''?></td>
<td align="left" class="td_bg" nowrap><?=$item->group?$item->group->getPath():''?></td>
<td class="td_bg" nowrap><?=$item->role?$item->role->name:''?></td>
<td class="td_bg" nowrap><?=$item->is_leave?'已离职':''?></td>
<td align="center" class="td_bg" nowrap data="<?=$item->id?>">
<?php
if(($item->is_delete === 0) && ($item->is_login === 1)){
echo '<a href="javascript:;"><span style="color:#fff;font-size:14px;background:green;padding:0px 25px;" onclick="changeState(0,$(this))">√</span></a>';
}else if(($item->is_delete === 1) && ($item->is_login === 0)){
echo '<a href="javascript:;"><span style="color:#fff;font-size:14px;background:red;padding:0px 25px;" onclick="changeState(1,$(this))">×</span></a>';
}else{
echo '<a href="javascript:;"><span style="color:#fff;font-size:14px;background:#b5b5b5;padding:0px 25px;" class="abnormal">?</span></a>';
}
?>
</td>
<td align="center" class="td_bg" nowrap>
[<a href="javascript:void(0);" onclick="edit(<?=$item->id?>)">修改</a>]
<?php
if($item->username != 'admin') {
?>
[<a href="javascript:void(0);" onclick="del(<?= $item->id ?>)">删除</a>]
<?php
}
?>
</td>
</tr>
<?php
}
?>
</form>
<tr >
<td height="25" colspan="11" align="center" class="td_bg"><?=$page_info?></td>
</tr>
</table>
<script type="text/javascript" language="javascript" src="/js/common2.js"></script>
<script>
/**
* 改变状态
*/
function changeState(state,this_dom){
var this_text = this_dom.parents("td");
var father = this_text.parents("tr");
var id = this_text.attr("data");
$.post("/user/deal-state",{id:id,state:state},function(obj){
if(obj.success) {
if(state == 1){
this_text.html('<a href="javascript:;"><span style="color:#fff;font-size:14px;background:green;padding:0px 25px;" onclick="changeState(0,$(this))">√</span></a>');
father.find("td").eq(4).html('是');
}else{
this_text.html('<a href="javascript:;"><span style="color:#fff;font-size:14px;background:red;padding:0px 25px;" onclick="changeState(1,$(this))">×</span></a>');
father.find("td").eq(4).html('');
}
}else{
alert(obj.msg);
window.location.reload();
}
},'json');
}
//回车搜索
mySearch('username', 'search-btn');
mySearch('name', 'search-btn');
mySearch('phone', 'search-btn');
</script>