var fID = 3192;
// 调取表单数据
$(function () {
$.ajax({
ContentType: "application/x-www-form-urlencoded",
url: '/rcms-external-rest/rmForm/getFormField?' + (new Date()).getTime(),
type: "post",
data: {
id: fID
},
success: function (data) {
if (data.code == "S1A00000" && data.data.length != "") {
var formhtml = "";
var option = "";
for (var i = 0; i < data.data.length; i++) {
if (data.data[i].columnType == "text") {
formhtml += '
' + '*' +
'' + '
';
} else if (data.data[i].columnType == "textarea") {
formhtml += '' + '
*' +
'
' + '
0/' + data.data[i]
.maxLength + '
';
} else if (data.data[i].columnType == "select") {
formhtml += '' + '*' + data.data[i].fieldName +
'' +
'
';
for (var j = 0; j < data.data[i].dictDataList.length; j++) {
option += ''
}
console.log(option)
}
}
$(".onlineMsgForm").prepend(formhtml);
$("select").prepend(option);
$(".ybtextarea textarea").bind("input propertychange", function (event) {
checkTxt()
});
}
},
error: function () {
console.log("失败")
}
});
function checkTxt(e) {
var value = $(".ybtextarea textarea").val()
var length = value.length;
$(".txtTotal span").html(length)
}
});
$("form").submit(function (e) {
e.preventDefault();
});
$(".yzm-font").on("click", function () {
$(".yzm").click();
})
// 表单提交
var flag = true;
var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
$("#crv-maskForm-submit").on("click", function () {
$(".crv-tips").remove();
$(".crv-suc").hide();
$(".crv-fail").hide();
$("input[name=people]").after('请输入您的姓名');
$("input[name=company]").after('请输入您的公司');
$("input[name=tel]").after('请输入您的电话');
$("textarea[name=content]").after('请输入您需要反馈的内容');
$("input[name=yzm]").after('请输入验证码');
$(".onlineMsgForm select[name=type]").after('请选择反馈类型')
var dataForm = {};
var num = 0;
dataForm = new FormData();
var people = $("input[name=people]").val();
var company = $("input[name=company]").val();
var tel = $("input[name=tel]").val();
var content = $("textarea[name=content]").val();
var yzm = $('.yzm-ipt').val();
var textLen = $(".onlineMsgForm input[type=text]");
var textareaLen = $(".onlineMsgForm textarea[name=content]");
var select = $(".onlineMsgForm select[name=type]");
for (var i = 0; i < textLen.length; i++) {
if ($.trim(textLen.eq(i).val()) == 0) {
textLen.eq(i).siblings(".crv-tips").show();
textLen.eq(i).css("border", "1px solid #FF829B");
num += 1
} else if (textLen.eq(i).attr("name") == "tel") {
var myreg = /^1[0-9]{10}$/;
if (!myreg.test(textLen.eq(i).val())) {
textLen.eq(i).siblings(".crv-tips").text("请输入正确的手机号码").show();
num += 1
} else {
textLen.eq(i).siblings(".crv-tips").hide();
textLen.eq(i).css("border", "1px solid #D9D9D9");
}
} else if (textLen.eq(i).attr("name") == "yzm") {
if ($(".yzm-ipt").val().length == 0) {
textLen.eq(i).siblings(".crv-tips").text("请输入验证码").show();
num += 1
} else {
textLen.eq(i).siblings(".crv-tips").hide();
textLen.eq(i).css("border", "1px solid #D9D9D9");
}
} else {
textLen.eq(i).siblings(".crv-tips").hide();
textLen.eq(i).css("border", "1px solid #D9D9D9");
}
textLen.eq(i).focus(function () {
$(this).next().hide();
$(this).css("border", "1px solid #64DC8E");
})
textLen.eq(i).blur(function () {
$(this).next().hide();
$(this).css("border", "1px solid #D9D9D9");
})
}
if ($.trim(textareaLen.val()) == "") {
textareaLen.siblings(".crv-tips").show();
textareaLen.css("border", "1px solid #FF829B");
num += 1
} else {
textareaLen.siblings(".crv-tips").hide();
textareaLen.css("border", "1px solid #D9D9D9");
}
if ($("option:selected").val() == 0) {
select.siblings(".crv-tips").show();
select.css("border", "1px solid #FF829B");
num += 1
} else {
select.siblings(".crv-tips").hide();
select.css("border", "1px solid #D9D9D9");
}
textareaLen.focus(function () {
$(this).next().hide();
$(this).css("border", "1px solid #64DC8E");
})
textareaLen.blur(function () {
$(this).next().hide();
$(this).css("border", "1px solid #D9D9D9");
})
if (num <= 0) {
var dataFormInfo = {
"type": $("option:selected").val(),
"people": people,
"company": company,
"tel": tel,
"content": content,
};
// id,captcha必传单独传
dataForm.append("id", fID);
// 表单数据
dataForm.append("requiredData", JSON.stringify(dataFormInfo));
dataForm.append("captcha", yzm);
$.ajax({
url: "/rcms-external-rest/rmForm/formSubmit",
type: "post",
async: true,
data: dataForm,
processData: false,
contentType: false,
success: function (data) {
if (data && data.code == "S1A00000") {
alert("提交成功")
setTimeout(function () {
location.reload(true)
$(".crv-suc").hide();
$(".yzm").click();
}, 3000)
} else {
dataForm = {}
alert(data.msg)
}
},
error: function () {
console.log("失败")
}
});
}
})
$("#crv-maskForm-reset").on("click", function () {
$("input").val("");
$("textarea").val("");
$("select").val('0');
})