index.php 9.5 KB
<!DOCTYPE html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html>
<head>
    <meta charset="UTF-8">
    <title>表单填写</title>
    <link rel="stylesheet" type="text/css" href="/assets/common/css/themes/gray/easyui.css" />
	<link rel="stylesheet" type="text/css" href="/assets/common/css/themes/gray/menu.css" />
    <link rel="stylesheet" type="text/css" href="/assets/common/css/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="/assets/web/css/jitnry.css" />
	<link rel="stylesheet" type="text/css" href="/assets/web/css/common_car.css" />
    <script type="text/javascript" src="/assets/common/js/jquery.min.1.9.4.js"></script>
	<script type="text/javascript" src="/assets/common/js/jquery.easyui.min.1.9.4.js"></script>
    <script type="text/javascript" src="/assets/common/js/jquery.cookie.1.4.1.js"></script>
	<!-- 插件调用 --->
	<script type="text/javascript" src="/assets/common/js/datagrid-detailview.js"></script>
	<script type="text/javascript" src="/assets/common/locale/easyui-lang-zh_CN.js"></script>
	<!-- 基础 JS 调用 -->
	<script type="text/javascript" src="/assets/web/js/src/easyui.base.js"></script>
	<script type="text/javascript" src="/assets/web/js/src/allCity.js"></script>
    <style>
        #fm>div {
            width: 100%;
            display: flex;
            justify-content: space-around;
            margin: 10px 0;
        }
        #fm>div input{
            width: 180px;
        }
    </style>
</head>
<body style="margin-bottom: 54px;">
	<div class="easyui-layout" data-options="fit:true">
        <div data-options="split:false,region:'west',collapsible:true,footer:'#win_base_org_form_footer'" title="部门列表" id="saveBox" style="width:100%;">
            <div class="easyui-panel" style="width:100%;max-width:100%;padding: 5px 5px">
                <div style="margin-bottom:5px;">
                    <a id="name_add_but" href="#" data-options="iconCls:'icon-add'" class="my_but"  style="vertical-align: middle;">新增</a>
                </div>
            </div>
            <table id="dg"  style="width: 100%; height: 100%"
                   data-options="rownumbers:true,singleSelect:true,pagination:true,toolbar:'#tb'">

            </table>

            <div id="tb" style="padding:5px;height:auto">
                <div>
                    部门名称: <input class="easyui-textbox" type="text" id='departmentNames' name='departmentNames'>
                    <a href="#" class="easyui-linkbutton" id="search_buttn" iconCls="icon-search">搜索</a>
                </div>
            </div>
        </div>
	</div>
    <div id="win" class="easyui-dialog" title="提示"  style="width: 800px; padding: 10px 20px; height: auto" closed="true" buttons="#dlg-buttons">
        <form id="fm" name="frm" method="post" style="margin-top: 20px; margin-left: 20px;">
            <table style="padding: 10px 20px;" cellspacing="10">
                <tr>
                    <td>部门名称:</td>
                    <td><input class="easyui-textbox" type="text" name="name" id="name" /></td>
                    <input class="easyui-textbox" type="hidden" name="id" id="id" />
                </tr>

                <tr>
                    <td>所属机构:</td>
                    <td>

                        <input id="cc1" name="mechanism" class="easyui-combobox" data-options="
                            valueField: 'id',
                            textField: 'mechanismName',
                            url: '/products/role/getMechanism',
                            onSelect: function(rec){
                            var url = '/products/role/getDepartment?id='+rec.id;
                            $.ajax({
                                    url:url,
                                    success:function(a){
                                            var arr1=JSON.parse(a);
                                            console.log(JSON.parse(a))
                                             $('#cc2').combobox({
                                                     data:JSON.parse(a),
                                                     valueField:'id',
                                                     textField: 'departmentName',
                                             });

                                    }
                            })

                            }">

                    </td>
                </tr>


                <div id="dlg-buttons" style="display: block">
                    <a id="confirm" href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick="submitForm()" style="width: 90px">提交</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#win').dialog('close')" style="width: 90px">取消</a>
                </div>


            </table>
        </form>
    </div>

