<?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 common\assets\ArtDialogAsset;
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(), ArtDialogAsset::className()]]);
?>

<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">
		<table class="table task-table dialog-table">
			<tbody>
				<tr>
					<th width="100" style="padding-left:10px;">姓名</th>
					<th >部门</th>
					<th >角色</th>
					<th width="50" style="text-align:center">性别</th>
					<th width="100">手机</th>
					<th width="50">操作</th>
				</tr>
				<?php if (empty($models)) : ?>
				<tr><td colspan="6" class="tac red" style="text-align: center;">没有任何数据...</td></tr>
				<?php else : ?>
				<?php foreach($models as $model) : ?>
				<tr title="双击选择此列" class="select-tr">
					<td style="padding-left:10px;"><?= $model['realname'] ?></td>
					<td><?= implode('，', $model['depts']) ?></td>
					<td><?= implode('，', $model['roles']) ?></td>
					<td style="text-align:center"><?= ($model['gender'] == User::GENDER_MALE) ? '男' : '女' ?></td>
					<td><?= empty($model['phone'])?'':$model['phone'] ?></td>
					<td>
						<a class="select" data-id="<?= $model['user_id'] ?>" data-name="<?= $model['realname'] ?>" href="javascript:;" title="单击选择">选择</a>
					</td>
				</tr>
				<?php endforeach; ?>
				<?php endif; ?>
			</tbody>
		</table>
	</form>

    <div class="pages">
        <?php if ($pages->totalCount != 0) : ?><span class="pagetotal">共<em><?= $pages->totalCount ?></em>条记录<em><?= $pages->page + 1 ?>/<?= $pages->pageCount ?></em>页 </span><?php endif; ?>
        <?= \yii\widgets\LinkPager::widget(['pagination' => $pages, 'prevPageLabel' => '上一页','nextPageLabel' => '下一页', 'firstPageLabel' => '首页', 'lastPageLabel' => '末页']); ?>
    </div>

</div>
