<?php
use yii\helpers\Url;
use qcbase\assets\MenuAsset;
use qcbase\models\Department;
use yii\widgets\ActiveForm;
use common\models\User;
use yii\helpers\StringHelper;

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \qcbase\models\Department */

?>
<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('/department/_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" class="box-select-all" />全选</td>
                <td width="50">排序</td>
                <td width="5%">ID</td>
                <td>部门名称</td>
                <td>部门领导</td>
                <td width="20%">人员</td>
                <td>创建时间</td>
                <td>状态</td>
                <td width="200" 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" <?= ($model['child_ids'] == $model['dept_id'])? '' : 'disabled="true"' ?> value="<?= $model['dept_id'] ?>" class="box-delete" name="delete[]"></td>
				<td align="center" style="vertical-align: middle;">
				<input type="text" name="sort[<?= $model['dept_id'] ?>]" class="input" value="<?= $model['sort'] ?>" size="4">
				</td>
				<td><?= $model['dept_id'] ?></td>
				<td><?= $model['tree_spacer'] . $model['name'] ?></td>
				<td><?= (isset($model['leader']['realname']) ||isset($model['leader']['username']) )? $model['leader']['realname'] ."[". $model['leader']['username'] ."]": '' ?></td>
                <td title="<?= $model['allUserStr'] ?>"><?= StringHelper::truncate($model['allUserStr'], 50) ?></td>
				<td><?= date('Y-m-d H:i:s',$model['create_time']) ?></td>
				<td align="center"><?= ($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['dept_id']]) ?>"> 修改 </a>&nbsp;&nbsp;|&nbsp;&nbsp;
					<a href="<?= Url::to([$this->context->id.'/create', 'parent_id' => $model['dept_id']]) ?>"> 添加子部门 </a>&nbsp;&nbsp;|&nbsp;&nbsp;
					<?php if ($model['child_ids'] == $model['dept_id']) : ?>
					<a class="link-delete" href="<?= Url::to([$this->context->id.'/delete', 'id'=>$model['dept_id']]) ?>">删除</a>
					<?php else : ?>
					<a class="link-undelete gray" href="javascript:;">删除</a>
					<?php endif; ?>
				</td>
            </tr>
			<?php endforeach; ?>
        <?php endif; ?>
    </table>
    <?php ActiveForm::end(); ?>
</div>
<div class="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>
        <button class="btn  mr10 batch-sort" data-url="<?= Url::to([$this->context->id.'/sort']) ?>" type="submit">排序</button>
    </div>
</div>

