<?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 common\models\User;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\helpers\StringHelper;
use yii\helpers\Html;
use home\modules\blog\models\Blog;

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

MenuAsset::register($this);

$this->title = '分类任务';
?>

<style>
.rightfl {margin-right:0px;}
</style>
<!--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">
                <button title="分类任务" type="button" onclick="javascript:window.location.href = '<?= Url::to(['index']) ?>'" class="btn btn-default  btn-task btn-focus">
                  <i class="icon-tasks"> 分类</i>
                </button>
                <button title="全部任务" type="button" onclick="javascript:window.location.href = '<?= Url::to(['list']) ?>'" class="btn btn-default  btn-task">
                  <i class="icon-desktop"> 全部</i>
                </button>
                <!--    <button type="button" class="btn btn-default  btn-task">
                       <a href="#">统计</a>
                   </button>
                -->    
                <?php if(Yii::$app->session->get('isSuperAdmin') || Yii::$app->user->can('task/task/create')) : ?>
                    
                    <button type="button" title="添加任务" data-url="<?= Url::to(['create', 'from' => Url::to('')]) ?>" data-title="添加任务" data-width="800" data-height="570" class="btn btn-default  btn-task open-dialog">
                        <i class="icon-plus"></i>
                    </button>

                <?php endif; ?>
                <div class="topserch">
                    <?php $searchForm = ActiveForm::begin([ 'id' => 'topserch', 'action' => ['list'], 'method' => 'get']); ?>
                    <input type="text" class="serchinput" name="keywords" placeholder="请输入关键字">
                    <input type="hidden" name="search_field" value="name" />
                    <input type="submit" class="serchbut" value="">
                    <?php ActiveForm::end(); ?>
                </div>
            </div>

            <?= \home\widgets\Alert::widget(); ?>

            <div class="task-one">
                <div class="task-title">
                    <p class="lefttitle">我负责的任务<span class="task-count"><?= $leadTasks['count'] ?></span></p>
                    <p class="rightfl task-title-links"><!--<span><em>|</em><a href="#">我的任务</a><em>|</em><a href="#">下属任务</a><em>|</em><a href="#">我分配的任务</a></span>--> <span><a href="<?= Url::to(['list', 'type' => 'lead']) ?>">全部</a>
                            <?php foreach ($taskStatus as $status) : ?>
                                <em>|</em><a href="<?= Url::to(['list', 'type' => 'lead', 'status_id' => $status['status_id']]) ?>"><?= $status['name'] ?></a>
                            <?php endforeach; ?>
                        </span>
                        <span>
                            <?php
                            $i = 0;
                            $timeOrder = Task::getTimeOrder();
                            foreach ($timeOrder as $id => $name) :
                                ?><a href="<?= url::to(['/task/task/list', 'type' => 'lead', 'time_order' => $id]) ?>"><?= $name ?></a><?php if($i < count($timeOrder) - 1) : ?><em>|</em><?php endif; ?><?php
                                $i++;
                            endforeach;
                            ?></span>
                    </p>
                </div>
                <table class="table task-table">
                    <tr>
                        <th width="17%">任务名</th>
                        <th width="10%">任务编号</th>
                        <th width="8%">负责人</th>
                        <th width="14%">参与人</th>
                        <th width="8%">创建日期</th>
                        <th width="8%">开始日期</th>
                        <th width="8%">结束日期</th>
                        <th width="8%">任务类别</th>
                        <th width="6%">状态</th>
                        <th width="28%">操作</th>
                    </tr>
                    <?php if(!empty($leadTasks['tasks'])) : ?>
                        <?php foreach ($leadTasks['tasks'] as $model) : ?>
                            <tr>
                                <td style="text-align:left;" title="<?= $model['name'] ?>" ><a href="<?= Url::to(['detail', 'id' => $model['task_id'], 'from' => Url::to('')]) ?>"><?= (isset($model['_is_child'])) ? '&nbsp;&nbsp;└─&nbsp;' . StringHelper::truncate($model['name'], 11) : StringHelper::truncate($model['name'], 13) ?></a><?php if(Blog::isWrite($model['task_no'],'task')):?><i class="icon-paste"></i><?php endif;?></td>
                                <td><?= $model['task_no'] ?></td>
                                <td><?= (!empty($model['leader']['realname'])) ? $model['leader']['realname'] : '' ?></td>
                                <td><?= (!empty($model['join_ids'])) ? implode(',', ArrayHelper::getColumn(User::getUserByDot($model['join_ids']), 'realname')) : '' ?></td>
                                <td><?= date('Y-m-d', $model['create_time']) ?></td>
                                <td><?= (!empty($model['begin_time'])) ? date('Y-m-d', $model['begin_time']) : '' ?></td>
                                <td><?= (!empty($model['end_time'])) ? date('Y-m-d', $model['end_time']) : '' ?></td>
                                <td><?= $model['category']['name'] ?></td>
                                <td><?= $model['status_name'] ?></td>
                                <td>
                                    <?php if(Task::checkTaskAccess($model, 'task/task/create-blog')) : ?>
                                    <a href="javascript:;" class="open-dialog" 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="false" data-width="600" data-height="380" >写日志</a>
                                    <?php endif; ?>
                                    <?php if(Task::checkTaskAccess($model, 'task/task/create-reimbursement')) : ?>
                                        <a href="javascript:;" class="open-dialog" data-url="<?= Url::to(['/reimbursement/reimbursement/create', 'link_id' => $model['task_no'], 'link_type' => 'task']) ?>" data-reload="false" data-title="任务报销" data-width="500" data-height="260">报销</a>
                                    <?php endif; ?>
                                    <?php if(Task::checkTaskAccess($model, 'task/task/create-child')) : ?>
                                        <a data-title="建子任务" data-url="<?= Url::to(['create', 'parent_id' => $model['task_id']]) ?>" data-width="800" data-height="570" href="javascript:;" class="open-dialog">建子任务</a>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        <?php if($leadTasks['count'] > $limit) : ?><tr><td colspan="10"><a href="<?= Url::to(['list', 'type' => 'lead']) ?>" >更多我负责的任务...</a></td></tr><?php endif; ?>
                    <?php else : ?>
                        <tr><td colspan="10">暂无任务</td></tr>
                    <?php endif; ?>
                </table>
            </div>
            <!--task-one-->

            <div class="task-one">
                <div class="task-title">
                    <p class="lefttitle">我参与的任务<span class="task-count"><?= $joinTasks['count'] ?></span></p>
                    <p class="rightfl task-title-links"><span><a href="<?= Url::to(['list', 'type' => 'join']) ?>">全部</a>
                            <?php foreach ($taskStatus as $status) : ?>
                                <em>|</em><a href="<?= Url::to(['list', 'type' => 'join', 'status_id' => $status['status_id']]) ?>"><?= $status['name'] ?></a>
                            <?php endforeach; ?>
                        </span> 
                        <span>
                            <?php
                            $i = 0;
                            $timeOrder = Task::getTimeOrder();
                            foreach ($timeOrder as $id => $name) :
                                ?><a href="<?= url::to(['/task/task/list', 'type' => 'join', 'time_order' => $id]) ?>"><?= $name ?></a><?php if($i < count($timeOrder) - 1) : ?><em>|</em><?php endif; ?><?php
                                $i++;
                            endforeach;
                            ?></span>
                    </p>
                </div>
                <table class="table task-table">
                    <tr>
                        <th width="17%">任务名</th>
                        <th width="10%">任务编号</th>
                        <th width="8%">负责人</th>
                        <th width="14%">参与人</th>
                        <th width="8%">创建日期</th>
                        <th width="8%">开始日期</th>
                        <th width="8%">结束日期</th>
                        <th width="8%">任务类别</th>
                        <th width="6%">状态</th>
                        <th width="28%">操作</th>
                    </tr>

                    <?php if(!empty($joinTasks['tasks'])) : ?>
                        <?php foreach ($joinTasks['tasks'] as $model) : ?>
                            <tr>
                                <td style="text-align:left;" title="<?= $model['name'] ?>" ><a href="<?= Url::to(['detail', 'id' => $model['task_id'], 'from' => Url::to('')]) ?>" ><?= (isset($model['_is_child'])) ? '&nbsp;&nbsp;└─&nbsp;' . StringHelper::truncate($model['name'], 11) : StringHelper::truncate($model['name'], 13) ?></a><?php if(Blog::isWrite($model['task_no'],'task')):?><i class="icon-paste"></i><?php endif;?></td>
                                <td><?= $model['task_no'] ?></td>
                                <td><?= (!empty($model['leader']['realname'])) ? $model['leader']['realname'] : '' ?></td>
                                <td><?= (!empty($model['join_ids'])) ? implode(',', ArrayHelper::getColumn(User::getUserByDot($model['join_ids']), 'realname')) : '' ?></td>
                                <td><?= date('Y-m-d', $model['create_time']) ?></td>
                                <td><?= (!empty($model['begin_time'])) ? date('Y-m-d', $model['begin_time']) : '' ?></td>
                                <td><?= (!empty($model['end_time'])) ? date('Y-m-d', $model['end_time']) : '' ?></td>
                                <td><?= $model['category']['name'] ?></td>
                                <td><?= $model['status_name'] ?></td>
                                <td>
                                    <?php if(Task::checkTaskAccess($model, 'task/task/create-blog')) : ?>
                                        <a href="javascript:;" class="open-dialog" 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="false" data-width="600" data-height="380" >写日志</a>
                                    <?php endif; ?>
                                    <?php if(Task::checkTaskAccess($model, 'task/task/create-reimbursement')) : ?>
                                        <a href="javascript:;" class="open-dialog" data-url="<?= Url::to(['/reimbursement/reimbursement/create', 'link_id' => $model['task_no'], 'link_type' => 'task']) ?>" data-reload="false" data-title="任务报销" data-width="500" data-height="260">报销</a>
                                    <?php endif; ?>
                                    <?php if(Task::checkTaskAccess($model, 'task/task/create-child')) : ?>
                                        <a data-title="建子任务" data-url="<?= Url::to(['create', 'parent_id' => $model['task_id']]) ?>" data-width="800" data-height="570" href="javascript:;" class="open-dialog">建子任务</a>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        <?php if($joinTasks['count'] > $limit) : ?><tr><td colspan="10"><a href="<?= Url::to(['list', 'type' => 'join']) ?>" >更多我参与的任务...</a></td></tr><?php endif; ?>
                    <?php else : ?>
                        <tr><td colspan="10">暂无任务</td></tr>
                    <?php endif; ?>

                </table>
            </div>
            <!--task-one-->
            <div class="task-one">
                <div class="task-title">
                    <p class="lefttitle">我关注的任务<span class="task-count"><?= $followTasks['count'] ?></span></p>
                    <p class="rightfl task-title-links"><span><a href="<?= Url::to(['list', 'type' => 'follow']) ?>">全部</a>
                            <?php foreach ($taskStatus as $status) : ?>
                                <em>|</em><a href="<?= Url::to(['list', 'type' => 'follow', 'status_id' => $status['status_id']]) ?>"><?= $status['name'] ?></a>
                            <?php endforeach; ?>
                        </span>
                        <span>
                            <?php
                            $i = 0;
                            $timeOrder = Task::getTimeOrder();
                            foreach ($timeOrder as $id => $name) :
                                ?><a href="<?= url::to(['/task/task/list', 'type' => 'follow', 'time_order' => $id]) ?>"><?= $name ?></a><?php if($i < count($timeOrder) - 1) : ?><em>|</em><?php endif; ?><?php
                                $i++;
                            endforeach;
                            ?></span>
                    </p>
                </div>
                <table class="table task-table">
                    <tr>
                        <th width="17%">任务名</th>
                        <th width="10%">任务编号</th>
                        <th width="8%">负责人</th>
                        <th width="14%">参与人</th>
                        <th width="8%">创建日期</th>
                        <th width="8%">开始日期</th>
                        <th width="8%">结束日期</th>
                        <th width="8%">任务类别</th>
                        <th width="6%">状态</th>
                        <th width="28%">操作</th>
                    </tr>

                    <?php if(!empty($followTasks['tasks'])) : ?>
                        <?php foreach ($followTasks['tasks'] as $model) : ?>
                            <tr>
                                <td style="text-align:left;" title="<?= $model['name'] ?>" ><a href="<?= Url::to(['detail', 'id' => $model['task_id'], 'from' => Url::to('')]) ?>"><?= (isset($model['_is_child'])) ? '&nbsp;&nbsp;└─&nbsp;' . StringHelper::truncate($model['name'], 11) : StringHelper::truncate($model['name'], 13) ?></a></td>
                                <td><?= $model['task_no'] ?></td>
                                <td><?= (!empty($model['leader']['realname'])) ? $model['leader']['realname'] : '' ?></td>
                                <td><?= (!empty($model['join_ids'])) ? implode(',', ArrayHelper::getColumn(User::getUserByDot($model['join_ids']), 'realname')) : '' ?></td>
                                <td><?= date('Y-m-d', $model['create_time']) ?></td>
                                <td><?= (!empty($model['begin_time'])) ? date('Y-m-d', $model['begin_time']) : '' ?></td>
                                <td><?= (!empty($model['end_time'])) ? date('Y-m-d', $model['end_time']) : '' ?></td>
                                <td><?= $model['category']['name'] ?></td>
                                <td><?= $model['status_name'] ?></td>
                                <td>
                                    <?php if(Task::checkTaskAccess($model, 'task/task/create-blog')) : ?>
                                        <a href="javascript:;" class="open-dialog" 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="false" data-width="600" data-height="380">写日志</a>
                                    <?php endif; ?>
                                    <?php if(Task::checkTaskAccess($model, 'task/task/create-reimbursement')) : ?>
                                        <a href="javascript:;" class="open-dialog" data-url="<?= Url::to(['/reimbursement/reimbursement/create', 'link_id' => $model['task_no'], 'link_type' => 'task']) ?>" data-reload="false" data-title="任务报销" data-width="500" data-height="260">报销</a>
                                    <?php endif; ?>
                                    <?php if(Task::checkTaskAccess($model, 'task/task/create-child')) : ?>
                                        <a data-title="建子任务" data-url="<?= Url::to(['create', 'parent_id' => $model['task_id']]) ?>" data-width="800" data-height="570" href="javascript:;" class="open-dialog">建子任务</a>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        <?php if($followTasks['count'] > $limit) : ?><tr><td colspan="10"><a href="<?= Url::to(['list', 'type' => 'follow']) ?>" >更多我关注的任务...</a></td></tr><?php endif; ?>
                    <?php else : ?>
                        <tr><td colspan="10">暂无任务</td></tr>
                    <?php endif; ?>

                </table>
            </div>
            <!--task-one--> 
        </div>
    </div>
</div>
<!--container-->


