sso

create_org.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. $(function() {
  2. $("#province_select").change(function() {
  3. $("#city_select option").remove();
  4. $("#district_select option").remove();
  5. $("#city_select").append("<option value='0'>市</option>");
  6. $("#district_select").append("<option value='0'>区/县</option>");
  7. var province = $("#province_select option:selected").val();
  8. $.ajax({
  9. url: "/city",
  10. type: "GET",
  11. data: {
  12. province_id: province,
  13. },
  14. async: false,
  15. dataType: "json",
  16. success: function(json) {
  17. if (json.state == 1) {
  18. var cities = json.data.list
  19. var optionStr = ""
  20. for (let index = 0; index < cities.length; index++) {
  21. const city = cities[index];
  22. optionStr = optionStr + "<option value = " + city.id + ">" + city.name + "</option>"
  23. }
  24. $("#city_select").append(optionStr);
  25. } else {
  26. console.log("获取城市失败", json.msg);
  27. }
  28. },
  29. error: function() {
  30. console.log("连接失败,请检查网络");
  31. }
  32. });
  33. });
  34. $("#city_select").change(function() {
  35. $("#district_select option").remove();
  36. $("#district_select").append("<option value='0'>区/县</option>");
  37. var city = $("#city_select option:selected").val();
  38. $.ajax({
  39. url: "/district",
  40. type: "GET",
  41. data: {
  42. city_id: city,
  43. },
  44. async: false,
  45. dataType: "json",
  46. success: function(json) {
  47. if (json.state == 1) {
  48. var districts = json.data.list
  49. var optionStr = ""
  50. for (let index = 0; index < districts.length; index++) {
  51. const district = districts[index];
  52. optionStr = optionStr + "<option value = " + district.id + ">" + district.name + "</option>"
  53. }
  54. $("#district_select").append(optionStr);
  55. } else {
  56. console.log("获取区县失败", json.msg);
  57. }
  58. },
  59. error: function() {
  60. console.log("连接失败,请检查网络");
  61. }
  62. });
  63. });
  64. $("#cat_p_select").change(function() {
  65. $("#cat_c_select option").remove();
  66. $("#cat_c_select").append("<option value='0'>详细类型</option>");
  67. $("#cat_c_select").parent().hide();
  68. $("#org_category").val("0");
  69. var p_cat = $("#cat_p_select option:selected").val();
  70. $.ajax({
  71. url: "/get_org_cat",
  72. type: "GET",
  73. data: {
  74. pid: p_cat,
  75. },
  76. async: false,
  77. dataType: "json",
  78. success: function(json) {
  79. if (json.state == 1) {
  80. var cats = json.data.list
  81. if (cats.length == 0) {
  82. $("#cat_c_select").parent().hide();
  83. $("#org_category").val(p_cat);
  84. } else {
  85. var optionStr = ""
  86. for (let index = 0; index < cats.length; index++) {
  87. const cat = cats[index];
  88. optionStr = optionStr + "<option value = " + cat.id + ">" + cat.short_name + "</option>"
  89. }
  90. $("#cat_c_select").append(optionStr);
  91. $("#cat_c_select").parent().show();
  92. }
  93. } else {
  94. layer.msg("获取详细类型失败: " + json.msg);
  95. }
  96. },
  97. error: function() {
  98. layer.msg("连接失败,请检查网络");
  99. }
  100. });
  101. });
  102. $("#cat_c_select").change(function() {
  103. $("#org_category").val($("#cat_c_select option:selected").val());
  104. });
  105. $("#submit").on("click", function() {
  106. var checkErr = checkInfoFull();
  107. if (checkErr.length > 0) {
  108. layer.msg(checkErr);
  109. return;
  110. }
  111. var postData = {
  112. name: $("#org_name").val(),
  113. short_name: $("#org_short_name").val(),
  114. province: $("#province_select option:selected").val(),
  115. city: $("#city_select option:selected").val(),
  116. district: $("#district_select option:selected").val(),
  117. address: $("#address").val(),
  118. category: $("#org_category").val(),
  119. org_phone: $("#org_phone").val(),
  120. }
  121. postRequest("/org/create/submit", postData, doSuccess, doFail);
  122. function doSuccess(res) {
  123. if (res.state == 0) {
  124. serverErrorMsg(res);
  125. return;
  126. }
  127. layer.msg("创建成功");
  128. window.location.href = res.data.url; //跳转网址
  129. }
  130. });
  131. });
  132. function checkInfoFull() {
  133. if ($("#org_name").val().length == 0) {
  134. return "请填写机构名称";
  135. }
  136. if ($("#org_short_name").val().length == 0) {
  137. return "请填写机构简称";
  138. }
  139. if ($("#province_select option:selected").val() == "0") {
  140. return "请选择省份";
  141. }
  142. if ($("#city_select option:selected").val() == "0") {
  143. return "请选择城市";
  144. }
  145. if ($("#district_select option:selected").val() == "0") {
  146. return "请选择区县";
  147. }
  148. if ($("#address").val().length == 0) {
  149. return "请填写地址";
  150. }
  151. if ($("#org_category").val().length == 0 || $("#org_category").val() == "0") {
  152. return "请选择机构类型";
  153. }
  154. if ($("#org_phone").val().length > 0) {
  155. if (/^(\d{3,4}-?\d{7,8}$)|(1\d{10}$)/.test($("#org_phone").val()) == false) {
  156. return "请填写正确的机构电话";
  157. }
  158. }
  159. return "";
  160. }
  161. function doFail(res) {
  162. serverErrorMsg(res);
  163. }