<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('经销商列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>经销商：</p>
                                <input type="text" name="chainsName"/>
                            </li>
                            <li>
                                <p>代号：</p>
                                <input type="text" name="chainsCode"/>
                            </li>
                            <li>
                                <p>用户账号：</p>
                                <input type="text" name="userAccount"/>
                            </li>
                            <li>
                                <p>用户名称：</p>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <p>用户号：</p>
                                <input type="text" name="userNo"/>
                            </li>
                            <li>
                                <p>信用分：</p>
                                <input type="text" name="creditScore"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" id="dealHistoryDataAll">
                    <i class="fa fa-edit"></i> 全部处理
                </a>
                <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:customers:add">-->
                    <!--<i class="fa fa-plus"></i> 添加-->
                <!--</a>-->
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:customers:edit">-->
                    <!--<i class="fa fa-edit"></i> 修改-->
                <!--</a>-->
                <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:customers:remove">-->
                    <!--<i class="fa fa-remove"></i> 删除-->
                <!--</a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="order:customers:export">
                    <i class="fa fa-download"></i> 导出已认证经销商
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">

        var prefix = ctx + "order/customers";

        $(function() {
            var options = {
                url: prefix + "/list",
                updateUrl: prefix + "/edit/{id}",
                exportUrl: prefix + "/export",
                modalName: "认证经销商",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'chainsName', 
                    title : '经销商'
                },
                {
                    field : 'chainsCode', 
                    title : '经销商代号'
                },
                {
                    field : 'stateName', 
                    title : '省份'
                },
                {
                    field : 'cityName', 
                    title : '市'
                },
                {
                    field : 'districtName', 
                    title : '区'
                },
                // {
                //     field : 'userAccount',
                //     title : '用户账号'
                // },
                // {
                //     field : 'userName',
                //     title : '用户名称'
                // },
                // {
                //     field : 'userNo',
                //     title : '用户号'
                // },
                {
                    field : 'creditScore', 
                    title : '信用分'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.editTitle(\'' + row.id + '\')"><i class="fa fa-edit"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="dealHistoryData(\'' + row.chainsCode + '\')"><i class="fa fa-edit"></i>处理</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

            //失去焦点事件
            //去除前后空格
            $(".select-list input").blur(function (event){
                var val =  $(event.target).val();
                val = val.replace(/^\s+|\s+$/g,"")
                $(event.target).val(val);
            })



            $("#dealHistoryDataAll").click(function () {
                $.ajax({
                    cache : true,
                    type : "GET",
                    url : prefix+"/dealHistoryData",
                    error : function(request) {
                        $.modal.alertError("系统错误");
                    },
                    success : function(data) {
                        if (data.success){
                            alert("处理完成");
                        } else {
                            alert("处理失败");
                        }
                    }
                })
            })
        });
        function dealHistoryData(customerCode){
            $.ajax({
                cache : true,
                type : "GET",
                url : prefix+"/dealHistoryData",
                data : {
                    "customerCode":customerCode
                },
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    if (data.success){
                        alert("处理完成");
                    } else {
                        alert("处理失败");
                    }
                }
            })
        }
    </script>
</body>
</html>