<!--<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:120px;*/
    /*}*/

    #roleTable tr:nth-child(2n) {
        background: #fafafa;
    }


    .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)';
    }
</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">
                            <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-danger" id="commitBtn">提交</button>
                            <span id="filespan" class="btn btn-success fileinput-button">
                                <span>导入</span>
                                <input style="width: 60px" 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/build" style="margin-bottom: 10px;width: 80px;" class="btn btn-success">导出</a>
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="table-responsive">
                                        <form id="buildConfData">
                                            <table id="roleTable" class="table table-bordered"                                              >
                                                <thead>
                                                <tr>
                                                    <?php if(!empty($title)){
                                                        foreach ($title as $val){ ?>
                                                            <th style="text-align: center"><?php echo $val;?></th>
                                                        <?php }
                                                    }?>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <?php
                                                if(is_array($list)  && !empty($list)){
                                                    foreach ($list as $key => $vl) { ?>
                                                        <tr>
                                                            <td style="text-align: center">
                                                                <div><?php echo $key;?></div>
                                                            </td>
                                                            <?php foreach ($vl as $k=>$v){ ?>

                                                                <td>
                                                                    <?php foreach ($v as $z => $y) { ?>
                                                                        <div>
                                                                            <div>
                                                                                <label> 费用: </label>
                                                                                <input name="coin[<?=$key?>][<?=$k?>][<?=$z?>]" type="number" value="<?php echo $y; ?>">
                                                                            </div>
                                                                            <div style="margin-top: 5px">
                                                                                <table class="col-sm-12" style="transform: scale(0.8)">
                                                                                    <tr>
                                                                                        <td class="formPropsRewardsTag" data-value='<?= json_encode($reward[$key][$k][$z]??[]) ?>' data-name="reward[<?=$key?>][<?=$k?>][<?=$z?>]">
                                                                                        </td>
                                                                                        <td class="text-right" style="width: 80px">
                                                                                            <button type="button"
                                                                                                    class="btn btn-outline btn-success"
                                                                                                    onclick="propsJs.initEdit(this, 'formPropsRewardsTag','func')">
                                                                                                奖励配置
                                                                                            </button>
                                                                                        </td>
                                                                                    </tr>
                                                                                </table>
                                                                            </div>
                                                                        </div>
                                                                        <br><hr>
                                                                    <?php } ?>
                                                                </td>
                                                            <?php } ?>
                                                            <!--                                                        <td><button type="button"  class="btn btn-danger delete-row" ><i class="fa fa-minus-square"></i>删除</button></td>-->
                                                        </tr>
                                                    <?php } } else{?>
                                                    <tr>
                                                        <td colspan="14">暂无数据</td>
                                                    </tr>
                                                <?php } ?>
                                                </tbody>
                                            </table>
                                        </form>
                                    </div>

                                    <nav>
                                        <ul class="pagination">
                                            <li class="disabled"><a href="#">共<span class="pagetotal"><?php echo $total;?></span>条</a></li>
                                            <?php echo $pageurl;?>
                                        </ul>
                                    </nav>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>


</div>


<script src="<?php echo base_url();?>public/js/common.js"></script>
<!--<script src="--><?php //echo base_url();?><!--public/js/imageChange.js"></script>-->

<script>
    propsJs.initTag('formPropsRewardsTag','func')

    $("#btn").click(function(){
        var formData = new FormData();
        formData.append("file",document.getElementById("upfile").files[0]);
        $.ajax({
            type: "POST", // 数据提交类型
            url: "Import/build", // 发送地址
            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
        }
    });

    //提交表格数据
    $('#commitBtn').click(function () {
        msgTip = $('#msg-tip');

        // var tr = $('#roleTable tr');
        // var arr = [];
        // for (var i = 1; i < tr.length; i++) {
        //     var temp = {};
        //     var tempData = [];
        //     td = $(tr[i]).find('td');
        //     for (var j = 0; j < td.length; j++) {
        //         if (j == 0) {
        //             div = $(td[j]).find('div');
        //             for (var x = 0; x < div.length; x++) {
        //                 temp['id'] = parseInt($(div[x]).html());
        //             }
        //         } else {
        //             var build = [];
        //             div = $(td[j]).find('div');
        //             for (var x = 0; x < div.length; x++) {
        //                 build[x] = $(div[x]).html();
        //             }
        //             tempData[j-1] = build
        //         }
        //     }
        //     temp['data'] = tempData;
        //     arr.push(temp)
        // }
        $.ajaxSetup({
            async: true
        });
        const data = $('#buildConfData').toObject();

        $.ajax({
            type: 'POST',
            dataType: 'json',
            data: {
                data: data,
                page: '<?php echo $page; ?>'
            },
            url: 'config/actionBuildConfig',
            success: function (data) {
                if (data.ret == 0) {
                    window.location.reload()
                    $('#commitBtn').attr('disabled', true);
                } else {
                    msgTip.messager().error(data.msg);
                }
            }

        });
    });

</script>

