/**
 * 考核列表
 */
var layer;
layui.use(['form', 'laydate', 'layer'], function () {
    var form = layui.form;
    var laydate = layui.laydate;
    layer = layui.layer;
    //监听考核类型下拉选择
    form.on('select(type)', function (data) {
        typeChange(data.value);
        form.render();
    });

    // 考核年份选择器渲染
    laydate.render({
        elem: '#year' //指定元素
        , type: 'year' //年选择器（year，month，date，time，datetime）
        , format: 'yyyy' //自定义格式
        , min: '1900-1-1' //最小值
        , max: '9999-12-31' //最大值
        ,change: function(value){
            $('#year').val(value);
            $('#layui-laydate100001').remove();
        }
    });

    //监听提交
    form.on('submit(submit)', function (data) {
        $.ajax({
            type: "post",
            data: JSON.stringify(data.field),
            url: '/jx/addJxCycle',
            timeout : 60000, //超时时间设置，单位毫秒
            dataType: "json",
            beforeSend: function() {
				startloading();
			},
            success: function(d){
            	if (d.code=='0'){
                    layer.alert('保存成功',function (d) {
                    		window.location.href='/jx/toJxCycleList';
                    });
                }else{
                    layer.alert("保存错误:"+d.msg);
                }
            },
            error: function(e){
            	 layer.alert("保存错误:"+e);
            },
			complete: function(xhr, status) {
				setTimeout(function() {
					try{
                        stoploading();
					}catch(e){

					}
				}, 500);
			}
        });
        
    });

});





/**
 * 考核类型 下拉框值改变
 * @param type
 */
function typeChange(type) {
    var monthlist = [["请选择...", ""], ["一月", "1"], ["二月", "2"], ["三月", "3"], ["四月", "4"], ["五月", "5"], ["六月", "6"], ["七月", "7"], ["八月", "8"], ["九月", "9"], ["十月", "10"], ["十一月", "11"], ["十二月", "12"]];
    var list = [];
    var khCycle = document.getElementById("khCycle");
    var khtype = document.getElementById("khtype");
    khCycle.length = 0; //下拉框清空
    // 根据考核类型初始化下拉框列表
    if (!(type == null || type == "")) {
        if (type == 1) {
            khtype.innerHTML = "考核月份";
            list = monthlist;
            $("#khCycle").attr("name","cycle_month");
        } else if (type == 3) {
            khtype.innerHTML = "年度类型";
            list = [["请选择...", ""], ["上半年", 1], ["下半年", 2],["年度", 3]];
            $("#khCycle").attr("name","cycle_yeartype");
        } else if (type == 2) {
            khtype.innerHTML = "考核季度";
            list = [["请选择...", ""], ["一季度", 1], ["二季度", 2], ["三季度", 3], ["四季度", 4]];
            $("#khCycle").attr("name","cycle_quarter");
        }
    }

    // 追加下拉框选项
    for (var i = 0; i < list.length; i++) {
        var option = document.createElement("Option");
        option.text = list[i][0];
        option.value = list[i][1];
        khCycle.options[khCycle.length] = option;
    }


}





