<?php
use home\assets\MainAsset;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\Menu;
use yii\helpers\ArrayHelper;
use home\modules\reimbursement\models\Application;
use yii\widgets\ActiveForm;
use yii\helpers\StringHelper;

/* @var $this \yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \home\modules\reimbursement\models\Reimbursement */
MainAsset::register($this);

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

$this->title = '申请单列表';
?>

<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
    <head>
        <meta charset="<?= Yii::$app->charset ?>"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <?= Html::csrfMetaTags() ?>
        <title><?= Html::encode($this->title) ?></title>
        <?php $this->head() ?>
        <script>
            var GV = {
                announceAjaxUrl:"<?= Url::to(['/announcement/ajax']) ?>"
            };

            var disable = <?= Application::ISVERIFY_DISABLE ?>;
        </script>
    </head>
    <body style="background: white;">
        <?= \home\widgets\Alert::widget(); ?>
        <?php $this->beginBody() ?>
        <div id="info" style="display:none;"></div>
            <!--task-table-->
            <?php $mainForm = ActiveForm::begin([ 'id' => 'main-form', 'action' => '']); ?>
            <table class="table task-table">
                <tr>
                    <th width="9%">申请人</th>
                    <th width="10%">申请日期</th>
                    <th width="23%">用途</th>
                    <th width="10%">申请金额</th>
                    <th width="10%">审核人</th>
                    <th width="8%">使用状态</th>
                    <th width="8%">审核状态</th>
                    <?php if ($showVerify) : ?><th width="10%">快捷通道</th><?php endif; ?>
                    <th width="160" align="center">操作</th>
                </tr>
                <?php if (empty($models)) : ?>
                    <tr><td colspan="9" class="tac red">还没有任何数据...</td></tr>
                    <?php else : ?>
                        <?php foreach ($models as $model) : ?>
                        <tr>
                            <td><?= isset(Yii::$app->cache->get('user_list')[$model->user_id]['realname'])?Yii::$app->cache->get('user_list')[$model->user_id]['realname']:'' ?></td>
                            <td><?= date('Y-m-d', $model->create_time) ?></td>
                            <td class='theleft-min <?= empty($model->remark)?"":"show-div" ?>' data-title="<?= $model->name ?>" data-remark="<?= $model->remark ?>">
                                <a target="_blank" href="<?= Url::to([$this->context->id . '/detail', 'id' => $model->appli_id, 'from' => Url::to('')]) ?>">
                                    <?= StringHelper::truncate($model->name, 24) ?>
                                </a>
                            </td>
                            <td class='theright-min'><?= number_format($model->money, 2 , '.' , ',') ?></td>
                            <td><?= implode(',', ArrayHelper::getColumn(\common\models\User::getUserByDot($model->verify_ids), 'realname')); ?></td>
                            <td><?= ($model->isused == Application::ISUSED_ENABLE) ? '<font color="green">未使用</font>' : '<font color="red">已使用</font>' ?></td>
                            <td>
                                <?php 
                                    if ($model->isverify == Application::ISVERIFY_WAIT) {
                                        echo '<font color="#0066FF">待审核</font>';
                                    } elseif ($model->isverify == Application::ISVERIFY_ENABLE) {
                                        echo '<font color="green">通过</font>';
                                    } else {
                                        echo '<font color="red">否决</font>';
                                    }
                                ?>
                            </td>

                            <?php if ($showVerify) : ?>
                            <td>
                                <?php if ($model->isverify == Application::ISVERIFY_WAIT) :?>
                                    <?php if (Application::checkAccess('set-status', $model->appli_id)) :?>
                                        <a href="javascript:;" class="set-vreify-status" data-status="accept" data-set-url="<?= Url::to(['set-status', 'id' => $model['appli_id'], 'status' => Application::ISVERIFY_ENABLE]) ?>"><font color="green">通过</font></a>/ 
                                        <a href="javascript:;" class="set-vreify-status" data-status="veto" data-set-url="<?= Url::to(['set-status', 'id' => $model['appli_id'], 'status' => Application::ISVERIFY_DISABLE]) ?>"><font color="red">否决</font></a>
                                    <?php else : ?>
                                        <a href="javascript:;" class="gray" title="当前没有审核权限">通过</a>/ 
                                        <a href="javascript:;" class="gray" title="当前没有审核权限">否决</a>
                                    <?php endif; ?>
                                <?php else : ?>
                                    <font color="#0066FF">-- --</font>
                                <?php endif; ?>
                            </td>
                            <?php endif; ?>

                            <td align="center" >
                                <?php if (Application::checkAccess('view', $model->appli_id)) : ?>
                                    <a href="javascript:;" class="open-dialog" data-height="300" data-width='600' data-url="<?= Url::to([$this->context->id .'/view', 'id' => $model->appli_id]) ?>" data-title='编辑申请'>编辑</a>
                                <?php else : ?>
                                    <a href="javascript:;" class="gray" title="当前没有编辑权限"><strike>编辑</strike></a>
                                <?php endif; ?>

                                <?php if ($showVerify) : ?>
                                <?php if (Application::checkAccess('verify', $model->appli_id)) : ?>
                                    <a href="javascript:;" class="open-verify-dialog"  data-url="<?= Url::to([$this->context->id .'/verify', 'id' => $model->appli_id]) ?>" data-title='申请单审核' data-width="650" data-height="450" <?= ($model->isverify == Application::ISVERIFY_WAIT) ? '':'data-submit=false' ?>>审核</a>
                                <?php else : ?>
                                    <a href="javascript:;" class="gray" title="当前没有审核权限"><del>审核</del></a>
                                <?php endif; ?>
                                <?php else : ?>
                                <?php endif; ?>
                                
                                <?php if (Application::checkAccess('delete', $model->appli_id)) : ?>
                                    <a class="link-delete" href="<?= Url::to([$this->context->id . '/delete', 'id' => $model->appli_id]) ?>">删除</a>
                                <?php else : ?>
                                    <a href="javascript:;" class="gray" title="当前没有删除权限">删除</a>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </table>
            <?php ActiveForm::end(); ?>
            <!--task-table--> 
            <!--分页标签-->
            <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>
            <!--分页标签-->
        <?php $this->endBody() ?>
    </body>
</html>
<?php $this->endPage() ?>
        