<?php

use home\assets\MainAsset;
use yii\helpers\Url;
use home\modules\sale\models\Opportunity;
use home\modules\sale\models\Category;
use home\modules\sale\models\Status;
use yii\widgets\ActiveForm;
use common\models\User;
use yii\helpers\StringHelper;

/* @var $this \yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \home\modules\sale\models\Opportunity */

$this->title = '销售机会列表';
?>

<!--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">

                <button type="button"  title="添加销售机会" class="btn btn-default btn-task open-dialog"  data-url="<?= Url::to(['create', 'from' => Url::to('')]) ?>" data-title="销售机会" data-width="650" data-height="400" >
                   <i class="icon-plus"></i>
                </button>

            </div>
            <p class="caption">销售机会列表</p>
        </div>
        <?= \home\widgets\Alert::widget(); ?>
        <?= $this->render('_search', ['model' => $model, 'get' => $get]) ?>
        <?php $mainForm = ActiveForm::begin([ 'id' => 'main-form', 'action' => '']); ?>
        <table class="table task-table">
            <tr>
                <!-- <th width="40"><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="20%">客户</th>
                <th width="10%">来源</th>
                <th width="10%">负责人</th>
                <th width="7%">热点</th>
                <th width="10%">阶段</th>
                <th width="10%">状态</th>
                <th width="50" align="center">操作</th>
            </tr>
            <?php if (empty($models)) : ?>
                <tr><td colspan="10" class="tac red">还没有任何数据...</td></tr>
            <?php else : ?>
                <?php foreach ($models as $model) : ?>
                    <tr>
                        <!-- <td><input type="checkbox" name="delete[]" class="box-delete" value="<?= $model->opportunity_id ?>" /></td> -->
                        <td class='theleft-min' title="<?= $model->name ?>">
                            <a target="_blank" href="<?= Url::to([$this->context->id . '/detail', 'id' => $model->opportunity_id, 'from' => Url::to('')]) ?>">
                                <?= StringHelper::truncate($model->name, 11) ?>
                            </a>
                        </td>
                        <?php if (isset($model->customer)) : ?>
                            <td class='theleft-min' title="<?= $model->customer->name ?>">
                                <a target="_blank" href="<?= Url::to(['/customer/customer/detail', 'id' => $model->customer->customer_id]) ?>">
                                    <?= StringHelper::truncate($model->customer->name, 12) ?>
                                </a>
                            </td>
                        <?php else : ?>
                            <td class='theleft-min' title="">
                                
                            </td>
                        <?php endif; ?>

                        <td><?= isset($model->origin) ? $model->origin->name : '' ?></td>
                        <td><?= isset($model->leader->realname) ? $model->leader->realname : '' ?></td>
                        <td><?= ($model['attention'] == Opportunity::STATUS_ENABLE) ? '<font color="green"><i class="icon-star"></i></font>' : '<font color="red"></font>' ?></td>
                        <td><?= isset($model->category) ? $model->category->name : '' ?></td>
                        <td><?= isset($model->saleStatus) ? $model->saleStatus->name : '' ?></td>
                        <td align="center" >
                            <?php if(Opportunity::readAccess('schedule/schedule/link-sale_opportunity')) : ?>
                                <a href="javascript:;" data-url='<?= Url::to(['/schedule/schedule/create','edit'=>true, 'link_id' => $model['opportunity_no'], 'link_type' => 'sale_opportunity', 'link_customer_no' => $model['customer_no']]) ?>' data-title='添加日程'  data-width="600" data-height="380" class="open-dialog" >日程</a>
                            <?php else : ?>
                                <a href="javascript:;" class="gray" title="当前没有权限添加日程">日程</a>
                            <?php endif; ?>
                            <a href="javascript:;" class="open-dialog" data-url="<?= Url::to(['/reimbursement/reimbursement/create', 'link_id' => $model['opportunity_no'], 'link_type' => 'sale_opportunity']) ?>" data-reload="false" data-title="任务报销" data-width="700">报销</a>
                        </td>
                    </tr>
                <?php endforeach; ?>
<?php endif; ?>
        </table>
<?php ActiveForm::end(); ?>
        <div class="pages">
            <span class="pagetotal">共<em><?= $pages->totalCount ?></em>条记录<em><?= $pages->page + 1 ?>/<?= $pages->pageCount ?></em>页 </span>
<?= \yii\widgets\LinkPager::widget(['pagination' => $pages, 'prevPageLabel' => '上一页', 'nextPageLabel' => '下一页', 'firstPageLabel' => '首页', 'lastPageLabel' => '末页']); ?>
        </div>
    </div>
    <!--manage-right--> 
</div>
<!--container-->
