/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-03-03 17:00
 * 描  述：元件库文件表
 */
var acceptClick;
var keyValue = request('keyValue');//主键
var LibraryCatalogueID = request('LibraryCatalogueID');
var openType = request('openType');//look为查看
var ProjectId = request('ProjectId');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            $('.lr-form-wrap').lrscroll();
            page.bind();
            page.initData();
        },
        bind: function () {
            $('#FolderId').lrUploader({
                format: ".*",
                multiple: false,
                value: Guid.NewGuid().toString(),
                callback: function (obj) {
                    if (obj.value != "" && obj.value != undefined && obj.value != null) {
                        window.setTimeout(function () {
                            var uplodname = $(".lrUploader-input").text();
                            if (uplodname != null && uplodname != "") {
                                //名称去掉文件后缀
                                uplodname = uplodname.substring(0, uplodname.lastIndexOf('.'));
                            }
                            if (!$("#LibraryFileName").val()) {
                                $("#LibraryFileName").val(uplodname);
                            }
                        }, 500);
                    }
                }
            });
        },
        initData: function () {
            if (!!keyValue) {
                $.lrSetForm(top.$.rootUrl + '/ZZDT_EC/ec_library_file/GetFormData?keyValue=' + keyValue + "&ProjectId=" + ProjectId, function (data) {
                    for (var id in data) {
                        if (!!data[id].length && data[id].length > 0) {
                            $('#' + id ).jfGridSet('refreshdata', data[id]);
                        }
                        else {
                            $('[data-table="' + id + '"]').lrSetFormData(data[id]);
                        }
                    }
                });
            }
            if (!!openType && openType == 'look') {
                $('.lr-form-item:not(.textarea,.file)').css("pointer-events", "none");
                $("#lrUploader_uploadBtn_FolderId").hide();
                $(".lrUploader-input").css("width", "115%");
                $('.lr-form-item textarea').prop("readonly", true)
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        //文字特殊字符及最大长度检测
        if (!verify()) {
            return false;
        }
        var formData = $('#form').lrGetFormData();
        formData.LibraryCatalogueID = LibraryCatalogueID;
        var postData = {
            strEntity: JSON.stringify(formData)
        };
        $.lrSaveForm(top.$.rootUrl + '/ZZDT_EC/ec_library_file/SaveForm?keyValue=' + keyValue + "&ProjectId=" + ProjectId, postData, function (res) {
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
            }
        });
    };
    page.init();
}
//文字特殊字符及最大长度检测
function verify() {
    var msg = checkStr($("#LibraryFileName").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#LibraryFileName"), msg);
        $('#LibraryFileName').click();
        return false;
    }
    msg = checkStr($("#Remark").val(), 500);
    if (msg) {
        $.lrValidformMessage($("#Remark"), msg);
        $('#Remark').click();
        return false;
    }
    return true;
}
