<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>

<link rel="stylesheet" href="${contextPath}/static/assets/css/jquery-ui.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/datepicker.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/ui.jqgrid.css" />

<div class="row">
    <div >
        <div class="col-xs-6" >
            <button class="btn btn-large btn-info" onclick="preAaddPlat()">添加平台</button>
            <table id="grid-table"></table>
            <div id="grid-pager"></div>
            <script type="text/javascript">
                var $path_base = "${contextPath}/static";//in Ace demo this will be used for editurl parameter
            </script>
            <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->

    <div style="float: right">
        <div class="col-xs-6" >
            <button class="btn btn-large btn-info" onclick="preAaddSubType()">添加选题类型</button>
            <table id="grid-table1"></table>
            <div id="grid-pager1"></div>
            <script type="text/javascript">
                var $path_base = "${contextPath}/static";//in Ace demo this will be used for editurl parameter
            </script>
            <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->
    <div>
        <div class="col-xs-6" >
            <button class="btn btn-large btn-info" onclick="preAaddSubTree()">添加选题领域</button>
            <table id="grid-table2"></table>
            <div id="grid-pager2"></div>
            <script type="text/javascript">
                var $path_base = "${contextPath}/static";//in Ace demo this will be used for editurl parameter
            </script>
            <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->

    <div style="float: right">
        <div class="col-xs-6" >
            <button class="btn btn-large btn-info" onclick="preAaddSubCon()">添加内容形式</button>
            <table id="grid-table3"></table>
            <div id="grid-pager3"></div>
            <script type="text/javascript">
                var $path_base = "${contextPath}/static";//in Ace demo this will be used for editurl parameter
            </script>
            <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</div>

<div id="modal-refund-body" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header no-padding">
                    <div class="table-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            <span class="white">&times;</span>
                        </button>
                        添加平台
                    </div>
                </div>
                <div class="modal-body" style="overflow-y: scroll;">
                    <div id="mod-add-tip" class="red clearfix"></div>
                    <div class="form-group" style="margin-left: 30px;">
                        <label class="control-label">新增平台名称：</label>
                    </div>
                    <div class="form-group" style="margin-left: 30px;">
                        <input type="text" id="add-platName">
                    </div>
                </div>
                <div class="modal-footer no-margin-top">
                    <div class="text-center">
                        <button id="mod-add-success" type="button" class="btn btn-sm btn-primary"
                                onclick="addPlat(1);">
                            确定
                        </button>
                        <button class="btn btn-sm" data-dismiss="modal">
                            取消
                        </button>
                    </div>
                </div>
            </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<div id="modal-addSubT-body" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">&times;</span>
                    </button>
                    添加选题类型
                </div>
            </div>
            <div class="modal-body" style="overflow-y: scroll;">
                <div id="mod-addSubT-tip" class="red clearfix"></div>
                <div class="form-group" style="margin-left: 30px;">
                    <label class="control-label">新增选题类型名称：</label>
                </div>
                <div class="form-group" style="margin-left: 30px;">
                    <input type="text" id="addSubT-subTName">
                </div>
            </div>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button id="mod-addSubT-success" type="button" class="btn btn-sm btn-primary"
                            onclick="addPlat(2);">
                        确定
                    </button>
                    <button class="btn btn-sm" data-dismiss="modal">
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<div id="modal-addSubTerr-body" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">&times;</span>
                    </button>
                    添加选题领域
                </div>
            </div>
            <div class="modal-body" style="overflow-y: scroll;">
                <div id="mod-addSubTerr-tip" class="red clearfix"></div>
                <div class="form-group" style="margin-left: 30px;">
                    <label class="control-label">新增选题领域名称：</label>
                </div>
                <div class="form-group" style="margin-left: 30px;">
                    <input type="text" id="addSubTerr-subTName">
                </div>
            </div>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button id="mod-addSubTerr-success" type="button" class="btn btn-sm btn-primary"
                            onclick="addPlat(3);">
                        确定
                    </button>
                    <button class="btn btn-sm" data-dismiss="modal">
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<div id="modal-addSubC-body" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">&times;</span>
                    </button>
                    添加选题内容形式
                </div>
            </div>
            <div class="modal-body" style="overflow-y: scroll;">
                <div id="mod-addSubC-tip" class="red clearfix"></div>
                <div class="form-group" style="margin-left: 30px;">
                    <label class="control-label">新增选题内容形式名称：</label>
                </div>
                <div class="form-group" style="margin-left: 30px;">
                    <input type="text" id="addSubC-subCName">
                </div>
            </div>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button id="mod-addSubC-success" type="button" class="btn btn-sm btn-primary"
                            onclick="addPlat(4);">
                        确定
                    </button>
                    <button class="btn btn-sm" data-dismiss="modal">
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>


