<?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'] == 'name') ? 'selected="selected"' : '' ?> value="name">客户名称</option>
            <option <?= (isset($get['search_field']) && $get['search_field'] == 'simple_name') ? 'selected="selected"' : '' ?> value="simple_name">客户简称</option>
        </select>
        <select name="cat_id" class=" f12 form-control fl dialog-search-control">
            <option value="">---所属分类---</option>
<?= home\modules\customer\models\Category::getDropDownTree((isset($get['cat_id'])) ? $get['cat_id'] : '') ?>
        </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="140" style="padding-left:10px;">编号</th>
                    <th >客户名称</th>
                    <th >客户简称</th>
                    <th >分类</th>
                    <th >区域</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['customer_no'] ?></td>
                            <td title="<?=$model['name']?>">
                            <a href="<?= Url::to(['/customer/customer/detail', 'id' => $model['customer_id']]) ?>" target="_blank">
                            <?= !empty($model['name'])? StringHelper::truncate($model['name'], 15):''?>
                            </a>
                            </td>
                            <td><?= $model['simple_name'] ?></td>
                            <td><?= $model['category']['name'] ?></td>
                            <td><?= $model['district']['name'] ?></td>
                            <td>
                                <a class="select" data-id="<?= $model['customer_no'] ?>" data-name="<?= $model['name'] ?>" 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>
