<?php
use yii\helpers\Url;
use yii\helpers\StringHelper;
use yii\helpers\ArrayHelper;
use home\modules\customer\models\Customer;
use common\models\User;

?>
<div class="p15">

    <table class="table task-table ">
        <tbody>
            <tr>
                <th width="24%">客户名称</th>
                <th width="10%">类别</th>
                <th width="10%">负责人</th>
                <th width="16%">共享人</th>
                <th width="20%">客户地址</th>
                <th width="20%">操作</th>
            </tr>
            <?php if (!empty($customers)) : ?>
            <?php foreach ($customers as $model) : ?>
            <tr>
                <!-- 客户名称 -->
                <?php if(Customer::readAccess('customer/customer/detail')) : ?>
                    <td class="theleft-min" title="<?= $model['name']; ?>" ><a href="<?= Url::to(['/customer/customer/detail', 'id' => $model['customer_id'], 'from' => Url::to('')]) ?>  ">
                            <?= StringHelper::truncate($model['name'], 10, '') ?>
                        </a>
                    </td>
                <?php else : ?>
                    <td class="theleft-min" title="<?= $model['name']; ?>" ><?= StringHelper::truncate($model['name'], 10, '') ?></td>
                <?php endif; ?>
                <!-- 客户类别 -->
                <td><?= empty($model['category']['name']) ? '' : $model['category']['name'] ?></td>
                
                <!-- 负责人 -->
                <td> <?= empty($model['leader']['realname']) ? '' : $model['leader']['realname'] ?></td>
                <!-- 共享人 -->
                <td> <?= empty($model['share_user_ids']) ? '' : implode(',', ArrayHelper::getColumn(User::getUserByDot($model['share_user_ids']), 'realname')) ?></td>
                <!-- 地址 -->
                <td title="<?= $model['address'] ?>"> <?= StringHelper::truncate($model['address'], 10, '') ?></td>
                
                <!-- 操作 -->
                <td align="center" >
                    <?php if(Customer::readAccess('sale/opportunity/create')) : ?>
                        <a target="_blank" href="<?= Url::to(['/sale/opportunity/create', 'customer_no' => $model['customer_no'], 'customer_name' => $model['name'],'from' => Url::to('')]) ?>">销售机会</a>
                    <?php else : ?>
                        <a href="javascript:;" class="gray" title="当前没有权限添加销售机会">销售机会</a>
                    <?php endif; ?>

                    <?php if(Customer::readAccess('home/schedule/link-customer')) : ?>
                        <a href="javascript:;" data-url="<?= Url::to(['/schedule/create', 'link_id' => $model['customer_no'], 'link_type' => 'customer']) ?>" data-title="添加日程"  data-width="600" data-height="380" class="open-dialog" >日程</a>
                    <?php else : ?>
                        <a href="javascript:;" class="gray" title="当前没有权限添加日程">日程</a>
                    <?php endif; ?>

                    <?php if(Customer::readAccess('reimbursement/reimbursement/create')) : ?>
                        <a href="javascript:;" data-url="<?= Url::to(['/reimbursement/reimbursement/create', 'link_id' => $model['customer_no'], 'link_type' => 'customer']) ?>" data-title="我要报销" data-width="600" data-height="380" class="open-dialog">报销</a>
                    <?php else : ?>
                        <a href="javascript:;" class="gray" title="当前没有权限添加报销">报销</a>
                    <?php endif; ?>
                </td>


            </tr>
            <?php endforeach; ?>
            <tr><td colspan="7"><a href="<?= Url::to(['/customer/customer/index']) ?>" >更多客户...</a></td></tr>
            <?php else : ?>
            <tr><td colspan="7">暂无数据...</td></tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>
