<?php

use yii\helpers\Url;
use common\models\User;
use yii\widgets\ActiveForm;
use qcbase\models\Auth;
use qcbase\models\Department;
use yii\helpers\ArrayHelper;
use qcbase\assets\RoleAuthAsset;

RoleAuthAsset::register($this);

/* @var $this yii\web\View */
?>

<div class="nav">
    <ul class="cc">
        <li class="current"><a href="<?= Url::to([$this->context->id . '/index']) ?>">用户管理</a></li>
        <li ><a href="<?= Url::to([$this->context->id . '/create']) ?>">添加用户</a></li>
    </ul>
</div>

<div class="h_a">温馨提示</div>
<div class="prompt_text">
    <p>请在添加、修改完所有用户后，<a href="javascript:parent.iframeJudge({elem:this, id:'cache', title:'更新缓存', href:'<?= Url::to(['/site/cache']) ?>' });">更新缓存</a>，否则数据将不会同步更新 !</p>
</div>


<?= $this->render('/site/_search', ['get' => $get, 'model' => $model]); ?>

<div class="table_list">
    <?php $mainForm = ActiveForm::begin([ 'id' => 'main-form', 'action' => '']); ?>
    <table width="100%">
        <thead>
            <tr>
                <td width="50"><input type="checkbox" name="select_all" class="box-select-all" />全选</td>
                <td width="5%">ID</td>
                <td>工号</td>
                <td>姓名</td>
                <td>用户名</td>
                <td>部门</td>
                <td>角色</td>
                <td>联系方式</td>
                <td>性别</td>
                <td>最后登录ip</td>
                <td>最后登录时间</td>
                <td>状态</td>
                <td width="120" align="center">操作</td>
            </tr>
        </thead>
        <?php if (empty($models)) : ?>
            <tr><td colspan="10" class="tac red">还没有任何数据...</td></tr>
        <?php else : ?>
            <?php foreach ($models as $model) : ?>
                <tr>
                    <td><input type="checkbox" name="delete[]" class="box-delete" value="<?= $model->user_id ?>" /></td>
                    <td><?= $model->user_id ?></td>
                    <td><?= $model->user_no ?></td>
                    <td><?= empty($model->realname) ? '' : $model->realname ?></td>
                    <td><?= $model->username ?></td>
                    <td><?= implode('，', ArrayHelper::getColumn($model->dept, 'name')) ?></td>
                    <td><?= implode('，', array_keys(Auth::getRolesByUser($model->user_id))) ?></td>
                    <td><?= empty($model->info->phone) ? '' : $model->info->phone ?></td>
                    <td><?= ($model->gender == User::GENDER_MALE) ? '男' : '女' ?></td>
                    <td><?= (empty($model->last_login_ip)) ? '未登录过' : $model->last_login_ip ?></td>
                    <td><?= (empty($model->last_login_time)) ? '未登录过' : date('Y-m-d H:i:s', $model->last_login_time) ?></td>
                    <td><?= ($model->status == User::STATUS_ENABLE) ? '<font color="green">启用</font>' : '<font color="red">禁用</font>' ?></td>
                    <td align="center" >
                        <a href="<?= Url::to([$this->context->id . '/view', 'id' => $model->user_id]) ?>" >编辑</a>&nbsp;&nbsp;|&nbsp;&nbsp;
                        <a href="<?= Url::to([$this->context->id . '/delete', 'id' => $model->user_id]) ?>" class="link-delete" >删除</a>
                    </td>
                </tr>
            <?php endforeach; ?>
        <?php endif; ?>

    </table>
    <?php ActiveForm::end(); ?>
</div>
<div class="pages">
    <?=
    \yii\widgets\LinkPager::widget([
        'pagination' => $pages,
    ]);
    ?>
</div>

<div class="btn_wrap">
    <div class="btn_wrap_pd">
        <button class="btn btn_submit mr10 batch-delete" data-url="<?= Url::to([$this->context->id . '/delete', 'id' => '']) ?>" type="submit" >删除</button>
    </div>
</div>

