//进入页面加载
$(function(){
    var list1=''
    　　var item=[{"type":"text","choice":"true","name":"文本框","limit":"undefined","limiterror":"undefined","placeholder":"无"},{"type":"checkbox","choice":"true","name":"复选222","content":"1,2,3,4"},{"type":"multiple","choice":"true","name":"多行文本框","placeholder":"22","height":"200"},{"type":"radio","choice":"true","name":"单选单选","content":"1,2,3"},{"type":"date","choice":"true","name":"时间事件","placeholder":"2020-03-10"},{"type":"checkbox","choice":"true","name":"复选复选","content":"复选,复选2,复选3,复选4"},{"type":"dropdown","choice":"true","name":"下拉下拉","content":"吃,喝,玩,热"},{"type":"img","choice":"true","name":"上传图片222","num":"1"},{"type":"file","choice":"true","name":"上传文件222","num":"1"}]
    console.log(item)
    for(var i = 0 ; i < item.length ; i ++){    
      var type=item[i].type;
     var str;
    switch (type) {
        // 单文本
        case "text":
    str = '<!--具体的表单控件 文本框-->';
    str += `<div class="row"><div class="questionnaireItem" data-name=${item[i].name} data-type=${item[i].type} data-choice=${item[i].choice}  data-limit=${item[i].limit}  data-limiterror=${item[i].limiterror} data-placeholder=${item[i].placeholder}> `;
    //'<!--表单控件的头部-->';
    str += '<div class="questionnaireItemHead">';
    //'<!--表单控件的名称-->';
    if(item[i].choice=="true"){
        str += `<div class="required">*</div><div class="questionnaireItemName">${item[i].name}</div>`;
    }else{
        str += `<div class="required"></div><div class="questionnaireItemName">${item[i].name}</div>`;
    }
    //'<!--表单控件的功能按钮-->';
    str += '<div class="questionnaireItemGroupButton">'
    str += '<button type="button" class="btn btn-primary controlMove">移动</button>';
    str += '<button type="button" class="btn btn-primary controlDelete">删除</button>';
    str += '</div></div>';
    //'<!--控件-->';
    str += '<div class="questionnaireItemContent">';
    str += '<div class="form-group hidMargin">';
    str += `<input type="text" class="form-control formVal" name="text" placeholder=${item[i].placeholder}>`;
    str += '</div><div class="errorMain"></div></div></div></div>';
            break;
        //多行文本
        case "multiple":
               //<!--具体的表单控件 多行文本框-->
    var str = `<div class="row"><div class="questionnaireItem" data-name=${item[i].name} data-type=${item[i].type} data-choice=${item[i].choice} data-height=${item[i].height} data-placeholder=${item[i].placeholder}> `;
    //<!--表单控件的头部-->
    str += '<div class="questionnaireItemHead">';
    //<!--表单控件的名称-->
    str += '<div class="required">*</div><div class="questionnaireItemName">多行文本框</div>';
    //<!--表单控件的功能按钮-->
    str += '<div class="questionnaireItemGroupButton">';
    str += '<button type="button" class="btn btn-primary controlMove">移动</button>';
    str += '<button type="button" class="btn btn-primary controlDelete">删除</button>';
    str += '</div></div>';
    //<!--控件-->
    str += '<div class="questionnaireItemContent">';
    str += '<div class="form-group hidMargin">';
    var height=Number(item[i].height)+14;
    str += `<textarea name="" class="form-control formVal" cols="30" rows="5" style="resize: none;height:${height}px"  placeholder=${item[i].placeholder}></textarea>`;
    str += '</div><div class="errorMain"></div></div></div></div>';
            break;
        // 时间框
        case "date":
    //<!--具体的表单控件 时间框-->
    var str = `<div class="row"><div class="questionnaireItem" data-name=${item[i].name} data-type=${item[i].type} data-choice=${item[i].choice} data-placeholder=${item[i].placeholder}>`;
    //<!--表单控件的头部-->
    str += '<div class="questionnaireItemHead">';
    //<!--表单控件的名称-->
    if(item[i].choice=="true"){
        str += `<div class="required">*</div><div class="questionnaireItemName">${item[i].name}</div>`;
    }else{
        str += `<div class="required"></div><div class="questionnaireItemName">${item[i].name}</div>`;
    }
    //<!--表单控件的功能按钮-->
    str += '<div class="questionnaireItemGroupButton">';
    str += '<button type="button" class="btn btn-primary controlMove">移动</button>';
    str += '<button type="button" class="btn btn-primary controlDelete">删除</button>';
    str += '</div></div>';
    //<!--控件-->
    str += '<div class="questionnaireItemContent">';
    str += '<div class="form-group hidMargin">';
    str += `<input type="date" class="form-control formVal" name="" placeholder=${item[i].placeholder}>`;
    str += '</div><div class="errorMain"></div></div></div></div>';
            break;
        // 单选框
        case "radio":
                //<!--具体的表单控件 单选框-->
    var str = `<div class="row"><div class="questionnaireItem" data-name=${item[i].name} data-type=${item[i].type} data-choice=${item[i].choice} data-content=${item[i].content}>`;
    //<!--表单控件的头部-->
    str += '<div class="questionnaireItemHead">';
    //<!--表单控件的名称-->
    if(item[i].choice=="true"){
        str += `<div class="required">*</div><div class="questionnaireItemName">${item[i].name}</div>`;
    }else{
        str += `<div class="required"></div><div class="questionnaireItemName">${item[i].name}</div>`;
    }
    //<!--表单控件的功能按钮-->
    str += '<div class="questionnaireItemGroupButton">';
    str += '<button type="button" class="btn btn-primary controlMove">移动</button>';
    str += '<button type="button" class="btn btn-primary controlDelete">删除</button>';
    str += '</div></div>';
    //<!--控件-->
    str += '<div class="questionnaireItemContent">';
    str += '<div class="form-group hidMargin">';
    var content=item[i].content.split(",");
    for(let i = 0 ; i < content.length ; i ++){
        str += '<div class="form-check">';
    str += '<label class="form-check-label">';
    str += `<input type="radio" class="form-check-input checkMargin" name="selectName" value="${content[i]}">${content[i]}</label></div>`;
    }
    str += '</div><div class="errorMain"></div></div></div></div>';
            break;
        //多选框
        case "checkbox":
             //<!--具体的表单控件 复选框-->
    var str = `<div class="row"><div class="questionnaireItem" data-name=${item[i].name}  data-type=${item[i].type} data-choice=${item[i].choice} data-content=${item[i].content}>`;
    //<!--表单控件的头部-->
    str += '<div class="questionnaireItemHead">';
    //<!--表单控件的名称-->
    if(item[i].choice=="true"){
        str += `<div class="required">*</div><div class="questionnaireItemName">${item[i].name}</div>`;
    }else{
        str += `<div class="required"></div><div class="questionnaireItemName">${item[i].name}</div>`;
    }
    //<!--表单控件的功能按钮-->
    str += '<div class="questionnaireItemGroupButton">';
    str += '<button type="button" class="btn btn-primary controlMove">移动</button>';
    str += '<button type="button" class="btn btn-primary controlDelete">删除</button>';
    str += '</div></div>';
    //<!--控件-->
    str += '<div class="questionnaireItemContent">';
    str += '<div class="form-group hidMargin">';
        var content=item[i].content.split(",");
    for(let i = 0 ; i < content.length ; i ++){
        str += '<div class="form-check">';
    str += '<label class="form-check-label">';
    str += `<input type="checkbox" class="form-check-input checkMargin" name="selectName" value="${content[i]}">${content[i]}</label></div>`;
    }
    
    str += '</div><div class="errorMain"></div></div></div></div>';
            break;
        //下拉框
        case "dropdown":
            //<!--具体的表单控件 下拉框-->
    var str = `<div class="row"><div class="questionnaireItem" data-name=${item[i].name} data-type=${item[i].type} data-choice=${item[i].choice} data-content=${item[i].content}>`;
    //<!--表单控件的头部-->
    str += '<div class="questionnaireItemHead">';
    //<!--表单控件的名称-->
    if(item[i].choice=="true"){
        str += `<div class="required">*</div><div class="questionnaireItemName">${item[i].name}</div>`;
    }else{
        str += `<div class="required"></div><div class="questionnaireItemName">${item[i].name}</div>`;
    }
    //<!--表单控件的功能按钮-->
    str += '<div class="questionnaireItemGroupButton">';
    str += '<button type="button" class="btn btn-primary controlMove">移动</button>';
    str += '<button type="button" class="btn btn-primary controlDelete">删除</button>';
    str += '</div></div>';
    //<!--控件-->
    str += '<div class="questionnaireItemContent">';
    str += '<div class="form-group hidMargin">';
    str += '<select class="form-control select">';
        var content=item[i].content.split(",");
    for(let i = 0 ; i < content.length ; i ++){
        str += `<option value=${content[i]}>${content[i]}</option>`;
    }

    str += '</select>';
    str += '</div><div class="errorMain"></div></div></div></div>';
            break;
        case "textdropdown":
            str = getTextDropdown();
            break;
        //上传图片
        case "img":
        var str = `<div class="row"><div class="questionnaireItem"  data-name=${item[i].name} data-type=${item[i].type} data-choice=${item[i].choice} data-num=${item[i].num}>`;
    //<!--表单控件的头部-->
    str += '<div class="questionnaireItemHead">';
    //<!--表单控件的名称-->
    if(item[i].choice=="true"){
        str += `<div class="required">*</div><div class="questionnaireItemName">${item[i].name}</div>`;
    }else{
        str += `<div class="required"></div><div class="questionnaireItemName">${item[i].name}</div>`;
    }
    //<!--表单控件的功能按钮-->
    str += '<div class="questionnaireItemGroupButton">';
    str += '<button type="button" class="btn btn-primary controlMove">移动</button>';
    str += '<button type="button" class="btn btn-primary controlDelete">删除</button>';
    str += '</div></div>';
    //<!--控件-->
    str += '<div class="questionnaireItemContent">';
    str += '<div class="form-group hidMargin">';
    str += '<div class="img-box full">';
    str += '<section class="img-section">';
    str += '<div class="z_photo upimg-div clear">';
    str += '<section class="z_file fl">';
    str += '<div class="z_fileImgDel">删除</div>';
    str += '<img src="../images/a11.png" class="add-img" />';
    str += '<input type="file" name="file" class="file imgFile" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" leipiplugins="imgupload" title="图片上传" />';
    str += '</section></div></section>';
    str += '<div class="imgExplain">支持jpg、jpeg、png、bmp等图片格式</div>';
    str += '<div class="errerClass imgErrer"></div>';
    str += '</div>';
    str += '</div><div class="errorMain"></div></div></div></div>';
    
            break;
        case "file":
        //上传文件
        var str = `<div class="row"><div class="questionnaireItem" data-name=${item[i].name} data-type=${item[i].type} data-choice=${item[i].choice} data-num=${item[i].num} >`;
    //<!--表单控件的头部-->
    str += '<div class="questionnaireItemHead">';
    //<!--表单控件的名称-->
    if(item[i].choice=="true"){
        str += `<div class="required">*</div><div class="questionnaireItemName">${item[i].name}</div>`;
    }else{
        str += `<div class="required"></div><div class="questionnaireItemName">${item[i].name}</div>`;
    }
    //<!--表单控件的功能按钮-->
    str += '<div class="questionnaireItemGroupButton">';
    str += '<button type="button" class="btn btn-primary controlMove">移动</button>';
    str += '<button type="button" class="btn btn-primary controlDelete">删除</button>';
    str += '</div></div>';
    //<!--控件-->
    str += '<div class="questionnaireItemContent">';
    str += '<div class="form-group hidMargin">';
    str += '<div class="message">';
    str += '<div class="messagedel">删除</div>';
    str += '<input type="text" name="txt" class="input fileUpload form-control" value="" disabled="disabled" />';
    str += '<input type="button" value="上传文件" size="30" class="liulan fileUploadBtn">';
    str += '<input type="file" name="f" style="height:26px;" class="files leipiplugins fileUploadReal" size="1" leipiplugins="uploadfile" title="文件上传" hidefocus></div>';
    str += '<div class="fileTips">';
    str += '<p>1.上传文档不超过100MB</p>';
    str += '<p>2.为了保证文档能正常使用，我们支持以下格式的文档上传：</p>';
    str += '<p>MS Office文档： doc,docx,ppt,pptx,xls,xlsx,vsd,pot,pps,rtf</p>';
    str += '<p>压缩文档： rar,zip,tar,gz,tgz</p>';
    str += '<p>图片： jpg,jpeg,gif,bmp,png</p>';
    str += '<p>WPS office系列： wps,et,dps</p>';
    str += '<p>PDF： pdf</p>';
    str += '<p>纯文本： txt</p>';
    str += '<p>EPUB： epub</p></div>';
    str += '<div class="errerClass FileErrer"></div>';
    str += '</div><div class="errorMain"></div></div></div></div>';
            break;
        default :
            str = ""; 
            break;
    }
     list1+=str;
    }
    $(".questionnaireSubjectForm").append(list1);
    $(".mainbackground").css('display','none');
var html = getCenterHtml();
var ch = '<div class="questionnaireItemGroupButton"><button type="button" class="btn btn-primary controlMove">移动</button><button type="button" class="btn btn-primary controlDelete">删除</button></div>';
var ch1='class="questionnaireSubjectForm"'
html = html.replace(new RegExp(ch,'g'),'');
html = html.replace(new RegExp(ch1,'g'),'');
$(".previewMain").show();
$(".previewMain").empty();
html += '<div style="width:100%;height:70px;line-height:70px;float:left;text-align: center;z-index:100;"><button type="button" class="btn btn-primary btnOk" id="tj" style="margin-right:50px">提交</button></div>';
$(".previewMain").append(html);
  }); 

//修改默认值
// $("body").on("change",".formVal",function(){
//     var val = $(this).val();
//     object.attr("data-val",val);
//     object.data("val",val);
// });
        