/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2021-03-11 17:22
 * 描  述：项目立项
 */
var acceptClick;
var keyValue = request('keyValue'); //new or update
var openType = request('openType');//look为查看
var iframeid = window.frameElement;

var bootstrap = function ($, learun) {
    "use strict";
    // 设置权限
    var page = {
        init: function () {
            $('.lr-form-wrap').lrscroll();
            page.bind();
            page.initData();
        },
        bind: function () {
            $('#SelectProjectId').lrselect({
                allowSearch: true,
                url: top.$.rootUrl + '/ZZDT_EC/ec_project/GetProjectSelectList',
                param: {},
                value: 'ProjectId',
                text: 'ProjectName',
                title: 'ProjectName',
                select: function (item) {
                    //选择后，触发的方法
                    relrtree();
                    curDrawingCatalogueID = '';
                    selectData = [];
                    //page.search();
                }
            });
            $('#ShipTypeCN').lrDataItemSelect({ code: 'Be_ShipTypeCN' });
            $('#ShipTypeEN').lrDataItemSelect({ code: 'Be_ShipTypeEN' });
            $('#ShipSociety').lrDataItemSelect({ code: 'Be_ShipSociety' });
            $('#FlagState').lrDataItemSelect({ code: 'Be_FlagState' });
        },
        initData: function () {
            if (!!keyValue) {
                $.lrSetForm(top.$.rootUrl + '/ZZDT_EC/ec_project/GetFormData?keyValue=' + keyValue, function (data) {
                    for (var id in data) {
                        if (!!data[id] && data[id].length > 0) {
                            $('#' + id).jfGridSet('refreshdata', data[id]);
                        }
                        else {
                            $('[data-table="' + id + '"]').lrSetFormData(data[id]);
                        }
                    }
                });

                $("#SelectProjectSegment").hide();
            }
            else {
                $("#SelectProjectSegment").show();
            }
            if (!!openType && openType == 'look') {
                $('.lr-form-item:not(.textarea)').css("pointer-events", "none");
                $('.lr-form-item textarea').prop("readonly", true)
            }
            if (openType == "edit" || openType == 'look') {

            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!!openType && openType == 'look') {
            return true;
        }
        if (!$('#form').lrValidform()) {
            return false;
        }
        //文字特殊字符及最大长度检测
        if (!verify()) {
            return false;
        }
        var formData = $('#form').lrGetFormData();
        var postData = {
            strEntity: JSON.stringify(formData)
        };
        var source = $('#SelectProjectId').lrselectGet();
        $.lrSaveForm(top.$.rootUrl + '/ZZDT_EC/ec_project/SaveForm?keyValue=' + keyValue + '&sourceProjId=' + source, postData, function (res) {
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
            }
        });
    };
    page.init();
}
//文字特殊字符及最大长度检测
function verify() {
    var msg = checkStr($("#ProjectName").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#ProjectName"), msg);
        $('#ProjectName').click();
        return false;
    }
    msg = checkStr($("#ProjectCode").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#ProjectCode"), msg);
        $('#ProjectCode').click();
        return false;
    }
    msg = checkStr($("#ShipNameCN").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#ShipNameCN"), msg);
        $('#ShipNameCN').click();
        return false;
    }
    msg = checkStr($("#ShipNameEN").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#ShipNameEN"), msg);
        $('#ShipNameEN').click();
        return false;
    }
    msg = checkStr($("#ShipOwner").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#ShipOwner"), msg);
        $('#ShipOwner').click();
        return false;
    }
    msg = checkStr($("#IMONumber").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#IMONumber"), msg);
        $('#IMONumber').click();
        return false;
    }
    msg = checkStr($("#Describe1").val(), 500);
    if (msg) {
        $.lrValidformMessage($("#Describe1"), msg);
        $('#Describe1').click();
        return false;
    }
    msg = checkStr($("#Describe2").val(), 500);
    if (msg) {
        $.lrValidformMessage($("#Describe2"), msg);
        $('#Describe2').click();
        return false;
    }
    msg = checkStr($("#Describe3").val(), 500);
    if (msg) {
        $.lrValidformMessage($("#Describe3"), msg);
        $('#Describe3').click();
        return false;
    }
    msg = checkStr($("#Describe4").val(), 500);
    if (msg) {
        $.lrValidformMessage($("#Describe4"), msg);
        $('#Describe4').click();
        return false;
    }
    msg = checkStr($("#Describe5").val(), 500);
    if (msg) {
        $.lrValidformMessage($("#Describe5"), msg);
        $('#Describe5').click();
        return false;
    }
    return true;
}
