<link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/bootstrap/bootstrap-table.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/bootstrap/table-fix-column.css">

<script src="<?php echo base_url();?>public/js/vendor/bootstrap/src/bootstrap-table.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap/src/table-fix-column.js"></script>

<style type="text/css">
    table {
        table-layout:fixed !important;
    }

    th{
        background: rgb(146, 208, 80);
    }

    td,th{
        max-width: 400px;
        word-wrap: break-word;
    }

    .table-hover > tbody > tr:hover {
        background-color: #c8bd6d;
    }

    input {
        width:60px;
    }

    #roleTable tr:nth-child(5n){
        background:rgb(198, 239, 206);
    } /**隔五行*/

    .fixed-table-toolbar {
        display: none;
    }

    .fileinput-button {
        position: relative;
        top: -5px;
    }

    .fileinput-button input{
        position:absolute;
        right: 0px;
        top: 0px;
        opacity: 0;
        -ms-filter: 'alpha(opacity=0)';
    }

    .asd{
        width:30%;
    }
</style>
<div class="content_wrapper">
    <div id="msg-tip"></div>
    <div class="container-fluid ">
        <div class="row hide">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <!--                                    <form class="form-inline" role="form" method="POST" action="#config/role">-->
                                    <!---->
                                    <!--                                        <button type="submit" class="btn btn-primary">查询</button>-->
                                    <!--                                    </form>-->
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>语言</header>
                    <section>
                        <div class="container-fluid">
                            <span id="filespan" class="btn btn-success fileinput-button">
                                <span>导入</span>
                                <input type="file" id="upfile">
                            </span>
                            <input type="button" style="display: none;margin-bottom: 10px;width: 80px;" class="btn btn-success" value="上传" id="btn"/>
                            <a type="button" href="/Export/lang/" style="margin-bottom: 10px;width: 80px;" class="btn btn-success">导出</a>
                            <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-primary add">新增</button>
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="table-responsive">
                                        <table id="roleTable" class="table table-bordered table-hover" data-toggle="table" data-classes="table table-hover" data-show-columns="true" data-striped="true">
                                            <thead>
                                            <tr>
<!--                                                <th class="asd">语言</th>-->
                                                <th class="asd">语言键</th>
                                                <th>语言值</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php
                                            if(is_array($list)  && !empty($list)){
                                                foreach ($list as $key => $vl) { ?>
                                                    <tr>
<!--                                                        <td class="asd">--><?php //echo $vl['lang'];?><!--</td>-->
                                                        <td class="asd"><input readonly onclick="tdCheck(this.value)" type="text" value="<?php echo $vl['key'];?>" class="form-control"></td>
                                                        <td><textarea rows="1" class="form-control" name='remark'><?php echo $vl['content'];?></textarea></td>
                                                    </tr>
                                                <?php } } else{?>
                                                <tr>
                                                    <td colspan="14">暂无数据</td>
                                                </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="actionShow" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="top: 5%;width: 50%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">配置</h4>
            </div>
            <form class="form-horizontal" role="form" method="post" action="#" data-callBack="" id="conf_set">
                <div class="modal-body">
                    <table id="langDivShow" class="table table-bordered">
                        <thead><tr><th style="width: 20%;">语言</th><th>内容</th></tr></thead>
                        <tbody id="table_body">
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="saveSub">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="<?php echo base_url();?>public/js/common.js"></script>
<script>
    var tmp = JSON.parse('<?php echo addslashes(json_encode($temp)); ?>');
    function check(value){
        for (key in tmp){
            if(value == key){
                for (lang in tmp[key]){
                    $("#input_"+lang).val(tmp[key][lang])
                }
            }
        }
    }
    function tdCheck(value){
        ShowEdit();
        $("#key").val(value)
        check(value)
    }

    function ShowEdit(){
        $("#table_body").children("tr").remove();
        var data = '<?php echo json_encode($lang) ?>';
        var html='';
        data = JSON.parse(data);
        html +='<tr>' +
            '<td>语言键</td>' +
            '<td><input onchange="check(this.value)" type="text" name="key" id="key" value="" class="form-control"></td>' +
            '</tr>';
        for (key in data){
            html +='<tr>' +
                '<td>'+data[key]+'</td>' +
                '<td><input id="input_'+key+'" type="text" name="conf['+key+']" value="" class="form-control"></td>' +
                '</tr>';
        }
        $("#table_body").append(html);
        $('#actionShow').modal('show')
    }
    $('.add').click(function () {
        ShowEdit();
    });
    $('#saveSub').click(function(){
        var datas = $('#conf_set').serializeArray();
        $.ajax({
            url: rootPath + 'config/addLang',
            type: 'POST',
            data: datas,
            dataType:'json',
            success: function (data) {
                alert(data.msg);
                if(data.ret == 0){
                    window.location.reload();
                }
            },
            error: function (data) {
                alert(data.msg);
            }
        });
    });
    $("#btn").click(function(){
        var formData = new FormData();
        formData.append("file",document.getElementById("upfile").files[0]);
        $.ajax({
            type: "POST", // 数据提交类型
            url: "Import/lang/", // 发送地址
            data: formData, //发送数据
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success: function(data) { // 成功回调
                data = JSON.parse(data);
                if(data.ret == 0){
                    window.location.reload();
                }else {
                    msgTip = $('#msg-tip');
                    msgTip.messager().warn('上传失败');
                }
            }
        });
    });

    $("#filespan").on("change", "input[type='file']", function() {
        var filePath = $(this).val();
        //如果仅上传图片 if(filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1) {
        if (filePath) {
            $('#filespan').hide();
            $('#btn').show();
        } else {
            return false
        }
    });
</script>

