123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- $(function() {
- $("#open_3").attr("checked", "checked");
-
- $("#province_select").change(function() {
- $("#city_select option").remove();
- $("#district_select option").remove();
- $("#city_select").append("<option value='0'>市</option>");
- $("#district_select").append("<option value='0'>区/县</option>");
- var province = $("#province_select option:selected").val();
- $.ajax({
- url: "/city",
- type: "GET",
- data: {
- province_id: province,
- },
- async: false,
- dataType: "json",
- success: function(json) {
- if (json.state == 1) {
- var cities = json.data.list
- var optionStr = ""
- for (let index = 0; index < cities.length; index++) {
- const city = cities[index];
- optionStr = optionStr + "<option value = " + city.id + ">" + city.name + "</option>"
- }
- $("#city_select").append(optionStr);
-
- } else {
- console.log("获取城市失败", json.msg);
- }
- },
- error: function() {
- console.log("连接失败,请检查网络");
- }
- });
- });
-
- $("#city_select").change(function() {
-
- $("#district_select option").remove();
- $("#district_select").append("<option value='0'>区/县</option>");
- var city = $("#city_select option:selected").val();
- $.ajax({
- url: "/district",
- type: "GET",
- data: {
- city_id: city,
- },
- async: false,
- dataType: "json",
- success: function(json) {
- if (json.state == 1) {
- var districts = json.data.list
- var optionStr = ""
- for (let index = 0; index < districts.length; index++) {
- const district = districts[index];
- optionStr = optionStr + "<option value = " + district.id + ">" + district.name + "</option>"
- }
- $("#district_select").append(optionStr);
-
- } else {
- console.log("获取区县失败", json.msg);
- }
- },
- error: function() {
- console.log("连接失败,请检查网络");
- }
- });
- });
-
- $("#cat_p_select").change(function() {
- $("#cat_c_select option").remove();
- $("#cat_c_select").append("<option value='0'>详细类型</option>");
- $("#cat_c_select").parent().hide();
- $("#org_category").val("0");
- var p_cat = $("#cat_p_select option:selected").val();
- $.ajax({
- url: "/get_org_cat",
- type: "GET",
- data: {
- pid: p_cat,
- },
- async: false,
- dataType: "json",
- success: function(json) {
- if (json.state == 1) {
- var cats = json.data.list
- if (cats.length == 0) {
- $("#cat_c_select").parent().hide();
- $("#org_category").val(p_cat);
- } else {
- var optionStr = ""
- for (let index = 0; index < cats.length; index++) {
- const cat = cats[index];
- optionStr = optionStr + "<option value = " + cat.id + ">" + cat.short_name + "</option>"
- }
- $("#cat_c_select").append(optionStr);
- $("#cat_c_select").parent().show();
- }
-
- } else {
- layer.msg("获取详细类型失败: " + json.msg);
- }
- },
- error: function() {
- layer.msg("连接失败,请检查网络");
- }
- });
- });
-
- $("#cat_c_select").change(function() {
- $("#org_category").val($("#cat_c_select option:selected").val());
- });
-
- $("#submit").on("click", function() {
- var checkErr = checkInfoFull();
- if (checkErr.length > 0) {
- layer.msg(checkErr);
- return;
- }
-
- var open_xt = false;
- var open_cdm = false;
- var open_scrm = false;
- var open_mall = false;
- if ($("#open_3").attr("checked") == "checked") {
- open_xt = true
- }
- if ($("#open_4").attr("checked") == "checked") {
- open_cdm = true
- }
- if ($("#open_1").attr("checked") == "checked") {
- open_scrm = true
- }
- if ($("#open_5").attr("checked") == "checked") {
- open_mall = true
- }
- if (!open_xt && !open_cdm && !open_scrm && !open_mall) {
- layer.msg("请选择要启用的应用");
- return;
- }
-
- var postData = {
- name: $("#org_name").val(),
- // short_name: $("#org_short_name").val(),
- contact_name: $("#contact_name").val(),
- province: $("#province_select option:selected").val(),
- city: $("#city_select option:selected").val(),
- district: $("#district_select option:selected").val(),
- address: $("#address").val(),
- category: $("#org_category").val(),
- org_phone: $("#org_phone").val(),
- open_xt: open_xt,
- open_cdm: open_cdm,
- open_scrm: open_scrm,
- open_mall: open_mall,
- }
- postRequest("/org/create/submit", postData, doSuccess, doFail);
-
- function doSuccess(res) {
- if (res.state == 0) {
- serverErrorMsg(res);
- return;
- }
- layer.msg("创建成功");
- window.location.href = res.data.url; //跳转网址
- }
- });
- });
-
- function checkInfoFull() {
- if ($("#org_name").val().length == 0) {
- return "请填写机构名称";
- }
- // if ($("#org_short_name").val().length == 0) {
- // return "请填写机构简称";
- // }
- if ($("#contact_name").val().length == 0) {
- return "请填写联系人姓名";
- }
- if ($("#province_select option:selected").val() == "0") {
- return "请选择省份";
- }
- if ($("#city_select option:selected").val() == "0") {
- return "请选择城市";
- }
- if ($("#district_select option:selected").val() == "0") {
- return "请选择区县";
- }
- if ($("#address").val().length == 0) {
- return "请填写地址";
- }
- if ($("#org_category").val().length == 0 || $("#org_category").val() == "0") {
- return "请选择机构类型";
- }
- if ($("#org_phone").val().length > 0) {
- if (/^(\d{3,4}-?\d{7,8}$)|(1\d{10}$)/.test($("#org_phone").val()) == false) {
- return "请填写正确的机构电话";
- }
- }
- return "";
- }
-
- function doFail(res) {
- serverErrorMsg(res);
- }
|