| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- $(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 = "<span class=\"c-red\">*</span>联系人:";
- phoneLabel = "<span class=\"c-red\">*</span>联系电话:";
- }
- var html = "<label class=\"form-label col-xs-4 col-sm-2 mt_10\">" + contactLabel + "</label>";
- html += "<div class=\"formControls col-xs-8 col-sm-4 mt_10\">";
- html += "<input type=\"text\" class=\"input-text\" readonly required maxlength=\"45\" value=\"" + company.companyContacts[i].contact + "\" />";
- html += "</div>";
- html += "<label class=\"form-label col-xs-4 col-sm-2 mt_10\">" + phoneLabel + "</label>";
- html += "<div class=\"formControls col-xs-8 col-sm-4 mt_10\">";
- html += "<input type=\"text\" class=\"input-text\" readonly required maxlength=\"45\" value=\"" + company.companyContacts[i].phone + "\" />";
- html += "</div>";
- $(".company_contact").append(html);
- }
- }
- }
- function contract_dialog(title, url, w, h) {
- layer_show(title, pagePath + url, w, h);
- }
|