<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="common/css/uePicPicker.css">
    <style>
        .previewImg {
            max-width: 100%;
            max-height: 100%;
            border: 0px;
            display: none;
            z-index: 999;
        }
    </style>

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <!--validate css-->
    <link rel="stylesheet" href="plugins/jquery-validation/css/validate.css">
    <!--fileinput css-->
    <link rel="stylesheet" href="plugins/bootstrap-fileinput/bootstrap-fileinput.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<!-- END HEAD -->
<body class="hold-transition skin-blue sidebar-mini">

<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">

        <div id="baidumap"></div>
        <div id="tencentmap"></div>

        <section class="content-header">
            <h1>
                经销商列表管理
                <small>经销商列表管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active"></a></li>
            </ol>
        </section>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <!-- general form elements disabled -->
                    <div class="box box-primary">
                        <form role="form" id="myForm">
                            <input name="id" value="$!{data.id}" hidden="true"/>
                            <div class="box-body">
                                <div class="form-group form-md-line-input">
                                    <label>经销商名称</label>
                                    <input type="text"
                                           class="form-control" name="company"
                                           id="company"
                                            maxlength="100" placeholder="经销商名称"
                                           value="$!{data.company}"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>电话</label>
                                    <input type="text"
                                           class="form-control" name="phone"
                                           id="phone"
                                           maxlength="100" placeholder="电话"
                                           value="$!{data.phone}"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>传真</label>
                                    <input type="text"
                                           class="form-control" name="fax"
                                           id="fax"
                                           maxlength="100" placeholder="传真"
                                           value="$!{data.fax}"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>邮箱</label>
                                    <input type="text"
                                           class="form-control" name="email"
                                           id="email"
                                           maxlength="100" placeholder="邮箱"
                                           value="$!{data.email}"
                                    >

                                </div>

                                <!--经销商图片-->
                                <div class="form-group form-md-line-input col-md-12" id="imageurl">

                                </div>

                                <div class="form-group form-md-line-input">
                                    <label>地址</label>
                                    <input type="text"
                                           class="form-control" name="address_detail"
                                           id="address_detail"
                                           maxlength="100" placeholder="地址"
                                           value="$!{data.address_detail}"
                                    >

                                </div>


                                <div class="form-group form-md-line-input ">
                                    <label>导航地址</label>
                                    <div class="input-group">
                                        <input type="text" name="address" id="address" value="$!{data.address}" class="form-control" disabled>
                                        <input name="longitude" id="lng" value="$!{longitude}" hidden="true"/>
                                        <input name="latitude" id="lat" value="$!{latitude}" hidden="true"/>
                                        <span class="input-group-btn">
                                            <button type="button" id="selectAddress"
                                                    class="btn btn-info btn-flat">选择</button>
                                                </span>
                                    </div>
                                <div class="form-group form-md-line-input ">
                                    <label>经销商类别</label>
                                    <div class="input-group">
                                        <input type="text" name="type_id" id="type_id"
                                               value="$!{type_id}"
                                               class="form-control" style="display: none" >
                                        <input type="text" name="type_name" id="type_name"
                                               value="$!{type_name}"
                                               class="form-control" disabled>
                                        <span class="input-group-btn">
                                            <button type="button" id="selectType"
                                                    class="btn btn-info btn-flat">选择类别</button>
                                                </span>
                                    </div>
                                </div>
                                    <input type="text" style="display: none" name="_csrf" value="${_csrf.token}"/>
                                    <input  type="text" style="display: none" name="_csrf_header" value="${_csrf.headerName}"/>
                                <div class="form-group form-md-line-input ">
                                    <label>经销商地区</label>
                                    <div class="input-group">
                                        <input type="text" name="area_id" id="area_id"
                                               value="$!{area_id}"
                                               class="form-control" style="display: none" >
                                        <input type="text" name="area_name" id="area_name"
                                               value="$!{area_name}"
                                               class="form-control" disabled>
                                        <span class="input-group-btn">
                                            <button type="button" id="selectArea"
                                                    class="btn btn-info btn-flat">选择地区</button>
                                                </span>
                                    </div>
                                </div>
                            </div>

                            <div class="box-footer">
                                #if($shiro.hasPermission("qy:distributor:edit"))
                                <input class="btn btn-primary" id="save" value="保存" type="submit">
                                #end
                                <a href="#springUrl('/a/distributor/list')" class="btn btn-default">取消</a>
                            </div>
                        </div>
                        </form>
                        <!-- /.box-body -->
                    </div><!-- /.box -->


                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->


    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->

