<?php

use home\assets\MainAsset;
use home\assets\MenuAsset;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\Menu;
use yii\helpers\ArrayHelper;
use home\modules\reimbursement\models\reimbursement;
use yii\widgets\ActiveForm;
use yii\helpers\StringHelper;
use common\assets\ZTreeAsset;
use common\widgets\DatePicker;
use common\assets\My97DatePickerAsset;

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

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

$assetUrl = $this->getAssetManager()->getBundle(MenuAsset::className())->baseUrl;
$this->registerJsFile($assetUrl . '/js/reim.list.tree.js', ['depends' => ZTreeAsset::className()]);

//$this->registerJsFile('@web/static/js/jquery/jquery.scrollto.js', ['depends' => [ZTreeAsset::className()]]);
//$this->registerJsFile($assetUrl.'/js/task.detail.js', ['depends' => [ZTreeAsset::className()]]);

$this->title = '报销列表';
?>

<!--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">
                    <button type="button" title="添加报销" data-url='<?= Url::to([$this->context->id . '/create']) ?>' data-title="我要报销" data-width="600" data-height="380" class="btn btn-default btn-task open-dialog">
                        <i class="icon-plus"></i>
                    </button>
                    <?php if(Reimbursement::readAccess('reimbursement/reimbursement/export')) : ?>
                        <?php if($selectTime) : ?>
                            <button type="button" title="导出报销" class="btn btn-default btn-task" onclick="javascript:window.location.href = '<?= Url::to([$this->context->id . '/export', 'beginTime' => $beginTime, 'endTime' => $endTime]) ?>'">
                                <i class="icon-download-alt"></i>
                            </button>
                        <?php else : ?>
                            <button type="button" title="导出报销" class="btn btn-default btn-task" onclick="javascript:alert('请选择报销时间段')">
                                <i style="color:#999;" class="icon-download-alt"></i>
                            </button>
                        <?php endif; ?>
                    <?php endif; ?>
                </div>
                <p class="caption">报销列表</p>
            </div>
            <?= $this->render('_search', ['model' => $model, 'get' => $get, 'action' => 'index', 'showVerify' => $showVerify,]) ?>

            <div class="manage-right-cont fix">

            <div class="mainleft-tree">
                <div class="labellink fix"> 
                    <a href="javascript:;" id="labelLink" class="labelfocus">人员</a>
                    <!-- <a href="javascript:;" id="labelLink">任务</a>  -->
                    <?php if(Reimbursement::readAccess('reimbursement/reimbursement/statistics')) : ?>
                        <a href="javascript:;" id="labelLink">类别</a> 
                    <?php endif; ?>
                </div>
                <div class="lefttree-user">
                    <ul id="tree"  class="ztree" ></ul>
                </div>
                <div class="lefttree-task" style="display: none;">
                    <ul id="task-tree" class="ztree" data-tree-list-url="<? Url::to(['/task/task/ajax-get-tree-data']) ?>" ></ul>
                </div>
                <div class="lefttree-category" style="display: none;">
                    <ul id="category-tree"  class="ztree"  ></ul>
                </div>
            </div>

            <div class="manage-right-iframe" style="margin-left: 166px;">
                <iframe id="iframe_default" name="iframe" src="<?= str_replace('%2Findex', '%2Findex-iframe', Yii::$app->request->getUrl()) ?>" style="max-height: 700px; width: 100%;display:none;" data-id="default" frameborder="0" scrolling="auto">
                </iframe>

            </div>
        </div>
        </div>
        <!--mainbody-->
    </div>
</div>
<script>
    var default_date = "<?= date('Y-m-d') ?>";
    var CSRF = "<?= Yii::$app->request->getCsrfToken() ?>";
    var getTreeDataUrl = "<?= Url::to(['/reimbursement/reimbursement/get-treedata', '_csrf' => Yii::$app->request->getCsrfToken()]) ?>";
    var index = "<?= Url::to(['index']) ?>";
    var getCategory = "<?= Url::to(['get-category']) ?>";

    var href = "<?= Yii::$app->request->getUrl() ?>".replace("%2Findex", "%2Findex-iframe");

    function zTreeOnClick(event, treeId, treeNode) {
        $('#iframe_default')[0].contentWindow.location.href = href + "&ids=" + treeNode.user_ids;
    }

    function categoryOnClick(event, treeId, treeNode) {
        window.location.href = "<?= Url::to([$this->context->id . '/statistics']) ?>" + "&id=" + treeNode.cat_id;
    }

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