sso

create_org_old.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. }
  256. postRequest("/org/create/submit", postData, doSuccess, doFail);
  257. function doSuccess(res) {
  258. if (res.state == 0) {
  259. serverErrorMsg(res);
  260. return;
  261. }
  262. layer.msg("创建成功");
  263. window.location.href = "/org/app/create"; //跳转网址
  264. }
  265. });
  266. $("input[name='week_checkbox']").change(function () {
  267. var business_week = [];
  268. $("input[name='week_checkbox']:checked").each(function () {
  269. var wid = $(this).attr('data-id');
  270. var wname = $(this).attr('data-name');
  271. business_week.push({ "id": wid, "name": wname });
  272. });
  273. if (business_week.length == 0) {
  274. $("#org_business_week").val('');
  275. } else if (business_week.length == 1) {
  276. $("#org_business_week").val(business_week[0]["name"]);
  277. } else {
  278. var blen = business_week.length;
  279. var lastindex = blen - 1;
  280. var btrue = true;
  281. for (let index = 0; index < lastindex; index++) {
  282. var sitem = parseInt(business_week[index]['id']);
  283. var eitem = parseInt(business_week[index + 1]['id']);
  284. sitem = sitem + 1;
  285. if (sitem != eitem) {
  286. btrue = false;
  287. break;
  288. }
  289. }
  290. if (btrue) {
  291. var week_show = business_week[0]["name"] + ' — ' + business_week[lastindex]["name"];
  292. $("#org_business_week").val(week_show);
  293. } else {
  294. var week_show = '';
  295. $.each(business_week, function (i, item) {
  296. week_show += item["name"];
  297. if (i != lastindex) {
  298. week_show += '、';
  299. }
  300. });
  301. $("#org_business_week").val(week_show);
  302. }
  303. }
  304. });
  305. $('input[name=time_checkbox_s], input[name=time_checkbox_x]').change(function () {
  306. if ($("input[name='time_checkbox_s']:checked").length == 0 || $("input[name='time_checkbox_x']:checked").length == 0) {
  307. return;
  308. }
  309. var thetime = $("input[name='time_checkbox_s']:checked").val();
  310. var mdatetime = $("input[name='time_checkbox_x']:checked").val();
  311. var timeshow = '上午' + thetime + '—' + '下午' + mdatetime;
  312. $("#org_business_time").val(timeshow);
  313. });
  314. Qiniu.uploader({
  315. runtimes: "html5,flash,html4",
  316. browse_button: "org_pic_uploader",
  317. uptoken: uptoken,
  318. domain: "https://images.shengws.com/",
  319. max_file_size: "4mb",
  320. flash_swf_url: "/static/js/qiniu/Moxie.swf",
  321. dragdrop: false,
  322. auto_start: true,
  323. unique_names: false,
  324. save_key: false,
  325. max_retries: 3,
  326. multi_selection: false,
  327. filters: {
  328. mime_types: [{
  329. title: "Image files",
  330. extensions: "jpg,jpeg,png"
  331. }]
  332. },
  333. init: {
  334. "FileUploaded": function(up, file, info) {
  335. // info 为 json,格式是后台获取 token 时设置的 ReturnBody
  336. var domain = up.getOption("domain");
  337. var infoObj = JSON.parse(info);
  338. var url = domain + infoObj.url;
  339. $("#org_pics_preview").append("<div class='article-cover-add border-radius'><img style='width: auto; height: 100%;' src=" + url + " /></div>");
  340. $("#org_pics").val($("#org_pics").val() + "@@" + url);
  341. },
  342. "Error": function(up, err, errTip) {
  343. console.log("上传出错:", err)
  344. },
  345. "UploadComplete": function() {
  346. console.log("队列文件处理完毕后,处理相关的事情");
  347. },
  348. "Key": function(up, file) {
  349. console.log("自定义上传文件名");
  350. var rand = Math.floor(Math.random() * 1000000000)
  351. var date = new Date()
  352. var ext = Qiniu.getFileExtension(file.name);
  353. var key = date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate() + "/" + "org_pic_" + rand + "." + ext;
  354. console.log(key);
  355. return key;
  356. }
  357. }
  358. });
  359. });
  360. function checkInfoFull(ue) {
  361. if ($("#org_name").val().length == 0) {
  362. return "请填写机构名称";
  363. }
  364. if ($("#org_short_name").val().length == 0) {
  365. return "请填写机构简称";
  366. }
  367. var intro = ue.getContent();
  368. console.log(intro);
  369. if (intro.length == 0) {
  370. return "请填写机构介绍";
  371. }
  372. if ($("#avatar_preview_img")[0].src.length == 0) {
  373. return "请上传机构头像";
  374. }
  375. if ($("#province_select option:selected").val() == "0") {
  376. return "请选择省份";
  377. }
  378. if ($("#city_select option:selected").val() == "0") {
  379. return "请选择城市";
  380. }
  381. if ($("#district_select option:selected").val() == "0") {
  382. return "请选择区县";
  383. }
  384. if ($("#address").val().length == 0) {
  385. return "请填写地址";
  386. }
  387. var selectIll = false;
  388. $("input[name='ill_checkbox']:checkbox:checked").each(function(){
  389. selectIll = true;
  390. return false;
  391. });
  392. if (selectIll == false) {
  393. return "请选择服务病种";
  394. }
  395. if ($("#org_category").val().length == 0 || $("#org_category").val() == "0") {
  396. return "请选择机构类型";
  397. }
  398. if ($("#org_phone").val().length > 0) {
  399. if (/^(\d{3,4}-?\d{7,8}$)|(1\d{10}$)/.test($("#org_phone").val()) == false) {
  400. return "请填写正确的机构电话";
  401. }
  402. }
  403. return "";
  404. }
  405. function doFail(res) {
  406. serverErrorMsg(res);
  407. }