/*
 * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：研发部
 * 日 期：2017.03.22
 * 描 述：部门管理	
 */
var selectedRow;
var refreshGirdData;
var ProjectId = request('ProjectId');
var parentPage = $(parent.document).find("li .lr-frame-iframe,.active")[3].contentWindow;

var bootstrap = function ($, learun) {
    "use strict";
    var companyId = '';
    var departmentId = '';
    var page = {
        init: function () {
            //page.inittree();
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 查询
            $('#btn_Search').on('click', function () {
                page.search();
            });

            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                selectedRow = null;
                learun.layerForm({
                    id: 'form',
                    title: '添加岗位',
                    url: top.$.rootUrl + '/LR_OrganizationModule/Post/Form?ProjectId=' + ProjectId,
                    width: 500,
                    height: 379,
                    callBack: function (id) {
                        parentPage.isClose = true;
                        return top[id].acceptClick(refreshGirdData);

                    }
                });
            });

            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('F_PostId');
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑岗位',
                        url: top.$.rootUrl + '/LR_OrganizationModule/Post/Form?keyValue=' + keyValue + '&ProjectId=' + ProjectId,
                        width: 500,
                        height: 379,
                        callBack: function (id) {
                            parentPage.isClose = true;
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });

            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('F_PostId');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/LR_OrganizationModule/Post/DeletePostForm', { keyValue: keyValue }, function () {
                                parentPage.isClose = true;
                                refreshGirdData();
                            });
                        }
                    });
                }
            });

            // 功能授权
            $('#lr_authorize').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('F_PostId');
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                var parentId = '';
                if (!!ProjectId) {
                    parentId = ConstantZSJT.MODULETYPEID_PROJECT;
                } else {
                    parentId = ConstantZSJT.MODULETYPEID_UNIT;
                }
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'authorizeForm',
                        title: '功能授权 - ' + selectedRow.F_Name,
                        url: top.$.rootUrl + '/LR_AuthorizeModule/Authorize/Form?objectId=' + keyValue + '&objectType=1' + '&parentId=' + parentId,
                        width: 550,
                        height: 690,
                        btn: null
                    });
                }
            });

            // 数据授权
            $('#lr_dataauthorize').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('F_PostId');
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'dataAuthorizeForm',
                        title: '数据授权 - ' + selectedRow.F_Name,
                        url: top.$.rootUrl + '/LR_AuthorizeModule/DataAuthorize/Index?objectId=' + keyValue + '&objectType=1',
                        width: 1100,
                        height: 700,
                        maxmin: true,
                        btn: null
                    });
                }
            });

            //自定义表单数据授权
            $('#lr_cdataauthorize').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('F_PostId');
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'dataAuthorizeForm',
                        title: '自定义表单数据授权 - ' + selectedRow.F_Name,
                        url: top.$.rootUrl + '/LR_AuthorizeModule/DataAuthorize/CustomerFormIndex?objectId=' + keyValue + '&objectType=1',
                        width: 1100,
                        height: 700,
                        maxmin: true,
                        btn: null
                    });
                }
            });

            // 移动功能授权
            $('#lr_appauthorize').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('F_PostId');
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'appAuthorizeForm',
                        title: '移动功能授权 - ' + selectedRow.F_Name,
                        url: top.$.rootUrl + '/LR_AuthorizeModule/Authorize/AppForm?objectId=' + keyValue + '&objectType=1',
                        width: 550,
                        height: 690,
                        callBack: function (id) {
                            return top[id].acceptClick();
                        }
                    });
                }
            });

        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/LR_OrganizationModule/Post/GetPageList',
                headData: [
                    { label: "岗位名称", name: "F_Name", width: 200, align: "left" },
                    { label: "岗位编号", name: "F_EnCode", width: 100, align: "center" },

                    { label: "创建人", name: "F_CreateUserName", width: 100, align: "center" },
                    {
                        label: "创建时间", name: "F_CreateDate", width: 100, align: "center",
                        formatter: function (cellvalue) {
                            return learun.formatDate(cellvalue, 'yyyy-MM-dd');
                        }
                    },
                    { label: "备注", name: "F_Description", width: 200, align: "left" },
                    { name: '', width:1 }
                ],
                isTree: true,
                parentId: 'F_ParentId',
                reloadSelected: true,
                mainId: 'F_PostId',
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            param.ProjectId = ProjectId;
            param.keyword = $('#txt_Keyword').val();
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };

    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };

    page.init();
}


