/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-06-21 15:33
 * 描  述：工程数据关联表
 */

var refreshGirdData;
var ProjectId = request('ProjectId');
var RelTypeID;
var EngineDataID = request('EngineDataID');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            // 初始化左侧树形数据
            $('#dataTree').lrtree({
                url: top.$.rootUrl + '/ZZDT_EC/ec_reltype/GetTreeData',
                param: { ProjectId: ProjectId },
                nodeClick: function (item) {
                    RelTypeID = item.value;
                    $("#titleinfo").html(item.text);
                    page.search();
                }
            });
            // 查询
            $('#btn_Search').on('click', function () {
                page.search();
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                if (!RelTypeID) {
                    learun.alert.warning("请选择关联类型！");
                    return;
                };
                learun.layerForm({
                    id: 'form',
                    title: '关联数据',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_enginedata_rel/Form?ProjectId=' + ProjectId + "&RelTypeID=" + RelTypeID + "&RelEngineData1ID=" + EngineDataID,
                    width: 950,
                    height: 600,
                    btn: null,
                    end: function () {
                        refreshGirdData();
                    }
                });
            });
            $('#lr_remove').on('click', function () {
                if (true) {
                    learun.alert.warning("未选择任何一条关联信息。");
                    return;
                };

            });
        },
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_enginedata_rel/GetPageList',
                headData: [
                    {
                        label: '关联工程数据', name: 'EngineDataRelID', width: 250, align: "left", sort: false,
                        formatter: function (cellvalue, row) {
                            if (row.RelEngineData1ID == EngineDataID) {
                                return row.TagNumber2;
                            } else {
                                return row.TagNumber1;
                            }
                        }
                    },
                    { label: "创建人", name: "CreateUserName", width: 120, align: "center", sort: false },
                    {
                        label: '创建时间', name: 'CreateTime', width: 150, align: "center", sort: false,
                        formatter: function (cellvalue) {
                            return learun.formatDate(cellvalue, 'yyyy-MM-dd hh:mm');
                        }
                    },
                    { name: "", width: 1, sort: false }
                ],
                mainId: 'EngineDataRelID',
                isPage: true
            });
            //page.search();
        },
        search: function (param) {
            param = param || {};
            param.ProjectId = ProjectId;
            param.RelTypeID = RelTypeID;
            param.RelEngineDataID = EngineDataID;
            param.TagNumber = $('#TagNumber').val();
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    page.init();
}
