batch.php 10.4 KB
<?php

use yii\helpers\Url;
use app\ht\widgets\LinkPager;

$this->title = '批次管理';
$this->params['breadcrumbs'][] = '二维码管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<script src="<?= Yii::$app->request->baseUrl . "/exts/combo-select/js/jquery.combo.select.js"?>"></script>
<link rel="stylesheet" type="text/css" href="<?= Yii::$app->request->baseUrl . "/exts/combo-select/css/combo.select.css"?>" />
<style>
    .combo-select{
        margin-bottom: 0;
        width: width: 252px;;
        float: left;
        height: 34px;
    }
    .combo-select .combo-input{
        padding: 7px!important;
    }
</style>
<div class="panel panel-default">
    <div class="panel-body">
        <form action="" method="get" class="filter-form">
            <table width="100%">
                <tbody>
                <tr >
                    <td width="10%" class="text-right">选择批次:</td>
                    <td width="40%"  class="text-left form-inline">
                        <select class="form-control combo-select-item" id="batch" name="batch">
                            <option value="0">--请选择批次--</option>
                            <?php foreach ($batchList as $batch) : ?>
                                <option value="<?=$batch['id'] ?>" <?php if ($batch['id'] == $gets['batch_id']){ echo "selected"; } ?> ><?=$batch['name'] ?></option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                    <td width="10%" class="text-right"></td>
                    <td width="40%"  class="text-left"></td>
                </tr>
                <tr >
                    <td width="10%" class="text-right">选择城市:</td>
                    <td width="40%"  class="text-left form-inline">
                        <select class="form-control combo-select-item" id="city" name="city">
                            <option value="0">--请选择城市--</option>
                            <?php foreach ($region as $regionItem) : ?>
                                <option value="<?=$regionItem['city'] ?>" <?php if ($regionItem['city'] == $gets['city']){ echo "selected"; } ?> ><?=$regionItem['city'] ?></option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                    <td width="10%" class="text-right"></td>
                    <td width="40%"  class="text-left"></td>
                </tr>
                <tr class="search">
                    <td colspan="6"  class="text-center">
                        <button type="submit" class="btn btn-primary" id="search"><i class="glyphicon glyphicon-search"></i> 查 询  </button>
                        <a class="btn btn-default"  href="<?=Url::toRoute("/device/qrcode/batch")?>">重&nbsp;&nbsp;&nbsp;&nbsp;置</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">
        <a href="<?php echo Url::toRoute('/device/qrcode/batch-create'); ?>" class="btn btn-success pull-left">新增批次</a>
        <div class="clearfix"></div>
    </div>
    <div  class="panel-body">
        <?php if (!empty($batchList)) : ?>
            <table class="table table-striped table-bordered"  id="brand-table">
                <thead>
                <tr>
                    <th style="width:5%;" class="text-center align-middle hqy-all-select">设备ID</th>
                    <th style="width:20%;">批次名称</th>
                    <th style="width:10%;">城市</th>
                    <th style="width:5%;">生成数量</th>
                    <th style="width:15%;">生成时间</th>
                    <th style="width:15%;">修改时间</th>
                    <th style="width:25%;">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($batchList as $batch) : ?>
                    <tr>
                        <td class="text-center align-middle hqy-row-select"><?= $batch['id'] ?></td>
                        <td >
                            <?= $batch['name'] ?>
                        </td>
                        <td >
                            <?= $batch['city'] ?>
                        </td>
                        <td >
                            <?= $batch['count'] ?>
                        </td>
                        <td >
                            <?=Yii::$app->formatter->asTime($batch['created_at'],"yyyy-MM-dd HH:mm:ss"); ?>
                        </td>
                        <td >
                            <?=Yii::$app->formatter->asTime($batch['updated_at'],"yyyy-MM-dd HH:mm:ss"); ?>
                        </td>
                        <td >
                            <a class="btn btn-primary" href="<?php echo Url::toRoute(['/device/qrcode/batch-update', 'batch_id' => $batch['id']])  ?>">编辑</a>
                            <?php if ($batch['status'] == 1): ?>
                                <a class="btn btn-primary" href="<?php echo Url::toRoute(['/device/qrcode/index', 'batch' => $batch['id']])  ?>">查看</a>
                                &nbsp;&nbsp;
                                <a class="btn btn-success" href="<?php echo Url::toRoute(['/device/qrcode/zip', 'batch_id' => $batch['id']])  ?>">二维码批量导出</a>
                            <?php else: ?>
                                <button class="btn btn-primary btn_generate" batchid="<?=$batch['id'] ?>">生成</button>
                            <?php endif;?>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        <?php else : ?>
            <p class="text-center">
                没有找到数据
            </p>
        <?php endif; ?>
    </div>

    <div class="panel-footer">
        <div class="hqy-panel-pager">
            <?= LinkPager::widget([
                'pagination' => $pages,
            ]); ?>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        $(".btn_generate").bind("click",function(){
            var batch_id = $.trim($(this).attr("batchid"));
            if (batch_id == null || batch_id == ""){
                alert("参数错误,请刷新后再试");
                return false;
            }
            //$(this).attr("disabled","true");
            var loading = $.ladda(this);
            $.ajax({
                type: "post",
                url: "do-generate-qrcode",
                dataType:"json",
                data: $.csrf({"batch_id":batch_id}),
                beforeSend : function(){
                    // 开始加载...
                    loading.start();
                },
                success:function(msg){
                    loading.stop();
                    alert(msg['msg']);
                    if (msg['status'] == 1){
                        location.reload();
                    }else{
                        //提示确认失败
                        //$(this).removeAttr("disabled");
                    }
                },
                error:function(msg){
                    //提示确认失败
                    $(this).removeAttr("disabled");
                }
            });
        });
    });

    var count = 1; // 正在执行页码
    var pageCount = 0; // 总页码
    function exportData(params) {
        $.ajax({
            url: "<?=Url::toRoute("/device/qrcode/export-zip-batch")?>",
            dataType: "json",
            data: params,
            type: "GET",
            cache: false,
            success: function (r) {
                if (!r.success) {
                    alert('系统出错,请联系管理员')
                } else {
                    $("#dialogContent2").html(r.html);
                    pageCount = r.pageCount;
                    gen(params, 1);
                    seajs.use("base/1.0.0/ui/block-ui/block-ui-1.0.0", function () {
                        $.blockUI({
                            message: $("#dialog2"),
                            css: {
                                width: "990px",
                                height: "220px",
                                top: "200px",
                                left:"20%",
                                cursor: null
                            }
                        })
                    })
                }
            },
            error: function (r) {
                if (r.status == 403) {
                    alert('您没有此操作权限,请联系管理员')
                }
            }
        })
    }

    function gen(params, pageNo) {
        var param = params;
        param += "&pageNo=" + pageNo + '&pageCount=' + pageCount;

        $.ajax({
            url: "<?=Url::toRoute("/device/qrcode/export-qrcode-batch")?>",
            dataType: "json",
            data: param,
            type: "POST",
            cache: false,
            beforeSend: function (XMLHttpRequest) {

            },
            success: function (dataResult) {
                if (dataResult.success) {
                    count++;
                    if (count <= pageCount) {
                        $('#count').html(count);
                        gen(params, count);
                    }
                    if (count > pageCount) {
                        seajs.use("base/1.0.0/ui/block-ui/block-ui-1.0.0", function () {
                            $.unblockUI();
                        });
                        location.reload();
                    }

                } else {
                    alert("生成二维码意外中断,请重试.");
                    seajs.use("base/1.0.0/ui/block-ui/block-ui-1.0.0", function () {
                        $.unblockUI();
                    });
                }

            },
            error: function (dateResult) {
                seajs.use("base/1.0.0/ui/block-ui/block-ui-1.0.0", function () {
                    $.unblockUI();
                });
            }
        })
    }
</script>
<div id="dialog2" style="display: none">
    <div style="position:absolute;right: 10px; top: 10px "><a href="javascript:void(0)" id="closeDialog2" >关闭</a></div>
    <div id="dialogContent2" style="margin-top:5px;text-align:left"></div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $('.combo-select-item').comboSelect();
    });
</script>