$(function () { $("#form-contract-edit").validate({ rules: { contract_no: { required: true, minlength: 1, maxlength: 45, remote: { url: pagePath + "/build/contract/isExistContractNo", type: "get", data: { 'contract_no': function () { return $("#contract_no").val(); }, 'id': $("#contract_id").val() } } }, company_phone: { isMobile: true }, paid_tenancy: { required: true, isFloat2: true }, paid_tenancy_month: { required: true, // min:1, // max: 12 }, deposit_fee: { required: true, isFloat2: true }, contract_start_date: { required: true, }, contract_end_date: { required: true, } }, messages: { contract_no: { remote: "该用合同号已被使用!" } }, onkeyup: false, focusCleanup: true, success: "valid", submitHandler: function (form) { if ($(".type:checked").length == 0) { errorMessage("至少选择一个模块"); return false; } $(form).ajaxSubmit({ type: 'put', url: pagePath + "/build/contract/updateContract/" + $("#contract_id").val(), dataType: "json", success: function (data) { if (data.status) { succeedMessage(data.message); setTimeClose(); } else { errorMessage(data.message); } } }); return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。 }, errorPlacement: function (error, element) { if (element.attr('name') == 'buildLives[0].use_area' || element.attr('name') == 'buildLives[0].pay' || element.attr('name') == 'buildLives[0].build_number' || element.attr('name') == 'buildLives[0].floor' ) { error.addClass('label_error') } if (element.attr('name') == 'contractWaterList[0].name' || element.attr('name') == 'contractWaterList[0].start_water_meter_count') { error.addClass('label_error') } if (element.attr('name') == 'paid_tenancy' || element.attr('name') == 'paid_tenancy_month') { error.addClass('label_error') } if (element.attr('name') == 'contractElectrics[0].name' || element.attr('name') == 'contractElectrics[0].start_electric_meter_count') { error.addClass('label_error') } if (element.attr('name') == 'contractProperties[0].price' || element.attr('name') == 'contractProperties[0].number' || element.attr('name') == 'contractProperties[0].payment_cycle' ) { error.addClass('label_error') } if (element.attr('name') == 'contractParkings[0].price' || element.attr('name') == 'contractParkings[0].number' || element.attr('name') == 'contractParkings[0].payment_cycle' ) { error.addClass('label_error') } error.appendTo(element.parent()); } }); }); function checkIsExistCompany() { $.ajax({ type: 'post', url: pagePath + "/build/contract/isExistCompanyName", dataType: "json", data: { company_name: function () { return $("#company_name").val(); } }, success: function (data) { if (data.success) { //succeedMessage(data.message); var company = data.obj.company; bindCompany(company); } else { errorMessage(data.message); } } }); } function bindCompany(company) { $("input[name='company_id']").val(company.id); $("input[name='company_name']").val(company.company_name); $("input[name='location']").val(company.location); $("input[name='business']").val(company.business); $(".company_contact").children().remove(); if (company.companyContacts.length > 0) { for (var i = 0; i < company.companyContacts.length; i++) { var contactLabel = ""; var phoneLabel = ""; if (i == 0) { contactLabel = "*联系人:"; phoneLabel = "*联系电话:"; } var html = ""; html += "
"; html += ""; html += "
"; html += ""; html += "
"; html += ""; html += "
"; $(".company_contact").append(html); } } } function contract_dialog(title, url, w, h) { layer_show(title, pagePath + url, w, h); }