var colFieldIDs = [];
function init(colFields) {
	
    const colFieldData = JSON.parse(colFields);
    console.log(colFieldData);
    for (var i = 0; i < colFieldData.length; i++) {
        let colField = colFieldData[i];
        colFieldIDs.push(colField.name);
        if (colField.type == 526) {//单行文本
            let htmlRow = '<div class="awsui-row" ' + (colField.readonly == 1 ? 'style="pointer-events: none;"' : '') + '><div class="awsui-col-xs-2 awsui-col-sm-2 awsui-col-md-2 awsui-col-lg-2 awsui-text">' + colField.comment + '</div><div class="awsui-col-xs-10 awsui-col-sm-10 awsui-col-md-10 awsui-col-lg-10 awsui-form-parent"><span class=" ' + (colField.required == 1 ? 'required' : '') + '" style="width:100%;"><input type="text" class="awsui-input" id="' + colField.name + '" name="' + colField.name + '"></span></div></div>';
            $("#confForm").append(htmlRow);
        } else if (colField.type == 527) {//多行文本
            let htmlRow = '<div class="awsui-row" ' + (colField.readonly == 1 ? 'style="pointer-events: none;"' : '') + '><div class="awsui-col-xs-2 awsui-col-sm-2 awsui-col-md-2 awsui-col-lg-2 awsui-textar">' + colField.comment + '</div><div class="awsui-col-xs-10 awsui-col-sm-10 awsui-col-md-10 awsui-col-lg-10 awsui-form-parent"><span class=" ' + (colField.required == 1 ? 'required' : '') + '"  style="width:100%;"><textarea type="text"  rows="4" class="awsui-input" id="' + colField.name + '" name="' + colField.name + '">' + colField.value + '</textarea></span></div></div>';
            $("#confForm").append(htmlRow);
        } else if (colField.type == 528) {//日期
            let htmlRow = '<div class="awsui-row" ' + (colField.readonly == 1 ? 'style="pointer-events: none;"' : '') + '><div class="awsui-col-xs-2 awsui-col-sm-2 awsui-col-md-2 awsui-col-lg-2 awsui-text">' + colField.comment + '</div><div class="awsui-col-xs-10 awsui-col-sm-10 awsui-col-md-10 awsui-col-lg-10 awsui-form-parent"><span class=" ' + (colField.required == 1 ? 'required' : '') + '"  style="width:100%;"><input type="text" class="awsui-datepicker awsui-input" id="' + colField.name + '" name="' + colField.name + '"/></span></div></div>';
            $("#confForm").append(htmlRow);
        } else if (colField.type == 529) {//数字
            let htmlRow = '<div class="awsui-row" ' + (colField.readonly == 1 ? 'style="pointer-events: none;"' : '') + '><div class="awsui-col-xs-2 awsui-col-sm-2 awsui-col-md-2 awsui-col-lg-2 awsui-text">' + colField.comment + '</div><div class="awsui-col-xs-10 awsui-col-sm-10 awsui-col-md-10 awsui-col-lg-10 awsui-form-parent"><span class=" ' + (colField.required == 1 ? 'required' : '') + '"  style="width:100%;"><input type="number" class="awsui-input" id="' + colField.name + '" name="' + colField.name + '"></span></div></div>';
            $("#confForm").append(htmlRow);
        } else if (colField.type == 530) {//列表
            let options = '';
            for (var j = 0; j < colField.list.length; j++) {
                let option = colField.list[j];
                options += '<option value="' + option.VALUE + '">' + option.LABEL + '</option>';
            }
            console.log("options",options);
            let htmlRow = '<div class="awsui-row" ' + (colField.readonly == 1 ? 'style="pointer-events: none;"' : '') + '><div class="awsui-col-xs-2 awsui-col-sm-2 awsui-col-md-2 awsui-col-lg-2 awsui-text">' + colField.comment + '</div><div class="awsui-col-xs-10 awsui-col-sm-10 awsui-col-md-10 awsui-col-lg-10 awsui-form-parent"><span class=" ' + (colField.required == 1 ? 'required' : '') + '"  style="width:100%;"><select id="' + colField.name + '" name="' + colField.name + '">' + options + '</select></span></div></div>';
            $("#confForm").append(htmlRow);
        } else if (colField.type == 532) {//布尔
            let htmlRow = '<div class="awsui-row" ' + (colField.readonly == 1 ? 'style="pointer-events: none;"' : '') + '><div class="awsui-col-xs-2 awsui-col-sm-2 awsui-col-md-2 awsui-col-lg-2 awsui-text">' + colField.comment + '</div><div class="awsui-col-xs-10 awsui-col-sm-10 awsui-col-md-10 awsui-col-lg-10 awsui-form-parent"><span class=" ' + (colField.required == 1 ? 'required' : '') + '"  style="width:100%;"><input type="checkbox" id="' + colField.name + '" name="' + colField.name + '" ' + (colField.value == 1 ? 'checked' : '') + '></span></div></div>';
            $("#confForm").append(htmlRow);
        }


        $("#" + colField.name).val(colField.value);
        if (colField.type == 528) {
            $("#" + colField.name).datepicker({
                format: "yyyy-mm-dd",
                autoclose: true
            });
        } else if (colField.type == 530) {
            $("#" + colField.name).select2();
            $(".select2-container").css("width", "100%");

            $("#" + colField.name).val([colField.value]).trigger("change"); //单选赋值

        } else if (colField.type == 532 && colField.value == 1) {
            $("#" + colField.name).switchButton();
        }
    }

   // $("#confFormDiv").css("height", colFieldIDs.length*50+"px");

    $(".required").find(".awsui-input").focus(function () {
        $.each($(".required").find(".awsui-input"), function (i, el) {
            $(el).css("background-color", "#fff");
        });
        $(this).css("background-color", "#FFFFCC");
    });
    $(".required").find(".awsui-input").blur(function () {
        var inputVal = $(this).val();
        if (inputVal == "") {
            $(this).tooltip({
                positon: "top",
                text: "不允许为空，请重新输入",
                bgcolor: "#f9f9f9",
                color: "red",
                borderColor: "red",
                close: false
            });
            return false;
        }
    });
}

function saveConf(objectId) {
	
    //必填校验
    $(".required").find(".awsui-input").each(function () {
        if ($(this).val() == "") {
        
        }
    });

    let confForm = {};
    for (var i = 0; i < colFieldIDs.length; i++) {
		
        let id = colFieldIDs[i];
		let aaa=$("#" + id).val();
		debugger;
        confForm[id] = aaa;
    }
    awsui.ajax.request({
        type: "POST",
        url: "./jd?cmd=com.awspaas.user.apps.donenow_crm_save&sid=" + sid,
        data: "cateId="+cateId+"&objectId="+objectId+"&data="+JSON.stringify(confForm),
        success: function (res) {
            console.log(res);

        }
    });
}



