auth-fail-index.php 9.5 KB
<?php
use yii\helpers\Url;
use app\ht\widgets\LinkPager;
use domain\device\Device;

$this->title = '授权失败管理';
$this->params['breadcrumbs'][] = '失败序列号管理';
$this->params['breadcrumbs'][] =  $this->title;
?>
<style>
    .cell-cls{width:60%;word-wrap: break-word}
    .td-cls{padding:8px 0}
</style>
<div class="panel panel-default">
    <div class="panel-body">
        <form action="" method="get" id="search-form" class="filter-form">
            <div class="form-group col-sm-12">
                <label for="manufacture" class="col-sm-1 control-label text-right">厂商:</label>
                <div class="col-sm-2 form-inline">
                    <input type="text" class="form-control" id="manufacture" name="manufacture" value="<?php if (!empty($gets['manufacture'])){ echo $gets['manufacture'];} ?>" autocomplete="off">
                </div>
                <label for="project" class="col-sm-1 control-label text-right">项目名:</label>
                <div class="col-sm-2 form-inline">
                    <input type="text" class="form-control" id="project" name="project" value="<?php if (!empty($gets['project'])){ echo $gets['project'];} ?>" autocomplete="off">
                </div>
                <label for="model" class="col-sm-1 control-label text-right">型号:</label>
                <div class="col-sm-2 form-inline">
                    <input type="text" class="form-control" id="model" name="model" value="<?php if (!empty($gets['model'])){ echo $gets['model'];} ?>" autocomplete="off">
                </div>
                <label for="production" class="col-sm-1 control-label text-right">生产日期:</label>
                <div class="col-sm-2 form-inline">
                    <input type="text" class="form-control" id="production" name="production" value="<?php if (!empty($gets['production'])){ echo $gets['production'];} ?>" autocomplete="off">
                </div>
            </div>

            <div class="form-group col-sm-12">

                <label for="device_id" class="col-sm-1 control-label text-right">设备ID:</label>
                <div class="col-sm-2 form-inline">
                    <input type="text" class="form-control" id="device_id" name="device_id" value="<?php if (!empty($gets['device_id'])){ echo $gets['device_id'];} ?>" autocomplete="off">
                </div>

                <label for="apply_at" class="col-sm-1 control-label text-right">申请时间:</label>
                <div class="col-sm-5 form-inline">
                    <input type="date" class="form-control" id="start_apply_at" name="start_apply_at" value="<?php if (!empty($gets['start_apply_at'])){ echo $gets['start_apply_at'];} ?>" autocomplete="off"> - <input type="date" class="form-control" id="end_apply_at" name="end_apply_at" value="<?php if (!empty($gets['end_apply_at'])){ echo $gets['end_apply_at'];} ?>" autocomplete="off">
                </div>

            </div>

            <div class="form-group col-sm-12" style="text-align: center;">
                <button type="submit" class="btn btn-primary font-1" id="submitFilterBtn">查询</button>
            </div>
        </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="4%"></th>
                <th width="5%">ID</th>
                <th width="10%">批次编码</th>
                <th width="10%">厂商</th>
                <th width="6%">项目</th>
                <th width="8%">设备型号</th>
                <th width="8%">生产日期</th>
                <th width="10%">设备ID</th>
                <th width="10%">申请时间</th>
                <th width="20%">操作</th>
            </tr>
            </thead>

            <tbody>
            <?php if ($deviceList) { ?>
                <?php foreach ($deviceList as $item) : ?>
                    <tr>
                        <td><input type="checkbox" class="check-cls check-item" value="<?= $item['id'] ?>"/></td>
                        <td class="td-cls">
                            <?= $item['id'] ?>
                        </td>
                        <td class="td-cls">
                            <?= Device::getBatchNo($item['manufacture_no'], $item['project_no'], $item['model_no'], $item['production_no']) ?>
                        </td>
                        <td class="td-cls">
                            <?= $item['manufacture'] ?>
                        </td>
                        <td class="td-cls">
                            <?= $item['project'] ?>
                        </td>
                        <td class="td-cls">
                            <?= $item['model'] ?>
                        </td>
                        <td class="td-cls">
                            <?= $item['production'] ?>
                        </td>

                        <td class="td-cls">
                            <div class="edit_device edit_device_<?=$item['id']?>" data-id="<?=$item['id']?>" data="<?=$item['device_id']?>"><?= $item['device_id']? $item['device_id']:'暂无'?></div>
                        </td>
                        <td class="td-cls">
                            <?= $item['apply_at']?date('Y-m-d H:i:s', $item['apply_at']):'暂无' ?>
                        </td>

                        <td class="td-cls">
                            <button class="btn btn-info btn-sm btn_edit" aid="<?=$item['id'] ?>" data-action="edit">编辑</button> &nbsp;|&nbsp;
                           <button class="btn btn-primary btn-sm btn_re_auth" aid="<?=$item['id'] ?>">处理</button>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php } else { ?>
                <tr>
                    <td colspan="12">
                        <center>暂无记录</center>
                    </td>
                </tr>
            <?php } ?>
            </tbody>
        </table>
        <div class="action-box">
            <label><input type="checkbox" class="check-all" value="all" /> 本页全选 </label> <button class="btn btn-primary btn-sm btn_batch_auth" >批量处理</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 authURL = "<?=Url::toRoute('/device/device/re-auth')?>";
    var batchReAuthURL = "<?=Url::toRoute('/device/device/batch-re-auth')?>";
    var delURL = "<?=Url::toRoute('/device/device/del-device')?>";
    var doEditURL = "<?=Url::toRoute('/device/device/do-edit-fail')?>";
    $(function () {
        $('.btn_re_auth').click(function(e) {
            var aid = $(this).attr('aid');
            $.post(authURL, {id:aid}, function(res) {
                if (!res.success) {
                    alert(res.message);
                    return false;
                }
                window.location.reload();
            }, 'json')
        })

        $('.btn_edit').click(function(e) {
            var editThis = $(this);
            var action = editThis.attr('data-action')
            var id = editThis.attr('aid');
            var editDevice = $('.edit_device_'+id);

            if ('edit' == action ) {

                var editDevices = $('.edit_device');
                $.each(editDevices, function(i,n){
                    $(n).html($(n).attr('data'));
                })
                var btnEdits = $('.btn_edit');
                $.each(btnEdits, function(i,n){
                    $(n).html('编辑').attr('data-action','edit');
                })
                editThis.html('保存').attr('data-action','save');

                var editDeviceVal = editDevice.attr('data');
                editDevice.html('<input type="text" class="device_edit" value="'+editDeviceVal+'">');
            } else {
                var newDevice = editDevice.find('.device_edit').val();
                // 请求之后保存
                $.post(doEditURL, {id:id, deviceId: newDevice}, function(res){
                    if (res.success) {

                        editDevice.html(newDevice).attr('data', newDevice);
                        editThis.html('编辑').attr('data-action','edit');
                    } else {
                        alert(res.message);
                    }

                }, 'json')

            }

        })

        $('.check-all').click(function(e) {
            var checkVal = $(this).prop('checked');
            $('.check-item').prop('checked', checkVal)

        })

        $('.btn_batch_auth').click(function(e) {
            var checkItems = $('.check-item:checked');
            if ( 0 == checkItems.length) {
                alert('请选择要操作的行');
                return false;
            }
            var ids = [];
            $.each(checkItems, function(i,n){
                var id = $(n).val();
                if ('' != id && 0 != id) {
                    ids.push(id);
                }
            })
            ids = ids.join(',');
            $.post(batchReAuthURL,{ids:ids},function(res){
                if (res.success) {
                    alert(res.message);
                    var _body = window.parent;
                    var _iframe1=_body.document.getElementById('x-iframe');
                    _iframe1.contentWindow.location.reload(true);
                } else {
                    alert(res.message);
                }
            }, 'json')
        })
    });
</script>