layui.define([ 'jquery','form', 'laydate', 'table', 'festivalApi'], function(exports) {
	var jquery = layui.jquery;
	var form = layui.form;
	var laydate = layui.laydate;
	var formSelects = layui.formSelects;
	var festivalApi = layui.festivalApi;

	var index = layui.index;
	var view = {
        init:function(fescod) {
            Lib.initGenrealForm($("#addForm"),form);
            $('#closeButton').click(function(){
                Lib.closeFrame();
            });

            $('select[name="paritycode"]').empty().append('<option selected value="">请选择</option>');
            $.post({
                url: Common.ctxPath + '/directed/festival/findAllFestival.json',
                dataType: 'JSON',
                success: function (data) {
                    $('select[name="paritycode"]').empty().append('<option selected value="">请选择</option>');

                    $.each(data, function (i, item) {
                        if (item.fescod != null && item.fescod != "") {
                            if (fescod == item.fescod) {
                                $('select[name="paritycode"]').append('<option selected value="' + item.fescod + '">' + item.fescod + ', ' + item.fesname + ', ' + item.title + '</option>');
                            } else {
                                $('select[name="paritycode"]').append('<option value="' + item.fescod + '">' + item.fescod + ', ' + item.fesname + ',' + item.title + '</option>');
                            }
                        }
                    })
                    form.render()
                },
                error: function (data) {
                    console.log(data)
                }
            });

            this.initSubmit();
        },

        initSubmit:function(){
        },

	};


    form.on('submit(submitButton)', function (data) {
        // 时间校验
        var stime = $('#stime').val().replace('-', '')
        var etime = $('#stime').val().replace('-', '')
        console.log(stime + ',' + etime)
        if (stime > etime) {
            Common.info("开始时间不能大于结束时间");
            return;
        }

        festivalApi.edit($('#addForm'), function(data){
            parent.window.dataReload();
            Common.info("更新成功！");
            Lib.closeFrame();
        });
    });



	 exports('edit',view);

});