<%@ Page Title="" Language="C#" MasterPageFile="~/Styles/MasterPage/MasterPage_Edit.master" AutoEventWireup="true" CodeFile="Department_Edit.aspx.cs" Inherits="Base_Department_Department_Edit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript">
        var action = '<%=xview["action"]%>';
        function Save() {
            <%=xview["Script_GetInput"] %>
            if (dep_name == "") {
                parent.AlertNO('请输入部门名称!');
                return;
            }
           
            var action = '<%=xview["action"]%>';
            parent.ShowLoadingMask(); //显示遮罩
            $.ajax({
                type: "POST",
                contentType: "application/json",
                url: 'Department_Service.asmx/Save',
                data: "{action:'" + action + "',<%=xview["Script_SaveJSON"]%>}",
                dataType: 'json',
                success: function (result) {
                    parent.HideLoadingMask(); //关闭遮罩
                    var r = result.d;
                    if (r == "success") {
                        parent.AlertOK('保存成功!');
                        parent.search_grid();
                        parent.load_tree();
                        CloseDivWin(); //关闭窗口
                    } else {
                        parent.AlertNO(r);
                    }
                }
            });
        }
    </script>
    <!--工具栏-->
    <div class="list_menu_bar">
        <a plain="true" class="easyui-linkbutton" iconcls="icon-save" onclick="Save()" style='<%=auth.AuthView("Base_Department_Edit")%>'>保存</a>
        <a plain="true" class="easyui-linkbutton" onclick="parent.DesignModuleFormat('Base_Department_Input');CloseDivWin();" style='<%=auth.FormatView()%>'>格式</a>
    </div>
    <div style="width:500px;height:300px;overflow:auto;">
        <div class="edit_area">
        <%=xview["input_ui"]%>
        </div>
    </div>
    <script type="text/javascript">
        //查询仓库
        function FastSearch_Warehouse() {
            $("#dep_wh_name").fast_search({
                url: '../../Component/FastSearch/FastSearch_Warehouse.aspx',
                replaceNull: true,
                searchButton: true,
                colModel: [{ 'columnName': 'wh_id', 'hidden': true, 'width': '80', 'label': 'id' },
                    { 'columnName': 'wh_code', 'width': '80', 'label': '仓库编码' },
                    { 'columnName': 'wh_name', 'width': '100', 'label': '仓库名称' }],
                select: function (event, ui) {
                    SearchService_Warehouse(ui.item.wh_id);
                    return false;
                }
            });
        }
        //通过主键_获取仓库
        function SearchService_Warehouse(wh_id) {
            $.ajax({
                type: "POST",
                contentType: "application/json",
                url: '../../Base/Warehouse/Warehouse_Service.asmx/Get',
                data: "{wh_id:'" + wh_id + "'}",
                dataType: 'json',
                success: function (result) {
                    $("#dep_wh_id").val(result.d.wh_id);
                    $("#dep_wh_name").val(result.d.wh_name);
                }
            });
        }
        //初始化页面
        function init_page() {
            FastSearch_Warehouse(); //查询仓库
            var is_workshop = $F("is_workshop");
            AddOption(is_workshop,'否','0');
            AddOption(is_workshop,'是','1');
            var is_stop = $F("is_stop");
            AddOption(is_stop,'否','0');
            AddOption(is_stop,'是','1');
            $F("trigger_parent_name").onclick = function () {
                AdvancedSearch_Department($("#parent_name").val());
            };
            <%if(action.Equals("Update")){ %>
                is_workshop.value = '<%=m.is_workshop%>';
                is_stop.value = '<%=m.is_stop%>';
                $F("parent_name").value = '<%=m.parent.dep_name%>';
                $F("dep_wh_name").value = '<%=m.warehouse==null?"":m.warehouse.wh_name%>';
            <%} %>
            if(action == "Add"){
                //新增时带出父类编码作为当前编码方便输入
                $F("dep_code").value = '<%=xview["parent_code"]%>';
                //新增时带出父类
                $F("parent_id").value = '<%=xview["parent_id"]%>';
                $F("parent_name").value = '<%=xview["parent_name"]%>';
            }
        }
        init_page();
        //弹出窗口_选择部门
        function AdvancedSearch_Department(keyword) {
            var url = "../../Component/AdvancedSearch/Department_List.aspx?keyword=" + escape(keyword);
            parent.asyncbox.open({
                id: 'win_select',
                url: url,
                modal: true,
                width: 400,
                height: 400,
                title: '选择部门'
            });
        }
        //通过主键_获取部门
        function SearchService_Department(dep_id) {
            $.ajax({
                type: "POST",
                contentType: "application/json",
                url: '../../Base/Department/Department_Service.asmx/Get',
                data: "{dep_id:'" + dep_id + "'}",
                dataType: 'json',
                success: function (result) {
                    $("#parent_id").val(result.d.dep_id);
                    $("#parent_name").val(result.d.dep_name);
                }
            });
        }
    </script>
</asp:Content>

