/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-02-23 11:30
 * 描  述：属性表
 */
var refreshGirdData;
var PropertyGID = "";
var relrtree; //初始化树形
var ProjectId = parent.request('ProjectId');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            //初始化tree
            relrtree();
            //查询
            $('#btn_Search').on('click', function () {
                page.search();
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                if (!PropertyGID) {
                    learun.alert.warning("请选择属性组");
                    return;
                }
                if (PropertyGID == "-8624") {
                    learun.alert.warning("系统内置的特殊属性组，无法新增属性！");
                    return false;
                }
                learun.layerForm({
                    id: 'form',
                    title: '新增',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_property/Form?PropertyGID=' + PropertyGID + "&ProjectId=" + ProjectId + '&openType=add',
                    width: 550,
                    height: 450,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('PropertyID');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_property/Form?keyValue=' + keyValue + "&ProjectId=" + ProjectId,
                        width: 750,
                        height: 450,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                if (PropertyGID == "-8624") {
                    learun.alert.warning("系统内置的特殊属性组，其下的属性，无法删除！");
                    return false;
                }
                var keyValue = $('#gridtable').jfGridValue('PropertyID');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/ZZDT_EC/ec_property/DeleteForm', { keyValue: keyValue, ProjectId: ProjectId }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
            // 属性组管理
            $('#lr_groupmanager').on('click', function () {
                learun.layerForm({
                    id: 'group',
                    title: '属性组管理',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_propertyg/Index?ProjectId=' + ProjectId,
                    width: 850,
                    height: 550,
                    btn: null,
                    end: function () {
                        location.reload();
                    }
                });
            });

            // 对象类型
            $('#lr_objecttypeset').on('click', function () {
                if (PropertyGID == "-8624") {
                    learun.alert.warning("系统内置的特殊属性组，无法进行对象类型管理！");
                    return false;
                }
                var keyValue = $('#gridtable').jfGridValue('PropertyID');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '对象类型',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_property/SelectObjectType?PropertyID=' + keyValue + "&ProjectId=" + ProjectId,
                        width: 700,
                        height: 600,
                        btn: null
                    });
                }
            });
        },
        // 初始化列表
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetPageList',
                headData: [
                    { label: "属性名称", name: "PropertyName", width: 300, align: "left", sort: false },
                    { label: "属性显示名", name: "PropertyNameEN", width: 200, align: "left", sort: false },
                    { label: "属性类型", name: "PropertyTypeName", width: 120, align: "center", sort: false },
                    { label: "小数点", name: "DecimalPoint", width: 100, align: "center", sort: false },
                    { label: "枚举数据", name: "EnumDataName", width: 200, align: "center", sort: false },
                    { label: "计量单位分类", name: "MeasuringUnitTypeName", width: 150, align: "center", sort: false },
                    { label: " 默认计量单位", name: "DefaultUnitName", width: 100, align: "center", sort: false },
                    { label: "默认值", name: "DefaultValue", width: 100, align: "center", sort: false },
                    //{
                    //    label: "是否必填", name: "IsRequired", width: 100, align: "center", sort: false,
                    //    formatter: function (cellvalue) {
                    //        if (cellvalue == '1') {
                    //            return "是";
                    //        } else {
                    //            return "否";
                    //        }
                    //    }
                    //},
                    {
                        label: "是否为常用", name: "BasicGroup", width: 100, align: "center", sort: false,
                        formatter: function (cellvalue) {
                            if (cellvalue == '1') {
                                return "是";
                            } else {
                                return "否";
                            }
                        }
                    },
                    { label: '排序', name: 'OrderID', width: 100, align: "center", sort: false },
                    { name: "", width: 1, sort: false }
                ],
                mainId: 'PropertyID',
                isPage: true
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            param.PropertyGID = PropertyGID;
            param.PropertyName = $("#PropertyName").val();
            param.ProjectId = ProjectId;
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    relrtree = function () {
        // 初始化左侧树形数据
        $('#dataTree').lrtree({
            url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetTree?ProjectId=' + ProjectId,
            nodeClick: function (item) {
                $("#titleinfo").html(item.text);
                PropertyGID = item.value;
                page.search();
            }
        });
    };
    page.init();
}
