index.php 11.2 KB
<?php

use yii\helpers\Url;
use app\ht\widgets\LinkPager;
use domain\upgrade\UpgradeStatus;
use domain\upgrade\UpgradeLogStatus;

if (isset($gets["type"]) && UpgradeStatus::TYPE_OTA == $gets["type"]) {
    $this->title = 'OTA升级统计';
} else {
    $this->title = 'APP升级统计';
}
$this->params['breadcrumbs'][] =  $this->title;
?>
<style>
    .table > tbody > tr > td
    {
        border: white 0px solid;
        border-top: solid 1px #fff;
        border-bottom: 1px solid #fff;
    }
    .table{
        margin-bottom: 0px!important;
    }
</style>
<div class="panel panel-default">
    <div class="panel-body">
        <form action="" method="get" id="search-form" class="filter-form">
            <table width="100%" class="table">
                <tbody>
                <tr >
                    <td width="10%" class="text-right">当前版本</td>
                    <td width="10%" class="text-left">
                        <input type="text" class="form-control" name="current_version" style="width: 150px;" placeholder="输入当前版本" value="<?php if (!empty($gets['current_version'])){ echo $gets['current_version']; } ?>">
                    </td>
                    <td width="10%" class="text-right">目标版本</td>
                    <td width="10%" class="text-left">
                        <input type="text" class="form-control" name="target_version" style="width: 150px;" placeholder="输入目标版本" value="<?php if (!empty($gets['target_version'])){ echo $gets['target_version']; } ?>">
                    </td>
                    <td width="10%" class="text-right">厂商</td>
                    <td width="10%" class="text-left">
                        <input type="text" class="form-control" name="manufacture_name" style="width: 150px;" placeholder="输入厂商" value="<?php if (!empty($gets['manufacture_name'])){ echo $gets['manufacture_name']; } ?>">
                    </td>
                    <td width="10%" class="text-right">机器型号</td>
                    <td width="30%" class="text-left">
                        <input type="text" class="form-control" name="device_no" style="width: 290px;" placeholder="输入机器型号" value="<?php if (!empty($gets['device_no'])){ echo $gets['device_no']; } ?>">
                    </td>
                </tr>
                <tr>
                    <td class="text-right">Barcode</td>
                    <td class="text-left">
                        <input type="text" class="form-control" name="barcode" style="width: 150px;" placeholder="输入Barcode" value="<?php if (!empty($gets['barcode'])){ echo $gets['barcode']; } ?>">
                    </td>
                    <td class="text-right">升级状态</td>
                    <td class="text-left">
                        <select class="form-control" style="width: 150px;" id="status" name="status">
                            <option value="">全部</option>
                            <?php foreach (UpgradeLogStatus::statusLabels() as $key => $value) { ?>
                            <option value="<?=$key ?>" <?php if (isset($gets['status']) && $gets['status'] == $key){ echo "selected"; } ?>><?=$value ?></option>
                            <?php } ?>
                        </select>
                    </td>
                    <td class="text-right">升级错误码</td>
                    <td class="text-left">
                        <input type="text" class="form-control" name="error_code" style="width: 150px;" placeholder="输入升级错误码" value="<?php if (!empty($gets['error_code'])){ echo $gets['error_code']; } ?>">
                    </td>
                    <td class="text-right">时间</td>
                    <td class="text-left">
                        <div class="form-inline">
                            <input type="date" class="form-control" style="width: 140px;" name="creatTime" placeholder="起" value="<?php if (!empty($gets['creatTime'])){ echo $gets['creatTime']; } ?>"> -
                            <input type="date" class="form-control" style="width: 140px;" name="endTime" placeholder="止" value="<?php if (!empty($gets['endTime'])){ echo $gets['endTime']; } ?>">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="text-right">设备ID</td>
                    <td class="text-left">
                        <input type="text" class="form-control" name="device_device_id" style="width: 150px;" placeholder="输入设备ID" value="<?php if (!empty($gets['device_device_id'])){ echo $gets['device_device_id']; } ?>">
                    </td>
                    <td class="text-right">包名</td>
                    <td class="text-left"> <input type="text" class="form-control" name="package_name" style="width: 150px;" placeholder="包名" value="<?php if (!empty($gets['package_name'])){ echo $gets['package_name']; } ?>"></td>
                    <td class="text-right"></td>
                    <td class="text-left"></td>
                    <td class="text-right"></td>
                    <td class="text-left"></td>
                </tr>
                <tr class="search">
                    <td colspan="8"  class="text-center">
                        <input type="hidden" name="type" value="<?= (isset($gets["type"]) ? $gets["type"] : UpgradeStatus::TYPE_APP) ?>">
                        <button type="submit" class="btn btn-primary btncls" id="search"><i class="glyphicon glyphicon-search"></i> 查 询  </button>
                        <a class="btn btn-default btncls" href="<?=Url::toRoute(["/datas/upgrade-log/index", "type" => (isset($gets["type"]) ? $gets["type"] : UpgradeStatus::TYPE_APP)])?>">重&nbsp;&nbsp;&nbsp;&nbsp;置</a>
                        <a class="btn btn-default" style="float: right;" href="javascript:void(0)" id="btn-export"> 导出数据 </a>&nbsp;&nbsp;
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
</div>

