<?php

use home\assets\MainAsset;
use home\assets\MenuAsset;
use yii\helpers\Url;
use home\modules\task\models\Category;
use home\modules\task\models\Task;
use home\modules\blog\models\Blog;
use common\models\User;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\helpers\StringHelper;
use yii\helpers\Html;
use home\models\Attachment;
use common\assets\ZTreeAsset;

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

MenuAsset::register($this);
ZTreeAsset::register($this);

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

$this->title = $model['name'] . ' - 任务详情';
?>



<script>
    var assetUrl = "<?= $assetUrl ?>";
    var treeListUrl = "<?= Url::to(['ajax-get-tree-data', 'id' => $model['task_id'], '_csrf' => Yii::$app->request->getCsrfToken()]) ?>";
</script>

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

         <div class="tab-column">
            <div class="tab-right">
                <?php if(Task::checkTaskAccess($model, 'task/task/create-blog')) : ?>
                    <button title="写日志" type="button" data-title="<?= $model['name'] ?> - 写日志" data-url="<?= Url::to(['/blog/blog/write-daily', 'link_id' => $model['task_no'], 'link_type' => 'task', 'link_title' => $model['name']]) ?>" data-reload="true" data-width="600" data-height="380" class="btn btn-default btn-task open-dialog">
                       <i class="icon-file-alt"></i>
                    </button>
                <?php endif; ?>
                <?php if(Task::checkTaskAccess($model, 'task/task/create-reimbursement')) : ?>
                    <button title="报销" type="button" data-title="<?= $model['name'] ?> - 报销" data-url="<?= Url::to(['/reimbursement/reimbursement/create', 'link_id' => $model['task_no'], 'link_type' => 'task']) ?>" data-reload="false" data-width="500" data-height="300" class="btn btn-default btn-task open-dialog">
                       <i class="icon-dollar"></i>
                    </button>
                <?php endif; ?>
                <?php if(Task::checkTaskAccess($model, 'task/task/create-child')) : ?>
                    <button title="建立子任务" type="button" data-title="建立子任务" data-url="<?= Url::to(['create', 'parent_id' => $model['task_id']]) ?>" data-width="800" data-height="570" class="btn btn-default btn-task open-dialog">
                       <i class=" icon-tasks"></i>
                    </button>
                <?php endif; ?>
                <?php if(Task::checkTaskAccess($model, 'task/task/view')) : ?>
                    <button title="编辑" type="button" data-title="编辑任务" data-url="<?= Url::to(['view', 'id' => $model['task_id'], 'from' => Url::to('')]) ?>'" data-width="800" data-height="570" class="btn btn-default btn-task open-dialog">
                       <i class="icon-edit"></i>
                    </button>
                <?php endif; ?>
                <?php if(Task::checkTaskAccess($model, 'task/task/delete')) : ?>
                    <?php if($model['child_ids'] == $model['task_id']) : ?>
                        <button title="删除" type="button" onclick="if (!confirm('确认删除?'))
                                    return false;
                                javascript:window.location.href = '<?= Url::to(['delete', 'id' => $model['task_id'], 'from' => (isset($_GET['from'])) ? $_GET['from'] : '']) ?>'" class="btn btn-default btn-task">
                         <i class="icon-trash"></i>
                        </button>
                    <?php endif; ?>
                <?php endif; ?>

                <!-- <button type="button" class="btn btn-default btn-task blog-btn">
                <a href="javascript:;" data-get-blog-url="<?= Url::to(['/blog/blog/ajax-get-list', 'task_no' => $model['task_no']]) ?>" id="blog-count" >进度日志(0)</a>
                </button> -->
            </div>
            <p class="caption">任务详情</p> 
        </div>

        <div class="manage-right-cont fix">
            <div class="left-nav" >
                <!--<div class="manage-left">-->
                <p class="tasklist-title" style="margin:0px">
                <?php if(!empty($model['topParent']['link_data']) && isset($model['topParent']['link_data']['name'])) : ?>
                    <a href="<?php
                    $linkType = $model['topParent']['link_data']['link_type'];
                    $linkType['view_url']['id'] = (!empty($model['topParent']['link_data'][$linkType['pk']])) ? $model['topParent']['link_data'][$linkType['pk']] : 0;
                    echo Url::to($linkType['view_url'])
                    ?>" title="<?= $model['topParent']['link_data']['name'] ?>" target="_blank" ><?= StringHelper::truncate($model['topParent']['link_data']['name'], 9) ?></a>
                   <?php else : ?>
                   任务列表
                <?php endif; ?>
                </p>
                <div class="left-tree">
                    <ul id="task-tree" class="ztree" data-tree-list-url="<? Url::to(['ajax-get-tree-data']) ?>" ></ul>
                </div>
            </div>
            <!--manage-left -->
            <div class="manage-right-iframe">
                <div class="task-title">
                    <p class="lefttitle"><span>任务名称：</span><font title="<?= $model['name'] ?>(<?= $model['task_no'] ?>)" ><?= StringHelper::truncate($model['name'], 24) ?>(<?= $model['task_no'] ?>)</font></font>&nbsp;<?php if(Blog::isWrite($model['task_no'],'task')):?><i class="icon-paste"></i><?php endif;?>&nbsp;&nbsp; <span>任务类别：</span><?= $model['category']['name'] ?>&nbsp;&nbsp;<span >任务状态：</span><font class="task-status"><?= $model['status_name'] ?></font></p>
                    <?php if(Task::checkTaskAccess($model, 'task/task/status')) : ?>
                        <select class="form-control tasklist-form task-status-select" data-set-url="<?= Url::to(['status', 'id' => $model['task_id'], 'status_id' => '']) ?>">
                            <?php foreach (\qcbase\models\TaskStatus::getDropDownList() as $id => $name) : ?>
                                <option <?= (isset($model['status_id']) && ($model['status_id'] == $id)) ? 'selected="selected"' : ''; ?> value="<?= $id ?>" ><?= $name ?></option>
                            <?php endforeach; ?>
                        </select>
                    <?php endif; ?>
                </div>
                <div class="mgt10">
                    <table class="table task-table taskdetail-table">
                        <tr>
                            <td width="20%" class="table-blue">父任务</td>  
                            <td width="30%" <?= Task::checkTaskAccess($model, 'task/task/view-link') ? '' : 'colspan="3"' ?>><?= (isset($model['parentTask'])) ? '<a href="' . Url::to(['detail', 'id' => $model['parentTask']['task_id']]) . '" >' . $model['parentTask']['name'] . '</a>' : '无' ?></td>

                            <?php if(Task::checkTaskAccess($model, 'task/task/view-link')) : ?>
                                <td width="20%" class="table-blue">关联<?= (!empty($model['link_data']) && isset($model['link_data']['link_type']['name'])) ? $model['link_data']['link_type']['name'] : '' ?></td>
                                <td width="30%">
                                    <?php if(!empty($model['link_data'])) : ?>
                                        <a href="<?php
                                        $linkType = $model['link_data']['link_type'];
                                        $linkType['view_url']['id'] = (!empty($model['link_data'][$linkType['pk']])) ? $model['link_data'][$linkType['pk']] : 0;
                                        echo Url::to($linkType['view_url'])
                                        ?>" target="_blank" ><?= isset($model['link_data']['name']) ? $model['link_data']['name'] : '关联信息不存在' ?></a>
                                       <?php else : ?>

                                    <?php endif; ?>
                                </td>
                            <?php endif; ?>
                        </tr>
                        <tr>
                            <td width="20%" class="table-blue">创建人</td>
                            <td width="30%"><?= $model['user']['realname'] ?> (<?= date('Y-m-d', $model['create_time']) ?>)</td>
                            <td width="20%" class="table-blue">负责人</td>
                            <td width="30%"><?= !empty($model['leader']['realname']) ? $model['leader']['realname'] : '' ?></td>
                        </tr>
                        <tr>
                            <td width="20%" class="table-blue">参与人</td>
                            <td width="30%"><?= (!empty($model['join_ids'])) ? implode(',', ArrayHelper::getColumn(User::getUserByDot($model['join_ids']), 'realname')) : '' ?></td>
                            <td width="20%" class="table-blue">关注人</td>
                            <td width="30%"><?= (!empty($model['follow_ids'])) ? implode(',', ArrayHelper::getColumn(User::getUserByDot($model['follow_ids']), 'realname')) : '' ?></td>
                        </tr>
                        <tr>
                            <td width="20%" class="table-blue">任务类别</td>
                            <td width="30%"><?= $model['category']['name'] ?></td>
                            <td width="20%" class="table-blue">预估工作量</td>
                            <td width="30%"><?= (!empty($model['workload'])) ? $model['workload'] : '' ?>H</td>
                        </tr>
                        <tr>
                            <td width="20%" class="table-blue">开始日期</td>
                            <td width="30%"><?= (!empty($model['begin_time'])) ? date('Y-m-d', $model['begin_time']) : '' ?></td>
                            <td width="20%" class="table-blue">结束日期</td>
                            <td width="30%"><?= (!empty($model['end_time'])) ? date('Y-m-d', $model['end_time']) : '' ?></td>
                        </tr>
                        <tr>
                            <td width="20%" class="table-blue">任务描述</td>
                            <td width="30%" style="max-width:300px" colspan="3"><?= $model['description'] ?></td>
                        </tr>
                        <tr>
                            <td width="20%" class="table-blue">任务备注</td>
                            <td width="30%" colspan="3"><?= $model['remark'] ?></td>
                        </tr>
                        <tr>
                            <td width="20%" class="table-blue">附件</td>
                            <td width="30%" colspan="3">
                                <?php if(!$attachs = Attachment::getAttachByDot($model['attach_ids'])) : ?>
                                <?php else : ?>
                                    <?php foreach ($attachs as $attach) : ?>
                                        <p><a href="<?= Url::to(['/attachment/download', 'id' => $attach['attach_id']]) ?>" title="点击下载" ><?= $attach['file_name'] ?></a> <?php if($attach['is_image'] == 1) : ?> <a href="javascript:imagePriview('<?= $attach['file_path'] ?>')" >[预览]</a><?php endif; ?></p>
                                    <?php endforeach; ?>
                                <?php endif; ?>
                            </td>
                        </tr>
                    </table>
                </div>

                <div class="task-title task-blog-title">
                    <p class="lefttitle">工作日志(<b id="blog-count" data-get-blog-url="<?= Url::to(['/blog/blog/ajax-get-link-blog', 'link_id' => $model['task_no'], 'link_type' => 'task']) ?>" >0</b>)：
                        <?php $blogUser = Blog::getLinkBlogUser('task', $model['task_no']); ?>
                        <?php if(!empty($blogUser)) : ?>
                            <button type="button" class="btn btn-default btn-sm btn-task blog-user" data-get-blog-url="<?= Url::to(['/blog/blog/ajax-get-link-blog', 'link_id' => $model['task_no'], 'link_type' => 'task']) ?>" >
                                <a href="javascript:;" >全部</a>
                            </button>
                            <?php foreach ($blogUser as $user) : ?>
                                <button type="button" class="btn btn-default btn-sm btn-task blog-user" data-get-blog-url="<?= Url::to(['/blog/blog/ajax-get-link-blog', 'link_id' => $model['task_no'], 'link_type' => 'task', 'user_id' => $user['user_id']]) ?>" >
                                    <a href="#" ><?= $user['realname'] ?></a>
                                </button>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </p>
                </div>
            </div>
        </div>
        <!--manage-right--> 
  </div>
    </div>
    <!--container-->
</div>