<div id="modal-edit-body" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <form id="checkForm">
            <div class="modal-content">
                <div class="modal-header no-padding">
                    <div class="table-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            <span class="white">&times;</span>
                        </button>
                        修改平台信息
                    </div>
                </div>
                <div class="modal-body" style="overflow-y: scroll;">
                    <div id="mod-edit-tip" class="red clearfix"></div>
                    <input style="display: none" class="control-label" type="text" id="platId">
                    <div class="form-group" style="margin-left: 30px;">
                        <label class="control-label">平台名称：</label>
                        <input class="control-label" type="text" id="edit-platName">
                    </div>
                </div>
                <div class="modal-footer no-margin-top">
                    <div class="text-center">
                        <button id="mod-check-success" type="button" class="btn btn-sm btn-primary"
                                onclick="editPlat(1);">
                            确定
                        </button>
                        <button class="btn btn-sm" data-dismiss="modal">
                            取消
                        </button>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div><!-- /.modal-dialog -->
</div>

<div id="modal-editSubT-body" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header no-padding">
                    <div class="table-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            <span class="white">&times;</span>
                        </button>
                        修改选题类型
                    </div>
                </div>
                <div class="modal-body" style="overflow-y: scroll;">
                    <div id="mod-editSubT-tip" class="red clearfix"></div>
                    <input style="display: none" class="control-label" type="text" id="subTypeId">
                    <div class="form-group" style="margin-left: 30px;">
                        <label class="control-label">选题类型名称：</label>
                        <input class="control-label" type="text" id="editSubT-subTName">
                    </div>
                </div>
                <div class="modal-footer no-margin-top">
                    <div class="text-center">
                        <button id="mod-editSubT-success" type="button" class="btn btn-sm btn-primary"
                                onclick="editPlat(2);">
                            确定
                        </button>
                        <button class="btn btn-sm" data-dismiss="modal">
                            取消
                        </button>
                    </div>
                </div>
            </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<div id="modal-editSubTerr-body" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">&times;</span>
                    </button>
                    修改选题领域
                </div>
            </div>
            <div class="modal-body" style="overflow-y: scroll;">
                <div id="mod-editSubTerr-tip" class="red clearfix"></div>
                <input style="display: none" class="control-label" type="text" id="subTerrId">
                <div class="form-group" style="margin-left: 30px;">
                    <label class="control-label">选题领域名称：</label>
                    <input class="control-label" type="text" id="editSubTerr-subName">
                </div>
            </div>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button id="mod-editSubTerr-success" type="button" class="btn btn-sm btn-primary"
                            onclick="editPlat(3);">
                        确定
                    </button>
                    <button class="btn btn-sm" data-dismiss="modal">
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<div id="modal-editSubC-body" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">&times;</span>
                    </button>
                    修改选题领域
                </div>
            </div>
            <div class="modal-body" style="overflow-y: scroll;">
                <div id="mod-editSubC-tip" class="red clearfix"></div>
                <input style="display: none" class="control-label" type="text" id="subConId">
                <div class="form-group" style="margin-left: 30px;">
                    <label class="control-label">选题领域名称：</label>
                    <input class="control-label" type="text" id="editSubC-subName">
                </div>
            </div>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button id="mod-editSubC-success" type="button" class="btn btn-sm btn-primary"
                            onclick="editPlat(4);">
                        确定
                    </button>
                    <button class="btn btn-sm" data-dismiss="modal">
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>


