@{
    ViewData["Title"] = "账单流水字段指定配置";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "销售平台流水", "账单流水字段指定配置列表" };
}


<div class="row">
    <div class="col-sm-12">
        <div class="alert alert-warning">
            
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>月份</label>
                        <input id="month" name="month" type="text" class="form-control" style="width:120px;" value="@(ViewBag.month)" placeholder="请输入月份" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
                        <button id="btn_uploadFlowing" type="button" class="btn btn-warning">导入</button>
                        <a href="@Url.Content("~/templatefile/汇率.xlsx")" target="_blank">模版下载</a>
                    </div>
                </div>
            </form>
        </div>

        <div class="ibox-content m-b-sm border-bottom">
            <table class="table table-hover table-bordered table-condensed table-striped">
                <thead>
                    <tr>
                        <th>月份</th>
                        <th>币种</th>
                        <th>汇率</th>
                    </tr>
                </thead>
                <tbody id="tb">
                </tbody>
            </table>
        </div>
    </div>
</div>
@section css{
    <link href="~/js/webuploader-0.1.5/webuploader.css" rel="stylesheet" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .webuploader-pick {
            position: relative;
            display: block;
            cursor: pointer;
            background: none;
            padding: 0px;
            color: #fff;
            text-align: center;
            border-radius: 3px;
            overflow: hidden;
        }

        .webuploader-container {
            background-color: cornflowerblue !important;
        }
    </style>
}
@section scripts{
    <script src="~/js/webuploader-0.1.5/webuploader.min.js"></script>

    <script type="text/javascript">
        var BASE_URL = '@(Url.Content("~/js/webuploader-0.1.5/"))';

        var tb;
        var companyid = 0;

        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 170));

            list();

            laydate.render({
                elem: '#month', type: 'month', done: function (value, date, endDate) {
                    //console.log(value); //得到日期生成的值，如：2017-08-18
                    //console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                    //console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。

                    month = value;
                    initUpload();
                }
            });

            initUpload();
        })

        function list() {
            $.submit({
                url: '@Url.Content("~/DataWareHouse/PlatformOrder/ExchangeRateJson")',
                paramData: $("#toolbar").serialize(),
                type:'POST',
                func: function (result) {
                    $('#tb').html('');
                    if (result.success) {
                        for (var i = 0; i < result.list.length; i++) {
                            var _obj = result.list[i];

                            var _str = '<tr>';
                            _str += '<td>' + _obj.month + '</td>';
                            _str += '<td>' + _obj.currency + '</td>';
                            _str += '<td>' + _obj.exchange_rate + '</td>';
                            _str += '</tr>';

                            $('#tb').append(_str);
                        }
                    }
                }
            })
        }


        function initUpload() {

            var month = $('#month').val();
            if (month == '') {

                alert('请选择月份');
                return false;
            }

            uploadfile('btn_uploadFlowing',
                '@Url.Content("~/DataWareHouse/PlatformOrder/UploadExchangeRate")' + '?month=' + month,
                function(result){
                    if(result.success)
                    {
                        alert('文件上传成功');

                    }
                    else
                    {
                        alert(result.msg);
                    }
                });
        }

        function uploadfile(id,url,callback)
        {
            var uploader = new WebUploader.Uploader({
                // swf文件路径
                swf: BASE_URL + 'Uploader.swf',
                // 文件接收服务端。
                server: url != undefined ? (url + '?companyid=' + companyid) : '@Url.Content("~/File/UploadFile")',
                // 选择文件的按钮。可选。
                // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                pick: '#'+id,
                // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
                resize: false,
                auto:true
            });

            uploader.on('uploadSuccess', function (file, response) {
                if(callback!=undefined)
                {
                    callback(response);
                }
            });

            uploader.on('uploadError', function (file) {
                layer.msg("上传出错");
            });
        }

    </script>
}

