sso

create_org.js 6.9KB

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