contract_edit.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. $(function () {
  2. $("#form-contract-edit").validate({
  3. rules: {
  4. contract_no: {
  5. required: true,
  6. minlength: 1,
  7. maxlength: 45,
  8. remote: {
  9. url: pagePath + "/build/contract/isExistContractNo",
  10. type: "get",
  11. data: {
  12. 'contract_no': function () {
  13. return $("#contract_no").val();
  14. },
  15. 'id': $("#contract_id").val()
  16. }
  17. }
  18. },
  19. company_phone: {
  20. isMobile: true
  21. },
  22. paid_tenancy: {
  23. required: true,
  24. isFloat2: true
  25. },
  26. paid_tenancy_month: {
  27. required: true,
  28. // min:1,
  29. // max: 12
  30. },
  31. deposit_fee: {
  32. required: true,
  33. isFloat2: true
  34. },
  35. contract_start_date: {
  36. required: true,
  37. },
  38. contract_end_date: {
  39. required: true,
  40. }
  41. },
  42. messages: {
  43. contract_no: {
  44. remote: "该用合同号已被使用!"
  45. }
  46. },
  47. onkeyup: false,
  48. focusCleanup: true,
  49. success: "valid",
  50. submitHandler: function (form) {
  51. if ($(".type:checked").length == 0) {
  52. errorMessage("至少选择一个模块");
  53. return false;
  54. }
  55. $(form).ajaxSubmit({
  56. type: 'put',
  57. url: pagePath + "/build/contract/updateContract/" + $("#contract_id").val(),
  58. dataType: "json",
  59. success: function (data) {
  60. if (data.status) {
  61. succeedMessage(data.message);
  62. setTimeClose();
  63. } else {
  64. errorMessage(data.message);
  65. }
  66. }
  67. });
  68. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  69. },
  70. errorPlacement: function (error, element) {
  71. if (element.attr('name') == 'buildLives[0].use_area' || element.attr('name') == 'buildLives[0].pay' ||
  72. element.attr('name') == 'buildLives[0].build_number' || element.attr('name') == 'buildLives[0].floor'
  73. ) {
  74. error.addClass('label_error')
  75. }
  76. if (element.attr('name') == 'contractWaterList[0].name' || element.attr('name') == 'contractWaterList[0].start_water_meter_count') {
  77. error.addClass('label_error')
  78. }
  79. if (element.attr('name') == 'paid_tenancy' || element.attr('name') == 'paid_tenancy_month') {
  80. error.addClass('label_error')
  81. }
  82. if (element.attr('name') == 'contractElectrics[0].name' || element.attr('name') == 'contractElectrics[0].start_electric_meter_count') {
  83. error.addClass('label_error')
  84. }
  85. if (element.attr('name') == 'contractProperties[0].price' || element.attr('name') == 'contractProperties[0].number' ||
  86. element.attr('name') == 'contractProperties[0].payment_cycle'
  87. ) {
  88. error.addClass('label_error')
  89. }
  90. if (element.attr('name') == 'contractParkings[0].price' || element.attr('name') == 'contractParkings[0].number' ||
  91. element.attr('name') == 'contractParkings[0].payment_cycle'
  92. ) {
  93. error.addClass('label_error')
  94. }
  95. error.appendTo(element.parent());
  96. }
  97. });
  98. });
  99. function checkIsExistCompany() {
  100. $.ajax({
  101. type: 'post',
  102. url: pagePath + "/build/contract/isExistCompanyName",
  103. dataType: "json",
  104. data: {
  105. company_name: function () {
  106. return $("#company_name").val();
  107. }
  108. },
  109. success: function (data) {
  110. if (data.success) {
  111. //succeedMessage(data.message);
  112. var company = data.obj.company;
  113. bindCompany(company);
  114. } else {
  115. errorMessage(data.message);
  116. }
  117. }
  118. });
  119. }
  120. function bindCompany(company) {
  121. $("input[name='company_id']").val(company.id);
  122. $("input[name='company_name']").val(company.company_name);
  123. $("input[name='location']").val(company.location);
  124. $("input[name='business']").val(company.business);
  125. $(".company_contact").children().remove();
  126. if (company.companyContacts.length > 0) {
  127. for (var i = 0; i < company.companyContacts.length; i++) {
  128. var contactLabel = "";
  129. var phoneLabel = "";
  130. if (i == 0) {
  131. contactLabel = "<span class=\"c-red\">*</span>联系人:";
  132. phoneLabel = "<span class=\"c-red\">*</span>联系电话:";
  133. }
  134. var html = "<label class=\"form-label col-xs-4 col-sm-2 mt_10\">" + contactLabel + "</label>";
  135. html += "<div class=\"formControls col-xs-8 col-sm-4 mt_10\">";
  136. html += "<input type=\"text\" class=\"input-text\" readonly required maxlength=\"45\" value=\"" + company.companyContacts[i].contact + "\" />";
  137. html += "</div>";
  138. html += "<label class=\"form-label col-xs-4 col-sm-2 mt_10\">" + phoneLabel + "</label>";
  139. html += "<div class=\"formControls col-xs-8 col-sm-4 mt_10\">";
  140. html += "<input type=\"text\" class=\"input-text\" readonly required maxlength=\"45\" value=\"" + company.companyContacts[i].phone + "\" />";
  141. html += "</div>";
  142. $(".company_contact").append(html);
  143. }
  144. }
  145. }
  146. function contract_dialog(title, url, w, h) {
  147. layer_show(title, pagePath + url, w, h);
  148. }