<?php

use home\assets\MainAsset;
use yii\helpers\Url;
use home\modules\customer\models\Contacter;
use yii\widgets\ActiveForm;
use common\components\Tool;
use yii\helpers\StringHelper;

/* @var $this yii\web\View */
$this->title = '联系人列表';


$assetUrl = $this->getAssetManager()->getBundle(MainAsset::className())->baseUrl;
$this->registerJsFile($assetUrl . '/js/table.designer.js', ['depends' => MainAsset::className()]);
?>

<!--container-->
<div class="container manage-project fix">
    <?= $this->render('@home/views/site/_left-menu') ?>
    <!--manage-left -->

    <div class="manage-right">
        <div class="tab-column tab-manage">
            <div class="tab-right">
                <?php if (Contacter::readAccess('customer/contacter/create')) : ?>
                    <button type="button" title="添加联系人" data-url='<?= Url::to([$this->context->id . '/create']) ?>' data-title='添加联系人' data-width="610" data-height="254" class="btn btn-default btn-task open-dialog">
                      <i class="icon-plus"></i>
                    </button>
                <?php endif; ?>
            </div>
            <p class="caption">联系人列表</p>
        </div>
        <?= \home\widgets\Alert::widget(); ?>
        <?= $this->render('@home/views/site/_search', ['model' => $model, 'get' => $get]) ?>
        <?php $mainForm = ActiveForm::begin([ 'id' => 'main-form', 'action' => '']); ?>
        <table class="table task-table design_table" data-rowspan="1" >

            <tr>
<!--                    <th width="60"><label style="font-weight:lighter" ><input type="checkbox" name="select_all" class="box-select-all" style="position:relative;top:2px;" /> 全选</label></th>-->
                <th width="25%">所属客户</th>
                <th width="10%">联系人名称</th>
                <th width="20%">职务</th>
                <th width="16%">联系电话</th>
                <th width="10%">创建人</th>
                <th width="50">状态</th>
                <th align="center">操作</th>
            </tr>
            <?php if (empty($models)) : ?>
                <tr><td colspan="10" class="tac red">还没有任何数据...</td></tr>
            <?php else : ?>
                <?php foreach ($models as $key => $model) : ?>
                    <tr>
                        <!--<td><input type="checkbox" name="delete[]" class="box-delete" value="<?= $model['contacter_id'] ?>" /></td>-->
                        <td class='theleft-min' title="<?= empty($model['customer']['name']) ? '' : $model['customer']['name'] ?>">
                            <a target="_blank" href="<?= !empty($model['customer']['name']) ? Url::to(['/customer/customer/detail', 'id' => $model['customer']['customer_id']]) : 'javascript:;' ?>">
                                <?= empty($model['customer']['name']) ? '' : StringHelper::truncate($model['customer']['name'], 17) ?>
                            </a>
                        </td>
                        <td class='theleft-min' title="<?= $model['name'] ?>"><a  href="javascript:void(0);"  data-title='<?= $model->name ?>' data-url='<?= Url::to([$this->context->id . '/detail', 'id' => $model->contacter_id]) ?>' data-height='200' data-width='440' class="open-only-see-dialog"><?=
                                StringHelper::truncate($model['name'], 8)
                                ?></a></td>
                        <td class='theleft-min' title="<?= $model['job'] ?>"><?= empty($model['job']) ? '' : StringHelper::truncate($model['job'], 12) ?></td>
                        <td class='theleft-min'><?= empty($model['phone']) ? '' : $model['phone'] ?></td>
                        <td class='theleft-min'><?=$model['user']['realname']?></td>
                        <td><?= ($model['status'] == Contacter::STATUS_ENABLE) ? '<font color="green">启用</font>' : '<font color="red">禁用</font>' ?></td>
                        <td align="center" >
                            <?php if (Contacter::readAccess('customer/contacter/view')) : ?>
                                <a href="javascript:;" class="open-dialog"  data-url="<?= Url::to([$this->context->id . '/view', 'id' => $model['contacter_id']]) ?>" data-width="610" data-height="254" data-title='编辑联系人-<?= $model->name ?>' >编辑</a>
                            <?php else : ?>
                                <a href="javascript:;" class="gray" title="当前没有编辑权限">编辑</a>
                            <?php endif; ?>
                            <?php if (Contacter::readAccess('customer/contacter/delete')) : ?>
                                <a href="<?= Url::to([$this->context->id . '/delete', 'id' => $model['contacter_id']]) ?>" class="link-delete" >删除</a>
                            <?php else : ?>
                                <a href="javascript:;" class="gray" title="当前没有删除权限">删除</a>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </table>
        <!-- <div class="tab-column tab-manage">
            <button type="button" class="btn btn-default btn-task batch-delete" data-url="<?= Url::to([$this->context->id . '/delete']) ?>" >
                <a href="javascript:;">删除</a>
            </button>
        </div> -->
        <?php ActiveForm::end(); ?>
        <!--分页标签-->
        <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>
    <!--manage-right-->
</div>
<!--container-->

