/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-07-04 10:00
 * 描  述：同步关联表
 */
var acceptClick;
var keyValue = request('keyValue');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.bind();
            page.initData();
        },
        bind: function () {
            $('#MainBusinessTableID').lrselect({
                allowSearch: true,
                url: top.$.rootUrl + '/ZZDT_EC/ec_business_table/GetList',
                param: {},
                value: 'BusinessTableID',
                text: 'BusinessTableName',
                title: 'BusinessTableCode',
                select: function (item) {
                }
            });

            $('#RelBusinessTableID').lrselect({
                allowSearch: true,
                type: keyValue ? 'default': 'multiple',
                url: top.$.rootUrl + '/ZZDT_EC/ec_business_table/GetList',
                param: {},
                value: 'BusinessTableID',
                text: 'BusinessTableName',
                title: 'BusinessTableCode',
                select: function (item) {
                }
            });
        },
        initData: function () {
            if (!!keyValue) {
                 $.lrSetForm(top.$.rootUrl + '/ZZDT_EC/ec_synrel_table/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]);
                         }
                     }
                 });
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        var formData = $('#form').lrGetFormData();

        if (formData.RelBusinessTableID.indexOf(formData.MainBusinessTableID) > -1) {
            $.lrValidformMessage($("#RelBusinessTableID"), "关联业务表中不能包含主业务表");
            $('#RelBusinessTableID').click();
            return false;
        }
        
        var postData = {
             strEntity: JSON.stringify(formData)
        }
        $.lrSaveForm(top.$.rootUrl + '/ZZDT_EC/ec_synrel_table/SaveForm?keyValue=' + keyValue, postData, function (res) {
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
            }
        });
    };
    page.init();
}
