sso

create_org_old.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. // 19.06.03 之前的版本,注册机构时需要填写很多信息
  2. $(function() {
  3. $("#avatar_preview_panel").hide();
  4. var ue = UE.getEditor('editor');
  5. // 编辑器加载完成后清除其中内容,因为像迅雷插件可能会在编辑器加载的时候插入一段文本,导致用户未输入内容却检测内容不为空
  6. ue.addListener("ready", function() {
  7. ue.setContent("");
  8. });
  9. uptoken = getQNToken();
  10. newUploader("avatar_file", uptoken, function(file) {
  11. console.log(file.name);
  12. $("#avatar_preview_panel").show();
  13. $("#avatar_upload").hide();
  14. }, function(progress) {
  15. }, function(err) {
  16. alert("头像上传失败: ", err);
  17. console.log("上传失败", err);
  18. }, function(url) {
  19. $("#avatar_preview_img").attr("src", url);
  20. });
  21. $("#avatar_upload").click(function() {
  22. $("#avatar_file").click();
  23. });
  24. $("#avatar_preview_panel").click(function() {
  25. $("#avatar_file").click();
  26. });
  27. function getQNToken() {
  28. var token = ""
  29. $.ajax({
  30. url: "/application/qntoken",
  31. type: "GET",
  32. async: false,
  33. dataType: "json",
  34. success: function(json) {
  35. if (json.state == 1) {
  36. token = json.data.token;
  37. } else {
  38. console.log("获取token失败", json.msg);
  39. }
  40. },
  41. error: function() {
  42. console.log("连接失败,请检查网络");
  43. }
  44. });
  45. console.log("token:", token);
  46. return token;
  47. }
  48. function newUploader(bindID, token, addImageHandler, progressHandler, errorHandler, finishUploadHandler) {
  49. return Qiniu.uploader({
  50. runtimes: "html5,flash,html4",
  51. browse_button: bindID,
  52. uptoken: token,
  53. domain: "https://images.shengws.com/",
  54. max_file_size: "300kb",
  55. flash_swf_url: "/static/js/qiniu/Moxie.swf",
  56. dragdrop: false,
  57. auto_start: true,
  58. unique_names: false,
  59. save_key: false,
  60. max_retries: 3,
  61. multi_selection: false,
  62. filters: {
  63. mime_types: [{
  64. title: "Image files",
  65. extensions: "jpg,jpeg,png"
  66. }]
  67. },
  68. init: {
  69. "FilesAdded": function(up, files) {
  70. console.log("文件添加进队列后,处理相关的事情");
  71. plupload.each(files, function(file) {
  72. // var nativeFile = file.getNative();
  73. // var img = new Image();
  74. // img.src = URL.createObjectURL(nativeFile)
  75. // img.onload = function() {
  76. // var w = img.naturalWidth;
  77. // var h = img.naturalHeight;
  78. // if (w > 108 || h > 108) {
  79. // alert("机构头像尺寸太大,请选择108*108以内的图片");
  80. // up.removeFile(file);
  81. // } else {
  82. addImageHandler(file);
  83. // }
  84. // }
  85. });
  86. },
  87. "BeforeUpload": function(up, file) {
  88. console.log("上传之前");
  89. },
  90. "UploadProgress": function(up, file) {
  91. console.log("上传进度:", file.percent + "%")
  92. progressHandler(file.percent);
  93. },
  94. "FileUploaded": function(up, file, info) {
  95. // info 为 json,格式是后台获取 token 时设置的 ReturnBody
  96. var domain = up.getOption("domain");
  97. var infoObj = JSON.parse(info);
  98. var url = domain + infoObj.url;
  99. // console.log("图片路径:", url);
  100. finishUploadHandler(url);
  101. },
  102. "Error": function(up, err, errTip) {
  103. console.log("上传出错:", err)
  104. errorHandler(err);
  105. },
  106. "UploadComplete": function() {
  107. console.log("队列文件处理完毕后,处理相关的事情");
  108. },
  109. "Key": function(up, file) {
  110. console.log("自定义上传文件名");
  111. var rand = Math.floor(Math.random() * 1000000000)
  112. var date = new Date()
  113. var ext = Qiniu.getFileExtension(file.name);
  114. var key = date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate() + "/" + "org_" + rand + "." + ext;
  115. console.log(key);
  116. return key;
  117. }
  118. }
  119. });
  120. }
  121. $("#province_select").change(function() {
  122. $("#city_select option").remove();
  123. $("#district_select option").remove();
  124. $("#city_select").append("<option value='0'>市</option>");
  125. $("#district_select").append("<option value='0'>区/县</option>");
  126. var province = $("#province_select option:selected").val();
  127. $.ajax({
  128. url: "/city",
  129. type: "GET",
  130. data: {
  131. province_id: province,
  132. },
  133. async: false,
  134. dataType: "json",
  135. success: function(json) {
  136. if (json.state == 1) {
  137. var cities = json.data.list
  138. var optionStr = ""
  139. for (let index = 0; index < cities.length; index++) {
  140. const city = cities[index];
  141. optionStr = optionStr + "<option value = " + city.id + ">" + city.name + "</option>"
  142. }
  143. $("#city_select").append(optionStr);
  144. } else {
  145. console.log("获取城市失败", json.msg);
  146. }
  147. },
  148. error: function() {
  149. console.log("连接失败,请检查网络");
  150. }
  151. });
  152. });
  153. $("#city_select").change(function() {
  154. $("#district_select option").remove();
  155. $("#district_select").append("<option value='0'>区/县</option>");
  156. var city = $("#city_select option:selected").val();
  157. $.ajax({
  158. url: "/district",
  159. type: "GET",
  160. data: {
  161. city_id: city,
  162. },
  163. async: false,
  164. dataType: "json",
  165. success: function(json) {
  166. if (json.state == 1) {
  167. var districts = json.data.list
  168. var optionStr = ""
  169. for (let index = 0; index < districts.length; index++) {
  170. const district = districts[index];
  171. optionStr = optionStr + "<option value = " + district.id + ">" + district.name + "</option>"
  172. }
  173. $("#district_select").append(optionStr);
  174. } else {
  175. console.log("获取区县失败", json.msg);
  176. }
  177. },
  178. error: function() {
  179. console.log("连接失败,请检查网络");
  180. }
  181. });
  182. });
  183. $("#cat_p_select").change(function() {
  184. $("#cat_c_select option").remove();
  185. $("#cat_c_select").append("<option value='0'>详细类型</option>");
  186. $("#cat_c_select").parent().hide();
  187. $("#org_category").val("0");
  188. var p_cat = $("#cat_p_select option:selected").val();
  189. $.ajax({
  190. url: "/get_org_cat",
  191. type: "GET",
  192. data: {
  193. pid: p_cat,
  194. },
  195. async: false,
  196. dataType: "json",
  197. success: function(json) {
  198. if (json.state == 1) {
  199. var cats = json.data.list
  200. if (cats.length == 0) {
  201. $("#cat_c_select").parent().hide();
  202. $("#org_category").val(p_cat);
  203. } else {
  204. var optionStr = ""
  205. for (let index = 0; index < cats.length; index++) {
  206. const cat = cats[index];
  207. optionStr = optionStr + "<option value = " + cat.id + ">" + cat.short_name + "</option>"
  208. }
  209. $("#cat_c_select").append(optionStr);
  210. $("#cat_c_select").parent().show();
  211. }
  212. } else {
  213. layer.msg("获取详细类型失败: " + json.msg);
  214. }
  215. },
  216. error: function() {
  217. layer.msg("连接失败,请检查网络");
  218. }
  219. });
  220. });
  221. $("#cat_c_select").change(function() {
  222. $("#org_category").val($("#cat_c_select option:selected").val());
  223. });
  224. $("#submit").on("click", function() {
  225. var checkErr = checkInfoFull(ue);
  226. if (checkErr.length > 0) {
  227. layer.msg(checkErr);
  228. return;
  229. }
  230. var ills = new Array();
  231. $("input[name='ill_checkbox']:checkbox:checked").each(function(){
  232. ills.push($(this).val());
  233. });
  234. var illstr = ills.join(",");
  235. var picsStr = $("#org_pics").val();
  236. if (picsStr.length > 2) {
  237. picsStr = picsStr.substr(2, picsStr.length - 2);
  238. }
  239. var postData = {
  240. name: $("#org_name").val(),
  241. short_name: $("#org_short_name").val(),
  242. intro: ue.getContent(),
  243. logo: $("#avatar_preview_img")[0].src,
  244. province: $("#province_select option:selected").val(),
  245. city: $("#city_select option:selected").val(),
  246. district: $("#district_select option:selected").val(),
  247. address: $("#address").val(),
  248. ill: illstr,
  249. category: $("#org_category").val(),
  250. org_phone: $("#org_phone").val(),
  251. business_week: $("#org_business_week").val(),
  252. business_time: $("#org_business_time").val(),
  253. business_state: $("input[name='org_business_state']:checked").val(),
  254. org_pics: picsStr,
  255. user_name:$("#user_name").val()
  256. }
  257. postRequest("/org/create/submit", postData, doSuccess, doFail);
  258. function doSuccess(res) {
  259. if (res.state == 0) {
  260. serverErrorMsg(res);
  261. return;
  262. }
  263. layer.msg("创建成功");
  264. window.location.href = "/org/app/create"; //跳转网址
  265. }
  266. });
  267. $("input[name='week_checkbox']").change(function () {
  268. var business_week = [];
  269. $("input[name='week_checkbox']:checked").each(function () {
  270. var wid = $(this).attr('data-id');
  271. var wname = $(this).attr('data-name');
  272. business_week.push({ "id": wid, "name": wname });
  273. });
  274. if (business_week.length == 0) {
  275. $("#org_business_week").val('');
  276. } else if (business_week.length == 1) {
  277. $("#org_business_week").val(business_week[0]["name"]);
  278. } else {
  279. var blen = business_week.length;
  280. var lastindex = blen - 1;
  281. var btrue = true;
  282. for (let index = 0; index < lastindex; index++) {
  283. var sitem = parseInt(business_week[index]['id']);
  284. var eitem = parseInt(business_week[index + 1]['id']);
  285. sitem = sitem + 1;
  286. if (sitem != eitem) {
  287. btrue = false;
  288. break;
  289. }
  290. }
  291. if (btrue) {
  292. var week_show = business_week[0]["name"] + ' — ' + business_week[lastindex]["name"];
  293. $("#org_business_week").val(week_show);
  294. } else {
  295. var week_show = '';
  296. $.each(business_week, function (i, item) {
  297. week_show += item["name"];
  298. if (i != lastindex) {
  299. week_show += '、';
  300. }
  301. });
  302. $("#org_business_week").val(week_show);
  303. }
  304. }
  305. });
  306. $('input[name=time_checkbox_s], input[name=time_checkbox_x]').change(function () {
  307. if ($("input[name='time_checkbox_s']:checked").length == 0 || $("input[name='time_checkbox_x']:checked").length == 0) {
  308. return;
  309. }
  310. var thetime = $("input[name='time_checkbox_s']:checked").val();
  311. var mdatetime = $("input[name='time_checkbox_x']:checked").val();
  312. var timeshow = '上午' + thetime + '—' + '下午' + mdatetime;
  313. $("#org_business_time").val(timeshow);
  314. });
  315. Qiniu.uploader({
  316. runtimes: "html5,flash,html4",
  317. browse_button: "org_pic_uploader",
  318. uptoken: uptoken,
  319. domain: "https://images.shengws.com/",
  320. max_file_size: "4mb",
  321. flash_swf_url: "/static/js/qiniu/Moxie.swf",
  322. dragdrop: false,
  323. auto_start: true,
  324. unique_names: false,
  325. save_key: false,
  326. max_retries: 3,
  327. multi_selection: false,
  328. filters: {
  329. mime_types: [{
  330. title: "Image files",
  331. extensions: "jpg,jpeg,png"
  332. }]
  333. },
  334. init: {
  335. "FileUploaded": function(up, file, info) {
  336. // info 为 json,格式是后台获取 token 时设置的 ReturnBody
  337. var domain = up.getOption("domain");
  338. var infoObj = JSON.parse(info);
  339. var url = domain + infoObj.url;
  340. $("#org_pics_preview").append("<div class='article-cover-add border-radius'><img style='width: auto; height: 100%;' src=" + url + " /></div>");
  341. $("#org_pics").val($("#org_pics").val() + "@@" + url);
  342. },
  343. "Error": function(up, err, errTip) {
  344. console.log("上传出错:", err)
  345. },
  346. "UploadComplete": function() {
  347. console.log("队列文件处理完毕后,处理相关的事情");
  348. },
  349. "Key": function(up, file) {
  350. console.log("自定义上传文件名");
  351. var rand = Math.floor(Math.random() * 1000000000)
  352. var date = new Date()
  353. var ext = Qiniu.getFileExtension(file.name);
  354. var key = date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate() + "/" + "org_pic_" + rand + "." + ext;
  355. console.log(key);
  356. return key;
  357. }
  358. }
  359. });
  360. });
  361. function checkInfoFull(ue) {
  362. if ($("#org_name").val().length == 0) {
  363. return "请填写机构名称";
  364. }
  365. if ($("#org_short_name").val().length == 0) {
  366. return "请填写机构简称";
  367. }
  368. var intro = ue.getContent();
  369. console.log(intro);
  370. if (intro.length == 0) {
  371. return "请填写机构介绍";
  372. }
  373. if ($("#avatar_preview_img")[0].src.length == 0) {
  374. return "请上传机构头像";
  375. }
  376. if ($("#province_select option:selected").val() == "0") {
  377. return "请选择省份";
  378. }
  379. if ($("#city_select option:selected").val() == "0") {
  380. return "请选择城市";
  381. }
  382. if ($("#district_select option:selected").val() == "0") {
  383. return "请选择区县";
  384. }
  385. if ($("#address").val().length == 0) {
  386. return "请填写地址";
  387. }
  388. var selectIll = false;
  389. $("input[name='ill_checkbox']:checkbox:checked").each(function(){
  390. selectIll = true;
  391. return false;
  392. });
  393. if (selectIll == false) {
  394. return "请选择服务病种";
  395. }
  396. if ($("#org_category").val().length == 0 || $("#org_category").val() == "0") {
  397. return "请选择机构类型";
  398. }
  399. if ($("#org_phone").val().length > 0) {
  400. if (/^(\d{3,4}-?\d{7,8}$)|(1\d{10}$)/.test($("#org_phone").val()) == false) {
  401. return "请填写正确的机构电话";
  402. }
  403. }
  404. return "";
  405. }
  406. function doFail(res) {
  407. serverErrorMsg(res);
  408. }