</body>
<tbody id="html_table"></tbody>
<script type="text/javascript" src="/assets/web/js/src/common_fu.js"></script>

<script>

    //添加
    $('#name_add_but').linkbutton({
        onClick: function () {

            addFile();
        }
    });
    //下拉框搜索
    init_datagrid('/products/department/department_list', 0);

    //下拉框搜索


    $('#search_buttn').bind('click', function() {

        var _data = $('#dg').data('datagrid'); // 拿到datagrid初始化的数据缓存
        if(_data && _data.options){
            _data.options.pageNumber = 1; // 修改缓存
        }
        $.data($('#dg')[0], 'datagrid', _data); // 把修改写回去


        var result=$('#departmentNames').textbox('getValue');
        console.log(result)
        //ajax请求数据
        $.ajax({
            type: "post",
            data: result,
            async: false,
            url: "/products/department/department_list",
            success: function(data) {
                console.log(data)
                //

            },
            error:function(data){
                console.log(data)
            }
        });
        var result = {
            result,
        }
        // console.log(result);return false;
        init_datagrid('/products/department/department_list', result);




    });


    function init_datagrid(data_url, res) {

        //表头字段
        var arr_columns = dg_columns();
        $("#dg").datagrid({
            rownumbers:true,
            singleSelect:true,
            pagination:true,
            url:data_url,
            queryParams: res,
            method:'post',
            columns: [arr_columns],
            loadMsg: '正在加载数据',
            emptyMsg: '列表为空',
        });
    }
    function dg_columns() {
        var arr = new Array();
        arr.push({
            field: 'mechanismName',
            title: '所属机构',
            width: 200,
            align: 'center'
        });
        arr.push({
            field: 'departmentName',
            title: '部门名称',
            width: 300,
            align: 'center'
        });
        arr.push({
            field: 'createTime',
            title: '创建时间',
            width: 200,
            align: 'center'
        });
        arr.push({
            field: 'id',
            title: '操作',
            width: 90,
            align: 'center',
            formatter:formatOper
        });
        //操作框
        function formatOper(val, row, index) {

            return '<a href="javascript:void(0)" onclick="showUser(' + val+','+ row.id + ')">编辑</a>  ';

        }
        // console.log(arr)
        return arr;
    }
    function addFile(){
        rule_id='';
        $('#entryTime').textbox({disabled:false})
        $('#win').form('clear')
        $('#win').dialog({
            title: '新增部门',
            width: 800,
            height: "auto",
            top:20,
            closed: false,//显示对话框
            cache: false,
            modal: true
        });
    }

    //修改
    function showUser(val,row){
        if(row){
            console.log(row)

            var result = {
                id:row
            }
            $("#win").dialog("open").dialog("setTitle","部门信息修改");

            //ajax请求数据
            $.ajax({
                type: "post",
                data: result,
                async: false,
                url: "/products/department/getDepartment",
                success: function(data) {
                    var arr = data;
                    console.log(arr)
                    $('#name').textbox('setValue',arr.departmentName);
                    $('#id').textbox('setValue',arr.id);

                    $('#cc1').combobox('select',arr.mechanismId);
                    //

                },
                error:function(data){
                    console.log(data)
                }
            });
        }
    }
    function submitForm(){
        $('#fm').form('submit', {
            url:'/products/department/department_add',
            onSubmit: function(){
                console.log($(this))
                // do some check
                // return false to prevent submit;
            },
            success:function(data){
                console.log(data);
                var arr = JSON.parse(data);
                $.messager.alert("提示", arr.msg);
                $('#dg').datagrid('reload');
                // console.log(data);
                //$.messager.alert('',msg);
                //console.log(data);
                //alert(data)
            }
        });
        $('#win').dialog({
            closed: true, // 隱藏列表
        });
    }

</script>
</html>