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

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

            this.initSubmit();

            $.post({
                url: Common.ctxPath + '/directed/festival/findAllFestival.json',
                dataType: 'JSON',
                success: function (data) {
                    $('select[name="festivalid"]').empty().append('<option selected value="">请选择</option>');
                    $.each(data, function (i, item) {
                        if (item.fescod != null && item.fescod != "") {
                            if (fescod == item.fescod) {
                                $('select[name="festivalid"]').append('<option selected value="' + item.id + '">' + item.fescod + ', ' + item.fesname + ',' + item.title + '</option>');
                            } else {
                                $('select[name="festivalid"]').append('<option value="' + item.id + '">' + item.fescod + ', ' + item.fesname + ',' + item.title + '</option>');
                            }
                        }
                    })
                    form.render()
                },
                error: function (data) {
                    console.log(data)
                }
            });

            $.post({
                url: Common.ctxPath + '/directed/channel/findAllChannel.json',
                dataType: 'JSON',
                success: function (data) {
                    $('select[name="channelid"]').empty().append('<option selected value="">请选择</option>');
                    $.each(data, function (i, item) {
                        if (item.orderchannel != null && item.orderchannel != "") {
                            if (orderchannel == item.orderchannel) {
                                $('select[name="channelid"]').append('<option selected value="' + item.id + '">' + item.channelname + ',' + item.channeltype + '</option>');
                            } else {
                                $('select[name="channelid"]').append('<option value="' + item.id + '">' + item.channelname + ',' + item.channeltype + '</option>');
                            }
                        }
                    })
                    form.render()
                },
                error: function (data) {
                    console.log(data)
                }
            });


        },

        initSubmit:function(){
        },

	};


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



	 exports('edit',view);

});