/* * 版 本 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 spid = request('SP_ID');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
            $('#gridtable').jfGridSet('reload');
        },
        bind: function () {
            // 新增
            $('#lr_add').on('click', function () {
                console.log(ProjectId); console.log(typeId);
                learun.layerForm({
                    id: 'structure_new',
                    title: '新增 Lookup属性定义',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_LookupTable/FormStructure?ProjectId=' + ProjectId + '&lookuptableid=' + spid,
                    width: 500,
                    height: 300,
                    callBack: function (id) {

                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('SP_ID');
                var PropertyID = $('#gridtable').jfGridValue('PropertyID');
                var PropertyName = $('#gridtable').jfGridValue('PropertyName');
                var inOutFlag = $('#gridtable').jfGridValue('inOutFlag');
                var overwriteFlag = $('#gridtable').jfGridValue('overwriteFlag');
                if (learun.checkrow(keyValue)) {
                    console.log("11"); //如果form出不来就换一换id啥的。特别是多重form打开
                    learun.layerForm({
                        id: 'structure_edit',
                        title: '编辑 Lookup属性定义',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_LookupTable/FormStructure?lookuptableid=' +spid + '&PropertyID=' + PropertyID + '&ProjectId=' + ProjectId+ '&PropertyName=' + encodeURIComponent(PropertyName)+ '&inOutFlag=' + inOutFlag+ '&overwriteFlag=' +overwriteFlag +'&keyValue=' + keyValue,
                        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/DeleteAttr', { keyValue: keyValue, ProjectId: ProjectId }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
        },
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_LookupTable/GetStructure?ProjectId=' + ProjectId + '&spid=' + spid,
                headData: [     
                    { label: '属性名', name: 'PropertyName', width: 300, align: "center", sort: false },
                    { label: '输入还是输出', name: 'inOutFlag', width: 100, align: "center", sort: false ,
                        formatter: function (cellvalue) {
                            if (cellvalue == '1') {
                                return "输入";
                            } else if(cellvalue == '2'){
                                return "输出";
                            }
                        }
                    },
                    { label: '已有值时是否覆盖', name: 'overwriteFlag', width: 150, align: "center", sort: false,
                        formatter: function (cellvalue) {
                            if (cellvalue == '1') {
                                return "是（允许覆盖）";
                            } else {
                                return "否";
                            }
                        }
                    },
                    { name: "", width: 1, sort: false }
                ],
                mainId: 'SP_ID',
                isPage: false
            });
          
        },
      
    };

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