<script type="text/javascript" >

    var myGrid = null;
    var scripts = [ null,  "${contextPath}/static/assets/js/date-time/bootstrap-datepicker.js", "${contextPath}/static/assets/js/date-time/locales/bootstrap-datepicker.zh-CN.js", "${contextPath}/static/assets/js/jqGrid/jquery.jqGrid.js", "${contextPath}/static/assets/js/jqGrid/i18n/grid.locale-cn.js", null ]

    $('.page-content-area').ace_ajax('loadScripts', scripts, function() {
        jQuery(function ($) {

            var grid_selector = "#grid-table";
            var grid_selector1 = "#grid-table1";
            var grid_selector2 = "#grid-table2";
            var grid_selector3 = "#grid-table3";
            var pager_selector = "#grid-pager";
            var pager_selector1 = "#grid-pager1";
            var pager_selector2 = "#grid-pager2";
            var pager_selector3 = "#grid-pager3";

            /*搜索框  主要对Jquery grid进行刷新 带参数刷新    */
            $("#searchd").click(function(){
                myGrid.setGridParam({postData:{page:1},
                    url : '${contextPath}/ads/vip/getPlatform',page:1}).trigger('reloadGrid');
            });


           /* $(document).keydown(function (event) {
                var key = window.event ? event.keyCode : event.which;
                if (key == 13) {
                    $("#searchd").click();
                }
            });*/

            myGrid=	jQuery(grid_selector).jqGrid({
                subGrid : false,
                url : "${contextPath}/xmt/manager/getAll?type=Platform",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['平台编号','平台名称'/*,'是否有效'*/,'操作'],
                colModel : [{
                    name : 'xmtKey',
                    index : 'xmtKey',
                    width : 170,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'xmtVal',
                    index : 'xmtVal',
                    width : 170,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },/*{
                    name : 'isValid',
                    index : 'isValid',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },*/{
                    name : '',
                    index : '',
                    width : 150,
                    editable : false,
                    search : false,
                    sortable : false,
                    fixed:true,
                    formatter : optionFormatter
                }],
                sortname : "name",
                sortorder : "asc",
                viewrecords : true,
                rowNum : 5,
                rowList : [ 5, 10, 30 ],
                pager : pager_selector,
                altRows : true,
                height:180,
                loadComplete : function() {
                    var table = this;
                    setTimeout(function(){
                        /*styleCheckbox(table);
                        updateActionIcons(table);*/
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                }
            });

            myGrid=	jQuery(grid_selector1).jqGrid({
                subGrid : false,
                url : "${contextPath}/xmt/manager/getAll?type=Type",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['选题类型编号','选题类型名称'/*,'是否有效'*/,'操作'],
                colModel : [{
                    name : 'xmtKey',
                    index : 'xmtKey',
                    width : 170,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'xmtVal',
                    index : 'xmtVal',
                    width : 170,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : '',
                    index : '',
                    width : 150,
                    editable : false,
                    search : false,
                    sortable : false,
                    fixed:true,
                    formatter : optionFormatter1
                }],
                sortname : "name",
                sortorder : "asc",
                viewrecords : true,
                rowNum : 5,
                rowList : [ 5, 10, 30 ],
                pager : pager_selector1,
                altRows : true,
                // height:"auto",//自动根据每页条数弹性调整表格高度
                height:180,
                loadComplete : function() {
                    var table = this;
                    setTimeout(function(){
                        /*styleCheckbox(table);
                        updateActionIcons(table);*/
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                }
            });

            myGrid=	jQuery(grid_selector2).jqGrid({
                subGrid : false,
                url : "${contextPath}/xmt/manager/getAll?type=Territory",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['选题领域编号','领域名称'/*,'是否有效'*/,'操作'],
                colModel : [{
                    name : 'xmtKey',
                    index : 'xmtKey',
                    width : 170,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'xmtVal',
                    index : 'xmtVal',
                    width : 170,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },/*{
                    name : 'isValid',
                    index : 'isValid',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },*/{
                    name : '',
                    index : '',
                    width : 150,
                    editable : false,
                    search : false,
                    sortable : false,
                    fixed:true,
                    formatter : optionFormatter2
                }],
                sortname : "name",
                sortorder : "asc",
                viewrecords : true,
                rowNum : 5,
                rowList : [ 5, 10, 30 ],
                pager : pager_selector2,
                altRows : true,
                height:180,
                loadComplete : function() {
                    var table = this;
                    setTimeout(function(){
                        /*styleCheckbox(table);
                        updateActionIcons(table);*/
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                }
            });

            myGrid=	jQuery(grid_selector3).jqGrid({
                subGrid : false,
                url : "${contextPath}/xmt/manager/getAll?type=Content",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['选题内容形式编号','内容形式名称'/*,'是否有效'*/,'操作'],
                colModel : [{
                    name : 'xmtKey',
                    index : 'xmtKey',
                    width : 170,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'xmtVal',
                    index : 'xmtVal',
                    width : 170,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },/*{
                    name : 'isValid',
                    index : 'isValid',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },*/{
                    name : '',
                    index : '',
                    width : 150,
                    editable : false,
                    search : false,
                    sortable : false,
                    fixed:true,
                    formatter : optionFormatter3
                }],
                sortname : "name",
                sortorder : "asc",
                viewrecords : true,
                rowNum : 5,
                rowList : [ 5, 10, 30 ],
                pager : pager_selector3,
                altRows : true,
                height:180,
                loadComplete : function() {
                    var table = this;
                    setTimeout(function(){
                        /*styleCheckbox(table);
                        updateActionIcons(table);*/
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                }
            });

            function updatePagerIcons(table) {
                var replacement = {
                    'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140',
                    'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140',
                    'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140',
                    'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140'
                };
                $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function() {
                    var icon = $(this);
                    var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

                    if ($class in replacement)
                        icon.attr('class', 'ui-icon ' + replacement[$class]);
                })
            }

            function enableTooltips(table) {
                $('.navtable .ui-pg-button').tooltip({
                    container : 'body'
                });
                $(table).find('.ui-pg-div').tooltip({
                    container : 'body'
                });
            };
            function optionFormatter(cellvalue, options, cell) {
                console.log(cell);
                var template = "<button data-toggle='modal'  onclick='showEdit(\""+cell.xmtKey+"\")' class='btn btn-minier btn-yellow'>修改</button>";
                template += "&nbsp;&nbsp;<button data-toggle='modal'  onclick='deletePlat(\""+cell.xmtKey+"\")' class='btn btn-minier btn-yellow'>删除</button>";
                return template;
            }
            function optionFormatter1(cellvalue, options, cell) {
                var template = "<button data-toggle='modal'  onclick='showEdit_a(\""+cell.xmtKey+"\")' class='btn btn-minier btn-yellow'>修改</button>";
                template += "&nbsp;&nbsp;<button data-toggle='modal'  onclick='delete_a(\""+cell.xmtKey+"\")' class='btn btn-minier btn-yellow'>删除</button>";
                return template;
            }
            function optionFormatter2(cellvalue, options, cell) {
                var template = "<button data-toggle='modal'  onclick='showEdit_b(\""+cell.xmtKey+"\")' class='btn btn-minier btn-yellow'>修改</button>";
                template += "&nbsp;&nbsp;<button data-toggle='modal'  onclick='delete_b(\""+cell.xmtKey+"\")' class='btn btn-minier btn-yellow'>删除</button>";
                return template;
            }

            function optionFormatter3(cellvalue, options, cell) {
                var template = "<button data-toggle='modal'  onclick='showEdit_c(\""+cell.xmtKey+"\")' class='btn btn-minier btn-yellow'>修改</button>";
                template += "&nbsp;&nbsp;<button data-toggle='modal'  onclick='delete_c(\""+cell.xmtKey+"\")' class='btn btn-minier btn-yellow'>删除</button>";
                return template;
            }


        });
    });
/*---------------------------新媒体平台---------------------------*/
    function showEdit(xmtKey) {
        $("#platId").val(xmtKey);
        $("#edit-platName").val("");
        $("#modal-edit-body").modal("toggle");
        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/get",
            type : "post",
            data : {
                'key' : xmtKey,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                $("#edit-platName").val(ret.xmtVal);
            }
        });
    }



    function editPlat(type) {
        var xmtKey;
        var val ;
        if (type === 1){
            xmtKey = $("#platId").val();
            val = $("#edit-platName").val();
        }else if(type === 2){
            xmtKey =  $("#subTypeId").val();
            val = $("#editSubT-subTName").val();
        }else if (type === 3){
            xmtKey =  $("#subTerrId").val();
            val = $("#editSubTerr-subName").val();
        }else{
            xmtKey = $("#subConId").val();
            val = $("#editSubC-subName").val();
        }
        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/createAndUpdate",
            type : "post",
            data : {
                'key' : xmtKey,
                'val' : val,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                alert(ret.message);
                if (type === 1){
                    $("#modal-edit-body").modal("toggle");
                    jQuery("#grid-table").trigger("reloadGrid");
                }else if(type === 2){
                    $("#modal-editSubT-body").modal("toggle");
                    jQuery("#grid-table1").trigger("reloadGrid");
                }else if(type === 3){
                    $("#modal-editSubTerr-body").modal("toggle");
                    jQuery("#grid-table2").trigger("reloadGrid");
                }else{
                    $("#modal-editSubC-body").modal("toggle");
                    jQuery("#grid-table3").trigger("reloadGrid");
                }
            }
        });
    }

    function deletePlat(xmtKey) {
        var result = confirm('是否删除？');
        if(result){
            deletep(xmtKey)
        }
    }

    function deletep(xmtKey) {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/deleteAll",
            type : "post",
            data : {
                'key' : xmtKey,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                alert(ret.message);
                jQuery("#grid-table").trigger("reloadGrid");
            }
        });
    }


    function preAaddPlat() {
        $("#add-platName").val("");
        $("#modal-refund-body").modal("toggle");
    }
    function addPlat(type) {
        var a;
        var name;
        if (type === 1){
            a = "Platform";
            name = $("#add-platName").val();
        }else if (type === 2){
            a = "Type";
            name = $("#addSubT-subTName").val();
        }else if (type === 3){
            a = "Territory";
            name = $("#addSubTerr-subTName").val();
        }else{
            a = "Content";
            name = $("#addSubC-subCName").val();
        }

        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/createAndUpdate",
            type : "post",
            data : {
                'val' : name,
                'type' : a,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                alert(ret.message);
                if (type === 1){
                    $("#modal-refund-body").modal("toggle");
                    jQuery("#grid-table").trigger("reloadGrid");
                }else if (type === 2){
                    $("#modal-addSubT-body").modal("toggle");
                    jQuery("#grid-table1").trigger("reloadGrid");
                }else if (type === 3){
                    $("#modal-addSubTerr-body").modal("toggle");
                    jQuery("#grid-table2").trigger("reloadGrid");
                }else{
                    $("#modal-addSubC-body").modal("toggle");
                    jQuery("#grid-table3").trigger("reloadGrid");
                }
            }
        });
    }

    /*--------------------------选题类型---------------------------*/
    function preAaddSubType() {
        $("#addSubT-subTName").val("");
        $("#modal-addSubT-body").modal("toggle");
    }

    function showEdit_a(xmtKey) {
        $("#subTypeId").val(xmtKey);
        $("#editSubT-subTName").val("");
        $("#modal-editSubT-body").modal("toggle");
        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/get",
            type : "post",
            data : {
                'key' : xmtKey,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                $("#editSubT-subTName").val(ret.xmtVal);
            }
        });
    }

    function delete_a(xmtKey) {
        var result = confirm('是否删除？');
        if(result){
            deleteT(xmtKey)
        }
    }

    function deleteT(xmtKey) {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/deleteAll",
            type : "post",
            data : {
                'key' : xmtKey,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                alert(ret.message);
                jQuery("#grid-table1").trigger("reloadGrid");
            }
        });
    }

    /*-----------------------选题领域-------------------*/
    function preAaddSubTree() {
        $("#addSubTerr-subTName").val("");
        $("#modal-addSubTerr-body").modal("toggle");
    }
    function showEdit_b(xmtKey) {
        $("#subTerrId").val(xmtKey);
        $("#editSubTerr-subName").val("");
        $("#modal-editSubTerr-body").modal("toggle");
        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/get",
            type : "post",
            data : {
                'key' : xmtKey,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                $("#editSubTerr-subName").val(ret.xmtVal);
            }
        });
    }

    function delete_b(xmtKey) {
        var result = confirm('是否删除？');
        if(result){
            deleteTerr(xmtKey)
        }
    }

    function deleteTerr(xmtKey) {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/deleteAll",
            type : "post",
            data : {
                'key' : xmtKey,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                alert(ret.message);
                jQuery("#grid-table2").trigger("reloadGrid");
            }
        });
    }


    /*----------------------选题内容-----------------------*/

    function preAaddSubCon() {
        $("#addSubC-subCName").val("");
        $("#modal-addSubC-body").modal("toggle");
    }

    function showEdit_c(xmtKey) {
        $("#subConId").val(xmtKey);
        $("#editSubC-subName").val("");
        $("#modal-editSubC-body").modal("toggle");
        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/get",
            type : "post",
            data : {
                'key' : xmtKey,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                $("#editSubC-subName").val(ret.xmtVal);
            }
        });
    }

    function delete_c(xmtKey) {
        var result = confirm('是否删除？');
        if(result){
            deleteC(xmtKey)
        }
    }

    function deleteC(xmtKey) {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/xmt/manager/deleteAll",
            type : "post",
            data : {
                'key' : xmtKey,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                alert(ret.message);
                jQuery("#grid-table3").trigger("reloadGrid");
            }
        });
    }
</script>