<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!--fileinput js-->
<script src="plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script src="plugins/bootstrap-maxlength/bootstrap-maxlength.min.js" type="text/javascript"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<script src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script src="js/jquery.form.min.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=9GOIFal1gekxBIBmOaippe1Y4ap9pXhk"></script>
<script src="common/js/cfapp.js"></script>
<script src="js/jquery.serializejson.js"></script>
<script src="plugins/Sortable/Sortable.min.js"></script>
<script src="common/component/uePicPicker.js"></script>
<script src="common/component/ueSPicPicker.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<script>

    var coverPP = null;
    var initPicsSel = function () {
        var smallimg = "$!{data.image}";
        coverPP = new uePicPicker({
            tarId: 'imageurl', //根据tarId 找到图片放入位置
            title: '图片',
            sizeDes: '544*350',
            max: 1,   //最多可选几个
            datas: smallimg == '' ? null : smallimg.split(","),//如果有多个图片路径就用逗号分割
            success: null  //回调函数
        });
        coverPP.init();
    }

    function formatDates(now) {
        var now = new Date(now);
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        var hour = now.getHours();
        var minute = now.getMinutes();
        var second = now.getSeconds();
        return year + "-" + month + "-" + date + "   " + hour + ":"
            + minute + ":" + second;
    }

    $().ready(function () {
        Cfapp.init();
        recdTypeAdd.init();
        initPicsSel();
    });

    //地址
    $("#selectAddress").click(function(){
        Cfapp.map({
            addressField: 'address',
            lngField: 'lng',
            latField: 'lat',
            success: function () {

            },
            cancel: function () {

            }
        })
    })

    //经销商类别
    $("#selectType").click(function () {
        // alert("a")
        Cfapp.f7({
            dataUrl: "#springUrl('/a/distributor_type/listData')",
            checkType: 'single', // 多选为multi
            title: "请选择经销商类别",
            btnoktext: "确定",
            btncanceltext: "取消",
            columns: ['选择', '类别名称','创建时间'],
            isSearch: '0',
            searchColumns: ["type_name"],//搜索的字段名称
            searchColumnsRemarks: ['类别名称'],//搜索的字段备注
            aoColumns: [{
                "mData": "id"
            }, {
                "mData": "type_name"
            },{
                "mData":"createTime"
            }],
            aoColumnDefs: [{
                "aTargets": [0],
                "mData": "id",
                "mRender": function (a, b, c, d) {
                    return '<input type="radio" id="' + a + '" name="sel" data-value="' + a + '" data-name="' + c.type_name + '">';
                }
            },{
                "aTargets":[2],
                "mData":"createTime",
                "mRender":function (a,b,c,d) {
                    return formatDates(a,"yyyy-MM-dd HH:mm:ss")
                }
            }],
            success: function () {

            },
            cancel: function () {

            },
            storeFields: 'type_id', // 储存的字段
            displayFields: 'type_name' //显示字段
        })
    });

    //经销商地区
    $("#selectArea").click(function () {
        // alert("a")
        Cfapp.f7({
            dataUrl: "#springUrl('/a/distributor_area/listData')",
            checkType: 'single', // 多选为multi
            title: "请选择经销商地区",
            btnoktext: "确定",
            btncanceltext: "取消",
            columns: ['选择', '地区名称','创建时间'],
            isSearch: '0',
            searchColumns: ["area_name"],//搜索的字段名称
            searchColumnsRemarks: ['地区名称'],//搜索的字段备注
            aoColumns: [{
                "mData": "id"
            }, {
                "mData": "area_name"
            },{
                "mData":"createTime"
            }],
            aoColumnDefs: [{
                "aTargets": [0],
                "mData": "id",
                "mRender": function (a, b, c, d) {
                    return '<input type="radio" id="' + a + '" name="sel" data-value="' + a + '" data-name="' + c.area_name + '">';
                }
            },{
                "aTargets":[2],
                "mData":"createTime",
                "mRender":function (a,b,c,d) {
                    return formatDates(a,"yyyy-MM-dd HH:mm:ss")
                }
            }],
            success: function () {

            },
            cancel: function () {

            },
            storeFields: 'area_id', // 储存的字段
            displayFields: 'area_name' //显示字段
        })
    });


    var recdTypeAdd = function () {
        var initForm = function () {
            var initFormCtrl = function () {
                bindEvent();
            };
            var bindEvent = function () {

                $("#myForm").validate({
                    rules: {},
                    messages: {},
                    submitHandler: function (form) {
                        $("#save").attr("disabled", true);
                        var dataJson = $("#myForm").serializeJSON();
                        var picurl = coverPP.getStringValues();
                        dataJson.address = $('#address').val();
                        dataJson.image = picurl.substring(0,picurl.lastIndexOf(','));
                        $.post("#springUrl('/a/distributor/formData')", dataJson, function (returnobj) {
                            $("#save").attr("disabled", false);
                            if (returnobj.errorNo == 2) {  //保存成功
                                Cfapp.confirm({
                                    message: "添加成功",
                                    btnoktext: "继续添加",
                                    btncanceltext: "关闭",
                                    success: function () {
                                        location.href = "#springUrl('/a/distributor/form')";
                                    },
                                    cancel: function () {
                                        location.href = "#springUrl('/a/distributor/list')";
                                    }
                                });
                            } else if (returnobj.errorNo == 0) {  //修改成功
                                Cfapp.alert({
                                    message: "更新成功",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/distributor/list')";
                                    }
                                });
                            } else {
                                Cfapp.alert({
                                    message: "创建失败",
                                    btntext: "确定",
                                    success: function () {
                                        return;
                                    }
                                });
                            }
                        });
                    }
                })
            }
            initFormCtrl();
        }
        return {

            //main function to initiate the module
            init: function () {
                initForm();
            }

        };
    }();
</script>
</body>
<!-- END BODY -->
</html>