<?php

use home\assets\MainAsset;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Url;
use common\widgets\Editor;
use common\widgets\DatePicker;
use yii\helpers\ArrayHelper;
use yii\helpers\StringHelper;
use home\modules\sale\models\Opportunity;
use home\modules\sale\models\Category;
//use home\modules\blog\models\Blog;
use home\modules\schedule\models\Schedule;


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

$assetUrl = $this->getAssetManager()->getBundle(MainAsset::className())->baseUrl;
$this->registerJsFile('@web/static/js/jquery/jquery.scrollto.js', ['depends' => [MainAsset::className()]]);

$this->registerJsFile($assetUrl . '/js/link.schedule.js', ['depends' => [MainAsset::className()]]);

$this->title = '销售机会详情';
?>

<script>
var assetUrl = "<?= $assetUrl ?>";
</script>

<!--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(Opportunity::readAccess('schedule/schedule/link-sale_opportunity')) : ?>
                    <button type="button" title="写日程" data-url='<?= Url::to(['/schedule/create', 'link_id' => $model['opportunity_no'], 'link_type' => 'sale_opportunity', 'link_customer_no' => $model['customer_no']]) ?>' data-title='添加日程'  data-width="600" data-height="380" class="btn btn-default btn-task open-dialog">
                        <i class="icon-calendar"></i>
                    </button>
                <?php endif;?>
                <button type="button" title="报销" data-title="<?= $model['name'] ?> - 报销" data-url="<?= Url::to(['/reimbursement/reimbursement/create', 'link_id' => $model['opportunity_no'], 'link_type' => 'sale_opportunity']) ?>" data-reload="false" data-width="600" data-height="320" class="btn btn-default btn-task open-dialog">
                       <i class="icon-dollar"></i>
                </button>
                
                <button type="button" title="编辑" data-url = "<?= Url::to(['view', 'id' => $model['opportunity_id'], 'from' => Url::to('')]) ?>" data-title="销售机会" data-width="650" data-height="400" class="btn btn-default btn-task open-dialog">
                       <i class="icon-edit"></i>
                </button>
                <button type="button" title="删除" onclick="if (!confirm('确认删除?'))
                            return false;
                        javascript:window.location.href = '<?= Url::to(['delete', 'id' => $model['opportunity_id'], 'from' => (isset($_GET['from'])) ? $_GET['from'] : '']) ?>'" class="btn btn-default btn-task">
                         <i class="icon-trash"></i>
                </button>
            </div>
            <p class="caption">销售机会详情</p>
        </div>
        <div class="task-title">
            <p class="lefttitle" title="<?= $model['name'] ?>"><span>销售机会名称：</span><?= StringHelper::truncate($model['name'], 30) ?>&nbsp;&nbsp;
                <span><?= $model->getAttributeLabel('category_id') ?>：</span><?= isset($model->category->name) ? $model->category->name : '' ?>
            </p>
        </div>
        <div class="mgt10">
            <table class="table task-table taskdetail-table">


                <tr>
                    <td width="20%" class="table-blue">销售机会名称</td>
                    <td title="<?= $model['name'] ?>" width="30%"><?= StringHelper::truncate($model['name'], 18) ?></td>
                    <td width="20%" class="table-blue">销售机会编号</td>
                    <td width="30%"><?= $model['opportunity_no'] ?></td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">发现人</td>
                    <td width="30%">
                        <?= ArrayHelper::getValue(\common\api\User::getOne($model->discoverer_id), 'realname'); ?>
                    </td>
                    <td width="20%" class="table-blue">所有人</td>
                    <td width="30%">
                        <?= ArrayHelper::getValue(\common\api\User::getOne($model->leader_id), 'realname'); ?>
                    </td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">客户名称</td>
                    <td width="30%">
                        <a target="_blank" href="<?= isset($model->customer) ? Url::to(['/customer/customer/detail', 'id' => $model->customer['customer_id']]) : 'javascript:;' ?>">
                            <?= isset($model->customer) ? $model->customer['name'] : '' ?>
                        </a>
                    </td>

                    <td width="20%" class="table-blue">联系人</td>
                    <td width="30%">
                        <a href="javascript:void(0);"  data-title='<?= $model['contacter']['name'] ?>' data-url='<?= Url::to(['/customer/contacter/detail', 'id' => $model->contacter_id]) ?>' data-height='160' data-width='440' class="open-only-see-dialog">
                            <?= ArrayHelper::getValue(\home\modules\customer\models\Contacter::findOne($model->contacter_id), 'name'); ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">阶段</td>
                    <td width="30%"><?= isset($model->category) ? $model->category->name : '' ?></td>
                    <td width="20%" class="table-blue">状态</td>
                    <td width="30%"><?= $model->saleStatus->name ?></td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">预计价格</td>  
                    <td width="30%"><?= $model->estimate_price ?></td>
                    <td width="20%" class="table-blue">预计成交日期</td>
                    <td width="30%"><?= date('Y-m-d', $model->due_date) ?></td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">来源</td>
                    <td width="30%"><?= isset($model->origin) ? $model->origin->name : '' ?></td>
                    <td width="20%" class="table-blue">热点</td>
                    <td width="30%">
                        <?= ($model['attention'] == Opportunity::STATUS_ENABLE) ? '<font color="green">是</font>' : '<font color="red">否</font>' ?>
                    </td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">商务分析</td>
                    <td colspan="3"><?= $model->nextstep ?></td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue"><?= $model->getAttributeLabel('remark') ?></td>
                    <td colspan="3"><?= $model->remark ?></td>
                </tr>
            </table>
        </div>

        <div class="task-title task-title2">
            <p class="lefttitle">机会日程(<b id="schedule-count" data-get-schedule-url="<?= Url::to(['/schedule/schedule/ajax-get-link-schedule', 'link_id' => $model['opportunity_no'], 'link_type' => 'sale_opportunity']) ?>" >0</b>)：
                <?php $blogUser = Schedule::getLinkScheduleUser('sale_opportunity', $model['opportunity_no']); ?>
                <?php if (!empty($blogUser)) : ?>
                    <button type="button" class="btn btn-default btn-sm btn-task schedule-user" data-get-schedule-url="<?= Url::to(['/schedule/schedule/ajax-get-link-schedule', 'link_id' => $model['opportunity_no'], 'link_type' => 'sale_opportunity', 'user_id' => '']) ?>" >
                        <a href="javascript:;" >全部</a>
                    </button>
                    <?php foreach ($blogUser as $user) : ?>
                        <button type="button" class="btn btn-default btn-sm btn-task schedule-user" data-get-schedule-url="<?= Url::to(['/schedule/schedule/ajax-get-link-schedule', 'link_id' => $model['opportunity_no'], 'link_type' => 'sale_opportunity', 'user_id' => $user['user_id']]) ?>" >
                            <a href="#" ><?= $user['realname'] ?></a>
                        </button>
                    <?php endforeach; ?>
                    
                <?php endif; ?>
            </p>
        </div>

        <!--manage-right-->
    </div>
    <!--container-->
</div>
