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

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

$this->title = '选择用户';

$assetUrl = $this->getAssetManager()->getBundle(ModalAsset::className())->baseUrl;
$this->registerJsFile($assetUrl.'/js/link.select.js', ['depends' => ModalAsset::className()]);
?>
<style>
	.tab-pane{
		padding: 10px;
	}
	label {
		margin-right: 20px;
		font-weight: lighter;
	}
	.checkbox-user {
		position:relative;
		top:2px;
		left: -4px;
	}
</style>
<div class="modal-window" >
	
	<?php $searchForm = ActiveForm::begin([ 'id' => 'search-form', 'action' => '', 'method' => 'get']); ?>
		<div class="dialog-search fix rel">
				<span class="fl">关键字：</span>
				<input name="keywords" value="<?= (isset($get['keywords']))?Html::encode($get['keywords']):'' ?>" type="text" class="f12 form-control fl  dialog-search-control">
				<select name="search_field" class=" f12 form-control fl dialog-search-control">
					<option <?= (isset($get['search_field']) && $get['search_field'] == 'realname')?'selected="selected"':'' ?> value="realname">姓名</option>
				</select>
				<select name="dept_id" class=" f12 form-control fl dialog-search-control">
					<option value="">---所属部门---</option>
					<?php foreach(Department::getDropDownList() as $deptId => $name) : ?>
					<option <?= (isset($get['dept_id']) && $get['dept_id'] == $deptId)?'selected="selected"':'' ?> value="<?= $deptId ?>"><?= $name ?></option>
					<?php endforeach; ?>
				</select>

				<button class="btn btn-primary fl dialog-btn" type="submit">搜索</button>
		</div>
	<?php ActiveForm::end(); ?>

	<form method="post" action="" class="dialog-form" id="main-form">

		<ul class="nav nav-tabs" role="tablist" id="myTab">
			<?php $i = 0; foreach ($models as $model) : ?>
			<li role="presentation" <?= $i == 0 ? 'class="active"' : '' ?> ><a href="#dept<?= $model['dept_id'] ?>" role="tab" data-toggle="tab"><?= $model['name'] ?></a></li>
			<?php $i++; endforeach; ?>
		</ul>

		<div class="tab-content">
			<?php $i = 0; foreach ($models as $model) : ?>
			<div role="tabpanel" class="tab-pane <?= $i == 0 ? 'active' : '' ?>" id="dept<?= $model['dept_id'] ?>">
				<label ><input type="checkbox"  class="checkbox-user checkbox-select-all" name="select_all"> <strong>全选</strong></label><br />
				<?php if (empty($model['user'])) : ?>
					<p>暂无人员</p>
				<?php else : ?>
					<?php foreach ($model['user'] as $user) : ?>
                    <label ><input type="checkbox"  class="checkbox-user" name="user[]" <?= in_array($user['user_id'], $value) ? 'checked="checked"' : '' ?> value="<?= $user['user_id'] ?>" data-name="<?= $user['realname'] ?>" /><?= $user['realname'] ?></label>
					<?php endforeach; ?>
				<?php endif; ?>
			</div>
			<?php $i++; endforeach; ?>
		</div>

		

	</form>


</div>
