/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-02-28 14:47
 * 描  述：lookup
 */
var refreshGirdData;
var ProjectId = request('ProjectId');
var typeId = request('ObjectTypeId');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            // 查询
            $('#btn_Search').on('click', function () {
                page.search();
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                console.log(ProjectId); console.log(typeId);
                learun.layerForm({
                    id: 'form_new',
                    title: '新增Lookup',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_LookupTable/Form?ProjectId=' + ProjectId + '&objectTypeId=' + typeId,
                    width: 500,
                    height: 300,
                    callBack: function (id) {

                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 定义in out结构
            $('#lr_structure').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('SP_ID');
                var Name = $('#gridtable').jfGridValue('Name');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form_edit',
                        title: '定义结构',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_LookupTable/Structure?ProjectId=' + ProjectId + '&objectTypeId=' + typeId + '&SP_ID=' + keyValue,
                        width: 800,
                        height: 400,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            //定义数据
            $('#lr_value').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('SP_ID'); 
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form_value',
                        title: '数据定义',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_LookupTable/DataDefinition?ProjectId=' + ProjectId +  '&SP_ID=' + keyValue,
                        width: 900,
                        height: 400,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('SP_ID');
                var Name = $('#gridtable').jfGridValue('Name');
                var flg = $('#gridtable').jfGridValue('DefaultFlag');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form_edit',
                        title: '编辑',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_LookupTable/Form?ProjectId=' + ProjectId + '&objectTypeId=' + typeId + '&SP_ID=' + keyValue + '&Name=' + Name + '&flg=' + flg,
                        width: 500,
                        height: 300,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('SP_ID');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/ZZDT_EC/ec_LookupTable/DeleteForm', { keyValue: keyValue, ProjectId: ProjectId }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
        },
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_LookupTable/GetList?ProjectId=' + ProjectId + "&objectTypeId=" + typeId,
                headData: [
                    { label: 'Lookup名称', name: 'Name', width: 300, align: "left", sort: false },
                    {
                        label: '是否默认', name: 'DefaultFlag', width: 100, align: "center", sort: false,
                        formatter: function (cellvalue) {
                            if (cellvalue == 0) {
                                return "否"
                            }
                            {
                                return "是"
                            }
                        }
                    },
                    { name: "", width: 1, sort: false }
                ],
                mainId: 'SP_ID',
                isPage: false
            });
            page.search();
        },
        search: function (param) {
            //param = param || {};
            //param.ProjectId = ProjectId;
            //param.filter = $("#Name").val();
            $('#gridtable').jfGridSet('reload', { filter: $("#Name").val() }); //getlist再请求一次，然后参数带进去
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    page.init();
}
