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

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

            this.initSubmit();

            $('select[name="cpid"]').empty().append('<option selected value="">请选择</option>');
            $.post({
                url: Common.ctxPath + '/directed/festivalProduct/findAllCpinfo.json',
                dataType: 'JSON',
                success: function (data) {
                    console.log(cpid)
                    console.log(data)
                    $.each(data, function (i, item) {
                        if (cpid == item.cpid) {
                            $('select[name="cpid"]').append('<option selected value="' + item.cpid + '">' + item.cpname + '</option>');
                        } else {
                            $('select[name="cpid"]').append('<option value="' + item.cpid + '">' + item.cpname + '</option>');
                        }
                    })
                    form.render()
                },
                error: function (data) {
                    console.log(data)
                }
            });
        },

        initSubmit:function(){
        },

	};


    form.on('submit(submitButton)', function (data) {
        smstemplateApi.edit($('#addForm'), function(data) {
            parent.window.dataReload();
            Common.info("更新成功, 刷新缓存后生效，请刷新缓存！");
            Lib.closeFrame();
        });
    });



	 exports('edit',view);

});