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


<div class="row">
    <div class="col-sm-12">
        <div class="alert alert-warning">
            提示：1、该配置是用于解析流水的订单号、时间、币种的相关信息，会用于流水的搜索条件和财务会计流水的搜索条件<br />
            
            2、必填字段：平台、时间、币种<br />

            3、如果流水文件没有时间、币种字段，请补充，时间可以默认统计月份的最后一天，币种请按流水的币种进行填写<br />

            4、亚马逊流水可以不填币种，已经按站点进行识别币种

        </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>
                        <select id="datatype" name="datatype" class="form-control" style="width:160px;">
                            <option value="1">销售平台</option>
                            <option value="2">物流账单</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>平台：</label>
                        <select id="platform" name="platform" class="form-control" style="width:150px;">
                            <option value="">请选择平台</option>
                            @if (ViewBag.listplatform.Count > 0)
                            {
                                foreach (var item in ViewBag.listplatform)
                                {
                                    <option value="@item">@item</option>
                                }
                            }
                        </select>
                    </div>
                    <div class="form-group">
                        <label>站点：</label>
                        <select id="website" name="website" class="form-control" style="width:120px;">
                            <option value="">请选择站点</option>
                            @if (ViewBag.website.Count > 0)
                            {
                                foreach (var item in ViewBag.website)
                                {
                                    <option value="@item">@item</option>
                                }
                            }
                        </select>
                    </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 type="button" class="btn btn-success" onclick="exportxls();">导出</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>
                        <th>时间对应字段</th>
                        <th>币种对应字段</th>
                        <th>Sku对应字段</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;

        var websiteCount = '@ViewBag.website.Count';

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

            $('#platform').val('@(ViewBag.platform)');

            $('#datatype').val('@ViewBag.datatype');

            list();


            $('#platform').change(function () {
                //获取平台站点
                getWebsite();
            })

            $('#datatype').change(function () {
                //获取平台
                getPlatform();
            })

            initUpload();
        })

        function list() {

            $.submit({
                url: '@Url.Content("~/DataWareHouse/PlatformOrder/FlowingConfigJson")',
                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.platform + '</td>';
                            _str += '<td>' + _obj.website + '</td>';
                            _str += '<td>' + _obj.colname_orderno + '</td>';
                            _str += '<td>' + _obj.colname_datatime + '</td>';
                            _str += '<td>' + _obj.colname_currency + '</td>';
                            _str += '<td>' + _obj.colname_platformsku + '</td>';
                            _str += '<td><a href="javascript:;" class="btn btn-danger btn-xs" onclick="DelConfig(' + _obj.id +')">删除</a></td>';
                            _str += '</tr>';

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

        function exportxls() {
            if (confirm('确定要导出吗？')) {
                window.open('@Url.Content("~/DataWareHouse/PlatformOrder/ExportFlowingConfig")' + '?' + $("#toolbar").serialize(), '_blank');
            }
        }

        function getWebsite() {
            var _platform = $('#platform').val();

            $.submit({
                url: '@Url.Content("~/DataWareHouse/PlatformOrder/ListWebsite?platform=")' + _platform,
                paramData: '',
                type:'POST',
                func: function (result) {
                    websiteCount = 0;
                    if (result.success) {
                        websiteCount = result.data.length
                        $('#website').html('<option value="">请选择站点</option>');
                        if (result.data.length > 0) {
                            for (var i in result.data) {
                                $('#website').append('<option value="' + result.data[i] + '">' + result.data[i] + '</option>');
                            }
                        }

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

        function getPlatform() {
            var _datatype = $('#datatype').val();

            $.submit({
                url: '@Url.Content("~/DataWareHouse/PlatformOrder/ListWebsite?datatype=")' + _datatype,
                paramData: '',
                type:'POST',
                func: function (result) {
                    if (result.success) {
                        $('#platform').html('<option value="">请选择平台</option>');

                        if (result.data.length > 0) {
                            for (var i in result.data) {
                                $('#platform').append('<option value="' + result.data[i] + '">' + result.data[i] + '</option>');
                            }
                        }

                        $('#website').html('<option value="">请选择站点</option>');
                    }
                    else {
                        alert(result.msg);
                    }

                }
            })
        }

        function initUpload() {

            var datatype = $('#datatype').val();

            uploadfile('btn_uploadFlowing',
                '@Url.Content("~/DataWareHouse/PlatformOrder/UploadFlowingConfig")' + '?datatype=' + datatype,
                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("上传出错");
            });
        }

        function DelConfig(id) {
            if (confirm('确定要删除当前配置吗？')) {

                $.submit({
                    url: '@Url.Content("~/DataWareHouse/PlatformOrder/DelConfig")',
                    paramData: 'id=' + id + '&datatype=' + $('#datatype').val(),
                    type:'POST',
                    func: function (result) {
                        if (result.success) {
                            alert('删除成功！');
                            list();
                        }
                        else {
                            alert(result.msg);
                        }
                    }
                })

            }
        }

    </script>
}

