basicinfo.js 1.9 KB
define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {

    var Controller = {
        edit: function(callback) {
            var form = $("form[role=form]")
            // 被删除的项目类型的id
            var delProjectTypeId = []

            // 监听单选按钮切换(限制报名人数)
            $('.radio').on('change', 'input[type="radio"]', function () {
                console.log($(this).attr('limitCount'));
                // 限制人数
                if ($(this).attr('limitCount')) {
                    $(this).parent().siblings('.js-countWrap').show()
                } else {
                    $(this).parent().siblings('.js-countWrap').children('input').val('');
                    $(this).parent().siblings('.js-countWrap').hide();
                }
            })
            // 移除项目类型
            $(".fieldlist", form).on("click", ".btn-remove", function () {
                var delId = $(this).parents('dd').find('input[type=hidden]').val()
                if (!delId) {return}
                delProjectTypeId.push(delId)
                $('input[name="row[del_project_type_id]"]').val(delProjectTypeId.join(','))
            });

            if (callback) {
                callback()
                return
            }

            Form.api.bindevent($("form[role=form]"), function () {
                top.location.reload()
            });
        },
        add: function () {
            Controller.edit(function () {
                Form.api.bindevent($("form[role=form]"), function () {
                    top.window.$("ul.nav-addtabs li.active .close-tab").trigger("click");
                });
            })
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});