<?php
use \common\libs\MyLib;
?>
<?php $this->beginBlock('header_css'); ?>
<link href="/assets/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<?php $this->endBlock(); ?>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>号码分配 -- <?=$assign_info->user->getShowName()?> -- <?=$assign_info->phone?></h5>
            <div class="ibox-tools">
                <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="create(0)">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="$('#listTable').bootstrapTable('refresh');">
                    <i class="fa fa-refresh"></i> 刷新
                </a>
                <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="history.back();">
                    <i class="fa fa-backward"></i> 返回
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <table id="listTable">
                        <thead>
                        <tr>
                            <th data-field="id">ID</th>
                            <th data-field="phone">电话号码</th>
                            <th data-field="status">状态</th>
                            <th data-formatter="opFormatter">操作</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>


<?php $this->beginBlock('footer_js'); ?>
<script src="/assets/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/assets/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="/assets/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
    function opFormatter(value, row, index) {
        var opStr = [];
        opStr.push('<a href="javascript:void(0);" onclick="link(' + row.id + ')">');
        opStr.push('<i class="fa fa-edit" title="绑定"></i>');
        opStr.push('</a>');
        opStr.push('<a href="javascript:void(0);" onclick="del(' + row.id + ')">');
        opStr.push('<i class="fa fa-trash" title="删除"></i>');
        opStr.push('</a>');

        return opStr.join(' ');
    }
    function create() {
        title = '新增小号';
        layer_show(title, '/phone-center/sub-edit?assign_id=<?=$assign_info->id?>');
    }
    function link(id) {
        $.get('/phone/ax-init',{id:id,assign_id:<?=$assign_info->id?>},function(obj){
            parent.layer.msg(obj.msg);
        },'json');

    }
    function del(id) {
        parent.layer.confirm('是否确认删除？', {
            btn: ['删除','取消'], //按钮
            shade: false //不显示遮罩
        }, function(){
            $.get('/phone/ax-unbind',{id:id},function(obj){
                if(obj.success){
                    $.post('/phone-center/sub-delete',{id:id},function(data) {
                        parent.layer.msg(data.msg);
                        refreshList();
                    }, 'json');
                } else {
                    parent.layer.msg(obj.msg);
                }
            });
        }, function(){
            //
        });
    }
    function refreshList() {
        $('#listTable').bootstrapTable('refresh');
    }

    function search() {
        $('#listTable').bootstrapTable('destroy');
        $('#listTable').bootstrapTable({
            url: "/phone-center/sub-index-json",
            pagination: true,
            sidePagination: 'server',
            queryParams: function(params) {
                params.phone_id = <?=$assign_info->id?>;
                params.type_id = $('#type_id').val();
                params.name = $('#name').val();
                return params;
            }
        });
        return false;
    }

    $(function() {
        search();
    });
</script>
<?php $this->endBlock(); ?>