<div class="panel panel-default">
    <div  class="panel-body">
        <table class="table table-striped table-bordered"  id="brand-table">
            <thead>
            <tr>
                <th width="9%">设备ID</th>
                <th width="8%">包名</th>
                <th width="8%">当前版本</th>
                <th width="9%">目标版本</th>
                <th width="9%">厂商</th>
                <th width="9%">机器型号</th>
                <th width="9%">Barcode</th>
                <th width="7%">升级状态</th>
                <th width="9%">升级错误码</th>
                <th width="9%">时间</th>
                <th width="8%">操作</th>
            </tr>
            </thead>

            <tbody>
            <?php if ($listdata) { ?>
                <?php foreach ($listdata as $item) : ?>
                    <tr>
                        <td style="padding:12px;"><?= (isset($item["device_id"]) ? $item["device_id"] : "") ?></td>
                        <td style="padding:12px;"><?= (isset($item["package_name"]) ? $item["package_name"] : "-") ?></td>
                        <td style="padding:12px;"><?= (isset($item["current_version"]) ? $item["current_version"] : "") ?></td>
                        <td style="padding:12px;"><?= (isset($item["target_version"]) ? $item["target_version"] : "") ?></td>
                        <td style="padding:12px;"><?= (isset($item["manufacture_name"]) ? $item["manufacture_name"] : "") ?></td>
                        <td style="padding:12px;"><?= (isset($item["model_name"]) ? $item["model_name"] : "") ?></td>
                        <td style="padding:12px;"><?= (isset($item["barcode"]) ? $item["barcode"] : "") ?></td>
                        <td style="padding:12px;"><?= UpgradeLogStatus::statusLabel($item['status'])?></td>
                        <td style="padding:12px;"><?= (!empty($item["error_code"]) ? $item["error_code"] : "-") ?></td>
                        <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['created_at'])?></td>
                        <td style="padding:12px;"><a class="del-item-btn" href="javascript:void(0)" data-id="<?=$item['id']?>">删除</a></td>
                    </tr>
                <?php endforeach; ?>
            <?php } else { ?>
            <tr>
                <td colspan="9">
                    <center>暂无记录</center>
                </td>
            </tr>
            <?php } ?>
            </tbody>
        </table>
        <div class="action-box">
                <button class="btn btn-danger btn-sm btn_search_del" >删除搜索结果</button>
        </div>
    </div>

    <div class="panel-footer">
        <div class="hqy-panel-pager">
            <?= LinkPager::widget([
                'pagination' => $pages,
            ]); ?>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<script>
    var delSearchURL = '<?=Url::to("del-search")?>';
    var delItemURL = '<?=Url::to("del-item")?>';
    window.queryParams = function(params) {
        $("#search-form").find('input[name]').each(function () {
            var val = $(this).val();
            var name = $(this).attr('name');
            if(val){
                params[name] = val;
            }
        });
        return params;
    }
    $(function () {
        $('#btn-export').click(function(e){
            var params = {};
            window.queryParams(params);

            $strQuery = "?";
            if (params) {
                for (var p in params) {
                    $strQuery += p + "=" + params[p] + "&";
                }
            }
            $strQuery = $strQuery.substring(0, $strQuery.length-1);
            window.location.href = "export" + $strQuery;
            return false;
        })


        $('.btn_search_del').click(function(e){
            var params = {};
            window.queryParams(params);

            if (null == params || '' == params) {
                alert('请录入搜索条件');
                return false;
            }

            var paramsLen = 0;
            var keyName = '';
            for(var key in params ) {
                paramsLen++;
                keyName = key;
            }

            if (('type' == keyName && 1 == paramsLen) || '' == keyName) {
                alert('请录入搜索条件');
                return false;
            }

            if (!confirm('确定删除么?')) {
                return false;
            }
            $.post(delSearchURL, params, function(ajaxRes){
                alert(ajaxRes.message);
                if(ajaxRes.success) {
                    var _body = window.parent;
                    var _iframe1=_body.document.getElementById('x-iframe');
                    _iframe1.contentWindow.location.reload(true);
                }
            }, 'json')

        })

        $('.del-item-btn').click(function(e){
            var id = $(this).attr('data-id');
            if (!confirm('确定删除该条记录么?')) {
                return false;
            }
            $.post(delItemURL, {id:id}, function(ajaxRes){
                alert(ajaxRes.message);
                if(ajaxRes.success) {
                    var _body = window.parent;
                    var _iframe1=_body.document.getElementById('x-iframe');
                    _iframe1.contentWindow.location.reload(true);
                }
            }, 'json')
        })

    });
</script>