contract_add.js 6.1 KB

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